|
|
|
|
|
by gruseom
4837 days ago
|
|
You're right and that's a fair point, but the argument still applies. The OP takes it as obvious that his rewritten jQuery snippet is better. In fact it's far from obvious, and learning the sense in which it's far from obvious is (in my experience) an important milestone, after which one stops arguing naively about readability and starts thinking more about the intelligibility of whole programs. If composed ternaries are an idiom that jQuery employs to do certain things compactly and repeatedly, that convention may well make it easier to understand jQuery. And that is what matters—not helicoptering into arbitrary bits of code. In terms of lines of code—an imperfect metric but a useful one—his rewritten example is twice as long. That may seem like a small price to pay for an easier-to-understand snippet in isolation but if you start thinking about a complex system as a whole, and consider how complexity compounds as programs grow, that intuition changes considerably. (I'm done being patronizing now.) |
|
Tangentially, I think his point about the descriptive variable names is far more important than avoiding if...else aliases (though it's not an original point, and the examples he shows are appropriate uses of short variable names).
I didn't think you were particularly patronizing. If you were, then I didn't mind.