Live data from Hacker News

If-then-else had to be invented

github.com

151–160 of 255 posts

Re: If-then-else had to be invented

#151

If the question is, what was the first programming language that introduced "If-then-else" then the read makes sense, but I'm not sure if was really an inventive step. In propositional logic, which was developed well before the first computers by Leibniz, Frege, Boole, De Morgan, etc.: "If A then B else C" can be stated as: (A --> B) ^ (¬A --> C) So, in patent/invention language, I'm not sure if it would really const…

Your formula `(A --> B) ^ (¬A --> C)` expands to `¬(A & B) & (A | ¬C)`. I would propose that `(A & B) ^ (¬A & C)`, which expands to `(¬A | B) & (A | C)`, comes closer to actual `if` semantics.

Re: If-then-else had to be invented

#152
post #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.

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

Re: If-then-else had to be invented

#153

If the question is, what was the first programming language that introduced "If-then-else" then the read makes sense, but I'm not sure if was really an inventive step. In propositional logic, which was developed well before the first computers by Leibniz, Frege, Boole, De Morgan, etc.: "If A then B else C" can be stated as: (A --> B) ^ (¬A --> C) So, in patent/invention language, I'm not sure if it would really const…

Your formula `(A --> B) ^ (¬A --> C)` expands to `¬(A & B) & (A | ¬C)`. I would propose that `(A & B) ^ (¬A & C)`, which expands to `(¬A | B) & (A | C)`, comes closer to actual `if` semantics.

They are equivalent (assuming ^ is the same as &). In particular, A --> B is equivalent to ¬A | B.

Re: If-then-else had to be invented

#155
post #119

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…

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.

Re: If-then-else had to be invented

#156

The story of development is interesting, but I doubt that the concept itself needed invention. Even in machine language using nothing but conditional branching the pattern would have appeared enough to be an idiom perhaps without a name: ... b? addr1 ...else stuff jmp addr2 addr1: ...then stuff addr2: ...always stuff What's more interesting is the generalization to any boolean expression, not the naming/placement of…

Yep. I remember naturally writing assembly like that when I was a kid. When I picked up a high level language if statements were not mind blowing, it was already what I had been doing the entire time. What did blow me away was seeing a function for the first time.

I learned on 6502 and used jsr/rts (jump-to/return-from subroutine). Recursive functions later in my learning was a mind-blowing moment, then seeing stack frames and call conventions made it less magical.

Re: If-then-else had to be invented

#157

Earlier quoted context omitted.

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…

The meaning of “and” in natural language predates the meaning of “and” used in logics and set theories. I’m not convinced that all semantics of “and” can be derived from set operations. 1) not every clause is a predicate and applying logical operators to a non-predicate makes very little sense to me. 2) I don’t see how ordering, time, and causation can be inferred, if you treat each clause as a predicate. “I punched…

I'm being a little sloppy in my language as well.

Since words and phrases necessarily occur in sequence, if you are speaking of things can be and typically are in sequence, it is natural to infer that the speaker is presenting them in the sequence of their occurrence. The speaker can do this, the speaker and the hearer both know that the speaker can do this, and it is a common understanding between the speaker and the hearer that the speaker intends the hearer to receive a particular representation of events: this is the purpose of communication. This being so, the speaker presenting events out of their temporal sequence would be perverse. If the speaker knows the hearer will assume she is presenting events in their temporal sequence, she must present them in this sequence or explain that they are not so presented. To do otherwise would be understood by the speaker and hearer as deliberate deception.

So the sequence comes not from the semantics of "and" but the pragmatics of speaking itself. In fact, you don't need "and" at all. If you leave "and" out -- asyndeton -- and list things, they will be understood to be in temporal sequence if they are the sort of thing that occur that way. "I opened the door. I went out."

All of these "meanings of and" can be explained via pragmatics and a very simple meaning of "and". The meaning I provided was intended as a hand-wavy gesture in the direction of a more formal theory.

Re: If-then-else had to be invented

#158
post #9

If/else is just as made up as for loops - it’s all if/goto underneath.

Unless you compile your program with movfuscator: https://github.com/xoreaxeaxeax/movfuscator Or you decide to execute code on The Fungus: https://www.bedroomlan.org/hardware/fungus I also recall reading a paper that got into implementing a GC on silicon for a graph rewriting based architecture WebAssembly is if/else blocks. There's a potential future where it gets implemented directly as a CPU ISA (albeit it'd likel…

> I also recall reading a paper that got into implementing a GC on silicon for a graph rewriting based architecture

Maybe this one:

https://github.com/tommythorn/Reduceron

Re: If-then-else had to be invented

#159
post #152
post #130

Earlier quoted context omitted.

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.

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…

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 my experience is that it is rare.

Re: If-then-else had to be invented

#160

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.

This may be why interrogative programming never caught on.
Post reply on HN