Wednesday, October 25, 2023

Five Developer Anti-Patterns

on my mind today, after 20+ years of writing code

1. Premature Optimization. Well known. You made the code more complex and less clear to make something faster, but it didn't need to be faster, and you wasted your own work making something faster that didn't need to be faster. (faster/smaller/other optimization goal)

2. Premature Generalization. Only slightly less well known. Making the system that could be anything, could grow in any direction, has hooks for every eventuality, but those most of those things won't be used and were a waste of time to build and add complexity and may ultimately make it harder to develop in the direction the code actually needs to go.

3. Dependency Bloat. Everything you import is a possible bug and a possible supply chain attack. It slows down builds. When I code review a pull request that adds a library maybe I should code review the entire library added. (A few things get a pass for sufficient reputation and community usage.)

4. Excessive Cleverness. Yeah, you could do it in a perl one-liner, but maybe you should write it plainly, opened up into normal nested loops on several lines to show all the parts clearly.

5. Spooky Action/Magic. If I call thing.foo.bar() is that exactly what happens or does hidden code happen automatically? If thing.foo is type A but can be automatically converted to type B to run .bar() on, that might be bad magic. (Ruby on Rails is the worst at this, C++ does it a bunch, and Rust does it more than it should; Go pushes back hard to the point of being a little tedious about it)

No comments: