Why Write Good Code?

A common refrain that one hears in science is that “I don’t care how ugly my code is as long as it works.” This is an enticing sentiment, as it does three things simultaneously

  1. Show that this person is a “real scientist” who only cares about the science and, by extension, imply that people who do care about code quality aren’t “real scientists”.
  2. Provide a cover for their unwillingness to branch out and learn new things, since that would be a waste of their time.
  3. Make their results impenetrable and unreproducible, since one would need to be able to read their poorly-written code to parse out the logic of what they did.

We’re going to push back on that sentiment as much as we can. Obviously, we’re not saying that you should only care about having elegant code. Still, having code that someone else can read, make sense of, and reproduce in a different context is crucial, and you’ll also find that the thinking patterns you develop when making your code more logically structured are broadly applicable. Moreover, good code actually saves time in the long run as

  1. Well-structured code can be reused and remixed much more efficiently than a haphazardly-constructed hack-tower.
  2. Writing good code requires a firm understanding of the logic of the problem, which speeds up comprehension in the future.

We think this is important. Good code, not just working code, does matter. And happily, there are only two things we need to do to write good code: write for other people and write for the future.

Next: Writing for Someone Else

Got questions? Ask them on the McCoy Group Stack Overflow


Edit on GitHub