Live data from Hacker News

If-then-else had to be invented

github.com

121–130 of 255 posts

Re: If-then-else had to be invented

#121

Earlier quoted context omitted.

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.

To make things even worse, we sometimes capitalise these words to emphasise that we're using them in a technical sense, but OR reads as if it's emphasising that it's an exclusive 'or'. You can have tea OR coffee is clearly emphasising that it's an XOR operation. Somewhat related: the Ada language uses and , or , xor for its logical operators, but uses and then and or else for the short-circuit forms. [0] Not a very n…

VB.NET also uses “OrElse” and “AndAlso” for short-circuiting. VB6 didn’t support short-circuiting at all.

Re: If-then-else had to be invented

#122
post #101

> That's just English, right? Except that it isn't. I can't use "else" as a conjunction in normal speech, only in computer programs. Sure you can! Shakespeare used 'else' in the same sense as 'otherwise': https://www.shakespeareswords.com/Public/GlossaryHeadword.as... "else used as a conjunction" https://wordtype.org/of/else "Or else!" was common speech before computers, and a common vague cartoon/cowboy/sign threat.

Even if it weren’t, that just means we would have called the construct “if-then-otherwise” instead (perhaps abbreviated as othw).

Re: If-then-else had to be invented

#123

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:…

In fact, when propositional logic was first formalised [1] George Boole gave "and" and "or" the same meaning, denoted by the symbol "+".

[1]: https://t.co/nBYXLPidoS?amp=1

Re: If-then-else had to be invented

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

Except that you’d then have to make all the operators postfix to match how German puts the verbs at the end of subordinate clauses :-p

“wenn a b ==...”

Re: If-then-else had to be invented

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

"A bit"? I've never heard that usage in modern English in my entire life. It's 100% archaic, I'd say. Any teacher or writing professor would mark that as a grammar mistake, end of story.

"A bit archaic" would be like writing "threescore years ago" -- not a normal or especially accessible way of writing, but still recognized as valid grammar.

Re: If-then-else had to be invented

#127
post #52

Just one of those things that no one really questions the existence of. It, like the semicolon, always has been and will be. Good work digging through these historic esoteric languages. Wikipedia states McCarthy of Lisp fame invented it so many of the evangelists here likely know the conclusion here.

“It, like the semicolon, always has been and will be.”

Not the best of examples. It hasn’t always been. Early fortran and lisp didn’t have it. Reading https://medium.com/better-programming/a-brief-history-of-the..., it seems Algol and PL/I set the trend to make it popular.

Looking at newer languages, I also get the impression it’s on the way out. Rust has them, but python, scala, go and swift try to avoid them (https://python-reference.readthedocs.io/en/latest/docs/opera...: “Avoid having multiple statements on a single line. Though the language definition allows one to use a semi-colon to delineate statements, doing so without reason makes one’s code harder to read”, https://golang.org/doc/effective_go.html#semicolons: “Like C, Go's formal grammar uses semicolons to terminate statements, but unlike in C, those semicolons do not appear in the source. Instead the lexer uses a simple rule to insert semicolons automatically as it scans, so the input text is mostly free of them.”, https://docs.swift.org/swift-book/LanguageGuide/TheBasics.ht...: “Unlike many other languages, Swift doesn’t require you to write a semicolon (;) after each statement in your code, although you can do so if you wish. However, semicolons are required if you want to write multiple separate statements on a single line”)

Re: If-then-else had to be invented

#128

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:…

What is the name of the paper?

I really want to know too

Re: If-then-else had to be invented

#129
post #58

Earlier quoted context omitted.

How is your set union example not another intersection (your quantification could go in one of two places though, they = (set of readers) cap (set of writers) versus they = { p in people such that (p writes) cap (p reads) }.

> they can read and write Note that I’m not joining people with AND. I joined abilities. For instance, to expand on the example. I have three Pokémons. They can read and write. I’m not saying that my three Pokémon are the intersection of reading Pokémon and writing Pokémon. There might be other Pokémon who can do just the same. I’m saying that what they can do is a union of writing and reading. EDIT: spelling

But they are in the intersection of "entities that can read" with "entities that can write".

Re: If-then-else had to be invented

#130
post #101

> That's just English, right? Except that it isn't. I can't use "else" as a conjunction in normal speech, only in computer programs. Sure you can! Shakespeare used 'else' in the same sense as 'otherwise': https://www.shakespeareswords.com/Public/GlossaryHeadword.as... "else used as a conjunction" https://wordtype.org/of/else "Or else!" was common speech before computers, and a common vague cartoon/cowboy/sign threat.

I am the author, and I mean that I can say "or else" in a normal sentence, but I cannot say "else" without an "or" in normal speech in my normal dialect.
Post reply on HN