Introduction – How to write clean code?

Anup MarwadiSoftwareLeave a Comment

One of the biggest challenges in Software development is the practice of writing clean code.

Writing clean code is like having great sex, you will not know anything about it until you’ve personally experienced it. There, we said it!

The sad state of the industry is that there’s no pragmatic guide to writing clean code. Clean Code mastery comes through tremendous discipline, practice and patience.

Yes, numerous books and articles have been published, but very few developers care to write clean code because modern programming practices and IDEs make it easier to debug through code, so naturally, developers take the easy way out.

The other problem in the industry is that people are so busy chasing shiny objects that they hardly take time to master one skill before jumping onto another.

The sorry state of affairs is quite evident in our Software industry today. The amount of Javascript frameworks that a developer now needs to be fully versed with to get anything done will blow your mind away.

If that wasn’t enough, Silicon Valley keeps on pushing new programming languages and frameworks out by the month and other startups follow the trend like lemmings thereby causing havoc in this already fragile and demanding industry.

We at HyperTrends have taken the opposite approach. We strongly believe that when everyone else zigs, we zag!

When Everyone Else Zigs, We Zag!

Instead of throwing our developers in hundred different directions, we have finalized our technology stack to a few core platforms. Doing a few things implies better focus. Better focus yields to better results. Better results lead to mastery in craft.

So, back to our original proposition. How do you write Clean code?

Here are fool proof steps that you can take:

  • Focus on one or two programming languages at the most. Pick something like .NET/C# or Java or Python and stick to it. Shut off everything else until you’ve mastered your language.
  • Master that one language inside out. It takes forever to master something. Immerse yourself in the language, learn the subtleties until you fully understand how to use the language to your advantage. Pure magic comes from effectively using the tools at hand instead of going on about searching for the right tools. Eddie Van Halen would probably make a $50 guitar sound better than an average Joe playing a $1500 guitar. Guaranteed!
  • Research or Contribute to open-source software/frameworks written using these languages. Learn how some great code is written using your favorite language. This is so important. You will probably take 4x as much to master something if you learn it by doing it yourself. Rather, focus on researching, or more importantly, contributing to open source software for the language you are trying to master. If will open up your world to an amazing realm of possibilities.
  • Learn ENGLISH! Yes, 99% of Software is written in English. You know what’s not good? Majority of the people writing this software don’t speak or write English as their primary language. The more you learn about the language, the better you will be able to represent/model software artifacts. After all, Software is a simulation of the real world in a computer program. If you cannot model relationships, or cannot identify objects aka nouns, you are already starting at a disadvantage. Here’s a great way to learn about Nouns. Learn Nouns, learn verbs, learn to identify relationships between things.
  • Spend time understanding and drawing up sub-components of a complex system. The more you practice understanding the relationships between sub-systems that make up a complex system, the better off you are. You hear a lot about Microservices today. Well, Microservices are nothing but subsystems that work together making a more complex system. Draw up pictures of complex systems like an Automobile Operating system, a Lead Distribution System, a Home Operating System. Don’t worry about the practicalities, your focus should be to write about the complexities and the relationships between various components that make that system up.
  • Write code that is easier to READ, not easier to WRITE. Have you ever run into a programmer that wrote 50 lines of code in 5, making it efficient, but nearly impossible to understand? Well, do the exact opposite. Write code that is easier to READ. Because no matter how good your code is, you are going to have to change it at some point of time. And when you change it, you will have to read it. And when you read it, you better be able to understand it in no time. Your code should be like poetry. It should be easy to read and truly communicate the intent in the shortest possible manner.
  • Don’t try to do everything at once in code. Have you ever seen a developer write a long, long, long, I mean a really long method that does everything under the sun? Yes, this developer has no clue what he is working with. He clearly doesn’t understand the symbiotic relationship between sub-components that make up a system or a module. Coach developers like these immediately. Or even better, run away from developers like these as quickly as you can. Find better developers who can write smaller modules that represent the code’s intent better. Great developers are extremely lazy (in a good way)!
  • TEACH CLEAN CODING SKILLS! Do yourself a favor and teach your fellow programmers the art of writing clean Software by practice. Put out as many examples as you can. Make as many peer-review sessions as you can. We have to collectively advance the agenda of the programmer community so that we all derive the benefits of writing and reading clean code. The business productivity losses in managing poorly written software add up to trillions of dollars, if they were ever measured. Let’s up the ante! Let’s make every line of code count.

These are just a few things that came to my mind today as I was going through some really old code written today. Nothing is perfect, but everything can be improved.

Nothing is perfect. But everything can be improvedAnup Marwadi

So start somewhere! Just start!

Leave a Reply

Your email address will not be published.