by goblin89 · 5y ago · 0 comments
if (X) { doY(); }
if not /* X is implied */ { doZ(); }
In languages like Python it could be generalized to enable one to use “if not” with an expression as usual but omit the expression if it is the last branch of a conditional, thus getting rid of the “else” keyword while maintaining or arguably improving readability.That said, there is no programming language that could entirely map to a spoken one, so perhaps it’s actually beneficial to shed any semblance of such mapping early-doors in the learning process.
A point could be made for restricting ifs to 1 or 2 clauses and delegating more complex conditions to switch/case, but that is arguably even more far out there (and in case of Python it actually doesn’t have the switch operator). Also, “if not X {…} if not {…}” would be confusing but possible.
I guess I should leave language design to the better-equipped for the time being.
if (X) { doY(); }
otherwise { doZ(); }[0]: https://en.wikipedia.org/wiki/MAD_(programming_language)