r/javascript • • Mar 02 '19

Useful javascript one-liners.

https://medium.com/@smellycode/js-one-liners-8bc0a6af2345?source=friends_link&sk=a9295a05aef9e514e137fca7eeb89cd1
344 Upvotes

96 comments sorted by

View all comments

43

u/Shaper_pmp Mar 02 '19

Why on earth would anyone use a font for programming that runs characters together and makes it difficult or impossible to determine whether something is a double- or triple-equals?

With a language like JS that's just asking for trouble...

21

u/Voidsheep Mar 02 '19 edited Mar 02 '19

The point of ligatures is to improve readability, because things commonly expressed by different combinations of characters get unique symbols.

=>
<=

The two above look either like arrows to right and left, or comparisons with equal or lesser/greater.

⇒
≤

The two above clearly have nothing to do with each other, one being an arrow to right and one being mathematical operator for "less than or equal".

Of course everyone will just learn what different characters mean together, but ligatures make the difference more explicit when you write and scan code quickly. In the specific case of strict/loose equals operators the benefit isn't that obvious, but it's still easy to tell them apart.

-10

u/Shaper_pmp Mar 02 '19 edited Mar 02 '19

Ligatures are fine, but like any tool they're only useful when they're useful.

Any font that's intended for programming that runs together arbitrary sequences of characters in a way that makes it difficult/impossible to tell at a glance how many there are, however, seems self-evidently sub-optimal... especially in cases where it's the difference between things like type-coercive- and strict equality.

Edit: I just noticed that the triple-equals glyph actually has three lines not two, so it's a little easier to tell them apart than I first realised.

That said, the fact it wasn't necessarily easy to tell whether it had two or three horizontal lines on a mobile screen kind of makes the same point in a different context...

6

u/[deleted] Mar 02 '19

Any font that's intended for programming that runs together arbitrary sequences of characters in a way that makes it difficult/impossible to tell

They aren’t “arbitrary sequences” of characters at all, though. They are specifically chosen to make specific code sequences less ambiguous or otherwise easier to read at a glance. In my opinion, that is far more important than knowing how many characters there are in a particular sequences at a glance (which honestly seems like a pretty arbitrary criterion by which to judge a font “sub-optimal”).

1

u/Murdathon3000 Mar 03 '19

the fact it wasn't necessarily easy to tell whether it had two or three horizontal lines on a mobile screen kind of makes the same point in a different context...

Yeah, that might be an issue that the minority of people have, it's not very difficult to see that there are 3 lines. Here's an example,

ll

lll

Did you catch it?