Software Engineering is a fascinating world, today millions of developers spend their time crafting new pieces of miracle and reading code snippets from developers across the planet. Let's talk about your interesting relationship with naming a simple variable today.
The naming of variables has an emotional meaning attached to the developer who has coded that program. Some of the factors influencing the code author to name those variables are:
- Author's understanding of that engineering problem.
- How the code author solved a similar problem earlier i.e their past engineering experience.
Also, there are some hidden factors which influence their decisions:
- Their life journey so far.
- Their emotional state during which the author is coding that program.
Fun fact: So the author came up with that variable name. If you don't understand the author's thinking behind naming that variable, you may struggle to understand the whole program due to that single variable name.β¬
βͺPRO TIPS:
- Detach yourself from the name of the variables instead look at what does the program aims at doing and then you will understand the logic line by line.
- As you have a different perspective of the world around you, you may come up with the idea of renaming those variables which according to you represents the logic better which is also a bias created by your brain. So donβt start cursing the original author of the program.
Example: Reversing a singly linked list in-place
βͺSome people create temporary variables naming them as next and prev to accomplish swapping of nodes and pointers, logically and conceptually singly linked list have no previous pointer.
So now you are confused looking at the program what is the role of variable prev here. Instead of getting confused, you should think about what does this program aims to solve. You should go through the code and understood it based on the operations being performed. Suddenly you will have a Eureka moment, now you come up with the idea of renaming those temporary variables as nextNode and newNextPtr which makes a little bit more sense but maybe it's just for you.
That's why understanding the moral, events, decisions, actions of any story are much more important than the character names and their fashion sense in any movie or a book πβ¬
βͺThatβs one of the hidden reason it's important to get your pull request reviewed thoroughly so that the code could be understood and be relatable by most of the people removing all the emotional and hidden past experiential baggage from it.
TIPS for reviewing a pull request, please check that:
- PR is small enough (otherwise, break it up)
- Variable names signify what they are being used for.
- Code is readable and understandable.
- Code is unit tested
- The features are documented
- Files are located and named correctly.
- Files are following a decided naming convention like camelCase, PascalCase, snake_case, kebab-case.
- Error states are properly handled
- Bonus: Screenshots/screencast demo included
Keep creating and contributing to the world while exchanging your positive thoughts, ideas, actions to improve everything you come across in your life whether its a piece of code, place or a person. Happy Coding!