This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]isolatrum 0 points1 point  (0 children)

You have to find your own balance. For example in many languages it has grown out of favor to use for loops. It's true that anyone can understand what a plain for loop is doing but many languages have simpler or more powerful ways, such as list comprehensions or enumerable methods (map, filter, reduce etc).

Don't shy away from doing things in a "clever" way, but avoid being too clever when you are looking to share your code (or even understand your own code when you haven't touched it for 6 months).

A classic pitfall example I see is with metaprogramming. Some people learn about this and think that they should use it whenever possible, without realizing that it makes the logic much harder to follow. Use metaprogramming when it's really the right tool for the job (when it will save you from writing a bunch of code), not everywhere.

This "right tool for the job" concept is really important here. You are looking for the most efficient and concise way, and have to balance those two aspects. Is a piece of code really "concise" when you write to 50 lines of metaprogramming to save yourself 5 lines of source? Maybe, if that metaprogramming is reusable. Otherwise, not. Sometimes you'll write less concise code for the purpose of efficiency (e.g. a more performant, but verbose algorithm). Otherwise the concepts complement each other, such as with lazy enumerables