Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: What do you use as a language litmus?

by vrk (Chaplain)
on Jul 31, 2007 at 10:40 UTC ( #629791=note: print w/replies, xml ) Need Help??

in reply to What do you use as a language litmus?

  1. First-class closures
  2. Most common idioms are easy or trivial to do

Anything else is negotiable. First-class closures were already mentioned in the OP, and by the second, I mean what Perl has got mostly right: sometimes you can even manage with a one-liner. Of course, how this is actually done depends on the language. Perl is bent towards text processing, thus regular expressions and many other features are easily accessible and embedded into the language core.

A good example of the opposite is Java. No matter what you want to do, you always have to create at least one class. There are no exceptions to this, no common case optimizations. The "main" function of the program is the most common function, as unless your program is a library (and even then, you might use the main function in testing!), your program will have the main function. In Perl, your program source code is, by default, the main function, unless you explicitly direct the program flow elsewhere. In Java, you have to:

class Somesuch { public void main(String[] arguments) { ... } }

That is, you always need to declare a class, even when it's completely useless, and you always need to explicitly name the variable where you want to put the command-line arguments, and you always need to explicitly declare the main function.

Another common-case optimization in Perl is the lexically bound implicit (loop) variable $_. In Java, C, C++, and awfully many other languages, you always need to declare the loop variable, even though when you write a loop, the most common case is that you are looping over some data structure and you need to access the contents inside the loop body. In C++, for example, using indexing:

std::vector<Data> myArray; /* Time passes... */ for (int i = 0; i < myArray.size(); i++) { process(&myArray[i]); }

or iterators:

for (std::vector<Data>::iterator i = myArray.begin(); i != myArray.end(); i++) { process(&*i); }

In Perl, of course:

for (@array) { process($_); }

or even

process($_) for (@array);

(Granted, the latter C++ example uses iterators, but still, it's an awfully verbose way to do a very common case in programming.)

The examples are not the best, but when such mentality pervades the language design, I steer clear.

print "Just Another Perl Adept\n";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://629791]
[LanX]: Do students have the constitutional right to get armed to defend themself against armed teachers?
[Discipulus]: vasanth.easyrider perseverare diabolicum

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2018-02-23 12:28 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (302 votes). Check out past polls.