#coding

Programming, coding, and software engineering / 12 posts

Newsletter
  • Get a newsletter digest every Friday:
Contact

Send me feedback, tips, bug reports, and anything else:

About me and the blog

My name is Marcin Wichary. I’ve worked as a UX designer, typographer, front-end person, and manager at Google, Medium, and Figma. I’ve also written a book about keyboards and typing, gave talks, and published essays about design, typography, and technology.

Unsung is my blog about software craft and quality.

More info about Unsung

Send me feedback, tips, bug reports, and anything else:

More info about Unsung

“I’m especially proud of the 1e+9 duration.”

I liked this post by Roel Nieskens, about

ten lines of code that, one way or another, mean something to me. Either because I wrote them, or I extensively copied them, or they made me laugh. Or cry.

It’s perhaps a different take on cursed knowledge, and made me wonder what those would be for me, or for other people with different specializations. (We previously talked about Duff’s device, which had a certain impact on me – even though I never used it myself.)

Responsive text and code

Many years ago, I put together a quick proposal of what I called “responsive text” for social proof:

I think you get the idea – instead of dumb truncation, the underlying code could prepare a few strings conveying the information with different levels of specificity, and then the UI could choose the longest one that could still fit.

This idea can apply in a few places. Here, in Figma, one of the menu items switches to a more “compact” string that uses four-letter abbreviations and skips “weight” altogether – but only because there isn’t room for a verbose treatment. You can also compare it with the original, naïve truncation:

Recently, I spotted Jake Archibald, developer working on Firefox, propose something in a similar vein – responsive code:

I think this is a lot more clever and a lot more important. Mobile phones are everywhere. Wrapping code like regular text without understanding it makes it basically impenetrable, but preserving long lines and introducing horizontal scrolling is also frustrating – just in a different way, forcing you to hold more stuff in your head:

I can see Archibald’s solution be very helpful here if used well – and not just on mobile – and perhaps could inspire other kinds of solutions for similar problems (have you ever tried to read any table on Wikipedia on your phone?).

“I want to code; I’m not looking to make lifestyle choices.”

Robin Sloan:

I still use Sublime Text for all of my programming and all of my newsletter-ing. […] The app is simple and superfast; I have it set up exactly the way I like it […], and it’s difficult for me to imagine ever switching to anything else.

Here is a piece of software as sturdy and obedient as a cast-iron pan.

Sloan links to a piece by David Bushnell about Sublime Text, who writes:

I don’t know who develops it and I don’t care. All I know is that I can place my text cursor and read the surrounding code without a bombardment of popovers, pop-unders, pop-left-and-rights, pop-inlines, pop-in-and-out-too-fast-to-sees. […]

The perfect dev stack is a collection of software that each does one job and doesn’t suffer main character syndrome. I want to code, I’m not looking to make lifestyle choices. I don’t want a bloated everything app. Don’t get me started on the “unified toolchain” plague! Show me the latest VC-backed build tool and I’ll show you ten lines of PHP that does a better job.

If you’re fed up of the absolute state of things, Sublime Text still works.

This is all very much in line with the post about TextEdit from a while back.

I do care who develops good software since, at the very least, I want to give them credit. This is the best I could find, if you too are curious. It was prompted by someone asking:

I’ve been a Sublime Text user for over a decade, and now a Sublime Merge user, too. But it occurs to me that I know almost nothing about the team/​company behind it.

I wonder if this is a nice example of the (quiet) posture of the company matching the (utilitarian) personality of the software it is making.

Xcode’s clever minimap

Minimaps are an interesting UI element because they often feel very exciting – something about things being small, or responsive, or maps just being cool? – but fail to actually be useful.

I find minimaps for coding particularly tricky because, at least in my world, code all looks very much the same from far away. Seeing a thumbnailed/greeked version of it felt just like a more expensive and distracting version of a regular scrollbar, without any benefits.

But Xcode does something interesting. It allows you to use MARK to create a sort of a “header” for the minimap anywhere you want:

The minimap then shows those headers not greeked, but as human-readable text:

I thought this was clever, allowing you to see the bird’s eye view of the code not just in the most obvious visual sense, but also as a sort of “table of contents,” adding so much more utility.

This, of course, is technically no longer a “zoomed out view” but then again, it’s not that there is some sort of rule that it has to be. As a matter of fact, quite the opposite; it all reminded me of the famous London subway map by Harry Beck, which also broke the expectations in a similar way.

The original, geographically accurate map of London’s tube looked like this:

Beck decided to take liberties with the geography and reimagine the map as a diagram to help the travellers, and ever since he’s done so in 1933, many transit maps followed suit:

“Every now and then some Unicode hyphen character makes its way into comments.”

Julian Fong, a software engineer at Pixar, wrote a short thread on Mastodon with an interesting take I haven’t seen before:

I still don’t use any AI code in my work, but I have to review more and more of it these days. One of the things bothering me about that these days is just how lacking in personality that code is.

RenderMan is a code base which is now over forty years old. It is a collection of idiosyncratic styles written by equally idiosyncratic people.

I’ve been in this code base for 26+ years and I can recognize the author of many chunks simply by looking at indentation, comments, or coding style. And I can often map style to personality quirks of the author.

Dan McCoy’s code for converting general polyhedra from 1990 still survives today. Probably one of the few pieces of code left that actually has a for ( ; l; l = l->next) loop for linked lists. Dan is also the only person I’ve ever seen use the abbreviation R.N.G in comments.

Tom Duff is the inventor of the Duff Device, so you can imagine what kind of code he might write. But he also left a comment in the implicit field code which was a quote from the Preface to Samuel Johnson’s Dictionary, from 1755. That’s just who he is.

(In a fit of hubris, many years later when I refactored the code, I left an answering comment which was a quote from the Preface to Noah Webster’s “An American Dictionary of the English Language. I’m not sure Tom ever noticed this.)

I was just thinking of Duff’s Device the other day!

I’ll let you read the rest on your own, but will excerpt the ending, too:

I could go on and on about all of our recognizable quirks, but living in a code base with that history is like living in a Berkeley Craftsman home. It’s old, it’s creaky, okay, it’s missing AC and you’re probably going to die when it hits 100 in the summer (which happens all too often these days), but dammit, it’s charming and it’s artsy. […]

[With Claude-generated code] there’s no typo or quirk that immediately recalls an interesting whiteboard discussion in the author’s office. It’s just code and comments repeating what the code does.

Code is art. I work at a studio full of ungodly talented artists, but I will still die on this hill. Code is often messy and dirty and it’s a pain to create and get right but the results reflect the personality of the creator and the pain of the creation. Just like the rest of art. Sometimes you have to look at the source code to see that, but it’s there if you look for it, hidden beneath the surface.

In the era of the telegraph, a century ago, you could listen to the dits and the dahs and decode the literal message, but you could also pay attention to the rhythm and the timing and the quirks of someone’s particular finger on someone’s particular Morse key – and learn to recognize not just a particular person, but also, sometimes, even their mood. There are stories of Allied spies knowing exactly which of the German operators they surveilled (but never met in person) was sending messages at a given moment, just by learning their tapping style, known as “fist.”

I found it delightful to read Fong’s stories of his coworker programming fists.

“Jokes, art projects, or cruel and unusual punishment”

A fun 19-minute video from commonLuke trying to write a short Fibonacci program in increasingly esoteric languages:

Here are the languages:

  • Python, Scratch, and assembly (as control),
  • LOLCODE, a language resembling lolcat memes of yore,
  • Piet, a language whose output looks like Piet Mondrian’s abstract art,
  • Brainfuck, whose programs are made chiefly of punctuation,
  • COW, a version of the above where each of the few instructions is a variant of “moo,”
  • Whitespace, whose code consists only of spaces, tabs, and returns,
  • Chef, where programs resemble cooking recipes.

My favourite was Shakespeare, in which the whole program resembles a play. Believe it or not, but this code outputs “HI”:

A New Beginning.

Hamlet, a literary/storage device.
Juliet, an orator.

Act I: The Only Act.

Scene I: The Prince's Speech.

[Enter Hamlet and Juliet]

Juliet: Thou art the sum of an amazing healthy honest noble peaceful
fine Lord and a lovely sweet golden summer's day. Speak your
mind!

[A pause]

Juliet: Thou art the sum of thyself and a King. Speak your mind!

Thou art the sum of an amazing healthy honest hamster and a golden
chihuahua. Speak your mind!

[Exeunt]

It was interesting for me to see programming languages that intentionally remove some of the niceties and affordances we learned to take for granted. My guess is most of them are just art, or jokes, or a certain one-upmanship. But I couldn’t help but think of Arika Okrent’s excellent book In The Land Of Invented Languages. The book is about “human” languages like Esperanto and Klingon, but it’s much more interesting than I imagined, and maybe even quite a bit sadder: a story of people afflicted with a certain perfectionism who are not willing to accept languages simply cannot be perfect.

I was wrong about Duff’s device

Duff’s device is a C language technique that looks like this:

send(to, from, count) {
register n = (count + 7) / 8;
switch (count % 8) {
case 0: do { *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
} while (--n > 0);
}
}

It achieves two things:

  • It unrolls the loop in chunks of eight. Unrolling the loop is when instead of telling the computer “do X 5 times,” you say “do X do X do X do X do X,” trading some code readability and memory usage for higher speed.
  • It cleverly (ab)uses a property of the C language to unroll the remainder of the loop, which normally would be impossible to do as the remainder is less than 8 and different every time. It does so by basically overlapping a do/while loop atop a switch/case structure in a way that should come with a coding equivalent of a parental warning.

I always assumed the technique is from the 1970s and was just a show-offy thing that didn’t serve any function, a “look how clever I am” from a programmer who was perhaps just a touch too nerdy. But yesterday, I found a 1988 message from the said programmer, Tom Duff, and it turns out I got almost everything wrong.

First of all, the technique was from 1983, when Duff was at Lucasfilm – much later than I expected.

Second of all, it actually solved a problem. Duff’s device wasn’t just making things faster abstractly, but actually fixed a user-visible performance issue. “[The loop before applying the device] was the bottleneck in a real-time animation playback program which ran too slowly by about 50%,” writes Duff.

Most importantly, however, Duff himself had mixed feelings about it:

Disgusting, no? But it compiles and runs just fine. I feel a combination of pride and revulsion at this discovery.

I recognize this set of feelings from many different software hacks I invented in my life. I think it’s important to carry them all with you – not fall in love with the hack and continue seeing it for what it is (and what it will be in the future as code ages), but at the same time not be above using it if it’s solving a real issue.

Also, Duff adds:

Many people […] have said that the worst feature of C is that switches don’t break automatically before each case label. This code forms some sort of argument in that debate, but I’m not sure whether it’s for or against.

I can’t speak for C, but I have always felt frustrated about JavaScript stealing that convention – it’s so error-prone, and in my many years programming in it, I have never had to use a Duff’s device or anything else that benefitted from it.

“Each one of these buttons has four distinct purposes.”

A nice blog post by Nathan Manceaux-Panot on Pending Design about the subtle design of the tabs underneath the search results in the programming editor Nova:

Through buttons right below its text field, the bar also lets you filter results: only show files, only show symbols, or only show symbols in current tabs. Here’s the thing, though: each one of these buttons has four distinct purposes. They’re not just for clicking.

The tabs are clickable as they normally are, but they’re also a treasure map (to tell you something is possible), a cheat sheet (to remind you how to do it again), and an onramp for faster keyboard navigation.

I’d add two more things to the celebration:

  • I myself often forget onboarding is not just about the first run, but also about reinforcement. Here, this UI does a lot of reinforcing over time, helping you build the habit. Pressing the key highlights the tab. Clicking on the tab adds a key as if you pressed it, and so does using an advanced shortcut (e.g. ⌃⌘O instead of ⇧⌘O). Even slash as a symbol comes from path names, so you might naturally associate it with files.
  • The search pop-up always has a nice contrasty appearance: dark when the background is light, or vice versa. Many modern interfaces go for white background for every UI element and surface. This seems like solely an aesthetic choice, but has more consequences when it comes to visibility of things, and even hierarchy. I am personally always excited when I see a duochrome app these days, because it feels like the team knows what they’re doing and isn’t just chasing visual trends. (Below is an example from Bear.)

“It can be really disorienting to scroll around a fully monochrome hexdump.”

A fun blog post from Alice Pellerin – if you can color code source code, why not try that for hex data?

This pairs nicely with a previous post on Unsung in that it too actively investigates what makes for useful, not just “pretty” color coding.

Raycast’s confetti cannon

Among many genuinely useful deeplinks you can use to control Raycast from afar in a simple way, I just spotted an interesting one:

raycast://confetti

This is what it does:

Despite it being a confetti cannon and nothing more, I think it goes deeper than stuff like e.g. Asana’s “celebration creatures”, and it deserves recognition for three actually kinda serious reasons:

  • You can use it to quickly test whether you’re wiring deeplinks correctly. It’s clever the Raycast team put it at the beginning of the doc page; I think every API or a complex connection method should have a simple and delightful “success scenario” for two reasons: to celebrate you establishing that connection, and to have something so simple it cannot itself be misbehaving (this way you know that if you can’t get confetti to work, you for sure messed up something elsewhere).
  • Once you know how to invoke it from far away, it’s also great for testing other things. Sounds can be muted. In JavaScript, console.log() can be too buried if you don’t have a console open or visible, and alert("Test") is kind of depressingly old-school and steals focus. This HUD-like thing feels like a modern way of approaching this: You know you’ll notice it when it fires away, and it will leave no lasting damage. (Okay, fair, it does steal focus too, so that’d be one thing to improve.)
  • It has great production value. I hate perhaps all of Google’s search easter eggs because they’re built so extremely cheaply – try searching for “do a barrel roll” or “askew” (and no, I’m not going to dignify them with links because links are my love language). It’s rare and worth celebrating when something that could very well be an internal joke or a test feature for nerds is actually something you want to use because it’s so well-made. (See also: Linear’s internal testing UI.)

“Coding typography is not like any other kind of typography.”

I was reminded of and rewatched this 43-minute 2016 talk by David Jonathan Ross with great interest:

Ross designed Input, a coding font superfamily which was very inspiring to me in the day, and taught me that coding fonts could be a place of surprising creativity and innovation.

First of all, Input has four width options: from regular through Narrow to Condensed to Compressed – this not only allows to avoid the “blocky/​squareish” nature of many coding fonts, but also, pragmatically, to squeeze in more stuff on mobile screens.

Secondly, since a lot of coding environments didn’t (and maybe still don’t) allow for fine-tuned typography settings, you can bake them into a font upon download – choose a different default line height to be there in the font itself, or have your favorite style of zero just hanging there in the default slot.

Thirdly, serif versions of Input coexist with sans serif, and so does italic, and you can mix them together.

But most important thing comes at the end: you can imagine coding in non-monospaced fonts! What seemed like blasphemy before made so much sense once I put it to use – I still code in Input Sans Narrow (non monospaced) to this day:

Of course, since the release of Input in 2014 a few other coding fonts did interesting creative things in this (mono)space. But to me this will always be the original that opened my eyes to what’s possible, and the talk captures so well a lot of deep thinking that went into the font. To quote Ross:

Type design is design and design is about solving problems.

“Christmas lights diarrhea”

I was just looking at some old 1980s screenshots and wondering “why don’t you ever see syntax highlighting in inverse video”? And then I randomly stumbled upon this deep dive into syntax highlighting from Nikita Prokopov.

I don’t know if I disagree with everything here, but there’s a lot of great stuff in there, and a lot of food for thought.

Highlighting everything is like assigning “top priority” to every task in Linear. It only works if most of the tasks have lesser priorities.

I thought the mention that comments should be visually promoted, not demoted, was particularly insightful.

Also, the idea that light themes are not popular because the colors are duller… this is very interesting. It could be so interesting to try a light theme with very prominent chiefly at the periphery of Display P3.

I have never been very invested in syntax highlighting because I find the UI to change it in text editors is usually pretty harrowing, but now I’m interested.