Live data from Hacker News

If-then-else had to be invented

github.com

211–220 of 255 posts

Re: If-then-else had to be invented

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

It underlies the decision tree model of computation: https://en.wikipedia.org/wiki/Decision_tree_model

Re: If-then-else had to be invented

#212
post #87

Earlier quoted context omitted.

"(Women were present) and (children were present)"

How would you distribute "Jack and Jill play together."? If you start introducing prepositions, then your theory of "and"-expansion is going to get quite complex as it covers more and more cases.

Isn't this basically proper nouns implicitly creating a set of size 1?

Re: If-then-else had to be invented

#213

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

Re: If-then-else had to be invented

#214
post #167

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.

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

Re: If-then-else had to be invented

#215
post #179
post #159

Earlier quoted context omitted.

I was a linguistics major in college and therefore am a descriptivist, not a prescriptivist about language. When I say I cannot say this, I mean that this construct does not exist in the ordinary dialect that I speak, in the same way that I can say "that doesn't need washed" even though speakers of many other dialects have to say "washing" instead. If it is in someone else's dialect, they can feel free to say it, but…

> If it is in someone else's dialect, they can feel free to say it, but my experience is that it is rare. Agreed. And this is the reason why use of 'else' in programming languages might not have had to be invented, right?

No. The article goes into great detail on this - if-else as a construct took a lot of iterations to finally appear in its current form. That fact is largely independent of how natural the word 'else' feels. If we used 'otherwise' instead of 'else', the control flow construct still wouldn't have been obvious.

Re: If-then-else had to be invented

#216
Referring to the three-way “FORTRAN” syntax, you say, “The three-way "if" was more powerful than just checking for a negative, but was probably more confusing,” this is not right. As a 15-year-old at Stuyvesant, in 1966, learning FORTRAN 4, I assure you it was the most natural thing in the world. Especially instructive was the fact that usually two of the target statement numbers would be the same. FORTRAN 4 didn’t have Boolean data types, OR, or AND and += was still in someone’s nightmare.

Note also that when Microsoft put IF( , , , ) into Excel, the most widely used computing application in the world, they essentially used this syntax.

Re: If-then-else had to be invented

#217

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. Imag…

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.

Re: If-then-else had to be invented

#218
post #179

Earlier quoted context omitted.

> If it is in someone else's dialect, they can feel free to say it, but my experience is that it is rare. Agreed. And this is the reason why use of 'else' in programming languages might not have had to be invented, right?

No. The article goes into great detail on this - if-else as a construct took a lot of iterations to finally appear in its current form. That fact is largely independent of how natural the word 'else' feels. If we used 'otherwise' instead of 'else', the control flow construct still wouldn't have been obvious.

Yes it is clear that the control flow construct was invented in this form, and that programming languages evolved. It’s still true that this use of “else” paralleled use of “else” in English, and that it’s appearance in programming languages, while interesting, is not a “mystery” or a misuse of language that was “invented” by German programmers.

Re: If-then-else had to be invented

#219
The logic of deciding on a course of action based on a single determinate decision was not a new concept.

I would think Soren Kierkegaard deserves a hat-tip to his existential work: Either/Or.

Re: If-then-else had to be invented

#220
post #134
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.

I said I can't say it, not that no one can say it. It is not in my dialect.

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...
Post reply on HN