Daily Thought - 2024-05-06
< back to listI explained why I like postfix operators, and why I think infix operators aren't an option for Caterpillar. But if I want to restrict Caterpillar to one kind of operator, I could use prefix operators, right? They are just as universal as postfix operators, and much more common. All true, but I think in a direct comparison, postfix operators win.
My main gripe with prefix operators, is that they cause a mismatch between the
order of operations as they are written down, and as they actually happen.
Consider something like work_with_thing(configure_thing(construct_thing()))
.
When reading this, you have to mentally evaluate it from the inside out.
And yes, you could use variables to store intermediate results, splitting this confusing expression over multiple lines, thereby fixing the mismatch. But you can also use variables with postfix operators, where they make things more clear. In cases where variables don't make things more clear, prefix operators end up more verbose.