if-then-else someone had to invent

Hi, today we are going to discuss a seemingly absurd idea: if-then-else someone had to invent.

If-then-else are conditional constructs in programming languages: if (if) something is true, then (then) perform one action, otherwise (else) perform another action.

It’s just English, isn’t it? Not really.

In ordinary speech in English, you cannot use “else” as a union, this word is used this way only in computer programs.

Where did it come from else? This is a mystery. Such a microscopic detail that it did not make it into the books on the history of programming languages.

It doesn’t seem to have come from reports, legal proceedings, or algorithms that were written before computers existed. These texts contain “if yes”, “if no” and “if however”, but not “else”.

It seems that the first computer capable of executing various commands depending on previous calculations was ENIAC. In 1946, Haskell Curry and Willa Wyatt wrote a report describing a program that inverts a function. They used the name “discrimination” for a construct that decides on which of the two numbers is greater.

ENIAC did not have a team called “discriminate”. It was programmed with wires and knobs on the patch panel, and the control panel of the command performing the calculation to make the decision was physically wired to the commands that were to follow.

Soon computers had enough memory so that programs could be stored in it, rather than connected by wires. Instead of a physical sequence of commands, there was a numerical one. Several special commands could tell the computer to go to another point in the sequence.

Here is an example of a conditional jump instruction from one of the first commercially available computers. It checks if the last calculated value was negative. If so, then it redirected the control flow to a specific place in memory, otherwise, it proceeded to the next command.

It was intended for a specific application pattern: if it was necessary to complete a task, say, 10 times, then the program counted how many times it had already been executed, and then subtracted 10. If the result was negative, it means that the task has not been completed yet, and the transition to one more repeat.

This idea was carried over to the first high-level programming languages, such as Halcombe Laning and Neil Zierler’s for the Whirlwind computer. Its conditional branch worked in a similar way, only the number of program cycles was algebraic calculations, not single machine instructions.

The first common programming language, Fortran, popularized the idea of ​​specifying transitions to three places at the same time, depending on the result of the calculation: zero, positive or negative. In Fortran, this construction is called “if”.

The triple “if” was more powerful than a simple negative test, but it was also more confusing, because each decision implied a break in the control flow, and previously programmers only had to think about the normal thread that continued the program execution, and the unusual one that executed transition.

The Flow-Matic language, developed by Grace Murray Hopper before Cobol, slightly simplified the perception of the triple if: now, not the signs of numbers, but two numbers were compared. The name “otherwise” appeared in it for the case when the result of comparison is not equal to what we are looking for.

Each of these programming languages ​​was associated with a specific computer from a specific manufacturer. In 1958, two American and two German computer organizations launched a joint project to develop a standard machine-independent language that would be convenient for people to discuss. Each of the groups brought their own draft proposal to the joint conference.

The German authors took two big conceptual steps in formulating the “if” construct.

First, in their project, the conditional operator was controlled by any boolean expression, and did not give special priority to the less / equal / greater than type.

The second big step was that instead of performing an abrupt transition in the control flow, their “if” construct only caused a temporary flow deflection. At the end of the conditional construction, regardless of whether the condition is true or false, the program continued to work with the “always” construction at the end of the block. The only difference was whether additional constructs were performed.

The example above shows two “if” s in one block; we can assume that the second one should work like a modern “else if”. But in fact, the program expects to evaluate all conditions, even if the first turned out to be true. Therefore, if the constructs controlled by the first if change the value on which the second comparison depends, then both blocks of constructs can be executed.

The German sentence also contained something like “else”, but in a completely different, conditional form, called “case”. Unlike the modern “case”, their “case” was another way of writing boolean conditions, in which the conditions were separated into a separate block from the constructs they controlled. It looks like the developers thought this view would be easier for more complex comparisons.

And here comes the first use case for “else” for a case in which none of the other cases apply.

Why did they call it “else”? No one knows.

All we know is that this document was originally written in German and hastily translated into English. I think that a carefully chosen German word was translated as an archaic English word, and then it was never corrected again. Unfortunately, we do not have the original text in German to compare.

The American proposal also contained the idea of ​​controlling constructs using boolean expressions. It didn’t even have the word “if” in it. If an expression was followed by an arrow, then the expression controlled the constructs that followed that arrow.

In such a notation it is not obvious, but unlike the “German” if block, in the American version if one expression in the block was true, then it went through a simplified scheme and skipped all subsequent expressions, as “else if” does now.

The two organizations held a joint meeting and combined their proposals into one document, which they called the International Algebraic Language. Soon this language was renamed to Algol (Algol).

The “if” clause in the generic document was similar to the German sentence, but it lacked the “always” clause at the end of the block. Each “if” stood separately, and if it was required that several constructs were controlled by one expression, then one could use “begin” and “end” to group them.

In this formulation of “if” there was nothing like “else”.

However, Algol 58 also had a second conditional form called “if either”. In this form, it was possible to write “or if” to perform the same task that we do today with the “else if”. But there was nothing equivalent to the “else” itself without another “if”.

The following year, the story becomes confusing – several articles about Algol were presented at the conference. One of them was an article in which John Backus, who previously led the Fortran project, proposed the idea of ​​formal grammars for programming languages.

The Algol described by Backus did not have the conditional form “if either”. Instead, there was the keyword “converge”, which made the top-level “if” within its block behave like an “else if”. It is unclear if this idea was to improve if either, or an earlier idea that was abandoned in favor of if either.

Be that as it may, “if either” was soon replaced. In 1957, John McCarthy of MIT wrote a proposal for a project that would later become LISP, another very old programming language that still exists today. His proposal outlines the idea of ​​a conditional expression replacing the conditional construction.

An important difference is that an expression must always have a value, and a construct may simply fail if its controlling condition is false.

So, its “if function” always ends with an “otherwise” statement that assigns the value to the expression if none of the other conditions are true.

McCarthy’s idea of ​​conditional expressions inspired Klaus Samelson to combine the two independent conditional models of Algol in 1959. He got rid of the “if either” form entirely, leaving only the “if”, but added a statement called “else”, which must be executed if the expression controlling the corresponding “if” turns out to be false.

With the help of “else if” it was possible to create chains of conditions, just like the previous “if either” allowed to do this with the help of “or if”, but it was also possible to use “else” separately in the last set of constructions, which was executed if none of conditions did not turn out to be true.

“If-then-else” was the only conditional form to appear in the ALGOL 60 report the following year, and this form was repeated by almost all subsequent programming languages.

Although it seems understandable to us today, it was difficult for people in 1960 to perceive it, so the report devotes a page and a half to explaining its operation, including this arrow diagram.

As I said, using “else” as a union seems strange. Christopher Strachey’s CPL programming language was the great-grandfather of the C language, and therefore the ancestor of most modern programming languages. Strachey refused to use “else”, calling it “cluelessly erroneous English.” He believed that one should write “test … then … or”, but this also sounded not very natural, and did not gain popularity.

The MAD programming language also went its own way. He is known for his extremely long words, and in addition to using “whenever” instead of “if”, he used “otherwise” instead of “else” and “or whenever” instead of “else if”.

Also worth mentioning is structuring in the example from the MAD manual. It was years before other programming languages ​​adopted this style of formatting, although today we cannot imagine anything else.

However, although the CPL and MAD rejected the word “else”, they retained the form and only changed the name. Language designers are still looking for the perfect way to write a loop for, however, the search for the perfect conditional form seems to have ended in 1959. Thanks to Klaus Samelson, who gave us a tool for thinking and a word to puzzle over.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *