Live data from Hacker News

If-then-else had to be invented

github.com

181–190 of 255 posts

Re: If-then-else had to be invented

#181

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.

What is wrong with a yes response to "do you want to eat pizza or pasta?" with yes implying that one would be willing to eat either rather than requiring an exclusive preference that could be asked with "either" before pizza? Similarly with the boy or girl question, "no" may be stillborn.

> What is wrong with a yes response to "do you want to eat pizza or pasta?"

It doesn't answer the question. The questioner is asking for your help in making a decision. If you are completely neutral about the two, then most people answer with the phrase, "Either one is fine". Saying just "yes" sounds like you misunderstood the question --- unless you say it with a wry smile, showing that you mean to be funny in your answer.

(I suppose occasionally someone could ask the question with a different inflection, with the last word at a higher pitch, meaning, "Are either of these fine with you?" rather than, "Please pick one.")

> Similarly with the boy or girl question, "no" may be stillborn.

The sex is set at conception.

Re: If-then-else had to be invented

#182
post #129

Earlier quoted context omitted.

> 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".

Yes having attributes containing the union of the sets of attributes {“can read”} and {“can write”} means being in the intersection of the set of things having the attribute “can read” and that having the attribute “can write”. Set union, intersection, and membership are related that way.

(Which means saying that “and” is about intersection and not union is nonsense, everything statement about set union can be rephrased to an equivalent statement about intersection, and vice versa.)

Re: If-then-else had to be invented

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

There is some anecdotal support for the article's position in a recent [1] article about the origin of the C programming language -- apparently the C predecessor language CPL used "OR" as a keyword where most modern languages now use "else", on precisely these grammatical grounds, as understood by Christopher Strachey. [1] https://arstechnica.com/features/2020/12/a-damn-stupid-thing...

Yes, that struck me as weird too, that someone would call it incorrect. I'm a native of the United States (the Midwest). I never gave the word a second thought. I was flummoxed by Strachey's remark and flummoxed again by this article's long investigation.

Re: If-then-else had to be invented

#184

Earlier quoted context omitted.

Hmmm, thinking about my dialect of English (Lancastrian) I can certainly say else without an or and it doesn't sound unnatural to my ears. Something like "if you're hungry now then I can make you a sandwich, else we'll eat when we get to the pub" doesn't sound more awkward than using otherwise. I can't say whether that's just because the Lancastrian dialect preserves quite a few old fashioned usages that have fallen…

I think it's relatively common in british english. Certainly, from cumbria, it sounds quite natural also. It's more spoken dialect than written. "What else do you want to do?" etc.

Funnily enough, to me "what else" sounds more like "what would you like to do in addition" as opposed to "what would you like to do otherwise".

Certainly in Australia, "anything else with that" is quite common in shops, particularly in food shops, or pubs. Or at least it used to be be when I was there.

Re: If-then-else had to be invented

#185

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

Regarding 'and', it's just that the implied order of precedence is crucial to the meaning. Compare:

(I ate all the chocolate candies) and (I ate all the waffles)

I ate everything that was (chocolate candy and waffles).

In the first example, the intersection is in the set of things that happened. In the second, it is in the set of things.

It's merely a convention that "I ate all the chocolates and waffles" means the first of these while "I ate all the chocolate waffles" means the second.

This is similar to how even if means "power" unambiguously, 2 3 5 doesn't mean one thing until you put parentheses in (explicitly or by convention).

Re: If-then-else had to be invented

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

Yeah exactly, the whole premise here is not correct.

Re: If-then-else had to be invented

#187

Earlier quoted context omitted.

> "access" as a verb But is it pronounced the same way? I stress the first or the second vowel depending on the case.

That's interesting, what accent do you have? In American English I've only ever heard them pronounced the same in noun or verb form.

Check out the wikipedia page on initial-stress derived nouns. [1] It's quite illuminating!

1. https://en.wikipedia.org/wiki/Initial-stress-derived_noun

Re: If-then-else had to be invented

#188
post #166

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

I like the use of language in perl and wish it was more prevalent in other languages. For example instead of saying "if not " you can also say "unless " which is more natural imo.

Yes it's a weird feature but I found myself drawn to it. Just like with natural language, sometimes the 'unless' keyword feels like a better fit.

Both keywords work in postfix form, and this is how I usually use 'unless' so it reads more like a sentence.

  do_thing() unless ($a == 1);
  do_thing() if ($a != 1);

Re: If-then-else had to be invented

#189

Earlier quoted context omitted.

Hmmm, thinking about my dialect of English (Lancastrian) I can certainly say else without an or and it doesn't sound unnatural to my ears. Something like "if you're hungry now then I can make you a sandwich, else we'll eat when we get to the pub" doesn't sound more awkward than using otherwise. I can't say whether that's just because the Lancastrian dialect preserves quite a few old fashioned usages that have fallen…

I think it's relatively common in british english. Certainly, from cumbria, it sounds quite natural also. It's more spoken dialect than written. "What else do you want to do?" etc.

The question isn't so much whether "else" is used at all, but rather whether it's used as a conjunction. That's why the article author mentioned "or else": here "or" is the conjunction, so that proves "else" isn't fulfilling that role. In this example you gave:

> What else do you want to do?

"else" is acting like a noun rather than a conjunction (compare with "what activity do you want to do?).

Re: If-then-else had to be invented

#190

Earlier quoted context omitted.

I think it's relatively common in british english. Certainly, from cumbria, it sounds quite natural also. It's more spoken dialect than written. "What else do you want to do?" etc.

Funnily enough, to me "what else" sounds more like "what would you like to do in addition" as opposed to "what would you like to do otherwise". Certainly in Australia, "anything else with that" is quite common in shops, particularly in food shops, or pubs. Or at least it used to be be when I was there.

Sure, but if you ask for A, B and C and someone asks "what else?" then they mean "what about things that aren't A, B or C?" It's still the same basic meaning, set complement, but about things rather than logical states.
Post reply on HN