What do you mean by the expressiveness of a programming language?

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 - 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?


    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.


    "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
  • Either dynamic typing or type inference
  • 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?


    I like Matthias Felleisen's notion of expressive power, which is comparative:

  • Language A is strictly more expressive than language B if both of the following are true:

  • Any program written in language B can be rewritten in language A while keeping the essential structure of the program intact.
  • Some programs written in language A have to be violently restructured in order to be written in language B.
  • Usually we want to make these comparisons by looking at some kind of "essential core" of a language—for example, maybe we want to consider a dialect of C with only while and not also for and do...while . Or maybe we want to consider a dialect of Perl with only a prefix if form and no unless form. But sometimes these superficial syntactic distinctions are exactly what we mean by "expressive power"; to some programmers it's important to say

    die ("found no solutions") unless length(solutions) > 0;
    

    instead of

    if (length(solutions) == 0) { die("found no solutions"); }
    

    So you have to establish whether you're asking about expressive power of surface syntax or deeper structure.

    The other thing I like about Felleisen's idea is that it admits of the notion of two languages which are definitely different, but neither is more expressive than the other.

    You can read a more detailed exposition in the first two pages of his paper On the Expressive Power of Programming Languages. After that comes a lot of pointy-headed theory :-)

    链接地址: http://www.djcxy.com/p/20680.html

    上一篇: 你讨厌你最喜欢的语言有什么五件事?

    下一篇: 编程语言的表现力是什么意思?