Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean when someone says that Perl is an "expressive language"?

Tags:

perl

  • What is an expressive language?
  • What does it mean when someone says that Perl is an expressive language?
like image 461
Rachel Avatar asked Oct 19 '09 16:10

Rachel


2 Answers

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

like image 59
Reed Copsey Avatar answered Sep 22 '22 16:09

Reed Copsey


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

like image 44
zoul Avatar answered Sep 22 '22 16:09

zoul