5 ms·
Used judiciously, ligatures can help make code more readable, not less. Consider JavaScript's == and ===, and their inverses != and !==. I personally find them
by jake-low 7y ago
Used judiciously, ligatures can help make code more readable, not less. Consider JavaScript's == and ===, and their inverses != and !==. I personally find them difficult to visually distinguish on occasion (especially the negative forms). Fira Code [0] replaces them with two-bar and three-bar equals signs (something like =, ≠, ≡, and ≢, only wider; see the link for a screenshot). I personally find these easier to distinguish from one another at a glance. I'm sure it's not for everyone, but in my opinion at least these ligatures improve readability.
I'm generally a fan of Practical Typography, but this post is unnecessarily condescending. It's sort of laughable to claim that "this isn’t a matter of taste" when users are making this choice in the privacy of their own editors.
[0]: https://github.com/tonsky/FiraCode https://github.com/tonsky/FiraCode
- taneq 7y ago> Fira Code [0] replaces them with [...] And that's how it should be done. If you want something modified visually then you can modify it for yourself without pushing it on the rest of the world. Edit: Disregard that, I was being dumb.
- svrtknst 7y agobut that's how programming ligatures work? Or, what is it that you're getting at? Fonts with ligatures, such as Fira Code or Hasklig, work by replacing characters with a ligature. The actual source code is still "->" or "===" or "|>" or whatever it may be. No one is "pushing it on the rest of the world"?
- amanzi 7y agoTo be fair, I find the "www" ligature to be a bit unnecessary, but apart from that I love the ligatures in Fira Code.
- psychoslave 7y agoWell, at this point, `store` (=), `equal` (==), `equiform` (===) are even more readable, meaningful and accurate. Of course other terms such as `equivalent`, `equiquantal` `equireference`, `equieffective` and more are also possible. Don't forget people read whole words, so they most likely don't spend much time on "==" recognition than they would with "equivalent". And with text completion, token length is an irrelevant metric on productivity as well. Any non literal symbol used in code is an incentive to use more of them and turn code bases into harder to maintain "smart" obfuscated trick stacks. On an historical perspective, how much people using "=" know where it comes from (nothing is more equal than two parallel lines), compared to how many people are able to make a good guess of the etymology of "equivalent" (same value)? Add to this observation that in the mid-time with the raise of non-euclidian geometry and topology the former insight is far less relevant nowaday.
- C1sc0cat 7y agoNo I do not what some ide to start fucking about with code and introducing god only knows strange edge cases. And I use profanity (Engineering language) for good reasons here can you imagine any other engineering discipline allowing this to happen - oh yes the CAD system added a ligature in the bridge design blueprints !!
- jon-wood 7y agoLigatures in your editor don't change the underlying, code they just change the presentation of that code when you're viewing it. While a ligature supporting font may show you ≥, the underlying source file still contains the distinct characters >=
- C1sc0cat 7y agoyes "up to a point lord copper". What what happens when this code is copy pasted, moved between machines in different countries or edited in multiple different editors you can get bizarre problems. Even moveing excel between countries gets some very strange changes Eg changing diacritical's but they look very very similar.
- ThJ 7y agoAbsolutely nothing happens. Ligatures are a feature of fonts and font rendering engines. They do not affect the character codes. If you copy-paste from an editor configured with one of these fonts to an editor that isn't, you'll simply see the ordinary characters, because that's what was in memory the entire time.
- dmos62 7y agoI'd argue the inverse. In my experience removing the gaps makes some symbols harder to read. Like distinguishing `==` and `===` without gaps is harder, though admittedly three-bar helps. Also, I find the ligatures I've tried a bit of an eye-sore, but that's just personal taste. What's a more serious concern is the "dumbness" mentioned in the article and the handling of ambiguous cases. To give my own example, in addition to those in the article, I use a series of more than 3 equals signs as a delimiter in my notes. With programming ligatures it looks distractingly bad. Normally it's a continuous row of two-bars, but with them ligatured they look like morse code divided into short groups of long two-bars. Essentially, when I'm writing code or whatever, I don't want there to be someone guessing what I mean and how I want something to look. Unless he guesses always right, he's a nuisance. Sorry for the personification.
- ballenf 7y agoThe article is "ligatures are always wrong for everyone in code" and your position seems to be "ligatures are wrong for me and people who are reading my code in their editor". I don't think anecdotes of cases where ligatures fail support a case for them being wrong for all people and all situations. Personally, I've never had a single instance of them doing something dumb in 2+ years of using them. Never a single instance of them creating any ambiguity or failing to add clarity to my reading of code. Dumb in "theory" might be smart enough 99% of the time. Just in the last couple months, I had to review code without the aid of a linter and they were invaluable.
- atoav 7y agoWell it is a matter of personal taste, isn’t it? For me it is just the opposite, the visual appearance of the ligatures burned itself itnto my brain in away that it is easier to spot when it is not there. Sometimes something not converting to a ligature can also be a hint (e.g. for a wrong hyphen beeing used etc)
- type0 7y ago> Sometimes something not converting to a ligature can also be a hint (e.g. for a wrong hyphen beeing used etc) So what languages actually benefit from this? haskell, clojure but maybe not the usual C family ones?
- Cthulhu_ 7y agoMy counter-argument: eslint and tools like that will warn or error when you use `==` when you should be using `===`, up to the point where `==` is considered a code smell (JS's 'loose' comparison has been the target of a lot of brouhaha)
- zamalek 7y agoWhile readability decreases the chances of bugs, it's not the only function of readability, not by a longshot.
- theoh 7y agoIt's one thing to write code with Unicode characters like ≢. That should be fine, and it's not difficult for programming languages to support it. (You could roll your own preprocessing tool). Doing it with ligatures is not a great idea, because ligatures are a PITA (not always well supported) and add too much incidental complexity.
- msla 7y agoThe problem I have with ligatures in source code files is that it makes pairs of codepoints visually indistinguishable from a single codepoint. For example, if I see "fl" in a string, is that "fl" or is it "fl"? That is, is it the codepoint sequence U+0066 U+006C turned into a ligated version visually, or is it U+FB02 the single codepoint? Then I get paranoid: Did my text editor Helpfully convert the sequence of characters into the ligature character? The paranoia is probably unjustified, and would be seen as a bug if it weren't (probably), but a clear visual distinction would banish it entirely.
- viklove 7y agoWhy are you ever using == in JS?