Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Mention the Principle of Least Astonishment #90

wants to merge 2 commits into from

Conversation

katrinleinweber
Copy link
Contributor

@katrinleinweber katrinleinweber commented Jun 26, 2019

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.

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]).
Copy link
Contributor Author

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.

Copy link
Member

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
Copy link
Contributor Author

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.

@jennybc jennybc deleted the branch tidyverse:master October 27, 2021 22:57
@jennybc jennybc closed this Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants