Live data from Hacker News

If-then-else had to be invented

github.com

11–20 of 255 posts

Re: If-then-else had to be invented

#11
post #4

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.

Re: If-then-else had to be invented

#12
It begs the question: did we search and find the answer of if-then-else, or did we find an answer that was sufficiently likeable and usable- but one of many possibilities? How do we know whether this choice was the global optimum vs a local one?

Is if-then-else the electron- a deep truth waiting to be discovered- or the gasoline powered car- an option we explored for decades among others options.

Re: If-then-else had to be invented

#13
post #4

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 */ {…

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

Re: If-then-else had to be invented

#14

If/else is just as made up as for loops - it’s all if/goto underneath.

Pretty sure at least 90% of the readers here know that, but still appreciate the convenience of higher-level language constructs. That's why they're called "higher-level" after all. BTW, it's not entirely correct that it's all if/goto. ARM has conditional execution that doesn't necessarily involve a jump, and there have been other exceptions as well.

x86 has CMOV, for Conditional MOVe, since the Pentium Pro, and of course there are tricks employed by compilers and low-level programmers to avoid the overhead of branches, like the `a = cond·b + !cond·c` idiom.

Re: If-then-else had to be invented

#15
post #12

It begs the question: did we search and find the answer of if-then-else, or did we find an answer that was sufficiently likeable and usable- but one of many possibilities? How do we know whether this choice was the global optimum vs a local one? Is if-then-else the electron- a deep truth waiting to be discovered- or the gasoline powered car- an option we explored for decades among others options.

Is pattern matching a generalization of if/then/else, a reframing of it, or something else entirely?

Re: If-then-else had to be invented

#16
post #6

You can use "else" that way in ordinary speech. "If this then do that else do the other thing" is perfectly legitimate English, just a bit archaic.

And “or else” has long been perfectly normal (“if a then do b, or else do c”).

See also “elsewise”, equivalent to “otherwise”; use in this construct “if a, b; elsewise, c” is a good deal rarer.

I would commonly speak sentences like “I was not hungry; else would I have eaten it” among family and friends, but not typically among the general public. It definitely feels a tad archaic, or at least highfalutin.

Re: If-then-else had to be invented

#17

This is fascinating! I started with BBC Basic II (on the Model B) which had IF..THEN but it was just one line and there was no ELSE. So if you wanted to make a 'block' you had to call a different PROC (thankfully there were PROCedures so you could avoid GOTO) As such when I was introduced to ELSE and ENDIF with BBC BASIC V on the Archimedes it seemed like very welcome syntactic sugar - it let you do the same stuff bu…

BBC Basic II does have ELSE, it just has to go on one line.

IF A=4 THEN PRINT "FOUR" ELSE PRINT "NOT FOUR"

Statements for the IF block and the ELSE block can be separated by ':'.

I was recently given a BBC Micro and it's a fascinatingly impressive machine, the hardware and software are so beautifully designed in tandem that it's quite awesome even in 2020.

Re: If-then-else had to be invented

#19
post #12

It begs the question: did we search and find the answer of if-then-else, or did we find an answer that was sufficiently likeable and usable- but one of many possibilities? How do we know whether this choice was the global optimum vs a local one? Is if-then-else the electron- a deep truth waiting to be discovered- or the gasoline powered car- an option we explored for decades among others options.

Is pattern matching a generalization of if/then/else, a reframing of it, or something else entirely?

I see it as a cross between a switch and if statement. You’re saying based on what `x` is (a switch), do these things that a switch can’t do (an if).

Re: If-then-else had to be invented

#20
post #8
post #6

You can use "else" that way in ordinary speech. "If this then do that else do the other thing" is perfectly legitimate English, just a bit archaic.

Wiktionary has a usage example from 1903, clearly before modern computers but not too ancient. > 1903, Jack London, The Call of the Wild, Grosset & Dunlap, page 44: > […] and his first experience taught him an unforgetable lesson. It is true, it was a vicarious experience, else he would not have lived to profit by it. As an aside there is at least one common word which does seem to have been invented by the software…

> “... one common word which does seem to have been invented by the software industry: "access" as a verb”

Really? That’s surprising because the French and Spanish equivalent verb (accéder / acceder) is common and has multiple meanings such as “reaching a peak”. I would have imagined this word transferred over in the Norman days.

Post reply on HN