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

前端 未结 11 1948
眼角桃花
眼角桃花 2021-01-31 07:56

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
11条回答
  •  感动是毒
    2021-01-31 08:31

    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 :-)

提交回复
热议问题