Hacker News new | comments | show | ask | jobs | submit login

Sure, that's basically a rule for when to do the "introduce explaining variable" refactoring [1]. There's a bit of taste as to when to name things in this instance, but certainly if a name can replace a comment then it's better to use a name. You might additionally use a name for something you wouldn't comment, if the logic is straightforward but the code is long enough that it would otherwise be hard to read.

If you use something more than once, then you either have to give it a name or repeat it, and generally people like to avoid repeating things. Some people will accept two copies and get rid of the duplication when they get to three copies, though purists would dislike that.

[1] http://www.refactoring.com/catalog/introduceExplainingVariab...

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact