Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Does anyone else occasionally spend an unreasonable amount of time deciding how to name a variable ? :)


Selecting a variable name is actually very meaningful, and not just for maintainability reasons.

If you have difficulty naming a variable, it could be because you don't have a good grasp of either the problem or your solution, or concepts are conflated. It could be because you don't yet have a vocabulary that provides the terms you need -- imagine if you didn't have the words "result" or "set", but were trying to name a variable to hold the output of a query. It could be that your functions don't do just one thing.

It could even be because your language isn't expressive enough.

I can generally tell when I'm doing things 'right' because decomposing the problem into functions, naming them, and composing them into a solution is easy: it feels like I'm cutting with the grain, not against it.

In this way, coding is like writing a speech or a poem. Deliberating on precisely the right words to use is a key part of the process, and the better your grip on the domain and your arguments, the easier it is to find the words.


Your question may infer more than you may have meant.

Yes, I occasionally spend an unreasonable amount of time deciding how to name a variable.

But what is "unreasonable". If 30 minutes of agonizing over a name (and a standard) saves me 6 hours of debugging next month, was it really unreasonable?


At a certain point, if it's that hard for me to reason about naming something, I like to step back and make sure I'm thinking about the problem at hand the right way.

Of course, I don't work on very hard problems, so I'm sure that's different for everyone.


> Your question may infer more than you may have meant.

Of course, it does. It is a simpler version of "Do you care enough to write elegant code ?".


Elegance was the last thing on my mind. I was referring to maintainability.


Elegance of the code typically implies its maintainability. Not every maintainable code is elegant though :)


Yes, last week I spend a lot of time to decide what name to use for a method and some vars. The bad thing is that I was extending the system and the existing names for related methods where... wrong.


Yes, when I'm programming alone, which is a microcosm example of why I really like pair programming.


Oh God yes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: