Readit News logoReadit News
tsimionescu · 5 years ago
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: more precisely, in natural language, 'and' usually implies set union, which is more similar to boolean Or. For example, 'women and children' means of course 'if X is a woman OR X is a child'.

The other interesting observation was that in natural language we usually describe operations on sets as taking the whole set as an argument, not in terms of what happens with each individual member. For example, it's more likely you'll say something like 'give candy to these kids' or 'wash these cars' than 'give a piece of candy to each kid' or 'wash each of these cars'. Of course, index based loops are essentially never used in common language, but even the common loop comprehensions that introduce a loop variable are quite far from natural language.

powersnail · 5 years ago
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.

chalst · 5 years ago
This is correct. The technical word linguists use for the role words like "and" play is coordination.

https://en.wikipedia.org/wiki/Coordination_(linguistics)

DFHippie · 5 years ago
I would say that in every case there is a set of things (maybe with a single member) and a set of predicates (maybe with a single member), a mapping from the things to the predicates, and every mapping produces a true proposition.

"Women and children were present" isn't saying the intersection of the women and children were present but that the things were women and children and they all were present.

The rest of the variety of "meanings" of "and" are just inferences on top of this basic meaning. If things occur in sequence, for instance, we can infer causality from what we know about the things conjoined apart from the conjunction.

Crucially, there is more here than just "joining multiple clauses together" (and many of the things conjoined aren't clauses), because "or" can be described this way too, but "and" does not mean the same thing as "or". With "or" you are only asserting that some of the propositions are true.

linuxrebe1 · 5 years ago
Short would be, 'and' implies, coincidence, not causality. 'Or' implies choice. If-then implies causality ("If my pants are dirty, then they need to be cleaned")

The big difference I see is with 'OR' in programing the options are exclusive. Ex: "Are you tired or hungry" The answer is yes if you are tired. Yes if you are hungry, Yes if you are both. No if you are neither. This is natural English. In programming if you are both. The answer is No.(False)

tel · 5 years ago
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) }.
phkahler · 5 years ago
>> Set union: they can read and write’

>> Set intersection: my jeans were creased and dirty

IMHO those are both unions. One describes two capabilities people have while the other describes two conditions some clothing has.

They both become intersection when using the pair of conditions as selection or decision criteria.

It's the difference between an assertion and a question.

_emacsomancer_ · 5 years ago
To join like constituents, not just clauses, as per your examples.
Toenex · 5 years ago
It's surprising how often you can replace 'but' with 'and' in a sentence.
fouronnes3 · 5 years ago
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.

csicseri · 5 years ago
If you say it out loud, you will realize that the question "Do you want to eat pizza or pasta?" (exclusive-or case with the answer "pizza" or "pasta," i.e. in the sense "these are your two choices, which would you prefer?") is an entirely different utterance from "Do you want to eat pizza or pasta?" (inclusive-or case with the answer "yes" or "no," i.e. in the sense "would you like to go to an Italian restaurant?"). The first case is pronounced with primary stress on the first syllables of both "pizza" and "pasta," and with a high tone on "pizza" and a low tone on "pasta," indicating a contrast between the two alternatives. The second case is pronounced with primary stress on the first syllable of "pizza," secondary stress on the first syllable of "pasta," and a uniform tone over the phrase "pizza or pasta" on which is superimposed the rising tone on the last syllable of the sentence indicating a yes/no question. (To see that the latter is true, add "tonight" to the yes/no sentence - "would you like to eat pizza or pasta tonight?" The tone does not rise until the syllable "night.")

You have to be very careful in reasoning about natural language based solely on the written record, since spoken language regularly includes features, such as the suprasegmentals (stress and intonation) in the above examples, that aren't recorded in the orthography.

MaxBarraclough · 5 years ago
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 natural solution in my opinion.

[0] https://en.wikibooks.org/wiki/Ada_Programming/Operators#Shor...

gpderetta · 5 years ago
Latin has both in inclusive ('vel') and exclusive ('aut') or.
hutzlibu · 5 years ago
"This is of course related to why the famous joke "Is it a boy or a girl? Yes." is so hilarious"

Only to IT people though. Common folks will just look at you in a weird way...

etripe · 5 years ago
It can also be used as the equivalent to a try/catch statement in most Germanic languages (including English, though Ingveonic, really) when ending a sentence with it.

"Do you like pizza, or?"

Depending on the exact statement, you might catch more or less flak.

cgriswald · 5 years ago
> "or" is almost always exclusive, i.e "do you want to eat pizza or pasta?" does not imply that eating both is an option.

English is way too ambiguous for this example and often relies heavily on context. Wanting to eat pizza does not preclude also wanting to eat pasta. If it was exclusive or, and you wanted to eat both pizza and pasta, the honest answer to this question would be "no," but what you should say is "yes."

potiuper · 5 years ago
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.
u801e · 5 years ago
One way to make the or inclusive is to use the construct and/or.
nmg · 5 years ago
This may be why interrogative programming never caught on.
lou1306 · 5 years ago
> For example, it's more likely you'll say something like 'give candy to these kids' or 'wash these cars'

That's one of the reasons I like functional programming. In ML-style languages you have something like `Set.map giveCandy kids`, which is both concise and close to natural language.

Comprehensions are also cool in my book, because they're very close to set-builder notation.

zodiac · 5 years ago
> in natural language, 'and' usually implies set union

well, sometimes it can be syntactically ambiguous too, right?

e.g. "I welcome big and small dogs" vs "I welcome well-behaved and properly groomed dogs"

ilyagr · 5 years ago
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).

m463 · 5 years ago
I like the use of language in perl and wish it was more prevalent in other languages.

For example instead of saying "if not <condition>" you can also say "unless <condition>" which is more natural imo.

hnick · 5 years ago
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);

Can_Not · 5 years ago
This is valid in crystal:

    unless a
        a = 4
    end
    return x unless y
    return z

SilasX · 5 years ago
> For example, it's more likely you'll say something like 'give candy to these kids' or 'wash these cars' than 'give a piece of candy to each kid' or 'wash each of these cars.

True but for more complex instructions, it’s common to say “do these things for that kid, then do that for all the kids”, which is pretty much a for loop. I can’t speak to how common this was in lay speech before programming was common though.

(There was an earlier thread about this but algolia’s search UI suddenly became a pain to use on mobile and it’s too tedious to find.)

proverbialbunny · 5 years ago
>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.

Wasn't that the goal of Perl? It was inspired from natural language first, not inspired from another programming language first. This is why it's so quick and easy to prototype in it, arguably far easier than any other language. I believe it is the only programming language to be inspired from natural language first.

wildmanx · 5 years ago
This use of "and" and "or" was inherited from mathematical logic though. It's not specific to programming languages.
alentist · 5 years ago
What you're describing seems to come down to the identity

(((w ∨ c) → a) ↔ ((w → a) ∧ (c → a)))

That is, an implication whose antecedent is a disjunction is a conjunction of implications. On the other hand,

((a → (w ∨ c)) ↔ ((a → w) ∨ (a → c)))

That is, an implication whose consequent is a disjunction is a disjunction of implications.

laumars · 5 years ago
Interestingly your index based loop example is the opposite of how shell scripting works. That is a lot more like a human language in its construct:

   candy | kids
Where candy and kids are self contained programs that already understand the operations which make up candy and kids.

still_grokking · 5 years ago
> it's more likely you'll say something like 'give candy to these kids' or 'wash these cars' than 'give a piece of candy to each kid' or 'wash each of these cars'.

Reminds me of APL.

But I'm not sure APL can be considered being close to natural language.

thomasahle · 5 years ago
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

gallerdude · 5 years ago
What is the name of the paper?
abhinav22 · 5 years ago
I really want to know too
yiyus · 5 years ago
> we usually describe operations on sets as taking the whole set as an argument, not in terms of what happens with each individual member.

That's something that array languages did right.

k__ · 5 years ago
"we usually describe operations on sets as taking the whole set as an argument, not in terms of what happens with each individual member"

Doesn't R do it like that too?

gnramires · 5 years ago
There's javascript's foreach, which also gives an optional index. Indices are important to uniquely identify members in case you want non-uniform behavior: for example, "give 3 kinds of candy alternatingly"; element variables in turn are important for behavior that's a function of the member, say when you want to "give candy in proportion to their age".
dragonwriter · 5 years ago
> For example, 'women and children' means of course 'if X is a woman OR X is a child'.

Well, no, “women and children” alone doesn't mean that, “if X is a member of women and children” means “if X is in women OR X is in children”.

But that's consistent with AND and OR as boolean operators in programming (it's inconsistent with the way &-and-| symbols are used as set operators in some programming languages, though; ∪ and ∩ would be better, but aren't in ASCII.)

dahart · 5 years ago
> 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.

reidacdc · 5 years ago
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...

combatentropy · 5 years ago
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.
enf · 5 years ago
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.
memetherapy · 5 years ago
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 out of use in "standard" (i.e. southern posh) British English and American English, whether it's common usage in other dialects of British English, or if its just because I'm a programmer. Going to go ask some English teachers!
dahart · 5 years ago
You’ve framed it in the article and here again as a correctness issue, but it’s not a correctness issue. It’s fair to say you haven’t heard it, or that it’s uncommon today, but if you use it, it’s not wrong. And people will understand you, even if you do get a sideways glance from some people. You can use “else” without “or”, if you like.

The article was fascinating, especially the historical examples from different programming languages, and I buy the plausibility of a German speaker using “else” this way... I work with German speakers and they do it all the time. From the small amount of German I know, it feels like there might be some parallel with “als”. Another common one they use that’s less common with English speakers is starting a sentence with “Means”, as opposed to “It means” or “That means”. It’s not incorrect, but it does sound different.

I just don’t think the German speaker explanation is the only possible one, because there absolutely is precedence for the English use of ‘else’ as a conjunction. Usage of ‘else’ with ‘or’ also makes some plausible sense here too...

armada651 · 5 years ago
Wouldn't it be fair to say that it's just a shortened version of "or else"? Just like most programming languages skip "then" in "if ... then" even though it's often required for the sentence to look natural.
echlebek · 5 years ago
Maybe not in your dialect of English, but what about older dialects?

"Pay for your beer. Else, leave this place at once!"

chx · 5 years ago
Fascinating. English is not my first language but I thought https://en.wiktionary.org/wiki/what_else_is_new and https://www.ldoceonline.com/dictionary/what-else-can-somebod... are perfectly fine phrases.
SilasX · 5 years ago
Even if it weren’t, that just means we would have called the construct “if-then-otherwise” instead (perhaps abbreviated as othw).
mlyle · 5 years ago
Yup, it grated on me to read that at the beginning.

Though: else as a conjunction isn't quite archaic today. But, it is one of those usages that when I encounter it, I begin to suspect that the document I'm reading is rather old.

Dead Comment

wozer · 5 years ago
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.
formerly_proven · 5 years ago
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.
BlackFingolfin · 5 years ago
As a research mathematician, I happily use "sonst" in e.g. case distinctions (well, in my undergrad lecture notes; papers are written in English ) and wouldn't use "andernfalls" as it is simply too long :-). Moreover, if they had looked up "andernfalls" in a dictionary, they would have found "otherwise" as translation. For "sonst", the number 1 translation in all dictionaries I have around or found online, is "else".

So I firmly believe they used "sonst".

wozer · 5 years ago
Maybe. On the other hand, "andernfalls" is a bit long as a keyword.
SilasX · 5 years ago
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 ==...”

Tainnor · 5 years ago
ah but it's more complicated because only the main verb is at the end of the sentence, so if you need an auxiliary or you have a copular construction like "ist gleich", you need to split the verb phrase...

in fact, Germans would say (and do say, e.g. in mathematics) "wenn a gleich b" as a shorthand for "wenn a gleich b ist".

enf · 5 years ago
Thanks for the insider German knowledge!
kens · 5 years ago
That's an interesting and well-researched article. I'd like to put if-then-else in the bigger historical context of "structured programming".

In the late 1960s and early 1970s, it was a big debate if programmers should use structured programming, building programs out of blocks with control structures such as iteration and conditionals. (Earlier programs were built from ad hoc control using goto.) This is the context of Dijkstra's famous "Go To Statement Considered Harmful.

Although structured programming seems obvious now, there was a lot of resistance. At first, people weren't even sure if structured programming could implement all the required control flows, so someone (Böhm–Jacopini) had to prove the "structured program theorem". Languages needed to be modified to support structured programming, e.g. adding block if-else to Fortran 77.

I have to wonder what modern programming debates will seem as obvious in retrospect as the victory of structured programming.

ilaksh · 5 years ago
Maybe almost every major advance.

Personally I think it's just that most people are not good at adapting to new contexts that evolve. And people are not really evaluating things rationally. For example, in the beginning those types of programming languages were completely infeasible to implement due to hardware constraints. So people were not used to them. That created a type of prejudice.

Another example. Look at CISC versus RISC. When the context is raw machine code or assembly language, you absolutely want more complex instructions because otherwise programmers are going to a competitor that provides them.

But then when you have high-level languages that part of the equation changes and reducing instructions gives other advantages.

Neural networks might be another example of an advance that was shunned initially.

Hizonner · 5 years ago
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.
shawnz · 5 years ago
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 industry: "access" as a verb

kibwen · 5 years ago
> "access" as a verb

The comic Calvin & Hobbes corroborates the novelty of this verb in this strip from 1993: https://www.gocomics.com/calvinandhobbes/1993/01/25

pavlov · 5 years ago
> “... 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.

enriquto · 5 years ago
> "access" as a verb

But is it pronounced the same way? I stress the first or the second vowel depending on the case.

jiofih · 5 years ago
I believe that sentence should read “or else he would have...” to be grammatically correct.
maire · 5 years ago
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 <foo> or else you will work for your uncle"

But the "or" makes the meaning ambiguous: "If it rains then I will work inside or else I will work outside."

It is not clear if this means you will work outside if and only if it is not raining? Maybe working outside is another option if it rains.

Otherwise is far more clear. "If it rains then I will work inside otherwise I will work outside."

Removing the "or" completely makes the statements unambiguous archaic English: "If you go to college then <foo> else you will work for your uncle" "If it rains then I will work inside else I will work outside."

FWIW - I am very glad they chose else over otherwise...

asciimov · 5 years ago
> 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.

darkerside · 5 years ago
The human language leaves the decision to the executor, dependency injecting an if/else framework into the entity making the decision.
chrismorgan · 5 years ago
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.

JoBrad · 5 years ago
Perhaps the or was dropped for ease of typing, and also readability/parsing?
macintux · 5 years ago
I'm inclined to suspect that someone who lived during this era had a pretty good sense of how ordinary "else" was at the time.

I would not be surprised to learn that "else" is more common now thanks to programming languages.

> Christopher Strachey's CPL programming language is the grandparent of C and therefore the ancestor of most current programming languages, and he refused to use "else," calling it "ignorantly incorrect English."

Given how hard it seemed everyone who designed languages tried to avoid using the word, it would seem Strachey's view was not uncommon.

Blikkentrekker · 5 years ago
It does not even register as “archaic” to me.

Methinks it's rather ordinary.

codeulike · 5 years ago
Indeed it would behoof us not to assay to declare words archaic ere their time
crazygringo · 5 years ago
"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.

enf · 5 years ago
I said I can't say it, not that no one can say it. It is not in my dialect.
dahart · 5 years ago
I really liked your article, and the evolution of this syntax is historically interesting. But, your article did quite clearly claim that this use of 'else' is not English. You claimed 'else' is not a conjuction, and you called it a 'mystery' why it ended up in a computer programming language. I'm fine with, and actually I support the idea of being descriptivist about language rather that prescriptivist. But your comment here does unambiguously contradict what you wrote in the article...
troelsSteegin · 5 years ago
The co-authors of the ENIAC paper are Haskell Curry [0] and Willa Wyatt. Curry is well known. Wyatt (Willa Wyatt Sigmund), along with other women who worked on ENIAC, is remembered here [1]

[0] https://en.wikipedia.org/wiki/Haskell_Curry [1] http://athena.union.edu/~hemmendd/Courses/cs80/eniac-women.p...

brandmeyer · 5 years ago
Chinese also has an interesting sentence structure that doesn't quite fit with European languages. In addition to subject.verb(object) form, there is also a kind of topic-comment form that might be reasonable to use in some assertion-like contexts.

    ensure(foo), !empty()
    require(bar), open()
Chinese also has a word that can transform some kinds of statements into a question. `ma` is used to form yes-no questions. Imagine if languages with truthy values required you to use an explicit keyword/character in postfix position to take a non-boolean value and use it in boolean context.

    if predicate:
        pass

    if non_predicate ma:
        pass

To be clear, I'm not actually advocating for such constructs. The topic-comment form breaks down as soon as you want a predicate on multiple objects. The automatic truthy values concept is already falling out of favor in preference for explicit predicates like file_handle.is_open(). I don't actually want to program in "Cobol, but Chinese". But it is interesting to explore the space.

Tyr42 · 5 years ago
If you want to go further, it sometimes feels like the "who what where" pronouns are like sql prepared statements.

In English, we have question and answer

Q: Where do you want to go for lunch?

A: I want to go to that pub for lunch.

In Chinese you'd say

Q: You want to go to ?? pub for lunch?

A: I want to go to that pub for lunch.

It even works for numbers, like

Q: It is ?? o'clock?

A: It is 7 o'clock.

henrikeh · 5 years ago
Bulgarian also has a question particle (li or ли). In many cases questions are phrased by simply inserting “li” next to the focus of the question.
wycy · 5 years ago
Semi-related: Fortran has a where() and elsewhere() statement for applying a mask to part of an array. e.g.,

    where (C/=0)
        A = B/C
    elsewhere
        A = 0.0
    end
It blew my mind the first time I saw it. I’d never seen else in anything but an if statement before.

Izkata · 5 years ago
Feels like a good place to drop this for anyone who hasn't encountered it: python's loops have an "else"

https://stackoverflow.com/questions/9979970/why-does-python-...