What is Clean Code Development? There is no other better way than telling a story about three little piggies. What do you think?
Once upon a time there were three little piggies extremely skilled as architects. Each of them could transform a mere idea into reality.
The first little piggy was an incredible sculptor as well. For building his home, he went out in the world to find the perfect boulder. The hardest part was to bring to his land such a heavy object. He worked on it night and day to shape it in a house. It wasn’t exactly welcoming but you could still call it a home. It was sturdy, reliable and robust. Nothing could ever move it from its place.
The second little piggy had as well a hidden talent. He was an architect, an artist. So he started playing with clay, making strange shapes and curves. The end result was more than a house; it was a masterpiece. One could guess only by looking at it that it belonged to Second Piggy.
The third little piggy had no special skill. He did what he knew best. He built a house from bricks using a house plan. The plan he drafted long ago was used already by other piggies to build houses. He made some adjustments, freshened up the details, added a few elements and then started the work. The end-result was a good house, well done, but nothing out of the ordinary.
The other piggies laughed about it: "it's too simple", "I could have done it in half of the time", "do you really think it will hold the test of time?". They were teasing their brother. The other piggies knew he was capable of something more interesting.
As in all stories, time passes quickly. Our heroes didn’t talk about this anymore and went on with their lives. Each piggy got married and after a while, each family had piglets. So the three little piggies had to bring out their tools again and make more space for their growing family.
The first piggy had some problems from the start. A rock is just a rock. You can't extend it. So he needed to find a new one. It had to respect clear criteria. He went again into the world to find a new rock. The whole process was more tedious than he expected and a lot of logistics was involved. After he found it, he shaped a new room from it. To connect and seal both parts, he used some special glue material. The biggest issue was that he needed to use this glue every once in a while. Otherwise, there would be leakage and water dripping when raining.
Building a new room was less of a headache for second piggy. With his artistic genius he built a new one as glamorous as the whole house. It fitted perfectly and nobody could even tell that there wasn't one before there.
The third little piggy had no problem annexing a new room too. He used the draft, enhanced it and then added a new room to his existing construction.
Fast-forward some more pig years and the three little piggies eventually died of piggletoporosis. Trust me, it's something very common for architect piggies.
Their piglets, now fully grown up, took over the job of their dadds. However, maintaining the houses was a real burden: none of them were as talented as their parents. Cracks started to appear in the rock-house. The son of the sculptor used more and more of that special glue material with each passing year. It was still a very strong home but the time needed to maintain it grew continuously. For the second piglet, the job was even worse. He had nothing from the genius of his father. He did not take any of the artistic vision of his. When renovations were needed, he ended up relying on plain old bricks. After a few years you could not recognize anything from the former masterpiece. One could still call that a work of art, but in the grotesque way. With the third house, things were much better. When it started getting in a bad shape, the piglet used the house plans his father drew many years ago. He easily learned how to work with them. In only a year he knew everything about his house, all the ins and outs. Every problem now had a solution.
In the end, all piglets lived happily ever after, even though some had more headaches than others.
I hope this story gives you an image of how we construct our projects and how some of us work on them. We all have different ways of writing code. Most of the time, we think that the way we do it it's the best way.
As a programmer I’ve found myself many times dusting and scavenging through other people’s piles of c***. Pardon my French, I meant "lines of code" ... trying to make sense out of them. As a SAP developer, you can still find code that is decades old, written with no consistent guidelines. I cringe when I have to debug old SAP modules and check old functions that hold thousands of lines of code. Most of the time, they offer close to nothing in terms of code readability.
I can understand that rewriting a whole module is not possible anymore, but adding a comment now and then would mean a lot for us, mere mortals, and would make our life easier. Yeah, sure. Dream on! I think SAP works on the principle “if it works, don’t ever touch it”.
When I started my programming career I couldn’t care less about the quality of my code. If it worked I was thrilled. That was all that mattered to me. Then came the code review sessions ... true horror. It usually happened that I had to rewrite the code from scratch. At first, I despised it. I found it pointless and time-consuming. Guidelines, technical documents, code comments? They were sooooo boring! Don’t get me wrong, I am grateful now that I had to go through that process and understand its importance.
If I managed to catch your attention until now, I am more than happy! This means I am not alone in my fight against spaghetti code. I can assume you are here because (1) obviously, you are a programmer and (2) you want to improve the quality of your code.
So let's see what CCD is and why we should implement it in our day-to-day lives. Clean Code is more like a philosophy. Others call it even a religion. For me it is more like a way of life. It sounds extreme, I know. Everyone out there that wants to be praised by his fellow programmers and not damned or cursed. CCD addresses issues like code readability, code repeatability, code maintenance and performance. In a word (or two): code quality.
Think about Clean Code Development like writing a book. You are the author and you want your readers to be thrilled by your story. You want them to understand every page you wrote. The story you wrote should be “the perfect story”. And you won’t put lousy paragraphs just to fill up the book and finish it quicker. And, to follow the same path, as writing a book, you start off with an outline, then you go with a draft and then you start to improve it until it gets to the point you can shout “Eureka!”.
In the next chapters I will talk about the technicalities of clean code development and come up with some ABAP examples. Stay tuned!
Comments