Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
The âone simple wayâ is nothing but âovercomingâ the âdelusion of creating future-ready codeâ which inevitably kills every developer sooner or later. Overcoming this delusion not only makes your code clearer and simpler but also helps you to grow in stature as a great developer.
Let me explain.
Back in my programming heydays, one fact was dogmatically taught to me at every occasion.
âNever write the same code twiceâ.
âYou need to refactor your code and make it reusable for the âgreater goodâ. Make the code akin to a black box which can be used by every other developer under the sun. Great developers leave greater code as their ever-lasting legacy.
So far so good.
Except that my code creations gradually evolved into ugly lumps of monstrous nothingness that became almost impossible to understand and interpret. My code hygiene went for a toss and I began to waste days and months âcorrectingâ and âresurrectingâ the demons which I had created.
Programming is hard. When you write a program, there can be anywhere from one to a gazillion lines of code, and you are going to make mistakes. Sometimes theyâre big, sometimes theyâre small, but no matter the size, they all take time to find and troubleshoot. Sometimes, you need help to come out of the âdangerousâ vortex of âhelplessnessâ that sucks you in rapidly.
And Sometimes, you just needâŠa rubber duck.
The concept of the rubber duck was first mentioned by Deane Parker in his excellent post âHow to Give a Good Conference Talkâ, where he described practicing a presentation out loud, in order to make it better. The idea of using a duck as a sounding board is not new but where it scores points is in its simplicity of use and the effectiveness.
The greatest advantage of using a rubber duck as a sounding board is that it is patient, it does not judge you and above all, it does not take somebody elseâs time. There is something magical about explaining your problems out loud, even to something as inanimate as a rubber duck, that can help you see the solution to your issues.
As you go through your code, explaining it line by line to the rubber duck, you stop yourself and begin to think of the situation from the outside. You force yourself to assess yourself and gain an objective understanding of all that you had written in the âheatâ of the moment.
And then sooner or later you get your âAH-HAâ moment. The answer just comes to you.
And thatâs how it feels almost every time: âDuh! I knew that!â
Here are some of the things the rubber duck sessions taught me about writing better code.
Writing a Reusable component is not required EVERYÂ TIME.
Some will argue that you should always try to make your components as reusable as possible, because it requires you to work through all of those quality issues no matter what, and will produce better software. This would be great if your sole goal was to create the best software in the world, but nobody is paying you to do that.
No, you are being paid to write software of sufficient quality within the time and budget allotted. If you spend unnecessary time gold-plating your code, it may make you feel cool, but it is outright wasteful. You need to draw a line in the sand of exactly how good this product really needs to be and stick to that, otherwise, youâll never finish.
You Arenât Gonna Need It
YouArentGonnaNeedIt (often abbreviated YAGNI) is an Extreme Programming practice which states:
âAlways implement things when you actually need them, never when you just foresee that you need them.â
Even if youâre totally, totally, totally sure that youâll need a feature later on, donât implement it now.
There are two main reasons to practice YagNi:
- You save time because you avoid writing code that is not required
- Your code is better because you avoid polluting it with âguessesâ that turn out to be more or less wrong but stick around anyway.
Make the Simplest Thing that could possibly work.
Extreme programming mentions two golden rules to write simple code.
· First, implement a new capability in the simplest way you can think of that âcould possibly workâ. Donât build a lot of amazing superstructures, donât do anything fancy, just put it in to make it work. Make the code pass the Unit Tests for the new feature (and all features, as always).
· Second, and this is critical to the rule, refactor the system to be the simplest possible code including all the features it now has. Follow the rule of OnceAndOnlyOnce and the other code quality rules to make the system as clean as it can possibly be.
Always remember, Weâre not looking for the quickest way; weâre looking for the simplest result. So, we first break the existing method into pieces. That leaves the existing test cases running. Then we modify (simply, now) one of the little methods to handle the next test case and so on.
Next time youâre stuck, try the duck
Sorting through bugs, problems, and general conundrums is a fundamental part of programming. So developing techniques to swat your way through the bugs and find your way out of the binds is as crucial as learning all of the syntaxes.
And when you are stuck and nothing seems to be working, try the rubber duck.
So go out and find your own rubber duck, be it the classic yellow bath toy, or one dressed up like a pirateâââpick one that youâre comfortable with and fits your personality.
Go ahead; Talk to him, ask questions, explain your problems aloud, clear your cobwebs and deliver great value in your code.
As Chris Pine has rightly said.
âProgramming isnât about what you know; itâs about what you can figure out.â
About the author-:
Ravi Rajan is a global IT program manager based out of Mumbai, India. He is also an avid blogger, Haiku poetry writer, archaeology enthusiast and history maniac. Connect with Ravi on LinkedIn, Medium and Twitter.
One SIMPLE Way To Be A BETTER Programmer was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.