3 ms·
Ok it may not exist as a debate outside my own head :) To offer one argument: the problem with expression oriented languages is their generality, in that you c
by zetalyrae 5y ago
Ok it may not exist as a debate outside my own head :)
To offer one argument: the problem with expression oriented languages is their generality, in that you can write "weird" expressions, e.g.:
let x =
[giant block of code with multiple nested lets, ifs, etc.]
in
f(x)
I've definitely done this a number of times. Languages that separate statements and expressions force you to break things down further and prevent the code from going too far to the right.
Also, for low level languages, the mapping between code and assembly is clearer in languages that separate statements and expressions (I need a more succinct term).
EDIT: Also, by preventing statements from being used as expressions, you encourage breaking up long and complex statements into smaller functions.
- TeMPOraL 5y ago> in that you can write "weird" expressions Oh, I see what you mean. I discovered Lisp after working in C++ and Java, so I avoided this pitfall in my code, but if I had a dollar for every instance of: (let ((some-variable (progn (do stuff) (do other stuff) (let ((some-helper-var ...)) (some more code with some-helper-var) (more-of-the-same (progn ...))) ;; 50-100 lines later, just return one of the values some-variable) that I saw in Lisp codebases, particularly in Emacs, well... I could feed my family for a month or two from that money. There's plenty of abuse potential here (and for the love of god, if your language has 'let', it probably also has lambdas or 'flet', use that to create local functions...). But mitigating this, arguably, is a problem for style guides - the overall feature of "everything is an expression" is powerful. It has nice simplicity to it, and reduces boilerplate :). > Also, for low level languages, the mapping between code and assembly is clearer in languages that separate statements and expressions I'm guessing this is where the separation originally came from. Assembly is essentially statement-only. But at this point, I think all programming languages in use crossed the threshold where we're actually programming to an "abstract machine", and being expression-oriented seems to confer greater expressiveness. > (I need a more succinct term). "Separatist"? :). > EDIT: Also, by preventing statements from being used as expressions, you encourage breaking up long and complex statements into smaller functions. Ah yes. The real debate. I edited my comment to mention it before I saw your edit :).
- zetalyrae 5y agoYes, thank you, your code example is much better than mine. The simplifying potential of expression-oriented languages is huge. Alan Perlis said[0]: "symmetry is a complexity-reducing concept; seek it everywhere", and this is a great example of that. For example, languages like C and Ada have both if statements and if expressions, this is a duplication that can be eliminated by making them expression-oriented so you only have an if expression like in Haskell or ML. But, interestingly, there is one historical case of a language going from expression-oriented to statement/expression separation: ALGOL-W[1] was expression oriented, Pascal[2], its successor, separates statements from expressions. Wirth designed both. I don't know what the motivation was, but I suspect it's because Pascal was designed to be an educational language, and Wirth must have thought that separating expressions and statements made didactic sense when teaching programming as a recipe or list of things to do, as opposed to the more mathematized formulation of expression-oriented languages (of having an evaluation function from expressions to values). The successors of Pascal (Ada, Modula and its sequels) retain the statement/expression separation. [0]: http://pu.inf.uni-tuebingen.de/users/klaeren/epigrams.html http://pu.inf.uni-tuebingen.de/users/klaeren/epigrams.html [1]: https://en.wikipedia.org/wiki/ALGOL_W https://en.wikipedia.org/wiki/ALGOL_W [2]: https://en.wikipedia.org/wiki/Pascal_(programming_language) https://en.wikipedia.org/wiki/Pascal_(programming_language)
- tangus 5y agoI can't say for sure, but I suspect it was a reaction to ALGOL-68. Creators of later Algolish languages usually made a point of rejecting features of Algol-68 they saw as prone to abuse. And the block expressions in Algol-68 were certainly used and abused. Basically, the type and value of a block (BEGIN ... END or ( ... )) are those of its last expression, so you can put them anywhere. For example, Algol-68 has the looping construct WHILE <condition> DO <body> OD, but not C's `do <body> while (<condition>)`. So what do you do if you want to have the test at the end of the loop body? Simply WHILE ( <body>; <condition> ) DO SKIP OD I guess you'd get used to those idioms eventually, or some coding conventions would have arisen if the language had been successful. But I can understand language creators looking at that and seeing how getting rid of it simplifies not only their compilers but also the programs written in their languages.