Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • 56
    Excellent advice. However I can't upvote for the "that is not so bad" comment. It is so bad. Low quality scientific scripts are a big issue for reproducibility in data analysis and a frequent source of error in analysis. Writing good code is valuable not just so that you can understand it later but also so that you can avoid errors in the first place. Commented Jul 6, 2018 at 13:24
  • 26
    If the code is an implementation of a well-known formula, then single-letter variable names and such might be the right thing to do. Depends on the audience...and more to the point, whether the reader is expected to already know what the names mean. Commented Jul 6, 2018 at 14:27
  • 13
    @cHao the problem is not when those variables are plugged in the formula (hence the "rename them inside the function" advice), but when they're read and manipulated outside of it, and when they start conflicting with other variables down the line (for example, I've seen people in need of three "x" variables name them x1, x2, x3) Commented Jul 6, 2018 at 14:37
  • 5
    "I'm gonna go against common sense..." No you're not. You're going against the prevailing dogma, which is itself against common sense. ;) This is all perfectly sound advice. Commented Jul 6, 2018 at 22:52
  • 3
    As a (former) scientific programmer, I generally adopt a rule of three. If I end up writing similar code three times, the functionality gets fleshed out and written up in a separate module with documentation (often just comments, but that's sufficient). This limits the chaos of ad-hoc programming, and allows me to build up a library that I can expand on in the future. Commented Jul 9, 2018 at 14:39