Back to Top

Wednesday, October 29, 2008

No stress Perl

What I like about Perl is that it is "turtles all the way down" (almost). You go in with the perl debugger (or something visual like ptkdb) and step through almost all the code and understand how it is done. See for example this post about "magically" turning on strict/warnings from a module.

In the same time I feel that almost all Perl tutorials (especially those aimed at people who have already used other languages) fail to convey a very important thing: Perl's slogan "there is more than one way to do it" means that much of what you see is syntactic sugar.

For example "," and "=>" are equivalent for all intents and purposes (actually, the second one is called "fat comma" which should suggest this equivalence). This means the following two pieces of source code are equivalent:

# a
foo('aaa', 'bbb', 'ccc', 'ddd');
# b
foo('aaa' => 'bbb', 'ccc' => 'ddd');

How you write it is entirely a question of style. One can argue that this freedoms makes it possible to write more expressive source code. However it is very confusing to anyone who used other programming languages because almost all other programming languages respect the "one idiom == one way to express it" rule. Thus people have the impression that "=>" is somehow special.

Clearing these misunderstandings up from the start would make programmers life easier (less stressful). It would also allow them to write "better styled" source code (because - knowing all the possibilities - they could choose the one which fits best the particular situation).

To all newcomers to Perl: have a stress free experience.

PS. One could argue that there is the perlop documentation, but I think that it is safe to assume that the percentage of the people learning Perl from the "official" manual is minuscule compared to the people who read all kinds of tutorials on the net.


Post a Comment

You can use some HTML tags, such as <b>, <i>, <a>. Comments are moderated, so there will be a delay until the comment appears. However if you comment, I follow.