Code Smell - Badly Name Variables
It can be easy to overlook the importance of having a good variable or method name. After all, it doesn't affect performance as the compiler will convert it to machine code. And it can sometimes be challenging to think of a good name. But without a good naming convention, it can be even harder for another engineer (or yourself in a few months) to read and understand what the code is doing. Self-explanatory methods and variables make code more intuitive, as developers can generally understand the code without going through it in detail.
Here's an example of badly named methods and variables in C#:
In this example, the variables nm
, mfg
, and pID
are poorly named, and the methods gtnm()
, getmfg()
, getID()
, updtmfg()
, and updtID()
do not follow the convention of using PascalCase for method names.
A better approach would be to use descriptive names for variables and follow naming conventions for methods. For example:
In this revised example, variable names use descriptive names, and the method names follow the convention of using PascalCase for methods.