3 ms·
> switches are arguably way, way (waaaay!) more readable than the code proposed The point in the article is not that switches are less readable, but that switc
by lucideer 8y ago
> switches are arguably way, way (waaaay!) more readable than the code proposed
The point in the article is not that switches are less readable, but that switches can be "less" readable. Or—more accurately—they can look like they're readable but obscure unexpected subtleties
The object syntax may be slightly less readable than the switch in its simplest, most well-written form, but the point is that unlike the switch, it always unambiguously does what you expect.
It's also worth noting that the object syntax is extremely idiomatic in modern JS. It may look less readable to a generalist, but to anyone regularly maintaining JS it's far more familiar than the switch. (I guess this isn't so much a point in it's favour, it's more a point against modern JS being easy to pick up, but hey).
> it is true that switch statements in JavaScript have issues with breaks and code blocks, but any half decent linter will tell you about those.
While you have a point about linters, and I do use a strict one in every project, I'm much more comfortable with it being a safety net than the first line of defence.
Also, those problems with breaks and code blocks are hardly unique to JavaScript.