Comment by krick
6 days ago
Even though the premise sounds true (kind of, sort of), everything about the post makes me question it. And it's not just that Stroustrup is among the last men I'd trust about syntax design, every example in the post just feels wrong.
Python walrus operator wasn't opposed by "teachers and beginners", because it's "harder to learn". Quite the opposite, it was opposed by purist old-timers, because for 20 years the absence of stuff like that was considered a feature and "the Python way". I don't think I pass as a beginner, but while I personally am not opposed to that operator, I totally get what's their problem with it. I think, that := is explicit enough, but addition-assignment was a native feature of most C-like languages which usage was actively discouraged by most teams, at least unless it really makes the concrete situation much more readable. Which the example in the post hardly does.
Rust ? operator isn't some example of terse Perl-like syntax, it's very intuitive and by no way it's any harder to grasp for a beginner, than the explicit match. In fact, it's probably the opposite, since it really matches the surface behavior. It only appeared after the explicit syntax, because it's really just syntactic sugar in Rust's case, and the language primitives are Ok/Err and pattern matching, not the "?" operator.
And I don't even know TLA+, but I could guess what "Good" example does, because it's basically plain English / standard math notation. The explicit "procedural" version is much less clear (mostly, because of the unfamiliar syntax).
Mainly I disliked the walrus operator because Python already has a keyword that means "capture the output of this clause into this variable": as.
E.g.,
And now: