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

The use of intermediate variables is something I'm conflicted about.

On the one hand, they can make code easier to reason about. Also, when using a crappy debugger that doesn't display return values you can more easily see what's going on. In some cases they make code that at least looks like it ought to run faster.

On the other hand, ditching intermediate variables makes refactoring more straightforward. You can immediately see the complete set of dependencies of a line of code and extract common bits of code into helper methods with less hassle.

In general I think I prefer the "cram a bunch of nested functions into one line" approach, but then that might be language-dependent (I mostly do Objective-C these days, and Xcode has a pretty smart automatic line-wrapping feature).

Lisp would be an extreme example where that's pretty much all you do.




An advantage of using intermediate variables is that they provide for a way to add comments without adding comments, in the form of the name of the intermediate result.

That helps in particular when you are calling several generic functions in a row. Names of local variables can contain a bit more of the terminology of the problem at hand.




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

Search: