Why are there no more control structures in most programming languages?

Why do most languages ​​seem to exhibit reasonably logical control structures from a logical point of view? Stuff like If ... then, Else ..., loop, for each, switch statement, etc. The standard list seems to be pretty simple from a logical point of view.

Why isn't there much more in logical syntactic sugar? Perhaps something like a suggestion mechanism where you can feed an array of rooms or functions that return complex self-relational interdependent functions and results. Something where you could combine a complex set of conditions, but presented in a way that makes it easy to read in code.

Room 1

Room 2 if and only if room 1

Room 3

Room 4, if room 2 and room 3

Room 5 if and only if room 4

etc...

Conclusion

I understand that this kind of logic can be built in functions and / or nested conditionals. But why, in most cases, there are no syntactic options for structuring such boolean statements that do not lead to hairy conditionals that are difficult to read and debug?

Is there an explanation for the types of control structures we usually see in major programming languages? Are there specific control structures that you would like to see directly supported by the syntax of the language? Does this just add unnecessary complexity to the language?

+2


source to share


9 replies


Have you looked at Prolog ? A Prolog program is basically a set of rules that become one big evaluation engine.



From my personal experience Prolog is a little weirder and I prefer ifs, whiles, etc., but YMMV.

+11


source


Boolean algebra is not hard and provides a solution to any convention you can think of, plus an infinite number of other options.

You can also ask for a special syntax for "common" arithmetic expressions. Who's to say what qualifies as commonly used? And where do you stop adding custom syntax?



Adding to the complexity of a parser language is not preferable to using constructive expression syntax combined with extensibility through function definitions.

+5


source


It's been a long time since my Logic class in college, but I would guess that it is difficult to write them in the language compared to the frequency with which they will be used. I cannot say that I have ever had a need for them (not that I can remember). For the times when you need something like this, the language designers probably assume that you can work out the logic yourself using only basic structures.

Just my wild guess though.

+2


source


Since most programming languages ​​do not provide sufficient tools to implement them, this is not seen as an important enough feature that a developer can provide as an extension, nor is it needed enough or used enough to be added to the standard.

If you really want it, use a language that provides it or provides tools to implement it (like lisp macros).

+1


source


It sounds like you are describing a rule engine .

+1


source


The basic control algorithms we use can use a processor that can operate efficiently. It basically comes down to simple tests and branches.

This may sound limited to you, but many people don't like the idea of ​​writing a simple line of code that takes hundreds or thousands (or millions) of CPU cycles to complete. Among them are the systems software people who write things like operating systems and compilers. Naturally, most compilers will reflect their own problems with writers.

+1


source


This refers to the problem of atomicity. If you can express A, B, C, D in simpler structures Y, Z, why not just put A, B, C, D and instead put Y, Z?

Existing languages ​​reflect 60 years of tension between atomicity and usability. The modern approach is "small language, large libraries". (C #, Java, C ++, etc.).

+1


source


Since computers are binary, all solutions should boil down to 1/0, yes / no, true / false, etc.

To be effective, language constructs must reflect this.

0


source


Ultimately, all your code goes to microcode, which executes one instruction at a time. Until the microcode and accompanying processor can describe something brighter, we stick to a very simple language.

0


source







All Articles