This is an excerpt from my article "Cleaning Up Your Code" on Medium. I'll be publishing each section daily, read ahead on Medium!
Programming is not a math equation. The vast majority of the programs you write will not be simple. They will have to interact with the rest of the program, forming complex relationships along the way, and therefore have to be read by other programmers. Someone with no idea of your contribution should be able to quickly understand what your code does.
Let’s look at an example, which code snippet is easier to grasp?
If you’d like to start using good names throughout your codebase, here are some general rules to follow:
- Expose meaning through names: Similar to the above example, the name of a variable should provide some meaning towards code functionality.
- Use pronounceable names: Software Development involves talking through your code with other developers. It will help a lot if you can actually talk through your code.
- Use searchable names: There will be many times you want to track a variable or function through your codebase. In this case, the variable should be unique enough that it can be searched for with few duplicates.
Thanks for reading! How do you make sure your code is understandable to yourself and colleagues?
Need to keep up with a fast-moving software industry?