Conscientious Development – “Failing to Plan is Planning to Fail”

Something weighing on me lately has been the idea of planning and I’m not talking about planning in an Waterfall, Agile, or even story or task level. I’m talking planning on a class by class and function by function level.

Fighting our Urges

I feel like as developers we jump head first into code and take a swing at the code without first thinking over all that we’ve been taught. Creating a class and function is so second nature to us that I feel like we fail to plan it out.

“But who needs to plan out a function. It has an input, an output and does something”

Okay, this is true to create a working function, that is very accurate. If you are pushing yourself past “good enough” though, there are a couple things to take into account. Just because it works, doesn’t make it good code. There are many many many examples of this out there so I’m not going to beat a dead horse, but there are other things to consider other than “does it work”

“Fine I’ll bite, please enlighten me oh mighty one. What do I need to plan for???”

Have you ever seen a function just ramble on? How about functions that are so hard to test that people give up on trying to test them (this is usually a byproduct of poor class planning)?

When planning a class and/or function, you should stop and think:

  • How am I going to unit test this (e.g. just the logic without altering any other system)
  • Do I need to / How am I going to integration test this (e.g. test integration with other systems like database, other APIs, etc)
  • Is this class made to solve a single problem (See Single Responsibility Principle: https://en.wikipedia.org/wiki/Single_responsibility_principle)
  • Is this class’ name succinct enough to not be overbear the read of my code. No one wants to try and understand what the NamingControllerGeneratorProxy does.

I think if we stopped and asked ourselves this at the beginning of developing classes and functions we can write cleaner code that doesn’t make people who come after you want to rip their hair out.