Live data from Hacker News

If-then-else had to be invented

github.com

41–50 of 255 posts

Re: If-then-else had to be invented

#41
post #36

"Else" is not archaic. Every kid growing up in the sixties knew that the way to start a fight was to say "Or else!" It was used a lot in cowboy movies before a gunfight.

I think for these purposes, “else” is different from the “or else” construction.

As in: “Read thee the article, else thou shall suffer great ridicule in the comments.”

Re: If-then-else had to be invented

#42
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.

Perhaps the or was dropped for ease of typing, and also readability/parsing?

Re: If-then-else had to be invented

#43
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.

>How do we know whether this choice was the global optimum vs a local one?

By letting anyone free to find a better alternative. Waiting...

Re: If-then-else had to be invented

#44
post #33

I guess the unknown German word mentioned in the post is probably "sonst". It can be translated to "otherwise" or "else". And "wenn...dann...sonst" sounds perfectly natural in German.

Willing to bet it's either "sonst" or "andernfalls"... I'd suspect the latter, the former is a little bit too informal for mathematicians. Both of these are commonly used for case enumerations in math.

Re: If-then-else had to be invented

#45
post #37
post #8

Earlier quoted context omitted.

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…

I believe that sentence should read “or else he would have...” to be grammatically correct.

Perhaps by modern usage. This usage sounds fine but dated, it seems that if you substitute 'otherwise' the sentence is fine.

Re: If-then-else had to be invented

#46

I remember there was a paper that tried to compare natural language usage of common programming language keywords to see if they may come up with other constructs to create a programming language that is easier to learn as your first one. There were a few interesting observations. The one that stuck with me the most is that 'and' is most commonly used with almost the opposite sense in natural language vs programming:…

Great observations. In the same idea, "or" is inclusive in all of programming and CS, i.e. A and B => A or B, but in natural languages (as least the ones I know) "or" is almost always exclusive, i.e "do you want to eat pizza or pasta?" does not imply that eating both is an option.

This is of course related to why the famous joke "Is it a boy or a girl? Yes." is so hilarious.

Re: If-then-else had to be invented

#47

I remember there was a paper that tried to compare natural language usage of common programming language keywords to see if they may come up with other constructs to create a programming language that is easier to learn as your first one. There were a few interesting observations. The one that stuck with me the most is that 'and' is most commonly used with almost the opposite sense in natural language vs programming:…

The word “and” in English is simply there to join multiple clauses together. Whether it is a set union or set intersection, (or some other relations) depends on the sentence.

Set union: they can read and write’

Set intersection: my jeans were creased and dirty

Sequential: he turned round and walked out

Causal: there was a flash flood and by the next morning the town was under water’

And, there are many more usages.

Re: If-then-else had to be invented

#48
post #5

Ah, interesting, I wish the title had been prefixed with "What if ". There's a language where THEN basically means ENDIF... Forth, if memory serves me right?

Yes. It is used in the sense of the English statement:

IF you go to the store get some butter THEN come right back.

So THEN is where the program continues on a false condition. Typically Forth. It uses an alternative way of looking at things.

Re: If-then-else had to be invented

#49
post #45
post #37

Earlier quoted context omitted.

I believe that sentence should read “or else he would have...” to be grammatically correct.

Perhaps by modern usage. This usage sounds fine but dated, it seems that if you substitute 'otherwise' the sentence is fine.

The article acknowledges that.

Re: If-then-else had to be invented

#50
post #27

Earlier quoted context omitted.

In colloquial english we usually put an "or" in front of else. It really breaks down when you put it in boolean form because the "or" implies other actions when true rather than actions if false. Removing the "or" completely is unambiguous but is antiquated English. Examples: "Go to college or else work for your uncle" Turn this into boolean form: "If you go to college then or else you will work for your uncle" But t…

> But the "or" makes the meaning ambiguous I disagree that or is ambiguous. In English we use or to mean xor, that is one item or the other item but not both. If we want to clarify that choosing both items is an option we use the term and/or.

> I disagree that or is ambiguous

There are examples of inclusive “or” in natural language. When the waiter asks: “Would you like cream or sugar?”, it’s not meant to imply that you should pick only one; it’s fine to answer “both” (example from: https://divisbyzero.com/2009/09/27/is-or-an-inclusive-or-or-... ).

Post reply on HN