Waktu asli posting blog: Fri, 19 Dec 2008 01:03:50 +0000
Verbosity of syntax and semantics is a persistent criticism of Java. Why,
look at the concepts you have to understand (or ignore) to write "Hello,
world!" in Java:<blockquote><div> <tt>public class hello
public static void main(String args[])
System.out.println("Hello, world!");
</tt></div> </blockquote>By rough count, you have to understand (or ignore) the connection between a
class and its file, how to invoke the Java compiler, visibility of methods,
methods, the distinction between class and instance methods, array syntax,
typed arrays, and particular details of Java's internal class library before
you can give a cheery greeting. Compare that to Perl's simplicity:<blockquote><div> <tt>say "Hello, world!";</tt></div> </blockquote>Even that trailing semicolon is optional. Those poor Java programmers don't
know how great life can be -- except that we're deluding ourselves to think
that Java programmers spend their days writing "Hello, world!" over and over.
Perl programmers don't. Why would Java programmers?What <em>do</em> Java programmers do all day? They write classes, for one. Maybe we should compare like to like. In Java:<blockquote><div> <tt>public class Foo extends Bar
...
</tt></div> </blockquote>Hm, that's not too bad. You have to understand what a class is and Java's
syntax for inheritance, as well as visibility modifiers, but syntactically
speaking that's not overtly complex and it reveals the intent of the code
fairly well. Now let's consider Perl 5:<blockquote><div> <tt>
package Foo;
use vars '@ISA';
push @ISA, 'Bar';
...
</tt></div> </blockquote>Hm. That could be clearer. You have to understand packages (and that
classes in Perl are packages, but not vice versa, except sometimes), package
scoping rules, global variables, the <code>vars</code> pragma, a magic package
global, and the order of inheritance in the face of open classes. How
about:<blockquote><div> <tt>
package Foo;
push @Foo::ISA, 'Bar';
...
</tt></div> </blockquote>Hm. That obviates the need to understand the <code>vars</code> pragma, but
it's still syntactically noisy. Maybe:<blockquote><div> <tt>
package Foo;
use base 'Bar';
...
</tt></div> </blockquote>That's slightly better, but it introduces the need to understand yet another
pragma and its implications if you don't have a file in <code>@INC</code> (yet
another magic global) named <em>Bar.pm</em>.Of course, the default Perl 5 syntax can't ever change because <a href="http://www.catb.org/esr/writings/taoup/html/ch15s04.html#id2986827">we
don't want to screw up our embedded base</a>. Oh dear. This may be the sound of a wall against which I <em>am</em> beating my head.(Before you tell me all I have to do is to use Moose/Mouse/Squirrel/Wombat/Ferret/Nematode/Whatever, allow me to indulge in one more list: the existence of CPAN, how to configure <a href="http://search.cpan.org/perldoc?CPAN::FirstTime">CPAN::FirstTime</a>, how to set up a development environment on your box, how to use a CPAN module, reading the documentation of a CPAN module, installing modules and distributions locally, .... If you're really good, I'll tell you the story of how a feature deprecated fourteen years, two months, and one day ago made the semi-doomed class patch more difficult to write.)
http://use.perl.org/~chromatic/journal/38118?from=rss