I was expecting something more profound. Isn't this just the concept of using variables to keep code readable? Not a new concept and likely one most devs learn early on.
post
Good advice. The few pages of blog posts I have read are a really great read
Yes, I've been doing this for years. It's great for both code readability as well as debugging.
Good advice, bad biology: mushrooms aren't plants and therefore nor vegetables.
Vegetable is probably meant in the culinary use here, not in the biological one. And like with many such terms the two do overlap but not entirely.
I don't think a lot of people think that mushrooms are vegetables in any sense. If you check culinary lists of vegetables, they don't contain edible fungi.
Good advice, clear, simple and to the point.
Stated otherwise: "whenever you need to add comments to an expression, try to use named intermediate variables, method or free function".
Sometimes this can help, but lately I've been running into the opposite problem where people have been following this advice to such a degree that one cannot ever figure out what is going on without having to constantly jump around to find the actual code involved in doing something.
Ah I hate that, too. It speaks of bad abstraction, over eager abstraction or unnecessary coupling that is the hidden behind this. Difficult to fix though without essentially starting over.
I absolutely agree that method extraction can be abused. One should not forget that locality is important. Functionnal idioms do help to minimise the layer of intermediate functions. Lamda/closure helps too by having the function much closer to its use site. And local variables can sometime be a better choice than having a function that return just an expression.
I do OOP because it naturally encourages me to do this sort of thing: abstract complicated logic into inspectable, reusable, testable properties of an object.
all 23 comments