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...

56

u/Microwawe Mar 02 '19

I'm not a fan of firacode either but the === has three horizontal lines whereas the == has only two so it's not that impossible to tell them apart.

18

u/deadcow5 Mar 02 '19

Personally I like the font (I use it myself), but I would probably not use it for screenshots intended for distribution. Too many people are gonna ask how to produce a triple bar equals, or WTH that even means.

0

u/[deleted] Mar 02 '19

[deleted]

7

u/haykam821 Mar 02 '19

You know you can just require("https://cdn-images-1.medium.com/max/2600/1*Y2FfIZMchiawzRIS_Rfrcg.png"), right?

That'd be a horrible future and an awesome joke package: importing code by detecting text in an image

3

u/smeijer87 Mar 02 '19
const ocr = require('ocr') ;
const img = await fetch('http://...png');
const code = ocr.parse(img);

eval(code);

Something like that? I'm pretty sure it would be possible. We only need someone to create a jsfiddle.

16

u/smellycode Mar 02 '19

I have been using Fira Code since last one year cause it's really good alternative to Operator Mono. I have never run into any problem. Indeed, I am loving it so much that every freaking editor I use both web/desktop I use with Fira Code.

→ More replies (2)

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...

→ More replies (2)
→ More replies (1)

10

u/careseite [🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) Mar 02 '19

Because it's not an issue because of the ligatures you dislike. Double == are easily discernible.

2

u/PizzaRollExpert Mar 02 '19

Tripple equals is three lines, double equals is two.

5

u/taniket Mar 02 '19

If you are using double = rather then triple, there's something wrong with your code other than the font.

-1

u/benihana react, node Mar 02 '19

that's great in theory and all. but in practice, on the web, a lot of values get coerced to strings, so it's not really that straightforward.

sometimes you have to deal with the fact that something that is represented as 35 in your database will be represented as "35" in your UI. Using strict equality will lead to subtle bugs in these kinds of situations.

8

u/folkrav Mar 02 '19

There's something wrong with your architecture if you're straight up comparing DB and UI values. For the odd time these things happen, I still much prefer to go with strict equally and cast manually. It's much easier to reason with, and easily testable.

→ More replies (3)

2

u/Otter_in_Jeans Mar 02 '19

If anything, for me, it looks clearer.

1

u/izuriel Mar 03 '19

It takes time to get familiarized with it, I’ll give you that. But IMO in the long run it enhances readability*.

As has been stated already triple equals has three bars vs two for double equals. Very distiguishable. Also not equals has a line through making it stand out as well. There are some ligatures I’m not as much a fan of (like less equal and greater equal being angled). For symbol heavy languages like Haskell this is a massive boost in readability there given the symbols used.

  • there are some odd cases in languages where symbol combinations are nonstandard and fall apart with ligatures.

1

u/[deleted] Mar 03 '19

Er. The triple equals has three lines. The double is twice as wide as it is high. The single is near-square.

Incidentally, I use Firacode, and love how it makes certain multi-character operators unambiguous.

1

u/[deleted] Mar 03 '19

I use glyphs all the time. But I agree with you on one level - folks should just make gists to save the confusion.

1

u/FanOfHoles Mar 03 '19

It works when you have eslint take care of complaining about double equals. Still, I tried a few times and always quickly went back to Consolas, which does not have ligature support.

1

u/ghillerd Mar 02 '19

It's actually not at all difficult to tell the difference between a == and a === in firacode. I bet of you ran a test of someone who's used it for a day, and asked them to glance at code and tell you if it used double or triple they'd have a 100% success rate.

-7

u/[deleted] Mar 02 '19

Cause its "hipster cool". After all, its JS.

7

u/[deleted] Mar 02 '19

How on Earth does font ligature have anything to do with JavaScript in any imaginable way??????

→ More replies (6)
→ More replies (1)