Crosscut

Daily Thought - 2024-05-07

Hey, I'm Hanno! These are my daily thoughts on Crosscut, the programming language I'm creating. If you have any questions, comments, or feedback, please get in touch!

This thought was published before Crosscut was called Crosscut! If it refers to "Caterpillar", that is the old name, just so you know.

< back to list

Yesterday, I talked about how prefix operators can cause a mismatch between reading order and evaluation order. Today, I'd like to look at how other programming languages address this problem by using postfix operators, or at least constructs that have some postfix-like qualities to them.

Let's start with something that we might see in JavaScript: const c = (await (await a()).b()).c();. Here we're dealing with multiple chained promises, but of course we shouldn't write it this way. We could use then instead:

const c = a()
    .then((a) => a.b())
    .then((b) => b.c());

Much nicer to read, and while then isn't quite a postfix operator, there's some postfix-ness in there! And of course, the Rust developers presumably studied this and decided to avoid the whole thing, by making their .await a postfix keyword (there's also ?). I think this shows that postfix operators have some nice properties, that even established languages want to benefit from.

<< previous thoughtnext thought >>

Hey, you! Want to subscribe to my daily thoughts? Just let me know (maybe include a nice message, if you're up for it), and I'll send you an email whenever I post a new one.