|Perl Monk, Perl Meditation|
Re: What do you use as a language litmus?by w-ber (Hermit)
|on Jul 31, 2007 at 10:40 UTC||Need Help??|
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:
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:
In Perl, of course:
(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.