How to write bad code

What most scientists get wrong when programming

In my previous post I wrote why it’s hard for programmers to program your models, and, while at it, I hinted that scientists typically write bad code.

What are the mistakes most scientists and engineers make when programming? Here’s a list:

  • No or insufficient version control

  • No automated testing

  • Huge functions with many nested control structures and large complexity

  • Uncareful memory management resulting in leaks and segfaults

  • Hacky patches upon hacky patches

  • Insufficient error handling

  • UI code inside functions that make calculations

In the next few posts I’ll go through these one by one. Many are really large subjects for which entire books have been written, so I may write more than one post for them.

Unfortunately, many professional programmers make the same mistakes. In fact, I have the sad feeling that most code written by professional programmers is worse than the code written by the scientists I’ve worked with. But this is a discussion for another publication.