One more argument for using descriptive variable names

Not too long ago someone asked me if I thought that rejecting (or requesting changes to) a GitHub PR because a variable or property is not named correctly was “a valid thing to do.”
I said: yeah. I’ve had that happen to me before, and I don’t think that’s an unreasonable thing to do within a healthy team environment.
The argument that you read code an order of magnitude more times than you write it has been beaten to death before, so I present to you yet another reason why naming things correctly is more than a matter of just style or personal preference: it helps your tools help you.

A common thing to do within the Objective-C runtime is to copy objects, calling -[object copy]. There’s no - copy method to implement on objects, though. The actual copying happens within the class method - copyWithZone:.
At this point, trying to get a list of all the places in the code that copy an instance of an object is impossible, because - copyWithZone: is not called directly from anywhere. So what did I do? Search for correctlyNamedObject copy].

Within our team, one of our guidelines is that things have to be named correctly, and not doing so is grounds for someone requesting changes to a Pull Request. I didn’t write all the calls to - copy, someone else did, and because we have that rule in place, I can make an educated guess of how an instance of an object of a certain class is likely to be named.
Consistency only makes our lives as developers easier.

Esta entrada fue publicada en Programming. Enlace permanente.