8th Light: Day 96

16 May 2016 . 8thlight . Comments #apprenticeship #8thlight #software #code-smells

Code smells: Speculative generality

Sometimes code is created “just in case” to support anticipated future features that never get implemented. As a result, code becomes hard to understand and support. - sourcemaking.com

I used to have the habit of adding things to a project before I needed them.

For example: when creating a new Clojure application if I thought I needed a database eventually, I would add it to the project.clj right after lein newing and pull down the dependencies. Though I plan on using a database in the future, this is bloat and an extra dependency I don’t need now. Additionally, what if I change my mind in the future and decide not to use a database? I’ll have to go back into the code and remove that dependency – if I even remember I added it in the first place.

Why should we avoid adding things we don’t need?

  • Code is cleaner
  • Code is easier to maintain, change, and understand