It is no secret that when tasked with solving problems in the real-world our solutions will always be just that, less than ideal. With that in mind, how can we make sure that we execute our solutions as cleanly as possible? How can we realistically ensure that any of our theoretical and idealistic approaches to problems can withstand the ever-growing demands of the workplace when applied?
The answer: clean code – applied realistically.
But what does it mean to realistically apply clean code? And what is clean code even really?
If you aren’t already googling away, I’ll make your life easy by summarizing both questions into one simple phrase, “code that humans can read, and understand.”
As they say winners know when to stop. If you often find yourself getting carried away with over-engineered, but admirably elegant architectures – then stop! There is beauty in simplicity; below we expand upon this simple phrase and what exactly it entails.
You Show Intent
The naming of things such as variables, methods and classes shows the intention of your logic.
You Are Consistent
There exists a clear naming convention – PSR-12 anyone?
You Reuse Code
Where applicable and where the effort required is low, you write generic and reusable code to simplify your solutions and reduce the ability to introduce new bugs.
You Don’t Comment Bad Code
Understanding what the code is doing is not equivalent to the code being good. If you have to write a comment, chances are, you are better off rewriting your solution in a format that doesn’t require comments.
You Don’t Pre-optimise
Yes, you read me right the first time. We often tend to pre-optimise code when the scale at which it would operate doesn’t even concern us yet, tone it down a bit. There is such a thing as coding too defensively, but that’s a topic for another discussion. Keep it current; keep it simple. We’ll cross that bridge when we get there.
I know it sounds easier said than done, but just focusing on these 5 points can save you a bunch of headaches down the line. That being said, enjoy the festivities and remember: keep it simple!