Make Understandable Code
Simple yet important — Conditional Statement
Code is simple, it only contains some essential fundamentals which are sequence and conditional statement. But, why many people said that code is hard, maybe because they see a lot of code are written badly? Or it’s truly hard?
“Indeed, the ratio of time spent reading versus writing is well over 10 to 1.”
- Robert C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship
He said that reading code is a lot harder than writing code. So, it’s maybe the code that is hard to read and understand. Even though the reader is the writer itself, it is still hard. I researched on Github and found that many coders make their code with high complexity and not understandable.
We can improve the learning curve from the smallest step, which is making a great if statement. Without further do, let’s get some examples:
- If your balance is more than 100 save 5%. If not, save 3%.
Humans are hard to remember numbers. It’s easier to remember github.com rather than 192.30.253.xxx
. From the example above, which one better? Hope you choose the second one. hasMinimumBalance has more understandable statement, instead of balance < 100. Always making it more readable, that’s why coders should have empathy.
Let’s go for the second example.
2. If you have your math score 0 < score< 60, you should learn it better.
From the example above, which one is better to read? Hope you answered the first option. Writing without the simplest math formula is not recommended, like in the third option. Even coders will have to put more effort to understand it.
The second option is better than the third option because without reading the numbers it is about the range of numbers. However, the first one is better for non coders, they don’t have to know about the math symbol. Also, it’s more readable right? When the non coders understand the code, the coder would be easier to coders to understand.
I challenge you to do it and challenge your mates to do it to! Good Luck! Let’s make this world move better and faster. 🔥.
Related Story: