1. 32
  1. 26

    People love arguing against using ligatures in code. I don’t know why. People who enjoy ligatures in code are going to continue using them. If you don’t like them don’t use them. Fonts let you control whether to enable them on a case-by-case basis, so I enable ligatures (I use Victor Mono) in my text editor (vscode) but disable them in my terminal (kitty).

    I’ve been using ligatures in my editor for years and have never once found myself in the author’s prophesied “swamp of despair”. My code just looks nicer with things like nice mathematical symbols (≤ instead of <=) and it hasn’t once caused me a problem.

    Article is from 2019 btw.

    1. 14

      You wrote:

      If you don’t like them don’t use them.

      But you’re responding to an article which says:

      “What do you mean, it’s not a matter of taste? I like using ligatures when I code.” Great! In so many ways, I don’t care what you do in private. Although I predict you will eventually burn yourself on this hot mess, my main concern is typography that faces other human beings. So if you’re preparing your code for others to read—whether on screen or on paper—skip the ligatures.

      And I really don’t have a choice but to read code with ligatures from time to time. Sometimes it’s on a blog post with ligatures, sometimes it’s in a screen shot of someone’s code they sent while asking for help. I wish people would follow his advice.

      1. 5

        His “main concern” is in a footnote, that basically he doesn’t want to have to read other people’s code with ligatures, which is your main point too. That’s fair! For many purposes (github, stack overflow, a textbook, maybe not an algorithms book) I even agree with you. I’ve never had a coworker complain when screen-sharing that they had trouble reading code, but it’s trivial to disable temporarily if they were to ask.

        But if someone wants to post code on their site in a font with ligatures I’d go “ooh nice that code looks pretty” and maybe “what font is that”? Despite protests, arguments, and vague predictions of doom, it does come down to taste and to circumstances. That’s my main concern, acting like it’s a matter of right and wrong.


        I’ve already given reasons in the thread why ligatures can actually increase readability. Check out the Victor Mono homepage for yourself for some code examples https://rubjo.github.io/victor-mono/ I just noticed that triple equals (JS) is represented by three bars. I don’t usually code JavaScript but triple equals being so visually distinct from double thanks to the ligatures I imagine would make it harder to make a mistake with them. On the other hand I dislike the use of dull color italics for comments that the author uses in the code samples… Again, it’s primarily about taste.

        Of course, I’d be interested in any real-life examples of the author’s once-in-10-to-15-year occurrence prognostications of despair.

        1. 9

          Luckily because taste is a factor, my userContent.css contains

          code, kbd, pre, samp {
             font-variant-ligatures: none !important;
          }
          
          1. 1

            That’s awesome, thanks for sharing. I’ve been meaning to set up a userContent.css! (What stopped me is that it seems difficult to source control across computers because the profile folder name changes between machines.)

            1. 1

              I usually just update a snippet every once in a while. It’s not something where the world ends if I’m missing it. What I do want to see is NixOS having better control over building and managing Mozilla profiles.

        2. 3

          Sometimes it’s on a blog post with ligatures,

          I’ve never seen bad ligatures in a blog post code block. Usually the kind of people who want ligatures in their blog are sensitive enough to know when to turn them off. There are plenty of other ways to mess up code blocks, colored highlighting is a very common one. You don’t see anyone arguing against highlighting do you?

          sometimes it’s in a screen shot of someone’s code they sent while asking for help.

          So? My eyes burn when I help someone not using dark mode, it’s never stopped me from helping them.

          1. 2

            And I really don’t have a choice but to read code with ligatures from time to time. Sometimes it’s on a blog post with ligatures, sometimes it’s in a screen shot of someone’s code they sent while asking for help. I wish people would follow his advice.

            Sincere question: Do you really struggle if there’s ligatures? Does seeing them a few times in those scenarios really cause a hassle?

            What about the inverse? What about people who struggle with “=” vs “==” vs “===”, for example? There are people who find “≡” preferable. Perhaps they wish people would not follow the author’s advice?

            Anyway, I have ligatures on, and I’ve never had a problem in the scenarios you’ve mentioned, and more importantly, I’ve never had a problem when pairing. I regularly explicitly check too that a. is the font-size okay and b. are the ligatures okay.

          2. 7

            I agree. I like the clean look; the ligatures make common symbols easier to recognize. I just started doing some HTML work yesterday, and was happily surprised to see that my current font has ligatures for HTML comments, which make them very recognizable even when the editor isn’t syntax-coloring them.

            1. 6

              the ligatures make common symbols easier to recognize

              Totally. I want to piggy back on this to point out that ligatures don’t just “change symbols into other symbols” (like the OP is arguing WRT things like ≠). Ligatures can actually help make your code clearer even without substituting symbols. For example, Victor Mono, when it sees things like || or &&, replaces them with a bolder ligature version to make them stand out in code, but they’re still the same two symbols.

              1. 2

                why is that called a ligature? isn’t it just a font change?

                  1. 1

                    this explains my confusion

                  2. 1

                    At a technical level, fonts have several tables in them which define ligatures. The application code doesn’t even get involved, this all happens within the font rendering library (which on many platforms is part of the OS). That mechanism is used here, so that’s what it’s called.

                    1. 1

                      Thanks. I guess OP’s complaints are about ligatures in the layman’s sense.

                1. 1

                  If the symbols are easier to recognize, then why not just use the Unicode symbols for them? Ask your language to adopt Unicode support.

                2. 3

                  I’ve been using ligatures in my editor for years and have never once found myself in the author’s prophesied “swamp of despair”. My code just looks nicer with things like nice mathematical symbols (≤ instead of <=) and it hasn’t once caused me a problem.

                  Likewise. Has anyone burnt themselves on “this hot mess”?

                  I also usually have the opposite experience of what the author, and some commenters here, are saying. People usually ask me how to get the ligatures since they look nice and help with understanding by making it quick and obvious to parse things like logical operators.

                  1. 3

                    It’s like they’re afraid they’re going to be forced to use ligatures against their will

                    1. 1

                      The ≤ case is a selling point for me because I can never remember if it’s spelt <= or =< and the font disambiguates that for me.

                      Mind you, it’s the year 2022 now, and digraphs like >= or != should be regarded as crutches just like trigraphs are. It’s sad that we have to misuse font features instead.

                      1. 1

                        because I can never remember if it’s spelt <= or =< and the font disambiguates that for me.

                        Ha. That’s a really interesting point. I never mistake <= because it’s spelled like it’s read (“less than or equal to”), but I could never get straight ~= or =~ for using Perl regular expressions.

                        digraphs like >= or != should be regarded as crutches just like trigraphs are. It’s sad that we have to misuse font features instead.

                        Disagree on that. It’s great that I can see “if err ≠ nil” over “if err != nil” (the ≠ actually looks much nicer as a ligature in my programming font than the Unicode character does alone) without having to cut and paste unicode characters (as if using ≠ over != were even allowed). Fact is there are only so many keys on the keyboard. Programming-specific ligatures seems like a perfectly natural use-case, I don’t see it as a mis-use. Further, many Unicode “characters” are composed of multiple code-points, so Unicode does “ligatures” internally as well. Typing in Asian languages is often accomplished by combining multiple keystrokes to type one character. Text isn’t simple.

                    2. 8

                      Have you ever been to a tech talk where the author insists on presenting with ligatures on? Every time someone in the audience has to ask for it to be disambiguated and this has been my experience the last 9 or so years.

                      1. 2

                        hm, even worse: I can imagine that if a teacher was presenting to a classroom and showing a symbol like ≠, chances are some students are going to try hard to insert the Unicode symbol ≠ rather than typing != which doesn’t produce the same result on their display.

                        Having to make this mental mapping to “what you see is not really what’s there” is a recipe for disaster. But I agree with most commenters here that in practice, if you enable it just for yourself you probably know what you’re doing and won’t run into any serious trouble. But it might cause trouble if you’re the cool hacker at work that all the juniors want to imitate without knowing what they’re doing.

                        1. 2

                          I’ve seen issues though with international keyboards and typing $ which lets us know there’s always going to be a cutoff for what’s “hard” to type.

                          1. 2

                            Yeah but at least there you know that when you managed to insert that symbol, it’s going to do its job. If your PL supports only != and you worked hard to insert ≠ instead, it will error out with a compiler error. For total beginners, that’s going to be rather difficult to grok.

                            1. 3

                              Honestly I bet lot of newbies failed to understand why ≠ didn’t work… like why is it 2022 and they can see the symbol in a math paper and can’t use it. Just as much, we read stories about newbies tripping up on = for assignment instead of comparison… the you get a whole Yoda-style conditional movement instead of fixing our languages.

                              1. 3

                                Fair enough, that would arguably be better than trying to shoehorn these in through the back door by using a font that pretends they’re supported…

                        2. 1

                          This hasn’t been my experience for the last how ever many years, on both sides of presenting or watching.

                          Like the article, it’s just some fun opinions and anecdotes. ;)

                        3. 6

                          The problem? Many of the programming ligatures shown above are easily confused with existing Unicode symbols

                          But existing Unicode symbols are already confusable with each other. The article also doesn’t explain why this is a problem.

                          1. 9

                            It seems to me that you are saying ‘there is already some ambiguity, this is a problem, why not add more ambiguity’. Seems like a question that answers itself.

                            I agree with most of the comments here that no one should be telling other people how to render their code to their own eyes, and no ligature settings are encoded in the source meaning it a completely individual choice with no consequences for others.

                            I also agree with the article that it is a terrible idea and you will never persuade me to allow ligatures anywhere near my IDE. I am also one of those strange people who hate wysiwyg editors of all kinds and avoid using them whenever possible so maybe I am just idiosyncratic. But I find when communicating with a computer, that precision is paramount and any ambiguity is dangerous.

                            Having said that I am interested in the idea mentioned above “when it sees things like || or &&, replaces them with a bolder ligature version to make them stand out in code”. This is a use for ligatures that deserves consideration. Don’t change my symbols, but highlighting certain sequences could be very handy.

                          2. 5

                            OK. Not a big fan of this article. To start:

                            Ligatures in programming fonts are likely to either misrepresent the meaning of the code, or cause miscues among readers. So in the end, even if they’re cute, the risk of error isn’t worth it.

                            The author has admitted that they’re not actually interested in a comprehensive discussion of the issues at play right off the bat by using the phrase “Even if they’re cute”.

                            Partially blind developer here. I love ligatures, and not because they’re “cute”. Ligatures create entirely new characters for logical character combinations which take on a totally different meaning from the individual characters themselves.

                            For example, I often trip over != in code because the ! is bumped right up against another character and I can very easily miss it, whereas with ligatures, != becomes an = with a diagonal slash through it. That’s impossible to miss.

                            The problem? Many of the programming ligatures shown above are easily confused with existing Unicode symbols. Suppose you’re looking at a code fragment that uses Unicode characters and see the symbol ≠. Are you looking at a != ligature that’s shaped like ≠? Or the actual Unicode character 0x2260, which also looks like ≠? The ligature introduces an ambiguity that wasn’t there before.

                            The author solves their own problem: Just use a hex literal instead. Just about every Unicode aware programming language supports this. Next!

                            They’re guaranteed to be wrong sometimes. There are a lot of ways for a given sequence of characters, like !=, to end up in a source file. Depending on context, it doesn’t always mean the same thing.

                            Ibid. Don’t use unicode literals. Use an alternate representation.

                            I’ll keep my ligatures thanks. I have enough to struggle with in my development workflow, I need every bit of help I can get, and the issues raised here are beyond academic as I see it.

                            1. 1

                              The author is also a typographer and coder so they do have more authority than the average programmer. character in Vim is a digraph (ctrl+k) of != which makes it pretty easy to insert. In the languages I code in (though not current contract), this character is either supported or the operator is trivial to define (e.g. infix 4 notEq as ≠). This also lets all readers not have to think about with the inconsistencies between languages and limitations of ASCII with !=, /=, =/=, and just use/read the “correct” symbol.

                              DO use them if you want, but there are drawbacks.

                              1. 2

                                ≠ character in Vim is a digraph (ctrl+k) of != which makes it pretty easy to insert

                                How did I not know about this

                                1. 1

                                  There’s a big list and it’s one line to create your own.

                                2. 1

                                  Absolutely. I use and love them because I’m partially blind and they HELP. I’m glad Vim supports similar magic that doesn’t require them. I’m not always in Vim :)

                                  I’d definitely not inflict them on unsuspecting readers because I understand they aren’t universal. But as a tool to help me overcome my visual limitations I’m just responding to the author’s “Hell no” with a resounding Hell Yes! I don’t care if they invented the Roman alphabet :)

                                  1. 1

                                    Living in a foreign country, ASCII and Roman script being forced onto other writing systems for ‘computers’ is still causing headaches. I can’t type commas to my bank because that symbol wasn’t support in their never-converted-to-UTF system.

                              2. 4

                                My terminal emulator of choice doesn’t support ligatures, but I wish it did, because my font of choice has ligatures that I like.

                                I don’t know if any of them are enabled by default, but I have enabled them all in fontconfig, so I know how easy it is to also disable them, and don’t see the problem.

                                1. 2

                                  As Rob Pike said in regards to variable names: “This is largely a matter of taste, but taste is relevant to clarity.”

                                  1. 1

                                    s/in regards to/about/

                                    I’m sorry

                                  2. 1

                                    The fun and comfyness factor are important for my enjoyement of programming. I am guilty of having spent more time editing my .emacs than doing a task I was assigned to on certain days. But actually visually and interactivly enjoying my programming environment are an important factor to me and by extension, looking forward to interacting with my text editor makes me better at my job IMO.

                                    Ligatures are such a factor. Ligatures, Hell yes.

                                    1. 1

                                      a swamp of despair. If you don’t believe me, try it for 10 or 15 years.

                                      I’ve been coding in a variable width font with ligatures every day for over 5 years, in a dozen of languages. Maybe I’m still too novice but I’ve never had a real problem.

                                      OTOH, just today I wrote a bug because of 0 and O confusion, and they do in fact look different. I only caught it cause my IDE told me (like it would with ligature confusions btw) so I question the value of his lauded disambiguation.

                                      1. 1

                                        Seems like the ambiguity could be fixed by hooking up the language parser to the ligatures? So it only uses ligatures when it’s in a non-ambiguous context (e.g. it never uses them in string literals). Not sure any editor actually does that, of course.

                                        1. 2

                                          This is basically what I do in Emacs. I use the Iosevka font in a “two width” variant, where various characters like arrows are double the width of the others.

                                          (Note: Iosevka also exists in multiple variants with “ligatures”, if you were to prefer to use it that way.)

                                          I then use prettify-mode in Emacs to replace some sequences in certain languages with those.

                                          This is a lot more flexible in that it allows completely different replacements even for the same underlying characters in different languages.

                                          Adjusting the position of characters is also possible, so of you wanted to do it with a regular monospace font and instead replace some pairs of characters with a different character centred on where they would normally be, that’s also possible. That same function can also be used to “pull together” certain characters like some programming fonts with “ligatures” do.

                                          Of course you can also make some characters bolder and so on with this feature as well, but that can also be done with regular syntax highlighting, so it’s not something I do with prettify-mode.

                                          PS. There is also ligature.el for Emacs that does let you so some of this by selectively enabling ligature features for certain characters and only in certain syntactic positions. This also allows different configurations for different languages, but is more limited in that you can still only turn a certain sequence into a single other character as defined by your font. (Unless you were to also use different font variants depending on language, but that sounds even more unwieldy.)

                                          1. 1

                                            The parser doesn’t see the ligatures, this post is a person complain about coding fonts that use the font’s ligature system to do things like replace != with ≠, etc. None of the sources bytes change, the only difference is the glyph being used to display the characters, so someone else using such a font has literally no impact on anyone other than that person[*]. But also because it’s literally a feature of the font it can’t parse the text so it can’t be contextually aware(having said that I’m sure someone will write a c parser in a ttf now). I’m guessing if there are code editors that use fonts like this, and don’t apply the ligatures everywhere they are probably changing the font entirely depending on context