Nested ternary conditional operators can be useful. In some cases, e.g. to promote better code readability, you may want to outlaw that practice. Armed with a code parser, a simplistic code analysis allows such a pattern detection. Once somebody understands the power of the ternary operation, it is very tempted to harness it in multiple… Read more »
Posts Tagged: api
Ternary Conditional and Boolean Values
Many programming languages support the ternary conditional operator. It is very useful to shorten the code since something like: if (fast) speed = 70; else speed = 25; can be rewritten to look like the following (C-style syntax). In such a form, it is also concise, readable, and unambiguous. speed = fast ? 70 :… Read more »
Detecting Boolean Traps with Esprima
A bad API can lead to ambiguities and reduced readability. One very common thing I still encounter in various JavaScript frameworks is the so-called Boolean trap, i.e. the unwise use of Boolean argument(s) in a function call. Reviewing or reading code which gets trapped there is not fun. The earlier we can catch such as… Read more »
api shame: non-descriptive property names
I had a lot of fun writing about the Boolean trap issue. I also have more similar API-related discussions in the pipeline. Rather than writing a long-ish essay again, I decide to put out more bite-size chunks. Here is the first. Careful when choosing the name of an object property! Let’s say you create a… Read more »
hall of api shame: boolean trap
Update: Read also the approach to detect Boolean traps (in JavaScript apps) using a simple script. The nice thing working for Trolltech was (among others) learning the principles behind the good API. The article Designing Qt-Style C++ API from Matthias 6 years ago is still a good reading till today. The content itself is now… Read more »
