tags:

views:

511

answers:

6
  • What is an expressive language?
  • What does it mean when someone says that Perl is an expressive language?
+20  A: 

An "expressive" language is a language that allows you to easily express logical concepts in code.

People often call Perl expressive since it allows you to use many different approaches to express a specific concept, so it's very flexible in this regard.

(There is a lot of debate about whether this is a good thing or not, though...)

Reed Copsey
+7  A: 

They mean TIMTOWTDI.

The language was designed with this idea in mind, in that it "doesn't try to tell the programmer how to program". This makes it easy to write extremely messy programs, but, as proponents of this motto argue, it also makes it easy to write beautiful and concise ones.

voyager
+15  A: 

In this context I think it means you can do a lot of things without writing too much code.

For example one-liners:

$ echo Foo | perl -pe "s/o/e/g"
Fee

Or Moose:

# A simple Point class with x and y coordinates.
package Point;
use Moose;
has [qw/x y/] => (is => 'ro', isa => 'Num', default => 0);
1;

Or the concept of context:

my @array = qw(foo bar baz);
my $count = @array; # three

Or the Schwartzian transform:

@sorted = map  { $_->[0] }
          sort { $a->[1] cmp $b->[1] }
          map  { [$_, foo($_)] }
               @unsorted;

This is good, because you can have things done the way you want. (If you feel like shotgunning through the problem, you can.) On the other hand it’s sometimes bad, because you can have things done the way you want :)

zoul
Didn't the Stones have a song about that? *You shouldn't always get what you want...*
Telemachus
@Telemachus: you don't always get what you want, but sometimes, you get what you need ;)
voyager
(Psst, @voyager, it's "can't," not "don't," but who's counting?)
Chris Lutz
@Chriz Lutz: Who's counting, I could give a million reasons. But who's counting anyway. Can't go to sleep so every night instead, I lay awake and do the math in my head. One after one I count the stars in the sky. There's one million six hundred eighty two thousand, Four hundred and five. But who's counting.
voyager
@Chris: Plus, it's "but if you try sometimes". Not just "but sometimes". :)
bcat
+8  A: 

Let's see, Merriam-Webster (s.v, 'expressive') offers this:

3: effectively conveying meaning or feeling 'an expressive silence', 'expressive line drawings'

I think that actually fits Perl to a T because of what other answerers are saying (1) there's more than one way to do things (so Perl has lots of ways to allow the programmer to express her ideas) and (2) Perl is often relatively compact (so you can express a lot with a little).

But I would add that Perl's pervasive tendency towards DWIM (do what I mean) is a big part of it as well.

Telemachus
+1 Perl's DWIM philosophy is nice, especially since other languages that take the opposite approach (not mentioning any names) suffer because I end up having to repeat the same operations, whereas Perl knows what I want to do. Readability may suffer to a Perl newbie, but hopefully that Perl newbie will come ask a question about it on Stack Overflow and learn some more about Perl in the process.
Chris Lutz
+9  A: 

The idea behind Perl's syntax is not only TMTOWTDI but an attempt to mimic natural language (as far as that's possible while keeping the precision of computer language). The goal is that Perl should be a language that you can become fluent in, like a native speaker, not like a tourist using a phrasebook.

One of the available ways to write the code should have a similar form to the way you think about the problem. When the shape of the code in the editor matches the shape of the problem in your head, you can get to the stage of having running and testable code more quickly, because there isn't a conscious step of translating between what you mean and what the computer wants to hear. This is why people will often tell you that Perl is excellent for prototyping.

It's this, not concision or TMTOWTDI, that's really meant by Perl's "expressiveness". Natural languages provide pronouns; Perl provides $_. Natural languages provide ellipsis; Perl provides builtins with default arguments. Natural language provides lots of different ways to phrase any given statement, with different shades of meaning, and different modes and registers of speech; Perl does just the same with code. A native speaker of English will usually choose the most concise way to get a point across, out of all of the available ones, but he doesn't have to -- he has the option of using a lot more words for clarity, or even to be poetic. In Perl it's much the same. The goal, to speak unscientifically, is that you should be able to "say what you mean".

Some thoughts of Larry Wall's about the influence of natural languages on Perl: Natural Language Principles in Perl.

hobbs
Perl and natural language in one sentence.. Is that even possible?
Ikke
@Ikke, YES. Larry Wall has a few things to say about natural language principles in Perl: http://www.wall.org/~larry/natural.html
daotoad
Thank you daotoad for finding the link I couldn't :)
hobbs
TMTOWTDI exists in natural languages: i.e. *Warlord* -> *Lord of War* :)
voyager
Perl was written by a natural linguist and is more similar to a natural language than most other programming languages. That's both a blessing and a curse.
Carl Smotricz
+1  A: 

Read through Larry Wall's "State of the Onion" address (find them with Google). In the first several speeches he talks about the idea and philosophy of Perl and how he thinks about them. They can be quite enlightening for the newcomer to Perl.

brian d foy