I've noticed many languages like Ruby and CofeeScript (well a transcompiler) support everything being an expression.
Now it makes the language somewhat simple to understand and definitely seems neat at the surface, but I was looking maybe for some scholarly publications about the positives and negatives of the two approaches.
It would be beneficial if the publications had clear examples that compared the benefits of having everything be an expression vs., well, not.
Examples in CoffeeScript vs Javascript would be nice, but not required.
The concept is definitely cool, but I'm still slightly unsure how revolutionary the whole idea really is (obviously something being revolutionary is somewhat an opinion).
Thanks!
Any expression could be used as a statement, but not every expression is actually used as a statement.
In programming language terminology, an “expression” is a combination of values and functions that are combined and interpreted by the compiler to create a new value, as opposed to a “statement” which is just a standalone unit of execution and doesn't return anything.
In programming, an expression is any legal combination of symbols that represents a value. Each programming language and application has its own rules for what is legal and illegal. For example, in the C language x+5 is an expression, as is the character string “MONKEYS.”
Scheme control structures are expressions, and return values. An if expression is a lot like a C if-then statement, but the "then" branch and the "else" branch are also expressions that return values; the if expression returns the value of whichever subexpression it evaluates.
There is nothing revolutionary about this per se. The expression-oriented approach is a functional programming technique.
Expression-oriented code is simpler and less cluttered than statement-oriented code, because of fewer assignments and no explicit return
statements. The lack of distinction between expressions and commands enables conceptual uniformity (see Referential transparency) and bottom-up structure.
Some modern languages have adopted functional programming concepts (e.g. C#, Python, Ruby).
Some scholarly insight on the benefits of functional practices:
- Can Programming Be Liberated from the von Neumann Style? A Functional Style and Its Algebra of Programs - John Backus
Interesting articles:
- Why Functional Programming is Important in a Mixed Environment
- Is C# becoming a functional language?
As to the comment about performance concerns, the possible overhead related to choice of paradigm is probably negligible. Even in C, most statements evaluate as an expression - however, a comparison between a compiled language (C) and an interpreted language (CoffeeScript) is rather useless.
On a theoretical note, an imperative language represents the control flow in more of a machine-oriented way, which may allow for easier hand-optimization than a functional language.
Language performance and its significance depend heavily on the use case. Concerning JavaScript and whatever code transformation on top of it, this performance discussion is completely irrelevant. The gains in productivity outweigh any slight performance hit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With