|
|
|
|
|
by upwardbound
1399 days ago
|
|
Very impressive! I have a question and I was wondering if you have any thoughts. In Artemis as well as in Jupyter and in 3D-oriented tools like Unity, it's common to see this pattern for defining inputs: In the code:
x = 3
Elsewhere in the GUI:
(User sets x to 5) I understand that this pattern has become popular but to me it always struck me as dangerous. It's scary that in the code I can't trust that x = 3 really means x = 3. Especially if I'm skimming the code quickly and not paying attention to the surrounding comments, I might make incorrect assumptions about flow control (if the value is a bool), or other dangerous incorrect assumptions about what the code is doing. Do you have any ideas for a safer pattern that could be used instead? Maybe something like one of these? x = 3 # !INPUT
x = GUIINPUT() # !DEFAULT=3
x = GUIINPUT(3) or equivalently x = GUIINPUT(default=3)
If you use the third option, GUIINPUT could be defined at the top of the file as something like this: def GUIINPUT(default):
# pseudocode:
if interpreter == "artemis":
return artemis_magic(default)
else:
sys.stderr.write(f"Warning: Assumed input is {default}; this may not be correct, especially if you the user were not the author of the script!")
return default
|
|