Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Perl Best Practices

timothy posted more than 9 years ago | from the keep-knife-in-mouth dept.

Perl 288

honestpuck (Tony Williams) writes "I have to admit that I can bristle at books that try to preach, so Perl Best Practices was on a hiding to nothing when I came to review it. I also have to admit to being torn about the author -- after all, he is one of those poor fools who insist on living in cold, unenlightened Melbourne, while I live in vastly superior Sydney. On the other hand, how can I dislike a man who manages to place a quote that involves my favourite character, Lady Bracknell. from my favourite comic play, 'The Importance of Being Earnest,' in the first few pages of his book?" Read on for Williams' review.

Many years ago I read a marvelous article that explained why so may early editors and word processors supported the keyboard commands of WordStar. When it's first born, a baby duck can be easily convinced that almost anything is its mother. The small bird imprints, and it takes a lot to shift its focus. "Baby Duck Syndrome" affects programmers in a number of ways, not just their choice of editor, and Conway is walking right into the middle and arguing with your imprinting on almost every page. A brave man; fortunately he has the street cred to make you at least listen.

So I carefully placed my bias and bigotry in the bottom drawer and prepared myself. I discovered a well-written, informed and engaging book that covers a number of methods (hey, 256 rules, come on Derrick, 2 ^ 8 rules can't be a coincidence!) for improving your Perl software when working in a team. That means all of us when you remember an adage a guru once told me: "Every piece of computer software, no matter how small, involves at least a team of two -- me, and me six months from now when I have to fix it." Conway puts it differently "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."

The first chapter outlines the why and where of the book. The why is to improve your code with three goals; robustness, efficiency and maintainability. The chapter finishes with a short exhortation to us to "rehabit." Don't like the word much but I applaud the aim.

Conway is far from timid. He jumps right in to the deep end of the wars, with formatting the appearance of your code. I thought the chapter was brilliantly written until he told me I shouldn't "cuddle else statements," at which point I realized what an ill-informed idiot he was. Oh, hang on. Hey, that almost makes sense. OK, that's a cogent argument for your point of view, Conway. I also have to admit that earlier you did say that your rules for this bit weren't gospel, that if you wanted a variation that was OK, just have a standard and make sure you can support it with a code prettier. Perhaps not a total idiot after all.

After successfully negotiating those shark infested waters, Conway -- obviously a man who knows no fear -- wades into naming conventions. Once again he gives coherent arguments, pointed examples and counterexamples. It all makes sense.

The book's page at O'Reilly has an example chapter and a good description, but no table of contents so here's a quick list of the headings:

  1. Best Practices
  2. Code Layout
  3. Naming Conventions
  4. Values and Expressions
  5. Variables
  6. Control Structures
  7. Documentation
  8. Built-in Functions
  9. Subroutines
  10. I/O
  11. References
  12. Regular Expressions
  13. Error Handling
  14. Command-Line Processing
  15. Objects
  16. Class Hierarchies
  17. Modules
  18. Testing and Debugging
  19. Miscellanea
Suffice to say that Conway leaves no corner of Perl uncovered, offering well-reasoned and well-explained advice on improving your Perl code.

The book is also well-written and well-edited. The order of topics covered is a sensible one, and the book is appropriately structured. It reads and feels as if you are being given the wisdom from many a hard-won battle coding and maintaining Perl code.

My one complaint is that I found it dry: you are reading through pages of argument and examples without much relief. Perhaps this book might be best digested in a number of chunks, making the effort to use the ideas from each chunk for a while before moving on to the next.

Every so often I read a book from O'Reilly that makes me fear that they are slipping, then along comes a book like Perl Best Practices, and I'm reminded that when it comes to Perl, O'Reilly authors wrote the book. Once you've rushed through Larry's book and learnt the finer points with Schwartz and Phoenix's 'Learning' titles, you may well find that this is the perfect volume to complete your Perl education. If you believe your Perl education is complete, then buy this volume and I'm sure you'll find a lesson or two for yourself.

This book is not really aimed at the occasional Perl programmer (though many of us would probably benefit from its wisdom), but at the person who is professionally programming in Perl and wants to produce better quality, more easily maintained code. For this person Perl Best Practices is a 9/10. For the rest of us, the 'rehabiting' process might be a little too arduous; personally, I'm going to pick a few of the chapters and work on those for a while, maybe naming conventions and variables. For me I'll give it an 8.


You can purchase Perl Best Practices from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

Sorry! There are no comments related to the filter you selected.

Nice attitude. (-1, Flamebait)

Anonymous Coward | more than 9 years ago | (#13559494)

...after all, he is one of those poor fools who insist on living in cold, unenlightened Melbourne, while I live in vastly superior Sydney.

Ok, jackass.

Melbourne? (1)

montreal!hahahahah (880120) | more than 9 years ago | (#13559543)

hahahahhahahah!

TripMaster Monkey a GNAA operative? (0)

Anonymous Coward | more than 9 years ago | (#13559822)

Why are you suggesting that TripMaster Monkey is the GNAA operative based in Melbourne? As far as I can tell, TripMaster Monkey is nothing more than your typical American software developer, most likely unemployed because his job was outsourced to India or Thailand. His chronic unemployment explains why he can post so frequently here.

Smile (4, Funny)

kerohazel (913211) | more than 9 years ago | (#13559498)

If it looks like an emoticon, your Perl is probably syntactically correct. ;)

Use Python (0, Flamebait)

Anonymous Coward | more than 9 years ago | (#13559506)

Perl Best Practices: don't

Grammar Best Practices (0, Funny)

Anonymous Coward | more than 9 years ago | (#13559510)

"I have to admit that I can bristle at books that try to preach, so Perl Best Practices was on a hiding to nothing when I came to review it."

me fail english? unpossible!

Re:Grammar Best Practices (5, Informative)

bmarklein (24314) | more than 9 years ago | (#13559695)

(BE) ON A HIDING TO NOTHING [phrases.org.uk] -- "Face annililation. Or, less dramatically, 'face insuperable odds,' 'be without a prayer,' i.e., with no hope of success. 'Hiding,' in this expression, is synonymous with 'thrashing,' and a 'hiding to nothing' means 'a thrashing to bits.'" From "British English: A to Zed" by Norman W. Schur (Harper Perennial, New York, 1987).

My best Perl practice... (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#13559513)

use Python!

Wordstar keybindings (0)

afd8856 (700296) | more than 9 years ago | (#13559516)

I'm too young to have used wordstar, but I can tell you one thing: is a lot easier to use wordstar keys for clipboard operation then it is to do the weird ctrl+c/ctrl+v thingy

Re:Wordstar keybindings (4, Interesting)

koehn (575405) | more than 9 years ago | (#13559545)

Do you know why Apple pioneered Command (nee control) Z, X, C, and V for Undo, Cut, Copy, and Paste? Take a look at a QWERTY keyboard: they're the easiest keys to hit with only the left hand. Same for Command-W for close, Q for Quit, and A for select all: one handed operation, leaving the right hand free to drive the mouse.

I grant you, left-handers and non-QWERTY keyboarders are left out in the cold, but at least there was a method to the madness.

Non-QWERTY (1)

cynicalmoose (720691) | more than 9 years ago | (#13559733)

Non-qwerty keyboarder's aren't left out in the cold provided the key mappings are changed to the same physical keys, in which case they have just the same performance.

Pity it's so much effort to change the bindings in most word processors.

Re:Wordstar keybindings (-1, Troll)

Anonymous Coward | more than 9 years ago | (#13559747)

one handed operation, leaving the right hand free to drive the mouse.

Yes, if by "drive the mouse" you mean "jacking one's cock," like I'm doing right now.

OH, OH, AH. HERE COMES YOUR PERL NECKLACE! SPURT

Re:Wordstar keybindings (2, Funny)

bhirsch (785803) | more than 9 years ago | (#13559892)

Amazing how the importance of typing one-handed has never evaded software engineers.

Re:Wordstar keybindings (0)

Anonymous Coward | more than 9 years ago | (#13559905)

Not necessarily bad for lefties. I know I am not alone in being left handed and using a mouse with the right hand. This leaves the lh free to make notes with an old fashioned pen(cil) on paper. If you look you'll see many left handed people with paper tucked under the keyboard or just to the left for this purpose. Personally, it seems to me that it must a real pain to have to transition from mouse to pen to write little notes. Aside from that most modern mice are terribly uncomfortable for lh use.

Re:Wordstar keybindings (and the left hander) (0)

Anonymous Coward | more than 9 years ago | (#13560098)

Actually lefties have the advantage. By leaving the mouse on the right, as we are prone to do because moving it all the time sucks, it leaves our more dextrous hand to work the keyboard while our "less dominate" hand points and grunts at the screen.

I often wonder why more right handers dont put the mouse on the left and enjoy the same advantage.

Then again, I am a avid keyboard user.

Characters per line (3, Funny)

RealityMogul (663835) | more than 9 years ago | (#13559522)

Perl programmers always say they can do anything in one line of code. Does this book finally set a limit on how many characters can be in that one line?

Re:Characters per line (3, Funny)

Karma_fucker_sucker (898393) | more than 9 years ago | (#13559550)

That would be good. I would also like to create an error handling module called "Neklace". So, a hard error handling routine would make a call into Perl Neklace, becuase you're fucked.

Re:Characters per line (2, Funny)

Phillup (317168) | more than 9 years ago | (#13560004)

Maybe I'm getting a little old... but I'd definitely call it a *soft* error after the neklace part happens. At which point you're fucked. (past tense)

;-)

Best Best Practice: Don't Bloat Perl (1, Interesting)

Anonymous Coward | more than 9 years ago | (#13559649)

The best thing that we can do is to convince that egomaniac, Larry Wall, to stop adding junk into Perl and bloating the language into something like PL/1.

Perl is getting to the point where you need a 2-semester college course on the subject before you can fully understand all aspects of the language.

People love C and Perl 5.x for their simplicity. Heed the advice of the bearded, coke-bottle-thick eyeglass wearing UNIX programmers. "Keep it simple, stupid."

Re:Best Best Practice: Don't Bloat Perl (4, Insightful)

Mr. Underbridge (666784) | more than 9 years ago | (#13559839)

Perl is getting to the point where you need a 2-semester college course on the subject before you can fully understand all aspects of the language

That a joke? I don't think there's any language that can be fully understood after a 2-semester course.

Re:Characters per line (1)

coaxial (28297) | more than 9 years ago | (#13559841)

Perl programmers always say they can do anything in one line of code.

(Big (deal . I) '(ve been) (doing (that in lisp) (for (years))))

Perl best practice number 1 (-1, Redundant)

Anonymous Coward | more than 9 years ago | (#13559525)

Use a better fucking language!

Obligatory joke (3, Funny)

Weaselmancer (533834) | more than 9 years ago | (#13559542)

Perl Best Practices, page 1.

Use Python.

Ba-dump-bump! Thanks, I'll be here all week. Be sure to tip your waitresses.

Re:Obligatory joke (0)

Anonymous Coward | more than 9 years ago | (#13559580)

That's nothing, you should have read the preface:

Just don't.
Friends don't let friends code perl.

Re:Obligatory joke (3, Funny)

Anonymous Coward | more than 9 years ago | (#13559677)

Python Best Practices, page 1.

Use Ruby.

Ba-hiss-hiss-hiss! Good bye you slimey snake.

Re:Obligatory joke (0)

Anonymous Coward | more than 9 years ago | (#13560026)

You mean, "Slow down! Use Ruby."

Re:Obligatory joke (1)

kdorff (313402) | more than 9 years ago | (#13559931)

Man you beat me to it! I completely agree.

Syntax problem (4, Funny)

lullabud (679893) | more than 9 years ago | (#13560053)

Being a Python programmer, not a Perl programmer, I'm sure you won't be angry if I point out your syntax problem: you forgot the semi-colon. It's a common mistake though. The proper syntax is:

use Python;

Intro paragraph (0)

Anonymous Coward | more than 9 years ago | (#13559556)

That review is so long. winded and obtuse. It makes me want. To write. Sentence fragments. Just to take a breath.

the best practice (0, Troll)

Surt (22457) | more than 9 years ago | (#13559559)

Don't use perl.

Re:the best practice (1)

Surt (22457) | more than 9 years ago | (#13559679)

Oh come on, troll? The python guy is already up to +5 funny!

Re:the best practice (1)

A beautiful mind (821714) | more than 9 years ago | (#13559906)

That doesn't make what you have said more funny.

#1 Perl Best Practice (4, Insightful)

GillBates0 (664202) | more than 9 years ago | (#13559565)

use strict;

Ofcourse if you're using Perl4 and below, you're out of luck...

#0 Perl Best Practice (0)

Anonymous Coward | more than 9 years ago | (#13559857)

use Python ;-)

Watch out for the SOAP... (0, Troll)

Wee (17189) | more than 9 years ago | (#13559983)

use Python ;-)

Unless you need to do anything with SOAP, in which case Python is the by far the worst tool for the job...

-B

Buzzkill (4, Funny)

red_dragon (1761) | more than 9 years ago | (#13559572)

What's the point of using Perl if your code suddenly becomes intelligible? After all, there is more than one way to obfuscate it.

Re:Buzzkill (1)

oneiros27 (46144) | more than 9 years ago | (#13559653)

You probably want to read the first three chapters, then, which cover standardizing your formats and naming conventions, so that things are easier to follow.

And it's possible to obfuscate crap in any language -- the problem is that there are just so many bad programmers who have written Perl. I'm guessing there are equally bad Visual Basic programmers to Matt Wright, but they're just not as infamous, as they didn't decide to share out their inintended malware for people to learn from.

Re:Buzzkill (1)

flakier (177415) | more than 9 years ago | (#13559870)

tehee, I remember seeing so much bad VB code on geocities.

Maybe it's just that there's so much of it that no one example really stands out.

For me I see perl as allowing one to write bad code and VB as actively encouraging it with poor string handling abilities, etc...! Note: I haven't learned nor have I any experience with the newer VB.Net which in theory would promote better coding.

My belief is that most VB6 utility programmers would be better off writing in Python or Ruby

Re:Buzzkill (1)

Sanity (1431) | more than 9 years ago | (#13560050)

You probably want to read the first three chapters, then, which cover standardizing your formats and naming conventions, so that things are easier to follow.
Indeed, the language positively encourages unreadability, but if you are stubbornly determined to write readable Perl, it is possible.
And it's possible to obfuscate crap in any language
Yeah, but at least some languages try to encourage readability, Perl is obfuscated by default.

Use Ruby... (-1, Troll)

Ingolfke (515826) | more than 9 years ago | (#13559574)

because it's shinier.

Perl best practices? (-1, Troll)

davevr (29843) | more than 9 years ago | (#13559588)

That's easy - use Python! /ducks!

Wanna know the BEST perl practice? (-1, Redundant)

Anonymous Coward | more than 9 years ago | (#13559596)

Use python instead.

Best Practice? (1, Funny)

kevin_conaway (585204) | more than 9 years ago | (#13559607)

Don't write it.

/I kid because I love.

Re:Best Practice? (4, Funny)

baadger (764884) | more than 9 years ago | (#13559688)

Warning: main(php/rss_parse.inc): failed to open stream: No such file or directory in /home/groups/p/py/pyscrabble/htdocs/inc/about.php on line 5

Fatal error: main(): Failed opening required 'php/rss_parse.inc' (include_path='') in /home/groups/p/py/pyscrabble/htdocs/inc/about.php on line 5
... yeah because PHP is working out so well for you.

Re:Best Practice? (1)

kevin_conaway (585204) | more than 9 years ago | (#13559762)

Meh. Its a hiccup on sf, not my php code. It does that from time to time.

sorry, I have to take a cheap shot: (-1, Troll)

lawpoop (604919) | more than 9 years ago | (#13559610)

Migrate to Python.

NT ;)

A "best-practice" in Perl is like... (-1, Troll)

scovetta (632629) | more than 9 years ago | (#13559626)

Following best-practices while coding in Perl is like following standards of hygiene when torturing someone to death.

I code in Perl sometimes, so therefore I have the right to knock it. And any programming language that allows garbage like this deserves to be knocked.

@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2) +=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[ P.]/&&
close$_}%p;wait until$?;map{/^r/&&}%p;$_=$d[$q];sleep rand(2)if/\S/;print

Re:A "best-practice" in Perl is like... (0)

Anonymous Coward | more than 9 years ago | (#13559642)

There's a bug in that code!

Perhaps it doesn't... (1)

RLiegh (247921) | more than 9 years ago | (#13559652)

Here's what I got when I put it into a file called 'wtf.pl'
Can't modify constant item in scalar assignment at ./wtf.pl line 2, near "".URRUU\c8R";"

syntax error at ./wtf.pl line 5, near "&&}"
Execution of ./wtf.pl aborted due to compilation errors.

Re:Perhaps it doesn't... (1)

scovetta (632629) | more than 9 years ago | (#13559690)

[obvious]First, you shouldn't just try to execute code you find on /.[/obvious] Second, you can send your bug reports to the site that I stole the snippet from: http://perl.plover.com/obfuscated/ [plover.com]

Re:Perhaps it doesn't... (1)

RLiegh (247921) | more than 9 years ago | (#13559717)

[obvious]First, you shouldn't just try to execute code you find on /.[/obvious]

After I'm done backing up my files from my linux partition to my windwos one, linux is getting nuked, so I don't really care; I just wanted to point out that

a)maybe it doesn't run it and therefore
b)maybe it doesn't deserve to be bashed. ;)

Re:Perhaps it doesn't... (1)

RLiegh (247921) | more than 9 years ago | (#13559740)

yes, yes; ,s/windwos/windows/g I didn't catch the typo in time. :(

Re:Perhaps it doesn't... (0)

Anonymous Coward | more than 9 years ago | (#13559754)

And what do you have against bash?

Re:Perhaps it doesn't... (1)

RLiegh (247921) | more than 9 years ago | (#13559779)

Nothing in particular; I'm just set env my ways.

Re:A "best-practice" in Perl is like... (4, Insightful)

Camel Pilot (78781) | more than 9 years ago | (#13559674)

O.K. so you are not using new lines and threw in a regular expression to make things look difficult. What is your point? I can gen up an equally obtuse statement in C and C++.

Re:A "best-practice" in Perl is like... (0)

Anonymous Coward | more than 9 years ago | (#13559749)

There's a regex in there? I'm looking hard, I still don't see it.

Re:A "best-practice" in Perl is like... (3, Informative)

That's Unpossible! (722232) | more than 9 years ago | (#13560063)

Actually, there are 4 (5 if you count the empty regex after the first split):

//

/ ^$P/ix

/^[ P.]/

/^r/

/\S/

I agree with the grandparent, I don't get how this code example means Perl is bad. You can do something similar with any language that doesn't require newlines between statements, and which allows regular expressions.

Re:A "best-practice" in Perl is like... (1)

kerohazel (913211) | more than 9 years ago | (#13559706)

So what would a language above knocking look like? Would it force you to use exactly the sort of syntax that the author thought "looked" the best, right down to the indentation/bracketing style?

I've seen beautiful but bloated Perl, and efficient but ugly Perl, and all shades in between. It's just a matter of compromise, and I for one like being able to choose where in the spectrum I want my code to fit.

Re:A "best-practice" in Perl is like... (1)

irc.goatse.cx troll (593289) | more than 9 years ago | (#13559838)

Yeah, fuck c [ioccc.org]

Re:A "best-practice" in Perl is like... (1)

qwijibo (101731) | more than 9 years ago | (#13559862)

I don't hold that against the language, but I'm sure not going to hire anyone who writes code like that. Anyone can write obfuscated code in any language if they are so inclined.

Regular expressions are a good example of something that is incredibly useful and powerful, but total gibberish to people who don't understand them. I'd hate to not have them just because some people think they're ugly.

Re:A "best-practice" in Perl is like... (0)

Anonymous Coward | more than 9 years ago | (#13559883)

php is supposed to be web easy, so you get a TONNE of web apps. if you don't use best practices, you get a very clunky program (osCommerce *cough cough*)

java is supposed to be oop, so you get everyone doing things oop style. if you don't use oop only when needed, you get a lot more oop than you may have wanted.

perl is supposed to be very english like. very expressive. so you get people doing things expressively. if what you posted is your expressiveness, then you should be knocked for writing that and expecting other people to easily understand you.

Re:A "best-practice" in Perl is like... (1)

rduke15 (721841) | more than 9 years ago | (#13560011)

Loks like a buggy would-be equivalent of
print "Just another Perl hacker\n";

Re:A "best-practice" in Perl is like... (0)

Anonymous Coward | more than 9 years ago | (#13560031)

I took the liberty of piping your obfuscated code through perltidy(1) and it now looks like this:

@P = split //, ".URRUU\c8R";
@d = split //, "\nrekcah xinU / lreP rehtona tsuJ";

sub p {
    @p{ "r$p", "u$p" } = ( P, P );
    pipe "r$p", "u$p";
    ++$p;
    ( $q *= 2 ) += $f = !fork;
    map {
        $P = $P[ $f ^ ord( $p{$_} ) & 6 ];
        $p{$_} = / ^$P/ix ? $P : close $_
    } keys %p;
}
p;
p;
p;
p;
p;
map { $p{$_} =~ /^[ P.]/ && close $_ }
  %p;
wait until $?;
map { /^r/ && } %p;
$_ = $d[$q];
sleep rand(2) if /\S/;
print

Appart from a few string constants of gibberish, and some really shitty variable names, it looks like perfectly normal code.
Maybe the problem is with your coding style and not Perl?  I think you might benefit from reading Conway's book. ;-)

Ay mate? (2, Funny)

boomgopher (627124) | more than 9 years ago | (#13559667)

after all, he is one of those poor fools who insist on living in cold, unenlightened Melbourne, while I live in vastly superior Sydney. On the other hand, how can I dislike a man who manages to place a quote that involves my favourite character, Lady Bracknell. from my favourite comic play, 'The Importance of Being Earnest,' in the first few pages of his book?"

Oh, you do slay me, mate.

Is this like http://slashdot.co.au/ [slashdot.co.au] or something?

This holds true (5, Funny)

ICECommander (811191) | more than 9 years ago | (#13559669)

My Data Structures professor once said: "Perl is a write-only language" :)

Re:This holds true (1)

CrazyTalk (662055) | more than 9 years ago | (#13559713)

Thats funny, I was told the same thing about APL 25 years ago.

Re:This holds true (1)

Bastian (66383) | more than 9 years ago | (#13559867)

Heh, but now that keyboards with all those funky symbols for APL silkscreened on the keys are becoming increasingly rare, it's quite the opposite for APL.

Re:This holds true (1)

Paradise Pete (33184) | more than 9 years ago | (#13559899)

I was told the same thing about APL 25 years ago.

APL looks like a cat walked across the keyboard.

Re:This holds true (1)

stuntpope (19736) | more than 9 years ago | (#13560112)

And my Assembly prof put it down as "Perl is just a bag of tricks."

only Perl best practice needed (0)

Anonymous Coward | more than 9 years ago | (#13559672)

Only Perl best practice is to not use this bloody awful language.

And The Number One Perl Best Practice... (-1, Redundant)

Anonymous Coward | more than 9 years ago | (#13559708)

switch to Python.

Perl Best Practice: Don't use it (-1, Redundant)

mrpotato (97715) | more than 9 years ago | (#13559732)

Use something better and more maintainable, like Python or Ruby. There's no reason anymore to stick to Perl, whatever problems it used to solve can now be solved more clearly and more efficiently with other programming languages.

Please stop writing glorified shell scripts.

Re:Perl Best Practice: Don't use it (3, Insightful)

gurps_npc (621217) | more than 9 years ago | (#13559856)

Sometimes you NEED glorified shell scripts, cause otherwise the shell becomes bloated with features that most people don't need.

Re:Perl Best Practice: Don't use it (1, Insightful)

Anonymous Coward | more than 9 years ago | (#13559955)

in no other scripting language you get as many great libraries as in perl. and if you are at the level of writing own modules (yeah, that is not as easy as in python), this book is for you-and you are already one of us. strange guys who love perl...

what I wanna say: the standard perl script is quite short ( 200lines). then libs and their apis are more important than anything else.

count me in.. (-1, Redundant)

Anonymous Coward | more than 9 years ago | (#13559739)

..with the folks here who are saying "use something else".

Seriously.

Perl is just too "clever". It forces you to stop and marvel (or scorn , more likely) it's design at every turn. I felt this just today while trying to write an exception handler. I wanted to write a function that took another function as an argument, ran the function, and made sure resources were cleaned up. Pretty typical idiom (think about Lisp macros that use unwind-protect, or Ruby blocks with "finally" clauses) Think about that, I had to *write* an exception handler. And deal with strings, objects, or other scalars being thrown. Having to decide if I should overload my objects to used "ne" or "==" for equality (or both?). Why should have to think about all this stuff? In Ruby it would be just a couple lines of code. And it would be easy to read (no dollar signs and arrows all over the place).

Not trying to troll here. I've written and maintained several large high-performance mod_perl apps. I think I know what I'm doing. But Perl just gets in my face way too much. I think it's because I've worked in so many other languages, I "see" Perl differently than others do.

Looking at Perl 6, they've cleaned stuff up, there are some nice things there, but made it even MORE complicated in the process.

So, I'm working on weaning myself off Perl completely, and I suggest to others, if you think you really need a book like this, take a moment and reflect and consider if maybe it's time to switch to another language completely.

coding style (2, Insightful)

Anonymous Coward | more than 9 years ago | (#13559761)

there is one rule of coding style: you should have one.

Save THIRTEEN BUCKS (-1)

Anonymous Coward | more than 9 years ago | (#13559766)

Save yourself $13.58 by buying the book here: Perl Best Practices [amazon.com] . And if you use the "secret" A9.com discount [amazon.com] , you can save an extra 1.57%!

ok (1)

darkwhite (139802) | more than 9 years ago | (#13559770)

# perl -cW foo.pl

and use strict

But really, if you want fancy error-catching technology you'll have to wait until Perl 6.

Re:is cameo wood spyware? (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#13559788)

cameo wood http://www.kiad.net/ [kiad.net] is my source for all things perl

Re:ok (1, Informative)

Anonymous Coward | more than 9 years ago | (#13559825)

use Error;

and you have the perl 6 error handling in perl 5

Re:ok (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#13559959)

CAMEO WOOD

Short article by the same author (3, Informative)

stevey (64018) | more than 9 years ago | (#13559780)

In a similar vein there was a recent article by the same author printed on perl.com:

own the book (5, Informative)

morgajel (568462) | more than 9 years ago | (#13559783)

I picked up this book probably a month ago, and for a seasoned perl dev who plans on exposing his code to the world, it's definately worth picking up.

One nice feature I found was the chapter on formatting included vim and emacs config snippets to achieve the same effect, as well as the config file to use perltidy to do the same thing.

I agree it is dry, and it's very "bam bam bam" with the examples. Not something you can read start to finish. you'll want to try implementing things right away. I suggest taking the book a chapter at a time and implementing the changes in your code then.

There were some bits I agreed with, and some I didn't agree with; however the parts that I didn't agree with they explained in a reasoned and rational manner, and made me rethink my own thoughts on the subject.

I've recently fallen into the position where I'll be leading possibly two other developers- this book will become a standardization format for our company.

again, I highly recommend this book.
-morgajel

Best Practice #1: Use Python (1)

I'm Spartacus! (238085) | more than 9 years ago | (#13559791)

In all seriousness, every perl script should begin with the first three lines:

#!/usr/bin/perl -w
use strict;
use diagnostics;

Best Perl Practice ... in action ... (-1, Troll)

Anonymous Coward | more than 9 years ago | (#13559800)

The best thing a perl user can do is run this script ...

rm /usr/bin/perl
wget ftp://ftp.funet.fi/pub/mirrors/gcc.gnu.org/pub/gcc /releases/gcc-4.0.1/File [funet.fi] : gcc-4.0.1.tar.bz2
bunzip2 gcc-4.0.1.tar.bz2
tar xvf gcc-4.0.1.tar
cd gcc-4.0.1
./configure
make
make install

Dumb review (3, Insightful)

Anonymous Coward | more than 9 years ago | (#13559801)

Jeezis, what a lame review. Three paragraphs about the reviewer, then a listing of the table of contents, then a few useless comments like "it's edited well", "it's dry". The author doesn't like uncuddled elses, and takes issue with "rehabit". Waa! How about mentioning some of the actual best practices?

eHpV.. (-1, Troll)

Anonymous Coward | more than 9 years ago | (#13559849)

hthe lon6est or [goat.cx]

What's Perl being used for today? (0, Flamebait)

CyricZ (887944) | more than 9 years ago | (#13559875)

What big-name projects is Perl being used for today? While it was once very big for web scripting, that arena now seems to be dominated by PHP, Ruby-on-Rails, ASP, JSP, and so forth. Even Pugs, a Perl 6 compiler, is written in Haskell rather than Perl.

While I'm sure that many people find it very useful to small throw-away scripts, perhaps it has outlived its usefulness as a general-purpose language suitable for large-scale development. As such, perhaps "best practices" aren't really needed, especially if the script will be discarded after a few uses.

Re:What's Perl being used for today? (2, Interesting)

A beautiful mind (821714) | more than 9 years ago | (#13559978)

Perl didn't decrease in popularity, the others increased as people found out they can do "professional" websites in php, etc.

RoR would be nice but it lacks the granularity of perl.

Re:What's Perl being used for today? (1)

CyricZ (887944) | more than 9 years ago | (#13560028)

Assuming that is the case, then Perl is not being used as often for new development projects. And such a lack of new Perl-based systems will eventually lead to the minimalization of Perl. That in itself could be considered a decrease in the popularity of Perl.

Re:What's Perl being used for today? (1)

UtucXul (658400) | more than 9 years ago | (#13560106)

What big-name projects is Perl being used for today?
Slashcode and fink come to mind. But big projects isn't what Perl is about. It is all the little scripts that people use to keep things running where Perl does its best.
Even Pugs, a Perl 6 compiler, is written in Haskell rather than Perl.
Well, since the Perl 5 interpreter is written in C, this isn't such a change. Perl just isn't meant for systems programming.

Best Practice (1, Insightful)

A beautiful mind (821714) | more than 9 years ago | (#13559890)

Use pyth^H^H^H^Hrub^H^H^H...oh wait. NO. Cue the fucking jokes about using something else.

We are here reading this review because we want to use perl, so f*ck off, RoR, PHP, Python fanboys. Everything you can do in those languages i can do in perl, with style, so i NO don't want to hear about the hype of the year.

I couldn't live without perl one liners and i found the review helpful. Like many said before, perl doesn't force you to write readable code, but it doesn't mean noone can.

Best practice would be "use strict;use warnings;" and using indents properly.

Re:Best Practice (0)

Anonymous Coward | more than 9 years ago | (#13560014)

> I couldn't live without perl one liners and i found the review helpful.

best practices for line-liners?

seriously man, if you want to keep perl around for the occasional one-liners go for it. but i think that most people are seriously moving over to python,ruby, and php for anything more serious.

Let the Perl bashing begin... (0)

Anonymous Coward | more than 9 years ago | (#13559902)

...in 1...2...3...

cuddling? (1)

Chris Pimlott (16212) | more than 9 years ago | (#13559904)

Since no one else asked, what does he mean by "cuddling" else statements?

Re:cuddling? (2, Informative)

Anonymous Coward | more than 9 years ago | (#13560087)

"Cuddling" else means doing this:

if (...) {
} else {
}

instead of this:

if (...) {
}
else {
}

Re:cuddling? (3, Informative)

Phillup (317168) | more than 9 years ago | (#13560111)

if ($something){
  do_something();
} else {
  do_something_else();
}
vs.
if ($something)
{
  do_something();
}
else
{
  do_something_else();
}

Perl Best Practices: use Python instead (0)

Anonymous Coward | more than 9 years ago | (#13560023)

Well, Python's better, isn't it?

Best Practices (4, Insightful)

SwiftOne (11497) | more than 9 years ago | (#13560064)

As a perl programmer, I can assure you that:

1) There are reasons to use Perl. Nothing REQUIRING it, granted, but that's true of any language. Python and Ruby inhabit similar but not identical niches.

2) Line noise reputation aside, Perl can be _very_ readable. Concise done correctly means that it says what it does and does it, without unnecessary compiler syntax effort. Concise done wrong means it's not obvious what you are doing. Perl gives you enough rope to hang yourself...kind of like computers, and open source in general.

3) As far as the book goes, I was eager to get my hands on it and learn, but worried that I'd find it too limiting and restrictive. The tips ranged from the obvious (strict and warnings), the non-syntactical useful (use code and documentation template for new projects), to the small but fascinating (make your hash names end it words like "for" or "of", so that normal usage is self documenting: $name_of{$user} ). Very few of the tips did I disagree with, and even though the book talks about the importance of HAVING standard practices over what those practices are, I'm moving my dept to adopting the standards in the book because my preference is often habit over any calculated reason.

Perhaps 50% of the tips have nothing or little to do with Perl and everything to do with programming, programmers, or users.

This is not a life altering book. It is, however, a high quality book with some very good tips.

Read It (2, Informative)

Chysn (898420) | more than 9 years ago | (#13560066)

I, too, purchased the book about a month ago. I was hoping it would be sort of an "Effective C++" but for Perl.

It's nice to have, and it gives me things to think about for improving code, but it's by no means essential.

In some cases, the author's advice is inconsistent. For example, he sometimes suggests that a programmer avoid constructs that would force a reader to look something up. And some other times, he suggests using a construct (e.g., \A and \z instead of $ and ^, respectively, in regular expressions) BECAUSE it's unusual and many people will have to look it up.
Load More Comments
Slashdot Login

Need an Account?

Forgot your password?