Random Notes

The Trouble with `

The grave accent, or more commonly in programmer circles, the backtick. A tiny character with so many uses. With the advent of computers, it has diversified its traditional role as an àccent with new purposes. It marks code in Markdown and Markdown-ish syntaxes. It delimits template literals in JavaScript. It executes code in shells and PHP. And it drives me up the wall.

There is nothing wrong with `, don’t get me wrong. But its technological implementation often leaves something to be desired. In the Swedish keyboard layout that we also use here in Finland, it is a dead key. What this means, in short, is that when you press the key, it’s not yet written into the output. Instead, usually a “ghost” character is displayed that waits until you press the next key, when it will be combined with the next typed character. On macOS, after hitting `, the display looks something like `, and when typing a, it turns into à.

This means that when typing just a backtick itself, I have to hit the backtick first and then space. With Markdown’s code blocks that start with three backticks, I can luckily hit just three backticks and one space, since backticks can’t be combined with each other. The backtick is already in an unergonomic position on the keyboard and now I have to hit space as well. And there’s a lot of backtick usage nowadays, thanks to Markdown style markup being ubiquitous.

The above I can change easily by modifying my keyboard layout or writing a macro that hits the key and space aftewards. But there’s also trouble with programs not understanding dead keys properly. One example was Discord. Whenever I closed a code block with a dead key, the cursor would jump to the start of the input field. This lead to a huge amount of frustration and mistakes, especially since I hang out on programming related servers and use code blocks often. I would have reported the issue, but Discord’s bug reporting system is one of the worst I’ve seen, so I gave up (that’s a subject for another post). Thankfully, this has recently been fixed.

Many mistakes were made due to this.

Another offender, even worse than Discord, is the beloved Microsoft Teams. Both the web and desktop apps have problems with the backtick, in different ways. The desktop version, when closing a code block, most of the time inserts a new backtick after the block, along with several zero width spaces that I have to delete. But if I delete too much and end up inside the code block, there is no way to escape it and type normal text after it any longer.

The web version, on the other hand, moves the cursor to the start of the last code block or the start of the line upon the first backtick after a successful code block insertion. So both versions work badly but in different ways.

Surprise! You're now typing at the start of the line.

The third offender I’ve faced was the JetBrains series of IDEs. When typing a backtick and a space, often the backtick just simply disappeared. I had to use another character, such as a second backtick, to type one backtick. Sometimes I had to hit the keys multiple times or nothing would happen, and occasionally I would receive errors bubbling from deep within the IDE. Luckily, this too has stopped in recent versions, leaving only Teams to annoy me daily.

What’s the lesson here? Well, it’s too late to get rid of the major part the backtick plays in the modern programming work. And it surely would be too much to ask, just to make life easier for a subset of users. But I do wish that products were tested on keyboard layouts that have dead keys. If I had one euro for every time a program had backtick related bugs, I’d have four euros, which is not much, but it’s weird that it has happened four times.

UPDATE 2021-07-17: I created a macro for my keyboard that types the backtick without it being a dead key. It uses the macOS Unicode Hex Input, which unfortunately is a separate keyboard layout. So it does ctrl + option + space twice to switch the input source to Unicode Hex Input, then inputs 0060 while keeping option held down, then does ctrl + option + space twice again to go back to Finnish. As you can see, it’s quite a hack, and unfortunately sometimes fails and types ] instead. Funnily, when input this way, MS Teams doesn’t detect the backtick at all, and doesn’t generate a code block between two backticks. So in the end the macro doesn’t really help me.