Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This reminds me of a note in FreeBSD rc(1) man page[0] under "INCOMPATIBILITIES"

> The Tenth Edition rc does not have the else keyword. Instead, if is

> optionally followed by an if not clause which is executed if the pre-

> ceding if test does not succeed.

which i found pretty interesting

[0]: https://www.freebsd.org/cgi/man.cgi?query=rc



Having taught programming to novices a little, I believe “if not” is clearer than “else”. Imagining “not” being prepended to the original conditional expression would be natural, especially in languages with “not X” construct (like Python), and it’s easy to forget that “else” is in fact archaic to non-programmer ears, slightly and possibly needlessly raising the barrier.

    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.


What if there were 3 cases though? "Else" should exclude both of the preceding cases, but the phrasing of "If not" seems to imply it would only exclude the previous case


True!

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.


I wonder whether anyone has used "otherwise" for this. It'd be a simple alias for "else", but it'd certainly sound natural:

    if (X) { doY(); }
    otherwise { doZ(); }


Towards the bottom of the article there is a example of MAD[0] that uses something similar, and there is also the John McCarthy proposal which also uses otherwise. I could imagine it being used in a language that had a tight connection to maths as otherwise is often used there.

[0]: https://en.wikipedia.org/wiki/MAD_(programming_language)


Oh, right, the article...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: