Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "expressive" mean when referring to programming languages?

I hear this word a lot in sentences like "javascript is a very expressive language". Does it just mean there aren't a lot of rules, or does "expressive" have a more specific meaning?

like image 307
morgancodes Avatar asked Mar 12 '09 14:03

morgancodes


People also ask

What is the most expressive programming language?

MacIver which interviewed 2576 programmers using the Hammer Principle. According to Maclver, the most expressive languages are Haskell, Clojure and Scala while the least expressive are C, PHP and ultimately TCL. Maclver's study did not include CoffeeScript.

What is meant by expressive language in Python?

Python is an expressive language. Expressive in this context means that a single line of Python code can do more than a single line of code in most other languages. The advantages of a more expressive language are obvious – the fewer lines of code you write, the faster you can complete the project.

Is C++ an expressive language?

C++ is a very rich, very expressive language with lots of features. It has to be because a successful general-purpose programming language must have more facilities than any one developer needs, and a living and evolving language will accumulate alternative idioms for expressing an idea.

Is Java an expressive language?

Java comes in with nearly identical expressiveness as C++ (both at 823 LOC/commit) but a vastly greater consistency (IQR of 277 vs 476).


2 Answers

'Expressive' means that it's easy to write code that's easy to understand, both for the compiler and for a human reader.

Two factors that make for expressiveness:

  • intuitively readable constructs
  • lack of boilerplate code

Compare this expressive Groovy, with the less expressive Java eqivalent:

3.times {    println 'Hip hip hooray' } 

vs

for(int i=0; i<3; i++) {     System.out.println("Hip hip hooray"); } 

Sometimes you trade precision for expressiveness -- the Groovy example works because it assumes stuff that Java makes you to specify explicitly.

like image 162
slim Avatar answered Sep 21 '22 08:09

slim


I take it to mean that it's capable of expressing ideas/algorithms/tasks in an easy-to-read and succinct way.

Usually I associate a language being expressive with syntactic sugar, although that's not always the case. Examples in C# of it being expressive would be:

  • foreach (instead of explicitly writing the iteration)
  • the using statement (instead of explicitly writing the try/finally)
  • query expressions (simpler syntax for writing LINQ queries)
  • extension methods (allowing chaining of method calls, again primarily for LINQ)
  • anonymous methods and lambda expressions (allowing easier delegate and expression tree construction)

A different example would be generics: before C# got generics, you couldn't express the idea of "an ArrayList containing only strings" in code. (You could document it, of course, or write your own StringList type, but that's not quite the same.)

like image 43
Jon Skeet Avatar answered Sep 22 '22 08:09

Jon Skeet