Slashdot Mirror


Perl Best Practices

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. Perl Best Practices author Damian Conway pages 492 publisher O'Reilly Media rating 8 reviewer Tony Williams ISBN 0596001738 summary Methods of coding to improve your Perl software

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.

288 comments

  1. Smile by kerohazel · · Score: 4, Funny

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

    --
    Skype is too convoluted... Now I'm reverse-engineering the Kyoto Protocol.
    1. Re:Smile by Phroggy · · Score: 4, Funny

      It's pretty annoying to paste perl code into an IM conversation and wind up with a big yellow smiley face in the middle of your regex, though.

      Try not to let my sig scare you too much.

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    2. Re:Smile by Anonymous Coward · · Score: 1, Funny

      It's not a smiley face -- that's just his regular expression [^:-].

    3. Re:Smile by SolitaryMan · · Score: 2, Informative

      Try not to let my sig scare you too much.

      Splitting into @_ is deprecated!

      --
      May Peace Prevail On Earth
    4. Re:Smile by bogado · · Score: 1

      Well unfortunaly this happens to me all the time with c++ also. Very anoying indeed, but it is not a problem with perl but with IM in general.

      --
      []'s Victor Bogado da Silva Lins

      ^[:wq

  2. Use Python by Anonymous Coward · · Score: 0, Flamebait

    Perl Best Practices: don't

    1. Re:Use Python by Jessta · · Score: 0, Offtopic

      yeah, use python.
      And stop melbourne bashing. Just because you're city is a global whore with annoying tourists and insane roads you think you can insult Melbourne.

      --
      ...and that is all I have to say about that.
      http://jessta.id.au
    2. Re:Use Python by moro_666 · · Score: 4, Insightful

      erm ... using python might be really better in some cases, but you should be reminded that almost every unix box has perl and as maybe a shocking surprise to you, pretty many of them are missing python ... for example a minimal debian install has perl but lacks python. i put up most server like machines with pure debian at start, so i have no python until i fetch a program that needs it.

      imho the power of python isnt the clear syntax, clear syntax can be written in perl too, some people are just too lazy to do it. python has really good threading and a nice oop model, perl's ithreads are still quite a mess and the variable & oop layer across it is even fuzzier and more difficult to bite through than the h4x0r'5 scripts ... this makes large python applications pretty manageable and turns large perl applications often into a mess. althrough the problem with both languages for me is that 3-rd party site packages likes wxwindows/tk/opengl bridge packages are often in broken dependancies and it really can make you swear a lot if you want to upgrade your box and because of 1 dependancy half of the python/perl gui programs wave you bye-bye. cant they really integrate some form of gui that would be python/perl native and work across platforms ? this way i would depend on 'john smith' to get some nice python/perl widget running ...

      both languages are excellent for writing tiny helper tools for linux (tools that linux is missing a lot for dumb users), C and Java are both overkills for such simple tasks (a nice example of an overkill is a installer that is powered by a java gui, this is inhuman, uses twice the memory and need a bloating jvm to run). but without a really stable and "always being there" gui package these tools break a lot :(

      i believe that perl is good in it's own key places, mostly being compact and very portable. in large and multithreaded applications ofcourse python rolls the house in the scripting world.

      and for ruby fans, lets wait until the next version rolls out, then we may have a really good spot for that one too :) (idea is good but current implementation does really cut it yet)

      use the right tool for the job and for the best practices use strict and warnings in perl, indent your code and avoid regexp hacks where you dont need them.

      --

      I'd tell you the chances of this story being a dupe, but you wouldn't like it.
    3. Re:Use Python by Anonymous Coward · · Score: 0
      Perl Best Practices: don't

      ...or at least wear a condom.

    4. Re:Use Python by Fujisawa+Sensei · · Score: 1

      If you like Python, you must love COBOL.

      Trying to think of a scripting language I like less than Python? AREXX? Nope; Perl? Nope; Ruby? Nope; TCL? Nope; BASH? Nope; KSH? Nope; AWK? Maybe, but that's just because the docs suck.

      Learning the basics of Perl is easy, just start with perldoc perl. But mastering perl is a different matter.

      Personally I like Perl, features like not having to use escaped strings for regualar expressions kick make coding the language a joy.

      --
      If someone is passing you on the right, you are an asshole for driving in the wrong lane.
  3. Grammar Best Practices by Anonymous Coward · · Score: 0, Funny

    "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!

    1. Re:Grammar Best Practices by bmarklein · · Score: 5, Informative

      (BE) ON A HIDING TO NOTHING -- "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).

  4. Wordstar keybindings by afd8856 · · Score: 0

    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

    --
    I'll do the stupid thing first and then you shy people follow...
    1. Re:Wordstar keybindings by koehn · · Score: 4, Interesting

      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.

    2. Re:Wordstar keybindings by bhirsch · · Score: 2, Funny

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

    3. Re:Wordstar keybindings by Anonymous Coward · · Score: 0

      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.

    4. Re:Wordstar keybindings by Procrastin8er · · Score: 0

      Apple pioneered Command
      Apple hardly pioneered the use of these keys. Apple may have applied the functions you mentioned to these sequences, but they were put to use in other OS's long before Apple came along, for the same reason you mention, ease of typing.

      --
      Slashdot - Where the slash is most definitely to the left.
    5. Re:Wordstar keybindings by avronius · · Score: 1

      Please feel free to identify which OS's used these keyboard combinations. I am curious (not baiting you), as I've used many in the past

    6. Re:Wordstar keybindings by BlueStraggler · · Score: 1
      The older WordStar keybindings had similar logic, except for navigation, not cut/paste. The WordStar bindings for E/S/D/X formed a navigation diamond from which various other operations derived. You could move anywhere in your document with your fingers never straying from a touch-typist's position. Apple discounted this approach because navigation in the future would be done with the mouse, so they moved the next-most-common features to the left hand. However, it's a poor tradeoff for power users who tend to evolve back to exclusive keyboard use after a while. Apple might not have anticipated that in the early design years.

      Meanwhile there is emacs where C-b moves left, and C-f moves right, but the b key is to the right of the f key. Completely back-assward, and clearly designed by 2-fingered knobs who were neither typists nor power users (yes, RMS, I'm talking to you) but for whom "b for backward, f for forward" seemed eminently logical. (And I say that as a hardcore emacs user.)

    7. Re:Wordstar keybindings by adavies42 · · Score: 1

      Apple has been doing so on Macs since System 1 in 1984, AFAIK. They presumably debuted in MacWrite, and possibly in the Finder's Edit menu as well (for use when editing file names). Windows picked them up in 3.1, IIRC, but the numpad versions from DOS were still useable for quite a while.

      --
      Media that can be recorded and distributed can be recorded and distributed.
      -kfg
    8. Re:Wordstar keybindings by Anonymous Coward · · Score: 0

      Not quite the same in RISC OS:

      ^Z: Clear selection
      ^X: Delete
      ^C: Copy
      ^V: Move

      ^X has caught me out a few times! You're probably wondering how ^V works when there's no Cut command: in RISC OS, the selection exists independently of the cursor (which is moved around by clicking, whereas the selection is changed by dragging.)

    9. Re:Wordstar keybindings by shobadobs · · Score: 1

      Yeah, and what's with the vi people and their counter intuitive hjkl navigation? Jesus, did they pull right out of their ass? htns would make sense, but the keys hjkl are all over the place, and only one is one the home row.

      Standards would be so much more fun if they revolved around me.

    10. Re:Wordstar keybindings by 1110110001 · · Score: 1

      Yeah and look at what they do now: cmd+opt+[left|right] for tab switching. And you can't change it to strg+tab in the system settings.

      b4n

    11. Re:Wordstar keybindings by avronius · · Score: 1

      This I know. The Grandparent suggested that there are other operating systems that provided this feature before the Macintosh. I've asked him to identify one, as I can't think of any.

      And I've used my fair share of OS's...

    12. Re:Wordstar keybindings by the+quick+brown+fox · · Score: 1

      That is really interesting! Now the original Windows clipboard keys make sense as well (Shift-Delete, Ctrl-Insert, and Shift-Insert for Cut, Copy, Paste respectively).

  5. Characters per line by RealityMogul · · Score: 3, Funny

    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?

    1. Re:Characters per line by Karma_fucker_sucker · · Score: 3, Funny

      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.

      --
      Evil people don't think they're evil. - George Lucas, Making of Ep III
    2. Re:Characters per line by coaxial · · Score: 1

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

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

    3. Re:Characters per line by Phillup · · Score: 2, Funny

      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)

      ;-)

      --

      --Phillip

      Can you say BIRTH TAX
  6. Obligatory joke by Weaselmancer · · Score: 3, Funny

    Perl Best Practices, page 1.

    Use Python.

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

    --
    Weaselmancer
    rediculous.
    1. Re:Obligatory joke by Anonymous Coward · · Score: 0

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

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

    2. Re:Obligatory joke by Anonymous Coward · · Score: 3, Funny

      Python Best Practices, page 1.

      Use Ruby.

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

    3. Re:Obligatory joke by kdorff · · Score: 1

      Man you beat me to it! I completely agree.

    4. Re:Obligatory joke by Anonymous Coward · · Score: 0

      You mean, "Slow down! Use Ruby."

    5. Re:Obligatory joke by Anonymous Coward · · Score: 0

      No, really, good comprimise: the elegance of python with the readability of perl. :)

    6. Re:Obligatory joke by shutdown+-p+now · · Score: 1

      Universal Best Practices, page 1. Use Common Lisp. Embrace the parentheses!

    7. Re:Obligatory joke by demi · · Score: 3, Insightful

      It's funny you bring it up, because here are my impressions of the book:

      It's really quite a good book. There are probably only two or three things I actually disagree with Conway on, and for a book that takes stands, that's immense. He even convinced me on the "inside-out" class approach, which I scoffed at when I first heard about it.

      The sad fact is, that if you follow all these practices, that's as good as Perl's going to get. And it's not very good. After using Ruby, or a good functional language, for a while, going back to Perl is like... well, it's not like visiting an old friend. It's like having to get back in your old jalopy because someone stole your "good" car.

      By showing us how good Perl can be, Conway shows us the limit of its quality. Once upon a time, this would be an exciting lesson (I wrote programs in Perl almost exclusively for years, and loved it). But now, it just shows how much of a papering-over it needs to seem competent.

      I like Ruby a lot. I like Erlang a lot. I wrote a lot of Python code on a huge project that used it exclusively; it has its charms, and is better than Perl, but its irritations as well ("char".join(array)? please). I'm not going to pick "the next big thing" except I will say that, for me at least, it's not Python.

      --
      demi
  7. Intro paragraph by Anonymous Coward · · Score: 0

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

  8. the best practice by Surt · · Score: 0, Troll

    Don't use perl.

    --
    "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    1. Re:the best practice by Surt · · Score: 1

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

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    2. Re:the best practice by A+beautiful+mind · · Score: 1

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

      --
      It takes a man to suffer ignorance and smile
      Be yourself no matter what they say
    3. Re:the best practice by Surt · · Score: 1

      No, but compared to his post, my post is more funny, and less trollish advocacy, and also more original, as it was posted sooner.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
  9. #1 Perl Best Practice by GillBates0 · · Score: 4, Insightful
    use strict;

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

    --
    An Indian-American Hindu committed to non-violent thought/speech/action alarmed by the global explosion of radical Islam
  10. Buzzkill by red_dragon · · Score: 4, Funny

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

    --
    In Soviet Russia, Jesus asks: "What Would You Do?"
    1. Re:Buzzkill by oneiros27 · · Score: 1

      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.

      --
      Build it, and they will come^Hplain.
    2. Re:Buzzkill by flakier · · Score: 1

      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

      --
      --
    3. Re:Buzzkill by Sanity · · Score: 1
      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.
    4. Re:Buzzkill by Jackmn · · Score: 1

      Perl is only as obfuscated as you make it. Code readability is entirely up to the developer - it is by no means 'obsfucated by default'.

      Still a nice troll though.

    5. Re:Buzzkill by elmegil · · Score: 1
      And it's possible to obfuscate crap in any language

      The grandparent needs to spend more time with http://thedailywtf.com/. I almost never see perl code, but I see bizarre coding every day.

      --
      7 November 2006: The day Americans realized corruption and incompetence weren't addressing 11 September 2001
    6. Re:Buzzkill by Phroggy · · Score: 2, Insightful

      Perl is only as obfuscated as you make it. Code readability is entirely up to the developer - it is by no means 'obsfucated by default'.

      This is exactly right. Perl doesn't force (or even encourage) you to write code in any particular style; it gives you a great deal of flexibility. If you want to write good clean maintainable code, you can; if you want to write something that looks like my sig, you can. The strict pragma will add certain restrictions to prevent you from doing particularly awful things (like not declaring your variables and not quoting your strings), but it's really up to you how you want to write your code.

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    7. Re:Buzzkill by Dwonis · · Score: 1

      As much as I agree with you about Perl, have you ever tried to write *correct* PHP code? Far, *far* worse...

    8. Re:Buzzkill by Darby · · Score: 1

      Yeah, but at least some languages try to encourage readability, Perl is obfuscated by default.

      Cripes man, just because you don't understand how to do perl.

      Write it first.
      Then compile it.
      *Then* debug it since it's easier to read now.

    9. Re:Buzzkill by owlstead · · Score: 1

      Yeah, and this makes for many scripts with different kind of make up, making all of them hard to read. Even as a computer programmer who knows C++, Java, a bit of PHP, XML, HTML, AWK, JavaScript etc. Perl scripts are a pretty hard read, normally I give up after a few sentences.

      You may be able to write readable code, almost no-one actually does.

    10. Re:Buzzkill by Phroggy · · Score: 1

      You may be able to write readable code, almost no-one actually does.

      Thus, this book. :-)

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    11. Re:Buzzkill by IpalindromeI · · Score: 1

      You may be able to write readable code, almost no-one actually does.

      The programmers that I know who write Perl make it quite readable. Unfortunately, many of the people writing Perl are not programmers. Those people would write shit in any language, because they don't know what they're doing.

      Perhaps you should not judge a language by its users, but by its uses.

      --

      --
      Promoting critical thinking since 1994.
  11. Best Practice? by kevin_conaway · · Score: 1, Funny

    Don't write it.

    /I kid because I love.

    1. Re:Best Practice? by baadger · · Score: 4, Funny
      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.
    2. Re:Best Practice? by kevin_conaway · · Score: 1

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

    3. Re:Best Practice? by Lorphos · · Score: 1

      Very encouraging. PHP seems to be very reliable.

  12. Re:A "best-practice" in Perl is like... by Anonymous Coward · · Score: 0

    There's a bug in that code!

  13. Best Best Practice: Don't Bloat Perl by Anonymous Coward · · Score: 1, Interesting
    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."

  14. Perhaps it doesn't... by RLiegh · · Score: 1
    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.
    1. Re:Perhaps it doesn't... by scovetta · · Score: 1

      [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/

      --
      Wer mit Ungeheuern kämpft, mag zusehn, dass er nicht dabei zum Ungeheuer wird. --Nietzsche
    2. Re:Perhaps it doesn't... by RLiegh · · Score: 1
      [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. ;)
    3. Re:Perhaps it doesn't... by RLiegh · · Score: 1

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

    4. Re:Perhaps it doesn't... by Anonymous Coward · · Score: 0

      And what do you have against bash?

    5. Re:Perhaps it doesn't... by RLiegh · · Score: 1

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

    6. Re:Perhaps it doesn't... by ArsonSmith · · Score: 1

      beter yet windwoes.

      --
      Paying taxes to buy civilization is like paying a hooker to buy love.
    7. Re:Perhaps it doesn't... by quasi_steller · · Score: 1

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

      Depends. Who's to say he didn't exicute that code in VMWare or some other protected environment? Just because somebody ran the code to see if you were telling the truth concerning whether that code actually ran, doesn't mean you should assume they were stupid and didn't run that code in some protected environment.

      --
      ...interesting if true.
    8. Re:Perhaps it doesn't... by mjd · · Score: 1
      scovetta says:
      Second, you can send your bug reports to the site that I stole the snippet from:
      No, the bug report goes to you, because you were the one who was too inept to cut-and-paste it correctly. The code on the web site works; the code in your post doesn't.

      By the way, your argument ("And any programming language that allows garbage like this deserves to be knocked") is inept too. There are intelligent arguments to be made against Perl, but this isn't one of them.

    9. Re:Perhaps it doesn't... by scovetta · · Score: 1

      Alright everyone. Every single thing I posted yesterday on /. was just crap. Please accept my humble apologies. It was just a bad day for expressing ideas without thinking them through.

      --
      Wer mit Ungeheuern kämpft, mag zusehn, dass er nicht dabei zum Ungeheuer wird. --Nietzsche
  15. Ay mate? by boomgopher · · Score: 2, Funny

    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/ or something?

    --
    Your hybrid is not saving the environment. Its purpose is to make you feel good about buying something.
    1. Re:Ay mate? by Anonymous Coward · · Score: 0

      Oh, you do slay me, mate.



      Actually, 'The Importance of Being Earnest' is plenty popular here in the States as well, at least among those who engage in pursuits other than watching WWF and playing Doom III.

    2. Re:Ay mate? by Anonymous Coward · · Score: 0

      Hm, sometimes Oscar Wilde is kinda gay if you ask me.

    3. Re:Ay mate? by shokk · · Score: 1

      Is that like being kinda pregnant?

      --
      "Beware of he who would deny you access to information, for in his heart, he dreams himself your master."
    4. Re:Ay mate? by brettper · · Score: 1

      Actually it would be http://slashdot.com.au/

      We don't use .co, that's the UK (and possibly NZ)

  16. This holds true by ICECommander · · Score: 5, Funny

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

    --
    All your Sybase are belong to us.
    1. Re:This holds true by CrazyTalk · · Score: 1

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

    2. Re:This holds true by Bastian · · Score: 1

      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.

    3. Re:This holds true by Paradise+Pete · · Score: 1
      I was told the same thing about APL 25 years ago.

      APL looks like a cat walked across the keyboard.

    4. Re:This holds true by stuntpope · · Score: 1

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

    5. Re:This holds true by VAXcat · · Score: 1

      Yeah, a space cat walking across a Martian's keyboard. My intro to computers course at Rice University, circa 1971, was based on APL. I concluded I hated computers and wasted 6 more years until I got a job at a DEC shop as an operator, and worked my way up to system programmer...APL almost threw me off the tracks for good.

      --
      There is no God, and Dirac is his prophet.
    6. Re:This holds true by cow-orker · · Score: 1

      You know, in Nethack, when you apply your bag of tricks, you pull a monster out of it.

      I find this kinda fitting.

    7. Re:This holds true by Phroggy · · Score: 3, Insightful

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

      Perl's syntax is very complex and it has a lot of operators. Most people don't know all of Perl's syntax, they only know a subset. However, each person knows a different subset of the language, so if you try to read code written by someone else who knows parts of the syntax you haven't learned yet, it won't make sense and you may not even be able to look it up in a reference to figure out what's going - it's easy to look up functions, but if you don't know what @foo[5..10] means, you may not know where to find out.

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    8. Re:This holds true by Angst+Badger · · Score: 1

      People have said that about just about every language when the speaker is not particularly experienced with it. Assembly language can be quite lucid if it's well-written, well-organized, and well-commented. Readable Perl code is possible. Where complex data structures are involved, it's really hard, but still possible.

      That said, having worked on some very large applications in Perl, I have been forced to the conclusion that you have to be an extremely self-disciplined programmer to write good code in Perl, mainly because the language itself tempts you at every turn to do it the easy (unreadable, unmaintainable) way. It seems to have been designed from the ground up to attract hotshots who want to prove how clever they are at the expense of the other developers who have to suffer through their code -- the sort of folks who will write a function that returns an anonymous list of anonymous hashes of anonymous functions using maps and greps nested six deep just because they can.

      Now mind you, I like Perl. But a large part of the reason I like it is that the general programming skills I learned in the course of working with a team of developers on a 750k line Perl application for a now defunct dot-bomb have served me well in other languages. If Perl doesn't teach you to write excellent comments and to refactor now when it occurs to you, and not later when you must, nothing will.

      --
      Proud member of the Weirdo-American community.
  17. only Perl best practice needed by Anonymous Coward · · Score: 0

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

  18. Re:A "best-practice" in Perl is like... by Camel+Pilot · · Score: 4, Insightful

    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++.

  19. Re:A "best-practice" in Perl is like... by kerohazel · · Score: 1

    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.

    --
    Skype is too convoluted... Now I'm reverse-engineering the Kyoto Protocol.
  20. Non-QWERTY by cynicalmoose · · Score: 1

    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.

    --
    Exercise your right not to vote. thinkoutside.org
  21. Re:A "best-practice" in Perl is like... by Anonymous Coward · · Score: 0

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

  22. coding style by Anonymous Coward · · Score: 2, Insightful

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

  23. ok by darkwhite · · Score: 1

    # perl -cW foo.pl

    and use strict

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

    --

    [an error occurred while processing this directive]
    1. Re:ok by Anonymous Coward · · Score: 1, Informative

      use Error;

      and you have the perl 6 error handling in perl 5

  24. Short article by the same author by stevey · · Score: 3, Informative

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

    1. Re:Short article by the same author by Mr.+Mikey · · Score: 1

      The first line of that article reads:

      "The following ten tips come from Perl Best Practices, a new book of Perl coding and development guidelines by Damian Conway."

      It's an excellent article, and those ten tips are good ideas no matter what language you code in.

      --
      wants to be the first monkey to touch the monolith
    2. Re:Short article by the same author by stevey · · Score: 1

      Yeah I realised after I posted the link that I'd been too quick. I should have added that to the list.

      I guess the points do apply to other environments generally, thinks like "write tests", and "use source control". It is just presented as a perl piece, with the sample code to match.

    3. Re:Short article by the same author by Anonymous Coward · · Score: 0

      The list:
      -------------
      1. Design the Module's Interface First
      2. Write the Test Cases Before the Code
      3. Create Standard POD Templates for Modules and Applications
      4. Use a Revision Control System
      5. Create Consistent Command-Line Interfaces
      6. Agree Upon a Coherent Layout Style and Automate It with perltidy
      7. Code in Commented Paragraphs
      8. Throw Exceptions Instead of Returning Special Values or Setting Flags
      9. Add New Test Cases Before you Start Debugging
      10. Don't Optimize Code--Benchmark It
      ---------------

      There are a couple of things about exceptions that I would quible about, but for the most part, its a no-shit-sherlock kind of list from the perspective of a professional developer.

      But it still doesn't address the fundamental problem with perl: Complexity. The sheer number of rules and possible interactions make it impossible for a human to:
      1. remeber all the rules that apply to a given situation, thus producing correct code.
      2. understand how the machine is going to interpret the code, and what is going to happen when optimizations of any kind take effect.
      3. Write an effecitive interpreter/compiler without having a large number of bugs.
      Note that this applies just as well to C++ and a whole load of other languages.

  25. own the book by morgajel · · Score: 5, Informative

    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

    --
    Looking for Book Reviews? Check out Literary Escapism.
  26. Best Practice #1: Use Python by I'm+Spartacus! · · Score: 1

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

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

    --
    "War is God's way of teaching Americans geography." -- Ambrose Bierce
    1. Re:Best Practice #1: Use Python by John+Bokma · · Score: 1

      instead of -w -> use warnings;

  27. Dumb review by Anonymous Coward · · Score: 3, Insightful

    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?

    1. Re:Dumb review by Anonymous Coward · · Score: 0

      Why three paragraphs about the reviewer? Because his opinions are subjective and if we are to understand what he's saying, we need to know a bit about where he's coming from.

      As for describing the book instead of giving examples, this is a "Review" and not a "Preview".

  28. TripMaster Monkey a GNAA operative? by Anonymous Coward · · Score: 0

    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.

  29. Re:A "best-practice" in Perl is like... by irc.goatse.cx+troll · · Score: 1

    Yeah, fuck c

    --
    Pain lasts, kid. Its how you know you're alive. Sometimes I think this growing up thing is just pain management-TheMaxx
  30. Re:Best Best Practice: Don't Bloat Perl by Mr.+Underbridge · · Score: 4, Insightful
    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.

  31. Re:Perl Best Practice: Don't use it by gurps_npc · · Score: 3, Insightful

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

    --
    excitingthingstodo.blogspot.com
  32. #0 Perl Best Practice by Anonymous Coward · · Score: 0

    use Python ;-)

  33. Re:A "best-practice" in Perl is like... by qwijibo · · Score: 1

    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.

  34. What's Perl being used for today? by CyricZ · · Score: 0, Flamebait

    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.

    --
    Cyric Zndovzny at your service.
    1. Re:What's Perl being used for today? by A+beautiful+mind · · Score: 2, Interesting

      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.

      --
      It takes a man to suffer ignorance and smile
      Be yourself no matter what they say
    2. Re:What's Perl being used for today? by CyricZ · · Score: 1

      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.

      --
      Cyric Zndovzny at your service.
    3. Re:What's Perl being used for today? by UtucXul · · Score: 1
      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.
    4. Re:What's Perl being used for today? by jbellis · · Score: 1

      That really proves his point, doesn't it?

      IIANM slashdot is over 6 years old and fink is at least 4.

      I'm sure there are better ways to become clinically depressed than maintaining a nontrivial perl codebase, but none comes to mind atm.

    5. Re:What's Perl being used for today? by SilicaiMan · · Score: 2, Interesting
      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.

      Which, IMHO, is the best thing to happen to Perl. One of the main reasons why Perl got such a bad reputation is because it is very easy to pick up. The web was (and still is) littered with a huge amount of Perl snippets written by teenage script kiddies who think that Perl and CGI are synonyms (Matt's Script Archive comes to mind).

      Personally, I have been using Perl professionally on an almost daily basis (and I'm NOT in IT or software) for over 7 years now, and have never written a single CGI program.

      Just because you don't see any web scripts written in Perl doesn't mean Perl is finished. I would actually consider that a new beginning.

    6. Re:What's Perl being used for today? by hanksdc · · Score: 2, Informative

      Is Amazon big-name enough for you?

      http://www.masonhq.com/?AmazonDotCom

      (Mason, btw, is a templating system written in Perl)

    7. Re:What's Perl being used for today? by cow-orker · · Score: 1

      Perl just isn't meant for systems programming.

      Neither is Haskell. Hell, one year ago most would have argued that Haskell is a research language, not meant for anything at all.

      Perl is about... all the little scripts.

      Perl is only good for scripting as long as you don't know anything better. One nice option is Scheme (via scsh). I'd really rather put up with nested parens than with the multitude of unpronounceable special characters in Perl. And I really dislike Perl's design principle of The Maximum Astonishment, too.

    8. Re:What's Perl being used for today? by Jackmn · · Score: 1

      use English;

    9. Re:What's Perl being used for today? by rascal1182 · · Score: 1

      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.

      The trends have moved towards frameworks. Perl now has Catalyst, which is "heavily inspired by such frameworks as Ruby On Rails, Maypole, and Spring," but it's coming a little late(r) to the party.

      Even Pugs, a Perl 6 compiler, is written in Haskell rather than Perl.

      I once had to write an interpreter for a subset of the OCaml language in OCaml for a class.

      --

      "Yarrgh! I be just a paintin' of a head..."
    10. Re:What's Perl being used for today? by Dryth · · Score: 2, Informative

      CPAN? Though let me know if it's not exactly what you had in mind.

      One of the reasons we're able to write quick throw-away scripts for virtually all purposes in Perl is that we have a massive Perl codebase to draw from. CPAN is often cited as one of Perl's greatest strengths, particularly against the likes of Ruby, Python, and even PHP. Not that their communities aren't moving in this direction, but the fact that each has projects whose mission statement is essentially "Be like CPAN for [insert language here]" should be an indicator of what remains desirable with Perl, and how we might characterize it as a big-name project.

      And if there's one place where you'd want to maintain best practices...

    11. Re:What's Perl being used for today? by Anonymous Coward · · Score: 0

      Throughout all the time that I have coded Perl professionally, I have found that there are indeed those throw-away scripts that are used probably one or two times. More often, however, many "throw-away" scripts end up being the unfortunate cornerstones of larger systems. My biggest complaint regarding these scripts is that they are seemingly without exception, poorly written and never documented. It always amazes me how little someone actually considers the future maintenance after they would be long gone. Five minutes in the original script documenting it typically would save an hour of time for someone later trying to figure out what all the spaghetti does. I've found that when written with some consideration of future maintenance, Perl can be an excellent scripting language that can be used to build some pretty complex software. There are quite a number of apps out there that use it such as mail clients, and bug tracking systems, and of course web frameworks.

    12. Re:What's Perl being used for today? by cow-orker · · Score: 1

      Helps an awful lot against gibberish like @{$a[0]} to get the first row of a matrix.

      Tell me again, how do i get the first element of the first array contained in the array of (references to) arrays? Was it ${$a[0]}[0] or probably @{$a[0]}}->[0] or a different permutation or another diacritical mark somewhere in there? Remind me, how do i pass a filehandle to a function? Something about \ or * or both and somehow I wouldn't pass a filehandle at all, but rather a "symbol table entry".

      Astonishing.

    13. Re:What's Perl being used for today? by belg4mit · · Score: 1

      Except that it's not see. Maypole is Perl, and Cataylst's daddy.

      --
      Were that I say, pancakes?
    14. Re:What's Perl being used for today? by belg4mit · · Score: 1

      Pugs is a proof of concept for the "white papers",
      but more so it's an excuse for the author to *learn* Haskell.

      --
      Were that I say, pancakes?
    15. Re:What's Perl being used for today? by ides · · Score: 3, Informative

      amazon.com
      ticketmaster.com
      imdb.com
      slashdot.org

      Just a few of the sites that run Perl...

      Pugs is more of a tool to aid in development of Perl 6, it is not the official "to be released" Perl 6.

      Personally I find Perl to be very useful in large scale enterprise development. You can write bad code in any language ( yes any language ), that is the fault of the programmer not the language.

      It's like trying to blame a poorly constructed house on the fact your dremel tool has 9,000 options to it! :)

    16. Re:What's Perl being used for today? by Lost+Found · · Score: 1

      You mean large-scale development of sites like Amazon.com or Slashdot.org?

      Oh, and Pugs is written in another language because Perl6 is meant to be self-hosting, and hence needs to be bootstrapped.

    17. Re:What's Perl being used for today? by Mr+Bill · · Score: 1
      my $matrix = [
      [0, 1, 2],
      [3, 4, 5],
      [6, 7, 8],
      ];

      # first element of first row
      my $p00 = $matrix->[0]->[0];

      # second element of second row
      my $p11 = $matrix->[1]->[1];

      Astonishing isn't it!

      open(my $fh, "filename") or die "Can't open filename: $!";

      # pass filehandle to a function
      process($fh);

      Wow, that was even more astonishing! If you don't know anything about perl then quit bad mouthing it.

    18. Re:What's Perl being used for today? by huiac · · Score: 1

      Just because things *can* be hard or ugly, doesn't mean they *need* to be.

      To answer your question:
          $a[0][0]

      Also, you don't need @{$a[0]}; $a[0] is every bit as much the 'first row of the matrix', just expressed as a reference than a list; in practice, it's more likely that's what you want most of the time anyway.

      As for filehandles, if you want to write code that is reusable or scale, you'll do something like this:

          use IO::File;
          my $fh = new IO::File('/etc/passwd');

      or you will need to take special measures to avoid polluting the global namespace (just like in any other language that allows you to use globals for your own ends).

      Many of the things you (and most people) complain about are things that are in Perl5 because they were in Perl4, and the Perl community has never been keen to break compatibility with a huge library of existing code, or require people to change their habits just because; however that doesn't mean you're smart to use them in projects of any scale.

      John.

    19. Re:What's Perl being used for today? by rascal1182 · · Score: 1

      Yeah, I noticed that after I posted. I was hoping nobody else would.

      Rails has gotten the most press, so it's naturally taken away some of the thunder. I haven't compared them extensively to claim one is better, because I don't care that much.

      If we're talking languages, though, comparing Perl to Rails like comparing apples to apple pie. Perl vs. Ruby is a discussion (that I've had before).

      --

      "Yarrgh! I be just a paintin' of a head..."
    20. Re:What's Perl being used for today? by Anonymous Coward · · Score: 0

      Enough of this bullshit!

      The Mandrake/Mandriva Linux Distribution uses perl heavily to provide a polished distribution.

      Perl is also hugely successful in bioinformatics and linguistics as well as a variety of sciences - one of my old school friends uses it heavily in his research for Wellcome Trust Sanger Institute, in cambridge.

      If you are buying or selling shares, gambling or shopping online then more likely than not the system will be powered by perl, often in combination with other languages. Perl still rules in ecommerce and system integration, and will continue to do so for some time.

      Most of the perl jobs I see in London are Finance, Utilities, Banking, Ecommerce, System Testing and Mobile Comms - a lot of large systems, critical systems and blue chip, and thats excluding the system administration and infrastructure jobs.

      In fact this year I have worked exclusively in Perl to provide webservices, ecommerce, data migration and logistics for our clients - all large systems, many involving legacy code from up to 5 or 6 years ago, many of the clients are bluechip with one ecommerce site turning over millions of GBP a year alone.

      In my own time I maintain and support several large projects and work with several other developers on the Maypole MVC framework, this is a midsize to large project with many users, large sites and an active community.

      If any of the slashdot kiddies here actually knew jack shit, they would be using perl rather than jumping on this weeks bandwagon. If you were doing anything important then you'd notice how essential perl is to the internet, open source and e-business but most of the fucktards here are all mouth and no trousers.

    21. Re:What's Perl being used for today? by cow-orker · · Score: 1

      ...it's more likely that's what you want most of the time anyway.

      And such a comment regarding to the language where there's "more than one way to do it"?

      My last real contact dates a while back, but it was Perl5, definitely. I distinctly remember that I certainly wanted the array. In list context. If I need that, I need that. Definitely, not unlikely. And the unpronounceable @{$...} was really annoying.

      $a[0][0]

      Nice. Works for array-of-references-to-arrays, but not for reference-to-array-of-references-to-arrays. Didn't you tell me it was the latter which I was more likely to want anyway? And why did the other poster put an arrow between the brackets? Just for fun or does it do something sometimes?

      ...or you will need to take special measures to avoid polluting the global namespace (just like in any other language that allows you to use globals for your own ends).

      That's exactly the point! WTF do I need special measures?! What globals?! I hate global state, that's why I want to pass the filehandle to a function. If it works with a goddamn hash table, it has to work with a friggin filehandle as well!

      Really, I have no prejudices against perl. I worked with it, together with coworkers who allegedly knew much, much more about it than I did. The application was unreliable. Everytime it broke, it broke in subtle, unpredictable ways, including algorithms that worked only "most of the time", HTML code visible to the user, because someone put a backslash too much somewhere, gross memory leaks and even segfaults due to an overeager garbage collector.

      It was a horrifying experience. This agony should not be foisted on anyone, really.

    22. Re:What's Perl being used for today? by huiac · · Score: 1

      Well, you can't have your cake and eat it too; I told you what to do with @a, which is what you used in your example; for my alternative, you'd use

          $a->[0][0]

      instead; (almost) any reference can be dereferenced in this way.

      FE:
          my $x = sub {
              return shift;
          }

          my $a = $x->(1);

      Unless you do something to localize it, a variable is global; if you don't specify a scope then there are few options. This is true of almost all languages that don't rely on explicit declarations. If you aren't familiar with the concept, then I'm guessing you've done a fair bit more PHP or VB than Perl (and haven't read many of the Perl manpages).

      Using a glob reference doesn't solve this problem - just disguises it by creating a reference to a symbol table slot; unless you've done something to ensure that the reference is to a localized variable, it's a poor practice that would be non-portable in any context; like using hard-coded file descriptor numbers would be in a C library function (to which this practice is broadly equivalent).

      Your comment 'If it works with a goddamn hash table, it should work with a frigging filehandle as well!' is just wrong; hash tables are purely internal constructs, whereas file handles are connected to the Real World and must conform to the requirements of the underlying system calls; in Perl4, each filehandle maps onto a file descriptor number that is global to the application - nothing you or I can do about that, although we're free to shuffle around how they're hooked up internally. Perl4 passes this model up to your code, and maps each descriptor to a symbol name (some pre-defined, some created as you open & close file handles); Perl5 provides an abstraction layer that hides these details, but they're still there underneath. If you don't want the hassle of dealing with the nuts-and-bolts (and you strike me as the kind of person who doesn't), use the abstraction layer and this particular poblem will largely go away.

      Perl 5 provides a clean, almost infinitely flexible OO environment you can use to build clean, scalable, protable code; if you don't use them, then I can't see it as Perl's fault if your code isn't clean, portable or scalable.

      The corollary is that Perl5 provides almost complete compatible with Perl4, and if you take advantage of that then you shouldn't be surprised if your Perl5 code looks like Perl4, and is relatively unportable and unscalable.

      As for your application issues, I'll pass more or less silently over issues like blaming the language because coder's can't type, and handing apparently untested code onto users; but some of the things you mentioned would prompt me to say 'Check the scope of your variables'; as for segfaults from an over-eager garbage collector - excuse me?? The only issues I've ever had with the garbage collector in Perl is that it's sometimes so cautious to avoid breaking circular references that it needs explicit help (which,m along with uncontrolled use of globas, may explain the 'memory leaks' you saw).

      And if you're paying, feel free to foist some of that horror my way :)

      John.

    23. Re:What's Perl being used for today? by huiac · · Score: 1

      Forgot one of your questions:

      > ...why did the other poster put an arrow between the brackets?

        '->' is the dereferencing operator; it's a postfix operator that translates as 'the thing this is a reference to', but also turns up in the OO syntax as a way to reference an object's methods.

      I omitted it because I can, and I'm lazy; the '[0]' is something that's only available for arrays, and as a convenience Perl5 allows me to omit the dereference in contexts like this where there's no ambiguity; for instance if I say
          my $a = [ { squared => 0, cubed => 0 },
                              { squared => 1, cubed => 1 },
                              { squared => 4, cubed => 8 }
                          ];
      then I can use
          $a->[2]{squared}

    24. Re:What's Perl being used for today? by cow-orker · · Score: 1

      Unless you do something to localize it, a variable is global;

      Oh, I know what "my" and "local" do, and I do use them. I don't know where globals got into your... uhm... scope, but what I meant is this: An argument to a function can be anything, scalar or list, but no file handle. This works:

      %a = { foo => bar }
      fun( %a )

      The same doesn't work with a file handle:

      open FILE, "test.txt"
      fun( FILE )

      (There may be a comma too much in there.) To make it work, I would have to pass a reference to the symbol table entry containing the handle, of all things. Come on, even if you know about that, it is surprising and anything but orthogonal! And there's no intrinsic difficulty, even C can pass file descriptors around.

      Perl 5 provides a clean, almost infinitely flexible OO environment

      No, it doesn't. There's support for doing what is usually termed OOP (though nobody has an exact definition), and it certainly is flexible, too flexible for some peoples tastes, but it most definitely is not clean. Years after using this I feel the need for a shower just thinking of it.

      segfaults from an over-eager garbage collector - excuse me??

      We were using CORBA from Perl. The two don't go together very well, or maybe the implementation sucked. Whatever, Perl routinely threw my servants away while they were still needed. The next incoming request sent the application down with a segfault. I "fixed" it by giving each servant a reference to itself, effectively playing another bug in the GC against the first. Actually, Perl5 has no garbage collector, just reference counting (or something very close to that).

      As for the memory leak... well, my variables were local. The problem was Parse::RecDescent, which leaves junk in the global symbol table each time it runs (it evals lots of subs). The GC cannot clean symbols, so this memory leaks. Granted, using a recdescent parser for ini-files was a stupid design anyway, but beyond my control.

      When I finally had it with the crashing server, I wrote a wrapper in C(!) that checked if the CORBA servants where still alive and then restarted the server. Most people would write a Perl wrapper when they don't trust their C code... You see, I'm not that stupid and have been programming for years in various languages, but Perl was the only one I positively hated afterwards.

      And if you're paying, feel free to foist some of that horror my way :)

      I don't think so. I have found my panacea in Haskell (you know, that strange language Pugs6 is implemented in). It's far more regular, is easier on the eye and - believe it or not - it is more concise.

    25. Re:What's Perl being used for today? by huiac · · Score: 1

      If you really want to 'pass a filehandle' and don't want the convenience of modern methods or passing a reference to its symbol table, you can always pass the underlying file descriptor number, but I can't see the appeal myself; the methods you despise arose when Perl was very young and file handles were first added as 'first and a half class citizens', and Perl5 gives you a more convenient, modern alternative; it's not Perl5's fault if you won't use them when you want portable, scalable code.

      The CORBA issues you have are almost certainly the fault of your CORBA interface; in the glue that ties Perl to C, it's much harder to get the memory management right - the interface has to ensure that C and Perl agree not only on the size and structure of items, but who's responsible for managing them; it's possible that (e.g.) the C Corba routines were being passed memory allocated by Perl and then passing it to free() or realloc(), or just hanging on to it until after Perl had GC'd it. Or something silly like passing an int when you need a long, or allocating a buffer of 32 bytes for a string of no more than 32 characters, etc.

      I can't comment on Parse::RecDescent, never having actually used it; however the changelog for version 1.24 references a bugfix that sounds like it may be your issue.

      Personally, when writing code that may have to read multiple ini files multiple times (sadly, a common requirement), I'd normally use a global hash to cache the parsed files - if there's one thing worse than attempting to extract allegedly useful information from a knock-kneed, illegitimate format like an .ini file, it's wasting time parsing the same file twice.

      And Haskell looks really neat - as a one-time fan of declarative languages I think most people take far too narrow a view on what a language should look like and how it should 'work', and I'm more than happy to give a cheer for functional languages.

      John.

  35. Re:A "best-practice" in Perl is like... by Anonymous Coward · · Score: 0

    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.

  36. Best Practice by A+beautiful+mind · · Score: 1, Insightful

    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.

    --
    It takes a man to suffer ignorance and smile
    Be yourself no matter what they say
    1. Re:Best Practice by Anonymous Coward · · Score: 0

      > 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.

    2. Re:Best Practice by KiltedKnight · · Score: 2, Insightful
      Where I am now, someone who is no longer here used Python to write a new project. He used this project to learn python, too. There's a problem... nobody else here knows it or even wants to know it. Why? It's HORRENDOUS for the job it's currently doing now... something very highly I/O bound. Depending on the machine it runs on, it could take anywhere from 2.5 hours (super-fast server-type machine) to 10 hours (P4-1.6 with 512MB) to run. The poor performance of this project has caused just about everyone in my group to swear off of python.

      It's also not worth our time rewriting it.

      Not too long ago, I discovered the results of operations testing on various languages. Python was the worst in every category except one, where Java (1.4.x) became the worst (Java 1.4.x was the second worst in most of the other cases). This benchmarking, however, was a couple of years old, so it's possible other improvements have been made along the way.

      For doing various system administration tasks, file massaging/processing, and stuff like that, I find perl to be quick and easy to use. Mainly because perl's regex engine has been so highly optimized, it tends to run a lot faster. I also have general issues with languages that are white-space dependant for their syntax... which is why unless it's something really simple, I tend to avoid UNIX shell scripts too.

      I've also had a Java addict compliment me on my perl style, syntax, etc, because it was clear and readable... and this was for a major financial securities project.

      If you really want a "best practice," try writing clear, understandable code, regardless of the language you use. It'll get you further.

      --
      OCO is Loco
    3. Re:Best Practice by the_rev_matt · · Score: 1

      Based on that logic I could say that Java is crap and useless for serious software development. I'm on a project where the original coding was done by people learning Java (and OO in general) on the job. It's horrendous, but I'm smart enough to realize that it's not the fault of the language that their code sucks.

      --
      this is getting old and so are you

      blog

    4. Re:Best Practice by geniusj · · Score: 1

      I wrote a log parser in perl that just accepted log input via STDIN, incremented a few variables depending on what it read, and then outputted those variables to a file (used for graphing). Well, during a huge traffic spike, that perl script was eating 90+% CPU (because the other 10% was being used by the daemon in question). I rewrote that in C and it started using less than 2%.

      If it were all about execution speed, no one would use perl.

    5. Re:Best Practice by Taladar · · Score: 2, Insightful
      Everything you can do in those languages i can do in perl, with style...
      Yeah, you can do it, but can you recognize everything when you see it as other people's perl code (say, a library you want to use, without documentation)?
    6. Re:Best Practice by A+beautiful+mind · · Score: 1

      Yes.

      --
      It takes a man to suffer ignorance and smile
      Be yourself no matter what they say
    7. Re:Best Practice by KiltedKnight · · Score: 2, Insightful
      Well, if you're looking for execution speed, economy of resources, and other things like that, languages like Java, Perl, Python, et al, are NOT ones you should even consider. I've heard more than enough complaints about friends being called "obstructionists" because they won't rewrite a critical system in Java, never mind that the Java versions of programs the name-callers have done take much longer to run... but they're oh-so-pretty and leading-edge technology.

      The problem with the program in question where I work is that it was poorly designed from the get-go. I can tell you for a fact that the vast majority of the program's run-time is in the single line that prints out a 512MB object to a file in human-readable format.

      Languages are tools. You should use the tool that's best for the job, not because it matches the newest buzz-words.

      --
      OCO is Loco
    8. Re:Best Practice by truckaxle · · Score: 1

      Then you are probably doing something wrong. Perhaps you are creating a large array with a push and the memory footprint increased until the system started thrashing.

      I often use perl to process large amounts of data such as demultiplexing binary data and doing some bit and byte swapping. I rewrote the application in C and increased the speed by less than 10%, wasn't worth the extra week of development. Another case in point I have a C based parsing program that analyzes C source to produce metrics like lines of code per function, complexity metric, indentation depth, etc. Several years later we rewrote the application in perl at a 4 to 1 reduction in sloc. The preformance (which was not an issue) was again within 10% of the C based approach.

    9. Re:Best Practice by bill_mcgonigle · · Score: 1

      Yeah, you can do it, but can you recognize everything when you see it as other people's perl code (say, a library you want to use, without documentation)?

      Is there a language where that's true for the worst library programmer? Java is somewhat close, but you can still write some terrible libraries in java. As long as foo.AkR catches the right exceptions it'll compile and you'll still have no idea what AkR() does.

      --
      My God, it's Full of Source!
      OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
    10. Re:Best Practice by the_rev_matt · · Score: 1

      Absolutely correct. Mod that sucker up.

      --
      this is getting old and so are you

      blog

    11. Re:Best Practice by A+beautiful+mind · · Score: 1

      Yea, right, "troll".

      You fucking SLASHBOTS CANT MAKE A FUCKING DIFFERENCE BETWEEN A REAL TROLL AND A PERFECTLY SOUND OPINION, you gaping assholes!

      The sample above was included so that it is possible to make difference between the above two. Please _moderate_ this post as troll, as this is what it deserves, but my original post would not.

      --
      It takes a man to suffer ignorance and smile
      Be yourself no matter what they say
  37. Let the Perl bashing begin... by Anonymous Coward · · Score: 0

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

  38. cuddling? by Chris+Pimlott · · Score: 1

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

    1. Re:cuddling? by Anonymous Coward · · Score: 2, Informative

      "Cuddling" else means doing this:

      if (...) {
      } else {
      }

      instead of this:

      if (...) {
      }
      else {
      }
    2. Re:cuddling? by Phillup · · Score: 3, Informative
      if ($something){
        do_something();
      } else {
        do_something_else();
      }
      vs.
      if ($something)
      {
        do_something();
      }
      else
      {
        do_something_else();
      }
      --

      --Phillip

      Can you say BIRTH TAX
    3. Re:cuddling? by Daniel_Staal · · Score: 2, Informative

      Cuddled:

      } else {

      Uncuddled:
      }
      else {
      or
      }
      else
      }

      (Suitably indented of course.)

      --
      'Sensible' is a curse word.
    4. Re:cuddling? by Anonymous Coward · · Score: 0

      The actual name for it is k&r style.

    5. Re:cuddling? by WillAffleckUW · · Score: 1
      have to admit that the ONLY time I use cuddled else statements is when it's a DEBUG statement, so that they stand out and run on one line.
      if ($DEBUG eq "Y") { print "OMFG/n"; } else { print "whew, missed that bullet/n"; };
      the rest of the time, uncuddled else statements make it easier to follow the logic flow.
      if ($foo)
      {
        if ($foo > 2)
        {
          if ($bar)
          {
            if ($bar eq "open")
            {
              print "spend money";
            }
            else
            {
              print "take home paycheck";
            }
          }
          else
          {
            print "no bar in this town";
          }
        }
        else
        {
          print "not enuf to buy bheer";
        }
      }
      else
      {
        print "no foo means no bar";
      }
      --
      -- Tigger warning: This post may contain tiggers! --
    6. Re:cuddling? by Anonymous Coward · · Score: 0

      I've seen this written like this and I like it better, maybe you will too.
      sub foobar {
          if (! $foo) {
              return "no foo means no bar";
          }
          if ($foo <=2 ) {
              return "not enuf to buy bheer";
          }
          if (! $bar) {
              return "no bar in this town";
          }
          if ($bar eq "open") {
              return "spend money";
          } else {
              return "take home paycheck";
          }
      }

    7. Re:cuddling? by justine_avalanche · · Score: 1

      oops, the last if is really:

      if ($bar eq "open") {
          return "spend money";
      }
      return "take home paycheck";

    8. Re:cuddling? by rendermaniac · · Score: 1

      This could be seen as (yet another) bad thing in Tcl - as you are forced to write "cuddled". Simon

    9. Re:cuddling? by sigzero · · Score: 1

      Yes, but everyone in Tcl (pretty much) agrees with that. I use Perl, but Tcl is a very nice language.

  39. Re:Perl Best Practice: Don't use it by Anonymous Coward · · Score: 1, Insightful

    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.

  40. Watch out for the SOAP... by Wee · · Score: 0, Troll
    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

    --

    Ash and Hickory, straight-grained and true, make excellent bludgeons, dandy for the cudgeling of vegetarians.

    1. Re:Watch out for the SOAP... by Phroggy · · Score: 1

      Perl may be a fun hobby-toy (which is faster than Python in string manipulation) used for quick scripts (which it is admittedly brilliant at). But I would still use Python for serious work.

      Python forces you to structure your code in a certain way, which makes it readable and maintainable in large projects. However, Perl doesn't in any way prevent you from writing readable and maintainable code - Perl just doesn't force you to write in a particular way, so it's up to you to implement self-imposed rules.

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    2. Re:Watch out for the SOAP... by Wee · · Score: 1
      Python forces you to structure your code in a certain way

      Which is one of the reasons I like Python. And one of the reasons I don't. Have you ever tried to email someone (or paste into am IM window) Python code? Be very careful of where you wrap.

      Having said that, anyone who writes bad Perl does so on purpose. There's nothing stopping anyone from writing maintainable Perl code. I've been doing it for years. The best practices article is very good at helping self-impose good writing styles, BTW. You're spot on there.

      And a side note: the person who modded my original post as a troll obviously never tried to use SOAPpy. I have. I'd love to use python for my SOAP stuff (not only because they strongly encourage it at work, and it would greatly simplify a few issues we have with non-Python code), but I can't since SOAPpy is very, very young, and riddled with bugs and unimplemented features. It's very nearly completely useable for what I need. And since I can't use Java, I get to use Perl. And it works well enough.

      It just isn't as slashbot-compliant as it could be. :-)

      -B

      --

      Ash and Hickory, straight-grained and true, make excellent bludgeons, dandy for the cudgeling of vegetarians.

    3. Re:Watch out for the SOAP... by Domini · · Score: 1

      You got problems? Some zealot marked mine as flamebait!

      Come on! It may be a sore point, but it's the truth.

      Sure one *could* write maintainable perl code (I'd like to think I have), but in large projects no-one has the same style (namind, coding, indenting)... leading to a mess even with some forced guidelines and averagely good coders.

      In python even novice programmers write best practice code.

      Look, I love programming, and am a very good C/C++ programmer, but even I have to admit to flaws in what I like. And even though I love writing complex clear code, even I have to admit that some other language may be better suited.

      Thus to come back to the point: It's sometimes good practice to choose another language.

    4. Re:Watch out for the SOAP... by Anonymous Coward · · Score: 0

      Sorry but this is crap..

      novice python programmers will be able to use any of a billion anti-patterns and bad practices in python, some specific to the language but most are general programming mistakes.

      As for this crap about large projects needing strict styling or strict typing -- that is utter crap. large projects need revision control, project management, seperation of concerns, expressive code, tests, and communication and knowledge sharing.

      Perl actually provides tests, the best templating systems available and the most expressive language and syntax available.

      It also provides many many standards and guidelines beyond the language itself such as cpan packaging, standardised testing, standardised idioms, and recognised practices. It also has more books, user groups, conferences and experts than any of the other scripting languages.

      This makes it ideally suited for large applications, particularly as you can utilise the range of Application Servers, Object Persistance Frameworks and general packages available on CPAN, as well as find the staff with the right skills.

  41. Re:A "best-practice" in Perl is like... by rduke15 · · Score: 1
    Loks like a buggy would-be equivalent of
    print "Just another Perl hacker\n";
  42. Perl Best Practices: use Python instead by Anonymous Coward · · Score: 0

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

  43. Re:A "best-practice" in Perl is like... by Anonymous Coward · · Score: 0

    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. ;-)

  44. Syntax problem by lullabud · · Score: 4, Funny

    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;

  45. Re:A "best-practice" in Perl is like... by That's+Unpossible! · · Score: 3, Informative

    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.

    --
    Ironically, the word ironically is often used incorrectly.
  46. Best Practices by SwiftOne · · Score: 4, Insightful

    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.

    1. Re:Best Practices by Just+Some+Guy · · Score: 2, Insightful
      Line noise reputation aside, Perl can be _very_ readable.

      I tell you what turned me away from Perl, though: the syntax for complex data structures was never clean enough that I could remember it from session to session. The python for getting a hash of arrays (in Perlspeak):

      a = {'first': [1,2,3], 'second': [4,5,6]}
      print a['first'][2]

      Perl made it possible, but Python made it easy. What about returning complex objects from functions? [1]

      def foo():
      ....return {'first': [1,2,3], 'second': [4,5,6]}
      print foo()['first'][2]

      Again, you can do that in Perl, but it was never anywhere near that easy. I've read and written lots of Perl in my day that was well-organized and well-written, but there are certain basic operations that are just inherently ugly. Those warts simple can't be made readable because of the relatively bizarre syntax required to create them.

      [1] Yes, I realize that Slashdot's broken "ecode" tags don't exactly help my case regarding Python's readability.

      --
      Dewey, what part of this looks like authorities should be involved?
    2. Re:Best Practices by friedo · · Score: 3, Informative

      I don't really see how these are any more complex in Perl:

      $a = { first => [ 1,2,3 ], second => [ 4,5,6 ] }
      print $a{first}[2];

      And...

      sub foo { return { first => [ 1,2,3 ], second => [ 4,5,6 ] } }
      print foo()->{first}[2];

      One place where Perl syntax really suffers is dereferencing nested structures though. Consider

      @array = @{ $hash{$key} };

      Blegh.

    3. Re:Best Practices by belg4mit · · Score: 2, Informative
      >Again, you can do that in Perl, but it was never anywhere near that easy.
      Bull.
      $a = {first=>[1,2,3], second=>[4,5,6]};
          print $a->{first}->[2];
      Looks easy enough to me. Damn near identical even.
      sub foo(){ return {first=>[1,2,3], second=>[4,5,6]} }
       
          print foo()->{first}->[2];
      Ditto. In modern perls the arrows tracing the path in the data structure are even optional (however code without them is as ugly as Python IMHO :-P)
      print foo()->{first}[2];
      Also note the omission of key quotes.
      --
      Were that I say, pancakes?
    4. Re:Best Practices by Chandon+Seldon · · Score: 3, Informative
      What's so hard about that code in perl?
      $a = {first => [1,2,3], second => [4,5,6]};
      print $a->{'first'}[2], "\n";

      or

      sub foo {
      ....return {first => [1,2,3], second => [4,5,6]};
      }
      print foo()->{'first'}[2], "\n";

      In fact, as far as I can see, the code is basically identical.

      --
      -- The act of censorship is always worse than whatever is being censored. Always.
    5. Re:Best Practices by glwtta · · Score: 1
      Again, you can do that in Perl, but it was never anywhere near that easy.

      What are you talking about? Replace the colons with '=>' (or plain commas) for hash element assignments and replace the square brackets with curlies for hash access (no need for quotes, either), and you have Perl. Oh, and you'd need to dereference the structure that foo returns: foo->{first}[2]

      I don't know, people who program in a language that has significant whitespace just shouldn't talk shit about the syntax of other languages.

      --
      sic transit gloria mundi
    6. Re:Best Practices by nihilogos · · Score: 1

      but there are certain basic operations that are just inherently ugly

      No, they are superficially ugly. And only because they use lots of non-alphanumeric characters. Inherently they are a joy to work with.

      Python, on the other hand, is basically quite boring .

      --
      :wq
    7. Re:Best Practices by Just+Some+Guy · · Score: 1
      sub foo { return { first => [ 1,2,3 ], second => [ 4,5,6 ] } }
      print foo()->{first}[2];

      See, that's the sort of thing that bugs me. I understand why you have to dereference the return value, but it's annoying once you've gotten used to not having to. I'll admit that I didn't give the best example, though. I was trying to remember one of the Perl data structures that I had to look up each and every time I used it, and it looks like I picked the wrong one.

      @array = @{ $hash{$key} };

      That's more along the lines of the kind of stuff I had in mind. Again, I don't hate Perl. It's just that I've found other languages that map much more closely to how I think of algorithms. I always got too stuck in the syntax of Perl to really express myself.

      --
      Dewey, what part of this looks like authorities should be involved?
    8. Re:Best Practices by Edward+Kmett · · Score: 1
      You need to throw a semi-colon in there after you declare the hash reference $a, and you should dereference $a like:
      print $a->{first}[2];
      instead of referring to the contents of the unspecified hash %a, like you are doing, but your second snippet should work fine. Nope, no more complex at all. =P
      --
      Sanity is a sandbox. I prefer the swings.
  47. Read It by Chysn · · Score: 2, Informative

    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.

    --
    --I'm so big, my sig has its own sig.
    -- See?
    1. Re:Read It by Chysn · · Score: 2, Funny

      Just realized, as soon as I hit submit, that I reversed $ and ^. Guess that sort of makes the case for \A and \z. But not because they make people look them up.

      --
      --I'm so big, my sig has its own sig.
      -- See?
  48. Re:Wordstar keybindings (and the left hander) by Anonymous Coward · · Score: 0

    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.

  49. Re:A "best-practice" in Perl is like... by Daniel_Staal · · Score: 1

    You need to read the book. Besides the bad variable names, you need whitespace and blocking. Comments and using better delimiters would help too.

    I've seen similarly unintelligeble C, and it has the same basic problems: Bad variable names, bad whitespacing, bad blocking.

    --
    'Sensible' is a curse word.
  50. Perls's popularity by markpapadakis · · Score: 1

    Is it just me, or Perl has lost much of its old prestige ? Ruby, Python and other languages ( such as the most excellent io language have gained so much momentum and popularity, that Perl just doesn't seem to be getting much attention from the users nowadays.
    Rightfully so, if I may say.

    --
    Technology ramblings : Simple is Beautiful
  51. Re:Best Best Practice: Don't Bloat Perl by rpresser · · Score: 2, Funny

    Sure there is. Brainf**k, for example, which has only eight instruction types. Or Malbolge, where you can peruse all existing programs in an afternoon.

  52. Same here... by lullabud · · Score: 1

    I had the same problem, except in foo.pl. Maybe my retarded. :(

  53. Re:A "best-practice" in Perl is like... by rpresser · · Score: 4, Funny

    000100 IDENTIFICATION DIVISION.
    000200 PROGRAM-ID.     HELLOWORLD.
    000300
    000400*
    000500 ENVIRONMENT DIVISION.
    000600 CONFIGURATION SECTION.
    000700 SOURCE-COMPUTER. RM-COBOL.
    000800 OBJECT-COMPUTER. RM-COBOL.
    000900
    001000 DATA DIVISION.
    001100 FILE SECTION.
    001200
    100000 PROCEDURE DIVISION.
    100100
    100200 MAIN-LOGIC SECTION.
    100300 BEGIN.
    100400     DISPLAY " " LINE 1 POSITION 1 ERASE EOS.
    100500     DISPLAY "Hello world!" LINE 15 POSITION 10.
    100600     STOP RUN.
    100700 MAIN-LOGIC-EXIT.
    100800     EXIT.

  54. Re:A "best-practice" in Perl is like... by WilliamSChips · · Score: 1

    Luckily, Python knocks bad whitespacing and bad blocking out by using syntactically significant whitespace. Bad variable names can't be helped, though...

    --
    Please, for the good of Humanity, vote Obama.
  55. They were given away to OSCON attendees... by cliveholloway · · Score: 3, Insightful

    ...and the poor guy didn't get a cent from that - so go out and buy this for all your devs, and buy Peopleware by Tom Demarco for all your managers while you're at it.

    I get a copy for every new dev now. I'm not going to force them to use all of it, but it definitely makes them think when they start working on larger projects.

    I'd also recommend MJD's Higher Order Perl if you want to go even deeper.

    I always think it's funny when people argue heavily about hating to work to a "best practices" style. And then start agruments about how crap Perl is because it's unreadable. Anyway - I digress.

    cLive ;-)

    --
    -- Trinity in high heels carrying a whip: The donimatrix - there is no spoonerism
    1. Re:They were given away to OSCON attendees... by Anonymous Coward · · Score: 0
      I'd also recommend MJD's Higher Order Perl if you want to go even deeper.
      Is that really a good book? Reading this thread and other postings by the author (Dominus) lead me to believe he is a little bit out of his league. Also, code snippets like this from his website aren't exactly the models of clear concise programming.
    2. Re:They were given away to OSCON attendees... by Vindaloo · · Score: 1

      That code example is pretty straightforward. What is not clear about it?


      As for MJD's book, it presents a good example of how to do functional programming in Perl.


      As for that thread, some people disagree on some things. How is MJD "out of his league"?

    3. Re:They were given away to OSCON attendees... by kwoff · · Score: 1
      Reading this thread and other postings by the author (Dominus) lead me to believe he is a little bit out of his league.

      You're either an ignorant troll, or MJD himself trying to see how many defenders he has. :)

    4. Re:They were given away to OSCON attendees... by Anonymous Coward · · Score: 0
      Ignorant? Hello! I said as much in the original post, where I was asking whether the author knew much about functional programming (his mad Perl skillz are not in doubt). I'm glad you didn't waste your time by actually answering. You know something like, "The author is a excellent candidate for writing a functional programming book because he...
      • Wrote his Ph.D. thesis on fucntional programming
      • Wrote several academic papers on the subject.
      • Is well know in the functional programming community
      • Played a part in (insert well known functional program/language/company X)
      • Uses FP as part of his day job.
      • Skimmed most of SICP
      • Lurks on comp.lang.functional
    5. Re:They were given away to OSCON attendees... by kwoff · · Score: 1

      You might be right that he's not a functional programming guru, but I think your argument is a bit of a strawman. On the book site, he says "Higher-Order Perl is about functional programming techniques in Perl. It's about how to write functions that can modify and manufacture other functions." It doesn't say it's about functional programming in general, or how to be a good functional programmer, but how techniques from functional programming can be applied to Perl. In any case, you might look at for example this message, or this one or this one to decide if he knows enough about functional programming (I couldn't tell you).

    6. Re:They were given away to OSCON attendees... by Anonymous Coward · · Score: 0
      Good examples. Let's take a look at the macro one. He's right of course, macros are a big part of what makes lisp cool. And you really can't compare them to a broken piece of crap like Perl's source filters. But then he goes off and makes a statement like...
      In Lisp, source filters never break.
      Never.
      Really? Never? Statements like that make me think he's never really wrote lisp macros of his own. Sounds like he needs to read chapters 9 and 10 of On Lisp. In fact, the Scheme community got sick of errors induced by lisp macros and created hygienic macros (with their own set of problems).
      Norvig was one of the technical reviewers for HOP, and asked in one of his reports why I spent so little space in the book discussing source code generation. I think only a Lisp expert would have asked that. Source code generation is unreliable and inadvisable in every language except Lisp.
      Along with his earlier statements about C macros, I'd say he is confusing the parsing of the language (which is hard in C (compared to lisp) and almost *impossible* in Perl) with code generation which is a much easier task. For code generation, Perl's really not that bad. Double quotes and string interpolation are Perl's answer to lisp's quote and unquote. But hey, I'd really like to know what Peter Norvig thought of the book. If he gives it a thumbs up, I'd buy it.
    7. Re:They were given away to OSCON attendees... by mjd · · Score: 1
      You're either ..., or MJD himself trying to see how many defenders he has. :)
      I would never do that, because my wife would be ashamed of me if I did.

  56. Re:A "best-practice" in Perl is like... by Daniel_Staal · · Score: 1

    Ok, sounds like I wouldn't like Python... (I'm having COBOL flashbacks here, needing a space on some line, just because...)

    --
    'Sensible' is a curse word.
  57. Re:Nice attitude. by tpgp · · Score: 2, Informative
    ...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.

    Why is this marked as offtopic?

    Both comments are clearly ontopic flamebait.

    For readers outside of Australia - Melbourne and Sydney have a rivalry big enough to affected the placement of the capital (Canberra) - it was eventually placed halfway between Sydney and Melbourne.

    Even the Australian Constitution had a clause that Canberra must be more then 100 miles from Sydney.

    I like honestpuck - but that statement is a troll. Not a particularly funny one unfortunately - because not enough people will get the joke.
    --
    My pics.
  58. just about everything... by Anonymous Coward · · Score: 0

    Apart from still being an excellent "glue" and prototyping language, it's also used in its own right. Some rather large companies (and smaller ones too) use mod_perl with one of the many templating engines to power their websites. Biotech/genetic researchers use Perl's powerful text parsing capabilities. OpenBSD and Debian use it in whole or in part for their package system tools. There are also many network apps and even some with GUI's like this one (which uses Tk as the GUI library, but Perl also has Wx, Gtk, and other bindings as well):
    http://butchersgrill.com/software/opentill.jpg

  59. Re:Best Best Practice: Don't Bloat Perl by Anonymous Coward · · Score: 0

    Doesn't look that HARD, just so mind-numbingly tedious as to make anyone who started out to give up out of sheer boredom as soon as they finished Hello World.

  60. Sad comments on a great book by KMitchell · · Score: 3, Insightful
    ...The same tired "Perl is a write-only scripting language that looks like line noise. XXXX is much cooler" If XXXX works for you, have a blast. Hell, maybe there's a good book about it and you can make those insightful comments in a review about *it*. You can write unmaintainable code in *any* language.


    More to the point, you will write crap in any language if you don't understand the conventions, idioms, and best practices of the language.


    Perl is a lot like Lisp. You need to think in terms of lists before you see anything but the sigils and you tend to write "C in Perl". Further, until you see *good* Perl code, it's hard to know any better. Before this book, the book I'd refer people to was "Effective Perl Programming" by Hall & Schwartz. The goal was to get beyond "baby talk" and use the language well.


    I'm about 130 pages into "Best Practices" and I like the book a lot. It's definately on the required reading list for any Perl programmers that we hire.


    I can't say I agree with Damian about *all* the conventions (I really *like* "unless") but I agree with most of them, and having met him once, I'll admit that he knows more about Perl than I'm ever going to know, and more about computing languages and PROGRAMMING best practices than most of the people that have responded to this topic.


    If you code in Perl often enough that you wish your code was better, you should pick up this book.

    1. Re:Sad comments on a great book by shaldannon · · Score: 1

      I agree, I like unless()

      I've never understood people's bias against it. Which is easier to read?:

      if (! $foo)
      {
      # do stuff
      }

      - or -

      unless ($foo)
      {
      # do stuff
      }

      - or in some cases -

      do_stuff() unless $foo;

      From what I've heard and read, this is a good book, and I'll check it out. I just don't think that one should ignore some of the more useful/human features of the language. Remember, it was designed to be human-idiomatic. unless() is a human-type of thing. if (! ...) is a computer (and C programmer) type of thing.

      --


      What is your Slash Rating?
  61. don't quit your day job by Anonymous Coward · · Score: 0

    Setting aside content, this is possibly the most poorly written piece of text I have ever had the misfortune to read. Buy some books on how to write.

  62. Wrong by Anonymous Coward · · Score: 0

    Wrong. Shell scripts use external programs to do all the heavy lifting, by design. (cat, tee, grep, xargs, etc) Shell scripting is infinitely extensible.

    I never saw the use for a language like Perl, except for those people who don't know shell scripting.

    1. Re:Wrong by shadow_slicer · · Score: 1

      I use it for all sorts of programmable etraction and reporting type tasks.
      Like I have a 83 line script that generates the dependency information for a set of supplied c source files recursively (ie checks the dependencies of all #include'd files [at least the #include "file.h" form) and outputs the results in makefile format.
      I also wrote a quick one at work once that would parse the file which listed the EEPROM datastructure locations and sizes in seemingly random order and then give me a list of free locations (and overlaps...)...

    2. Re:Wrong by gurps_npc · · Score: 1
      So you think people should learn external progams instead of languages like perl?

      What a load of stupidity. You must learn multiple different external progams instead of a single, organized program.

      My job involves Perl programming all the time.

      Yes, I COULD do everything with those things, but Perl is FAR more effecient for the kind of heavy text manipulation that I need to do, involving tons of special characters, and combining multiple lines with changes made to line 1 dependent on what was originally in line 2.

      Perl is 1,000 times more efficient when you have to convert something like:

      DP04200000096 Production Number

      DT 397823

      Text of Document 001-001: Jo Japui .

      Into: &DT-397823&|&\001-001: Jo Japui .\&|&DP04200000096&

      Which is fairly typical in my job

      What you are is someone that is prejudiced against Pearl simply cause the particular jobs YOU PERSONALLY DO are not easy to do with it.

      --
      excitingthingstodo.blogspot.com
  63. Perl has best practices?? by Anonymous Coward · · Score: 0

    The code I have to deal with you'd never know.

  64. Re:Best Best Practice: Don't Bloat Perl by quasi_steller · · Score: 1

    Any of the LISP's are simple. Ruby tends to be simple too. Now, if you are including in that 2 semester course the libraries as well, then you might be correct, but there are plenty of examples of very simple, orthogonal languages.

    --
    ...interesting if true.
  65. Perl Tip of the Day by evildogeye · · Score: 2, Interesting

    In 5 years of studying computer science (BS, MS) I was never formally taught Perl in a class. I learned it as the side effect of a Relational Database class. Now, 6 years later, I use Perl, ASP, and Microsoft Access on a daily basis. Not exactly the path I envisioned when I was a bright eyed 21 year old open source zealot.

    Anyway, last week my mom told me it was important for me to start giving back to society, so here is your Perl tip of the day. It took me a few months of writing awful, inefficient regular expressions to learn this doozy:

    the ? is your friend. It forces regular expressions to search for the first match, instead of the last."

    Example:

    $test = "Perl regular expression tip of the day: the ? is your friend. It forces regular expressions to search for the first match, instead of the last.";

    $test =~ /(.*?)the/;
    print $1;
    print "\n--\n";
    $test =~ /(.*)the/;
    print $1;

    C:\>perl test.pl
    Perl regular expression tip of
    --
    Perl regular expression tip of the day: the ? is your friend. It forces regular expressions to search for the first match, instead of

    1. Re:Perl Tip of the Day by belg4mit · · Score: 3, Informative

      Gah! Not only was your choice of test output delimiter unfortunate (used for sigs) but it's
      wrong. ? makes the sub-expression lazy/non-greedy.
      Read Jeff Friedl's Mastering Regular Expressions.

      --
      Were that I say, pancakes?
    2. Re:Perl Tip of the Day by evildogeye · · Score: 1

      Ah, I guess it is wrong. Sorry. Still, using the ? is very useful and a lot of people don't know about it.

  66. Comment removed by account_deleted · · Score: 2, Interesting

    Comment removed based on user account deletion

  67. Re:Best Best Practice: Don't Bloat Perl by RichDice · · Score: 1
    I normally don't feed the trolls, but I'll make an exception this time.
    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.

    You've obviously never met Larry Wall. You, sir, are no Larry Wall.

    People love C and Perl 5.x for their simplicity.
    People (well, some people) love C for its simplicity, and people (some people, maybe some overlap with the previous group, maybe not) love Perl 5... but I doubt for its simplicity. (Try to find an EBNF description of Perl 5. What's the construction count?)

    - Richard

  68. Re:how about?... by namekuseijin · · Score: 2, Interesting

    ... yours truly, slashdot? Yes, perl. And Amazon.com, perl too. Show me PHP websites of this magnitude...

    and Haskell is being used to _implement_ the Perl 6 compiler for the same reason Python or Ruby interpreters are writter in C. Except, of course, Haskell is a lot higher level than C and more secure, meaning the current size of the project is just short of 4K lines. and no side-effects... ^_^

    --
    I don't feel like it...
  69. Re:Best Best Practice: Don't Bloat Perl by cow-orker · · Score: 1

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

    Scheme and Forth, maybe even Smalltalk don't count?

  70. Re:Best Best Practice: Don't Bloat Perl by Anonymous Coward · · Score: 0

    Yea, learning any language syntactically might be feasible in a 2 semester college course, but learning HOW to use a language properly takes longer, even LISP and HASKELL

      I took a one semester course that taught syntax of both previously mentioned langs, but to really LEARN them would take MUCH longer.

    (The course was a programming language theory course and was designed specifically to show that syntax isn't everything)

  71. Re:Best Best Practice: Don't Bloat Perl by Phroggy · · Score: 3, Insightful

    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.

    Perl's syntax is very complex; it has a lot of operators and provides many different ways to do the same thing. This makes reading other people's code very difficult.

    Everyone starts by learning a subset of the language, then building upon that by learning more after they've mastered the basics. You can write a lot of perl code without knowing half the syntax. The problem is, since everyone learns a different subset, reading someone else's code is impossible for a beginner, and unfamiliar syntax isn't something you can easily look up in a reference. A language like PHP has a simpler syntax and far fewer operators, and makes up for it by having a large number of functions; once you've got the syntax down, you can just look up unfamiliar functions in the documentation and figure out what's going on. The result of this is that PHP looks easier to beginners while Perl looks daunting.

    I'm completely ignoring Perl 6, and I'd advise others to do the same for at least a few more years.

    --
    $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
    $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
  72. Re:A "best-practice" in Perl is like... by WilliamSChips · · Score: 1

    Go look up ESR's experiences with Python, they'll quench your fears--I'm too lazy to do so right now :P

    --
    Please, for the good of Humanity, vote Obama.
  73. Best practices, hm? by RicardoStaudt · · Score: 0, Redundant

    The very best practice for any Perl developer is to move to Python and save his sanity, if any is left.

  74. Re:Best Best Practice: Don't Bloat Perl by Jherek+Carnelian · · Score: 2, Funny

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

    I disagree. Most people I know are able to completely master pig latin with just a couple of days of study and use.

  75. Who's Derrick? by Anonymous Coward · · Score: 0

    Itym Damian

  76. Perl Best Practices by fforw · · Score: 3, Funny

    1. Don't

    --
    while (!asleep()) sheep++
    1. Re:Perl Best Practices by Vindaloo · · Score: 1


      Hahahahahahahahahahahahahahaha.

      Troll.

    2. Re:Perl Best Practices by tgv · · Score: 1

      No, the parent has a point.

      Perl may be an easy language for doing things on files for which grep is insufficient, but for more complex programs Perl Sucks.

      The language has no design whatsoever (read the part on "local" vs. "my"; that makes every self-respecting computer scientist cringe) and at least version 5 implementations had such horrible bugs that even a simple program would do not execute properly.

      The only reason Perl is so popular is because it's today's Basic: you open an editor, write something, type "perl ..." and hey, it works. That kind of instant gratification is seldomly obtained when writing in Haskell or C++. And Perl has a lot of built-in functionality, which makes certain tasks a lot easier.

      But the consequence is bad programming and trying to fit the whole world into a regular expression. And most programmers don't really understand regexps. I've seen people try to parse context-free languages with regexps and saying that they couldn't nail it completely, but delivering the code anyway.

    3. Re:Perl Best Practices by Vindaloo · · Score: 1

      No, the grandparent had no point. You at least have some points (though I disagree with them), but I don't see any point to the grandparent post.

    4. Re:Perl Best Practices by shaldannon · · Score: 1

      The parent was a troll. Thanks for trying to bring some level of intellectual credit to it :) As an experienced Perl programmer, I can see deficiencies in the language (my/local, problems with SOAP::Lite's ability to transfer large files, the unfortunate lack of using File::Slurp as a native module, not requiring strict), but it also serves a purpose for more than small utility scripts. The problems often attributed to Perl are not the fault of the language per se. Rather, they are the result of sloppy programming. To borrow a phrase, Perl doesn't ruin programs, programmers ruin programs. I've had a part in a several thousand line company-designed CMS written in Perl, Mason, and JavaScript, and a several thousand line company-designed system monitoring tool. From personal experience with both the best of code (OO Perl, well abstracted and well designed) and the worst (implicit $_ everywhere, constructs like $True = (1 == 1); $False = ! $True;) (wth!?)), I know what the language is capable of if misused. This is where a book like this serves a purpose. Someone recently recommended it to me, and while I haven't read it yet, what I've read about it (including reviews on Amazon) suggests to me that it should be required reading for all Perl programmers.

      --


      What is your Slash Rating?
  77. DDJ and Baby Ducks by Anthony · · Score: 1

    I recall the "Baby Duck Syndrome", which I use conversationally on a semi-regular basis, appeared in a Doctor Dobbs Journal Issue. It even had a picture of a duckling on the cover. Must have been around 1983.

    --
    Slashdot: Where nerds gather to pool their ignorance
  78. military intelligence? by wingbat · · Score: 1

    Having hacked with Perl for many years, I must say I find seeing "best practices" and "Perl" in the same title seems a bit oxymoronic.

    *waterfowl*

  79. PERL BEST PRACTICES by Anonymous Coward · · Score: 0

    "don't use it".

    better click that anonymous thingy.

  80. Re:Perl best practice number 1 by Anonymous Coward · · Score: 3, Funny
    Use a better fucking language!

    They have languages for that?! Oh man am I clueless.

  81. can't help but love it by miletwo · · Score: 1

    Sounds like a great book but from the sample pages, a bit hard reading. As a perl hack (forced by use of Interwoven's TeamSite product) I'm happy to have any resource... especially my Perl 5 Pocket Reference (O'Reilly). Rock on.

  82. Aunt Augusta by jefu · · Score: 1
    I'm curious about the quote from Lady Bracknell. A well spoken lady indeed and well worth quoting - but so much so that it is hard to pick out any one quote worthy (so to speak) of being quoted in the context of Perl.

    However, looking at a copy of the play online I discover :
    "Three addresses always inspire confidence.
    But certainly that pertains more to C than Perl.

  83. #2 Perl Best Practice by Chandon+Seldon · · Score: 1
    use warnings FATAL => 'all';

    If you're used to perl, you'll spend at least an hour figuring out what it doesn't want you to do... BUT, you'll save days of debug time later.

    --
    -- The act of censorship is always worse than whatever is being censored. Always.
  84. hate regexs, not perl by mvaneerde · · Score: 1

    Perl does allow line noise, yes. But regular expressions require line noise. A lot of my Perl reads fine until I hit a regexp.

  85. Re:A "best-practice" in Perl is like... by sleepingsquirrel · · Score: 1
    Bad variable names can't be helped, though...
    Well, unless you use a langauge which gets rid of variables and names.
  86. Re:A "best-practice" in Perl is like... by dcam · · Score: 1

    I've said this before many times, but perl is pecularly well suited to obfuscation. It is a lanugage that is harder to read than any other language that is frequently in use, at least than any other language I am aware of.

    This comes back to the core of perl itself. TMTOWTDI. There shouldn't be. At most there should be two ways to do it. If there is more than one way to do it, you get people using each of the different ways, and the amount of variation makes the code harder to read which means harder to debug which means harder to code.

    TMTOWTDI is a huge mistake.

    I code some perl, but I force myself to use a small subset of the language.

    --
    meh
  87. Re:A "best-practice" in Perl is like... by chromatic · · Score: 1
    I code some perl, but I force myself to use a small subset of the language.

    If not for TIMTOWDI, you wouldn't be able to do so.

  88. Re:A "best-practice" in Perl is like... by Delphiki · · Score: 1
    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.

    Maybe a language above knocking would be one that didn't force you to choose between unreadable code and efficient code.

    --

    Feel free to mod me "-1 - Angry Jerk".

  89. Re:Best Best Practice: Don't Bloat Perl by Anonymous Coward · · Score: 0

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

    How about Visual Basic.
    The core language can be learned in a day or two. In order to do anything useful with it however invloves massive amounts of work to get around its shortcomings.

  90. Re:A "best-practice" in Perl is like... by dcam · · Score: 1

    No, if not for TIMTOWDI I woudn't have to force myself.

    --
    meh
  91. Left hand is more useful in Qwerty by ThreeDayMonk · · Score: 2, Interesting

    I had a theory about this, so I checked it out with this frequency table and Gnumeric.

    In the Qwerty layout, more of the most commonly-used letters are located under the left hand. Taking the limit as T, G, B, you can hit about 57% of letters by frequency. If you include occasional jumps as far as U, J, N (within reach of my relatively small hand), it's nearly 73%. Thus, it's more useful to keep the left hand on the keyboard. You can of course argue that one could move the right hand across, but the left hand starts from an advantageous position for one-handed typing.

    --
    If your comment title says 'Re: Foo', I'm not likely to read it.
  92. Indeed... by mx.2000 · · Score: 2, Informative

    Indeed, it does.

    Right at the start on page 18:
    Use 78-column lines.

    Bet you didn't expect that ;-)

  93. Dead Languages by Bronster · · Score: 1

    I went to his talk on Dead Languages last night at Melbourne.PM - very funny. Especially when C++ made the dead list!

    My work purchased a copy of the book there, so I'll check it out when I'm in the office next (today is a work-from-home day :)

  94. Re:A "best-practice" in Perl is like... by WilliamSChips · · Score: 1

    I'm sure they could find a way to fuck up Joy too... :P

    --
    Please, for the good of Humanity, vote Obama.
  95. Re:Best Best Practice: Don't Bloat Perl by Mr.+Underbridge · · Score: 2, Insightful
    I guarantee you, it would take you longer to master brainfuck than any other language around. Learning the instructions isn't the problem - doing what you want in the most efficient means is. That's kind of like mistaking an online dictionary for a native speaker of a language.

    In other words, if all you know is the syntax, you don't know the language.

  96. Re:A "best-practice" in Perl is like... by chromatic · · Score: 1

    What if your way to do it didn't fit with the vision of whoever chose the one or two ways to do it?

    If you're working on a multi-person project that's a mixture of many different styles and techniques, then the problem is with the development process, not the language. Until someone invents a language where there's one true formatting style, one true symbol naming style, one obviously right name for every symbol, one single API for every necessary library, and so on, you're going to have to trust other people to write maintainable code where the language doesn't help you. If that language ever comes about, you ought to hope that the choices the language designer made match the problems you have to solve -- if not, you may have some ugly, ugly workarounds. Hopefully the language supports those with sufficient encapsulation to keep the ugliness confined appropriately.

  97. Re:Nice attitude. by Vindaloo · · Score: 1
    Not a particularly funny one unfortunately - because not enough people will get the joke.
    That doesn't make it any less funny. And how many is "enough"?
  98. Re:A "best-practice" in Perl is like... by dcam · · Score: 1

    What if your way to do it didn't fit with the vision of whoever chose the one or two ways to do it?

    In that case there can be a later revison to the language. Or it would be a case for the person coding to write around the issue.

    If you're working on a multi-person project that's a mixture of many different styles and techniques, then the problem is with the development process, not the language.

    Every environment is a multi-person project. As someone else has quipped, there are always a minimum of two people working on any project: myself and myself in 6 months time.

    Until someone invents a language where there's one true formatting style, one true symbol naming style...

    You and I both know that this language does not exist and will never exist.

    I realise that there is a conflict. On one hand, when designing the language you cannot envisage every situation in which that language will be used. But on the other hand if you create a multiplicity of means of doing the same thing, it quickly becomes close to unmaintainable. I also consider that there are different languages for a reason, use them in the siuations where they are most appropriate.

    You will notice that I said at most *2* ways of doing things. I have no problem with having 2 ways to do things, it is just that perl takes this to extremes. It is also interesting that perl is pretty much the only major language that goes to these extremes. I think that in itself is pretty telling.

    There are many other things relating to perl I could whinge about (classes for one), but at the core I take issue with the underlying philosophy.

    --
    meh
  99. Re:how about?... by SolarCanine · · Score: 1

    Show me PHP websites of this magnitude...

    Let's see...there's Yahoo, for one. Then there's also MIT who seems to process 3 million hits on over 1.1 million documents a day, according to their reported stats.

    Throwing a couple high-profile links out to websites using foo on the backend does not a good language make. Coders with style and best practices a good backend make.

  100. Re:Best Best Practice: Don't Bloat Perl by crucini · · Score: 1

    I understand your sentiment, but I think that on balance Perl 6 will be an improvement. The changes are not the product of Larry's imagination, but have been hashed out thoroughly and publicly as RFCs. As time goes by, other languages are catching up to or passing Perl in its core strengths, while offering other strengths Perl doesn't have. Perl must adapt or die.

  101. Re:A "best-practice" in Perl is like... by crucini · · Score: 1
    In practice, Perl's TIMTOWTDI is largely mythical. C++ has at least as much TIMTOWDI. Don't believe me?
    • How many ways are there to iterate through a vector? Some choices are:
      1. Use an integer index and the [] operator.
      2. Integer index and cache the size().
      3. Integer index; start at size(), count down.
      4. Use an iterator.
      5. Use an iterator and cache end().
      6. Use std::for_each.
      All of these were seriously advocated on comp.lang.c++.moderated.
    • How many ways are there to return an object from a function?
      1. Function simply returns object.
      2. Caller creates object and passes reference.
      3. Caller creates object and passes pointer.
      4. Function allocates object with new, returns pointer; caller must delete.
      5. Function returns smart pointer.

  102. Re:Perl best practice number 1 by Anonymous Coward · · Score: 0

    "Cunning linguists do it with their tongues."

  103. An instant classic by Anonymous Coward · · Score: 1, Interesting

    Damian was actually gracious enough to visit our LUG last month, and hand out a few copies of Best Practices. The guy is AMAZING in person, funny, engaging and a guru of Perl and programming in general. Ive been reading the Best Practices book for the last month, and i'd say this should be on every programmers shelf, whether they use Perl or not.
    May your Rakudo never fail...

  104. Re:A "best-practice" in Perl is like... by dcam · · Score: 1
    Regarding iterating through vectors: First off, items 2 and 3 are effectively the same. As are items 4 and 5. Caching values is a standard part of any well featured programming language, this is not a new concept. So we are down to 4 distinct methods.

    Looking at those 4, I see each of those ways to iterate through a vector and I intuitively understand them. 4-5 and 6 might be a little more difficult to someone who is new to C++, however iterators are increasingly becoming part of other programming languages. std::for_each is also something that intuitively makes sense (syntax and operation), and equally this is common in other languages.

    Looking at your list of options to return from a function, 3-5 of the variations relate to pointers (yes I do understand the nuances between the different options). 2 and 3 are also pretty close to identical. I'd agree this is one area (pointers) where things get complications, which leads to variation.

    Perl does things its own way, which I have found generally less intuitive.

    C++ shows TIMTOWTDI done right. Perl does it wrong. Don't believe me?

    Off the top of my head (I don't write a whole lot of perl, so I don't have a whole stack more available immediately):
    • Can you explain why there are so many different ways to quote a string?
    • ditto for regexes
    • Why are you able to modify an instance class (by adding member values) so that it is not the same as declared?
    --
    meh
  105. Welcome to Slashdot. by Anonymous Coward · · Score: 0

    Want to learn some best practices? Buy the book, you cheap hippie!

    Also: fuck uncuddled elses. And rehabit too. What a dumb fucking word.

  106. Taught Me C++ by XtremeGod · · Score: 1

    Having actually been a student of Conway at Monash University (far superior to anything NSW can offer). I can honestly say that he was by far the best lecturer of any I studied under. The guy seemed to know everything about anything. Probably the most entertaining lectures we sat through were generally not about anything to do with computing. From my point of view the guy was a genius.

  107. Re:A "best-practice" in Perl is like... by crucini · · Score: 1
    Can you explain why there are so many different ways to quote a string?
    In essence, there are three ways to quote a string.
    1. The q operator, usually expressed as '. Used when interpolation is not wanted - that is, a $ is just a $.
    2. The qq operator, usually expressed as ". Used when interpolation is wanted - that is, "Name: $name" evaluates as 'Name: Billy Bob'
    3. The << operator, or "here document" - used when the string could contain any characters and you don't want to have to escape any characters. Let's you use an arbitrary terminating string.

    The first two allow the programmer to use an arbitrary character as delimiter. This avoids having to excessively escape the delimiter character when it occurs in the string. For example, when quoting an XML string in C, one often has many occurrences of \". These escapes both reduce clarity and prevent you from directly pasting the string to or from a testing context.

    Since domain specific languages like Postscript, SQL, HTML and XML are often embedded in Perl code, it's useful to have these quoting operators that remove the burden of meticulously escaping special characters.

    The qx (backticks) and m (//) operators follow the same logic. Without the ability to pick an arbitrary delimiter, regexes often fall victim to "leaning toothpick syndrome".
  108. Perl best practices...? by Anonymous Coward · · Score: 0

    Programs looking like ascii art!

  109. Re:A "best-practice" in Perl is like... by crucini · · Score: 1
    Why are you able to modify an instance class (by adding member values) so that it is not the same as declared?

    More broadly, why can you violate the encapsulation of an object? Because Perl is not a paranoid language. It assumes that programmers are basically sensible. It is, of course, possible to violate encapsulation in C++ (though perhaps not in Java, which lacks pointers). In several years of professional Perl programming, I have never seen a Perl programmer do this in production code.

    Might as well ask why C++ lets you cast an object pointer to one of a different class.
  110. For experts only.... by Welshalian · · Score: 1

    2. Don't do it yet

  111. Re:Best Best Practice: Don't Bloat Perl by fireboy1919 · · Score: 3, Informative

    Everyone starts by learning a subset of the language
    As someone who regularly downloads and fixes broken perl modules, I have to disagree.

    Everyone tends to use the same subset at the start.

    The big thing you see in a beginner's code are just control structures (especially foreach statements), and regular expressions (and then mostly only stuff you'll see in an awk expression).

    Things like inventing a new inheritance structure (as is done by Class::DBI, OOTools, and PDF::Template), embedding a LALR parser (all the template engines), are a sign of a mature coder, and happen much less. These people are more likely to write code in a logically consistent, well designed manner such that it is easy to extend.

    So far I've found one module that I tried to fix (and ended up not because it was too much work) that wasn't either simple or well designed (Class::DBI::FormBuilder).

    --
    Mod me down and I will become more powerful than you can possibly imagine!
  112. Re:A "best-practice" in Perl is like... by scovetta · · Score: 1

    Just for the record, I was going for +5 Funny, not Flamebait, so I'll explain:

    I generally use Java on large projects and PHP on smaller "toy" ones. I've used Perl enough to know how easy it is to write unreadable code, but that you can write elegant, clean code as well. This is probably true for almost any language.

    I guess the point I was trying to make is that Perl gives you __more__ multiple ways of doing the same thing, and more syntactic shortcuts that don't make the underlying program any more expressive, only saving programmer's wrists. (all of the $_, $* commands, predicate conditionals, etc)

    As an example, the "f() unless x;" statement is almost certainly translated into "if (!x) f();" within the interpreter/compiler somewhere. It's syntactic sugar, albeit nice when translating your thoughts into code.

    I'm really not trying to knock Perl, but only suggest that perhaps the uber-expressiveness of it is both a crutch as well as a feature.

    --
    Wer mit Ungeheuern kämpft, mag zusehn, dass er nicht dabei zum Ungeheuer wird. --Nietzsche
  113. Re:It works, and is much smarter than you think by rduke15 · · Score: 1

    to make things look difficult
    (or like in another post :
    it looks like perfectly normal code)

    I don't think it does. I couldn't make sense out of it, even though I also cleaned it up first.

    It doesn't run on Windows, and I've never used pipe in Unix, and very rarely used fork. So that's my excuse for not understanding it. But I suspect those who consider it as normal code don't quite understand it either. Or those who do must be quite great Perl hackers. On par with the author: Mark-Jason Dominus.

    Anyway, the explanation is well worth reading.

    Perl hackers may prefer to try to guess how it works from as little hints as possible:

    Hint 1 | Hint 2 | Hint 3 | Hint 4 | Hint 5 | Hint 6 | Hint 7 | Hint 8 | Hint 9 | Hint 10 | Hint 11

    Others will jump straight to the spoiler.

  114. Re:Not buggy by rduke15 · · Score: 1

    It's not a bug, it's a feature: it doesn't run on Windows. Works fine in Unix.

    Links to the explanations are here, but it's not for novices.

  115. Re:Slashdot mangled it by rduke15 · · Score: 1
    In fact, the code is buggy in the /. post version which removed angle brackets in the last line.

    Should be
    @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
    (looks alright in the preview. hopefully it stays like that in the post)
  116. Re:clear syntax by namekuseijin · · Score: 1

    "clear syntax can be written in perl too"

    yep, but let's not stretch that definition too much, ok? I'm a Perl fan myself, but i'll never claim

    sub foo {
    my ( $arg1, $arg2 ) = @_;
    $arg2 = "default" unless $arg2;
    ...
    }

    to be as clear and concise as

    def foo( arg1, arg2 = "default" ):

    let's get real there. Of course, Perl6 will change that...

    --
    I don't feel like it...
  117. Re:clear syntax by bovinewasteproduct · · Score: 1

    I'm sorry, Python reminds me too much of old basics and lisp...shudder. If I really need threading that bad (I've never had a problem with Perl's OOP, you just have to remember that it's not enforced with any strength) I'll just use C++ and kill two birds with one stone.

    As for the Perl, what's wrong with the following?
    sub bar {
    my $arg1 = shift;
    my $arg2 = shift || 'default';
    # XXX #
    }

    You still get a default value for $arg2 if no value is passed. I've never liked list processing for sub args. My perference is to just pass a hash ref and use named args for anything but simple subs.

    BWP

  118. Re:clear syntax by namekuseijin · · Score: 1

    "what's wrong with the following?"

    it's even more verbose? there are many cases in which Perl can be really concise, mostly when doing IO, general file operations and, sure, the integrated regex. traditional functional constructs are not one of them.

    actually, did you know even the simple lexical variable aliasing for the array parameters comes with a huge performance penalty? learned that in the language shootout benchmarks...

    --
    I don't feel like it...
  119. Two things wrong with Perl Best Practices by persicom · · Score: 1

    1) It was not available seven years ago when I started using Perl in earnest.
    2) In the tradition of The Camel and The Panther, it could end up being known as The Dog...