views:

628

answers:

10

I see a lot of the word 'expressiveness' when people want to stress one language is better than the other. But I don't see exactly what they mean by it.

  • Is it the verboseness/succinctness? I mean, if one language can write down something shorter than the other, does that mean expressiveness? Please refer to my other question - http://stackoverflow.com/questions/2411772/article-about-code-density-as-a-measure-of-programming-language-power
  • Is it the power of the language? Paul Graham says that one language is more powerful than the other language in a sense that one language can do that the other language can't do (for example, LISP can do something with macro that the other language can't do).
  • Is it just something that makes life easier? Regular expression can be one of the examples.
  • Is it a different way of solving the same problem: something like SQL to solve the search problem?

What do you think about the expressiveness of a programming language? Can you show the expressiveness using some code?

What's the relationship with the expressiveness and DSL? Do people come up with DSL to get the expressiveness?

+2  A: 

Wikipedia has a bit about the concept. I myself take it to mean that a language can accomplish more with less (the so called "informal usage" in the Wikipedia article).

I consider JavaScript expressive (though this could be because Douglas Crockford drilled that idea into my noggin) because it can do so much with just a few keywords. For instance, the function keyword is a function, as well as a method, a class, and a lambda.

Some code illustration (leaving out some details for brevity) in JavaScript. It's an event class I wrote:

SJJS.util.Event = (function() {
    var _listeners = [];
    var _listenerReturns = [];

    return {
        addDomListener: function(element, eventName, listener) {
        },
        trigger: function(element, eventName) {
        },
        removeListener: function(eventlistener) {
        }
    }
})();

With just function, var, and some curly braces and parentheses I made a static class with methods and private variables.

Bob
TBH, it's not very clear what that's doing speaking as a non-javascript developer.
RCIX
+20  A: 

Personally, I feel that the "expressiveness" of a language really comes down to how clearly the language constructs can "express" the developer's intentions.

For example, I feel that C# (especially LINQ via C# 3+) is becoming much more expressive. This LINQ statement is a great example:

var results = collection.Where(item => item > 5);

Without knowing the details of the language or the implementation being used, the developer intent is (in my opinion) very clear in the above statement.

I do not think that the verboseness of the language is equal to its expressiveness, however, there is some correlation in place. If a language requires a lot of code in order to express an abstraction, it is less expressive. These are two related, but different, concepts.

The same is true with power - although here a language's features (ie: power) must be complete enough to express the abstraction clearly. Without this, expressiveness will suffer. That being said, a language can be very "powerful" in terms of features, but not necessarily be expressive, if the feature set is difficult to understand.

Reed Copsey
So declarative rather than imperative?
TrueWill
@TrueWill: No, not necessarily. However, I think declarative programming often is more expressive by nature - it's more about whether or not the programmer's intention is clear based on the code written... at least for me.
Reed Copsey
A: 

Generally speaking, with a programming language which is turing complete you can do anything that another turing complete language can do. That being said, some can do it a lot better than other.

I take expressiveness to mean how much you can say easily, and how well / clearly it can be said. The ability to be terse is part of that ( a very powerful and terse language is one like J ). Generally I find that being concise is a good marker of being expressive. If the language can express a complex operation in a simple manner, it's going in the proper direction.

As to the power, expressiveness isn't all the power of a language. While it may be part of it, speed, security, stability, all of those things factor in as well.

example: summation of a list in Common lisp using the loop operator is concise and expressive

(loop for x in list sum x)

Mimisbrunnr
A: 

Precision, concision, and readability are the primary components in expressiveness.

Paul Nathan
+3  A: 

For me is the ability that the language has to clearly express my logic and ideas through code, in a way that somebody else reading the code I've wrote can easily figure out what I was thinking about when I did it.

Andres
+1  A: 

If you want an answer that's somewhat theoretical but more rigorous than most, you might want to look around for Matthias Felleisen's On the Expressive Power of Programming Languages. I'm pretty sure a bit of looking around the net will turn up at least a few copies.

If you want a more practical answer of what most people really mean when they say it, that's, frankly, rather different. Usually, at least in my experience, an "expressive" language means: "I like the language, but can't cite any objective support for doing so." Conversely, things like "less expressive", or "not expressive" generally mean: "I don't like the language [as well], but can't cite any objective support for doing so."

"Not expressive" is similar to a politician accusing another of being "fascist" -- clearly pejorative, but without any meaningful definition of what's supposedly wrong.

Jerry Coffin
+12  A: 

"Expressiveness" means the ability to say only what you want done:

bad_event = events.find(&:bad)

rather than how you want it done:

i = 0
bad_event = nil
while i < events.size && bad_event.nil?
  event = events[i]
  if event.bad?
    bad_event = event
  end
  i += 1
end

Among the things that contribute to expressiveness are:

  • A lack of required syntactic sugar
  • First-class functions
  • Garbage collection
  • Dynamic typing
  • The language core not being slavishly minimalistic
  • Good functionality in the standard library

To some degree, the expressiveness of any language can be increased by shoving as much "how to do it" off into subroutines/objects as possible so that most of the remaining code is "what to do." The amount of "how to do it" code needed in the most abstract code is one measure of a language's expressiveness: The more the code looks like pseudocode, the more expressive it is of the programmer's intent.

One can also think about the "meta-expressiveness" of a language: How expressive is the language at constructing Domain Specific Languages?

Wayne Conrad
A: 

I always took it to be roughly equivalent to how high-level a language is. If you wanted to try to quantify expressiveness, the units would be something like "machine code instructions per language statement"

A more expressive language might be very good at doing rather a lot of work without writing a lot of code. However, it would probably be more domain-specific and a wee bit slower for some tasks than a less expressive one.

T.E.D.
A: 

Take for example LINQ. It allows you to use functional programming.

Functional programming emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state.

LINQ allows your to express what you want done instead of how to do it. This is a clear example os expressiveness.

Leniel Macaferi
+3  A: 
Norman Ramsey
Actually, I'd say a better example would be Ada (or C++) and C. You can write C code in Ada all day long if you choose to. However, try converting an Ada program using tasks, generics, and/or protected objects into C and you are liable to end up in tears. It really can't be done without OS help.
T.E.D.