Communication Through Code
Programs are meant to be read by humans and only incidentally for computers to execute.
– Donald Knuth
We write code not just for the computer; also, for communicating with fellow programmers and ourselves in the future.
Programmers spend most of their time reading code than writing it. Simplicity and Implicity play a significant role in understanding code.
Simplicity = Conciseness of Code
Simplicity is all about keeping the code concise so that it is easy to manage. It is removing unnecessary clutters by leveraging the programming language features or abstracting code or anything that helps in reducing numbers of lines.
Both sides of codes are computationally equivalent, but the right-sided ones are perceived better.
Linting tools assist in maintaining the code style in check. It may enforce some useless rules which may disturb the beauty of code.
Remember, tools are not perfect; No doubt they assist in avoiding some problems, but enforcing robotic style-guide may not always be suitable. These should not enslave us!
Do not sacrifice simplicity for the sake of a tool!
- Python is the first choice for data scientists and physicists because it allows us to do more with less.
- Humans are bad at keeping short-term memory. It is effortful activity. It is helpful to keep the unit of code within view of the viewport.
When code cross boundaries of the viewport, then you have to scroll it up or down to have one view of the code in your mind.
Code to be understood = code in the view + code out of sight (cognitive load)
The key is to keep the unit of code short and manageable.
Implicity = Expressiveness of Code
Implicity is related to the expressiveness of code subjected to the problem for which code is being written. In other words, how easy it is to perceive the intent of the code. Implicity leverages programming skills of naming variables, comments, and maybe more.
Both the left and right sides are computationally equivalent. However, it is easy to perceive the right-sided code. Just doing the naming right has drastically improved the code understandability and reduce the guesswork. Isn’t it?
Implicity helps avoid problems like: it is possible that you come across your code after a long time and not understand it.
Code Obfuscators tools work by renaming, reformatting, optimizing the input code without affecting the functionality. These tools make resultant code looks ugly, making it hard and painful to be perceived by humans.
In other words, they make the code to lose Implicity.
- ProGuard for Java
- BitBoost for Python
Both Simplicity and Implicity help in reducing the efforts of maintaining code. There may be time; code conciseness (Simplicity) hinder the perception of code; it is always better to choose Implicity over Simplicity. One can be on the right track by developing the design thinking so-called Developer Empathy. It is walking in the shoes of your clients: future code readers.
- Empathy in Development
- Naming it right
- Clean Code by Robert C Martin