Everything is An Expression
Asked Answered
B

2

6

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!

Billington answered 7/9, 2011 at 0:5 Comment(6)
two words: functional programming.Coligny
one word: elaboration :DBillington
Reading through wikipedia it appears having everything an expression adds overhead that languages like c don't have. Is this the correct conclusion or should I be determining something else? @MauricioBillington
@Lime: If your main concern is about performance than the rule of profiling your application code is the same regardless of the type of language you are using. What is the type of environment of your application and its requirements.Ermentrude
@Lime, there is no overhead at all. E.g., a ternary expression is as efficient as its clumsy if counterpart in C.Stigmasterol
@Ermentrude I have no concern with overhead right now, I was just trying to figure out what Mauricio was referring to.Billington
E
4

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:

Interesting articles:

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.

Ev answered 7/9, 2011 at 6:50 Comment(0)
I
0

By "everything is an expression," I assume you mean what is described at http://jashkenas.github.com/coffee-script/

It kinda sounds like what you're asking about are functional languages. Consider, for example, Lisp, which did this sort of thing back in the '50s. This ultimately comes out of the Lambda Calculus, in which code and data are really the same thing, and you can pass code around as though it were data (because it is).

I don't know of any scholarly articles discussing this specifically, but now you at least have some more keywords to search for.

Idiopathy answered 7/9, 2011 at 0:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.