-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mention the Principle of Least Astonishment #90
Conversation
script can run cleanly. But if someone else `source()`s your script, it will | ||
delete objects that might be important to them. (Of course, you'd hope that | ||
all of those objects could easily be recreated from another script, but that | ||
is not always the case). | ||
|
||
Because R doesn't constrain the potential scope of functions and scripts, *you* have to. By avoiding these actions, you will create code that is less suprising to other R users. At first, this might seem like tedious busywork. You might find that spooky action is convenient in the moment, and you might convince yourself that it’s necessary or a good idea. But as you share your code with more people and run more code that has been shared with you[^teachers], you'll find spooky action to get more and more surprising and frustrating. | ||
Because R doesn't constrain the potential scope of functions and scripts, *you* have to. By avoiding these actions, you will create code that is less surprising to other R users. Moreover, you'll benefit from the experience of other programming pioneers, summarised in the "Principle of Least Astonishment/Surprise" (POLA[^pola]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this doesn't sound too cheesy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I'd like to touch on (but I don't yet know how), is that this is also establishing what you should be surprised be. IOTW, you can only be surprised by something if you have a strong prior expectation, and part of this principle is establishing that your expectation should be that functions act locally.
Because R doesn't constrain the potential scope of functions and scripts, *you* have to. By avoiding these actions, you will create code that is less suprising to other R users. At first, this might seem like tedious busywork. You might find that spooky action is convenient in the moment, and you might convince yourself that it’s necessary or a good idea. But as you share your code with more people and run more code that has been shared with you[^teachers], you'll find spooky action to get more and more surprising and frustrating. | ||
Because R doesn't constrain the potential scope of functions and scripts, *you* have to. By avoiding these actions, you will create code that is less surprising to other R users. Moreover, you'll benefit from the experience of other programming pioneers, summarised in the "Principle of Least Astonishment/Surprise" (POLA[^pola]). | ||
|
||
[^pola]: https://web.archive.org/web/20181216083109/http://wiki.c2.com/?PrincipleOfLeastAstonishment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reference could be updated to https://en.wikipedia.org/wiki/Principle_of_least_astonishment or a new version of the C2Wiki.
Includes #88, so please merge that one 1st or close it.
See https://github.com/tidyverse/principles/pull/90/files#diff-80b7d431843e2948b25a9583860511afL33 for diff & some comments.