Aesthetics, vocabulary and the idiomatic

If you only count lines of executable code (ignoring imports, pragmas, module declarations, etc.), they’re quite comparable.

And while there are differences in style at work here, I think some differences are exactly the sort of thing I was talking about. Look at this:

Exactly the same effect, one achieved by importing the best word from a module that already defines it, one achieved by expressing the idea by building a larger expression from a more limited vocabulary. You don’t need to extrapolate anything to 10 kilo-LoC to see why one might be more compelling than the other.

Another:

One solution loads a list of tuples into a map once and uses a pre-written function to find, in constant time, the appropriate element. The other scans a list of tuples every time it needs to do a lookup, with a custom scanning function. The asymptotics probably don’t matter for this toy problem, but I know which I’d rather see in a code review.

One last example, though it’s no longer comparing the things you asked me to compare: your solution contains

The other solution inlines the lexing and the summing into the same scanl, instead of separating them out as you did, and I prefer the overall shape of your approach. But I’d have read this expression much faster if it were written

I’ll freely admit that biliftA2 isn’t a very common vocabulary word! But the nice thing about this approach is that even if you haven’t seen biliftA2 before, you can pick it up pretty easily from context, especially if you know what liftA2 does. You’re scanling a [(Int, Int)], using an initial (1, 1), and somehow addition is being invoked twice per element; shouldn’t take too many guesses to figure out what that code does, and—bonus—once you’ve done so, you’ve learned a new vocabulary word (and maybe more than one if you go look up biliftA2 and get your first introduction to Biapplicative and Bifunctor that way).


Library functions exist not just to save the programmer work, but also to save future readers of the programmer’s code from having to relearn everything from scratch. Every vocabulary word you share with another project is a concept that someone reading both projects only has to learn once instead of twice. Learn them hungrily and use them liberally!

7 Likes