3 ms·
a11y, i18n, l10n are all reminiscent of a software anti-pattern - optimizing writability over readability. if (condition); then 1; else 0; is 31 character
by syndicatedjelly 3y ago
a11y, i18n, l10n are all reminiscent of a software anti-pattern - optimizing writability over readability.
if (condition); then 1; else 0;
is 31 characters long, while
condition ? 1 : 0
is 17 characters long, or about 45% shorter. However, the first option imposes less cognitive load on the (code) reader. The only code syntax one needs to know is the if-then-else construct, which is taught in every introductory programming course. The second option requires specific knowledge of the ternary operator, which a significant number of programmers are not familiar with. The syntax of the ternary operator also varies by programming language, whereas if-then-else is far more ubiquitous.
Shorthand is useful when taking notes or when working with limited space. In the context of discussing a11y, i18n, and l10n in online documentation, neither of these things are true.
- TeMPOraL 3y agoThat's a really bad example for a comparison. > However, the first option imposes less cognitive load on the (code) reader. Not in this trivial case; cognitive load here is dominated by effort to identify meaningful parts and reject the noise. It rings true in case of more complex conditionals and expressions, where it quickly gets hard to identify at first glance where the three parts start and end. However: > The second option requires specific knowledge of the ternary operator, which a significant number of programmers are not familiar with. Those programmers should then familiarize themselves with it. For those reading this comment right now, here's a primer: condition ? if-true-expression : if-false-expression; That's it. The more important insight is that the whole thing is an expression, which always has a value, unlike regular if/else construct. This of course matters only for languages which, for some incomprehensible reason, needlessly complicate things by having "statements" and "expressions" be distinct things. Anyway. The larger point is that ternary operator is both very useful and very basic part of programming. Refusing to use it when appropriate, on the basis of "think of the juniors" is like refusing to sell paints and paintbrushes because hey, some adults never advanced past crayons and are artistically still 2 year old. And sure, if it's only about your hobby, then you do you - but when you want to do it professionally, you have to respect the fact that programming is a profession - as in, you're expected to learn stuff. > The syntax of the ternary operator also varies by programming language, whereas if-then-else is far more ubiquitous. Nah, arguably it's the if/then/else syntax that differs more often between languages. Starting with "then" thing being nonexistent in most. The extreme aversion to learning, bordering on antiintellectualism, that's plaguing this industry, is not helping in making better software. It's helping companies in solving problems by throwing large amounts of easily replaceable fresh juniors at them.
- syndicatedjelly 3y agoThose were all really good points, and I agree with most of what you said. Do you agree with my original thesis though, "writability over readability" is a software anti-pattern and also applies to numeronyms such as a11y and i18n? > The extreme aversion to learning, bordering on antiintellectualism, that's plaguing this industry, is not helping in making better software. It's helping companies in solving problems by throwing large amounts of easily replaceable fresh juniors at them. I feel the same way about any business or tool that advertises itself as "write less code!". It's not the quantity of typing that is difficult about a programmer's job; it's the cognitive load and context that must be held at any given time. I'm always interested in tools that can help reduce cognitive load, but I am also fearful of leaky abstractions. If a tool wants to inject itself between myself and the machine, the abstraction better be flawless and rooted in first principles.