HomeCloud ComputingNaming is straightforward! A information for builders

Naming is straightforward! A information for builders



Sheer laziness

Whereas naming issues isn’t exhausting, it does take a little bit of thought. I assume some of us simply don’t wish 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 identify. The one exception I’ll quarter is utilizing i because the variable in a loop. (However I’ll argue vehemently that Index is best.)

In any other case, give a variable a very good, full identify. Positive, it might take some effort, however when you cease and ask, “What, precisely, is that this factor?” after which identify it primarily based on what your reply is, you’ll have an ideal identify. As an illustration, when 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 signify. It could be very exhausting to confuse what is going on there, and it reduces the cognitive load of the subsequent developer, who not has to parse complicated boolean statements. 

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments