"Mental friction": my view on why D rox

Posted 2021-02-08

Core D Development Statistics

In the community

Community announcements

See more at the announce forum.

Adam's thoughts on mental friction

People often ask "what is D's killer feature?" and that's difficult to answer because the real benefit is a couple big things sure, but mostly a lot of little things that cut down what I call mental friction.

Regular friction is a force that works against ongoing movement when two surfaces are in contact with each other. Any sliding or rolling object will eventually come to a stop without more energy input.

I somewhat prefer to use the analogy of a headwind when bicycling. In contrast to a hill, there you can see there's a summit and just push a little harder to get over it and know the pain will end, with a headwind, it just constantly drains you and the harder you push against it the harder it pushes back, but the difference between a headwind and friction is you can change direction and turn it into a helpful tailwind, whereas friction will change direction with you and never be helpful.

(ok friction is certainly helpful when you WANT to stop! Brakes are good.)

Anyway, the key idea is that this isn't like slamming into a wall. You aren't stopped by it. You might not even be slowed by it... you've just gotta put in a little more constant energy to maintain your velocity and it can be reduced, but never eliminated.

Mental friction is what I call this same idea inside your brain. A bunch of little annoyances or thought/code mismatches that never stop you, but take just a bit of constant effort to keep going. Like with regular friction, this extra energy just goes to heat rather than useful work. Most the times, this heat dissipates harmlessly, but a mental overheat makes you frustrated and angry which can be a real productivity killer.

Sometimes, it is a requirement by the language to type. This analogy first came to my mind around 2006 when I was coding PHP on a keyboard with a finicky $ key. Every other second I had to hit the $ thing and 10% of the time it wouldn't register and I'd have to do it again just because the language required the annoying sigil on common variables.

That didn't objectively slow me down or lead to more bugs in the final code, but it still drove me nuts!

However, it is a mistake to think all typing is mental friction or vice versa. Some instances are due to paradigm mismatches. This, of course, could be more akin to the headwind, where if you change direction to align with you it can help. But I tend to just find it annoying when I think of one thing then have to translate it to something else just because a language was too opinionated to let me work.

Sometimes it is speed. When compiling, even a small wait of a second or two - while objectively no big deal - is a constant annoyance that irks me. Mental friction since now the computer feels like it is getting in the way every time I want to see something instead of working with me.

And sometimes it is when things try to be helpful but don't really succeed. Going back to typing, I hate IDEs that insert matching parens automatically and then I end up backspacing.

Language features can do this too. I get annoyed every time I do byte a; a = -a; and dmd complains. It isn't a huge deal, and I get what it is trying to do, but it doesn't actually do useful work, it is just frustration-causing mental friction.

But overall, D excels at minimizing mental friction. Since the language itself is quite flexible, it can meet you where you are. You can just write what comes to mind and it usually works. There are some exceptions, of course, but I rarely feel like I'm fighting the language. And that's ultimately why I like it - even when things take a little longer, it generates less heat so I leave it feeling better.