23.1 C
New York
Friday, June 6, 2025

Naming is simple! A information for builders



Sheer laziness

Whereas naming issues isn’t laborious, it does take a little bit of thought. I suppose some of us simply don’t need to take the time to consider naming issues. I’m not even going to speak about how foolish it’s to make use of a single letter for a variable title. The one exception I’ll quarter is utilizing i because the variable in a loop. (However I’ll argue vehemently that Index is healthier.)

In any other case, give a variable a extremely good, full title. Certain, it could take some effort, however should you cease and ask, “What, precisely, is that this factor?” after which title it primarily based on what your reply is, you’ll have an amazing title. For example, should you really feel the necessity to do that:


If (EmployeeNumber > 0) and (OrderNumber >  0) {
 // ...
}

Don’t be afraid to go the additional mile:


EmployeeIsValid = EmployeeUniqueIDInDatabase > 0;
ThereIsAnOrder = OrderNumber > 0;
ItIsOkayToProcessTheOrder := EmployeeIsValid and ThereIsAnOrder;
If ItIsOkayToProcessTheOrder {
  // ...
}

That’s massively extra readable, and the variable names clearly clarify what they symbolize. It might be very laborious to confuse what is occurring there, and it reduces the cognitive load of the following developer, who not has to parse advanced boolean statements. 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles