Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Learn better Perl Coding

by Anonymous Monk
on Feb 21, 2012 at 23:53 UTC ( #955414=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I've been coding in Perl for awhile now but want to become better. Unfortunately those around me are just hacks like me. I find the best way to learn is from others rather than books. I use Perl Critic and try to use Best Practice but that is only really a start. Looking to improve my OO code and general design. Any suggestions for courses perhaps? Had a look at this one from O'Reilly. Perl 4: Applied Perl http://www.oreillyschool.com/courses/perl4/ I'm willing to take classes online or off. Any suggestion much appreciated. FYI: I'm based in the Chicago area. Thanks Monks!

Replies are listed 'Best First'.
Re: Learn better Perl Coding
by eyepopslikeamosquito (Bishop) on Feb 22, 2012 at 07:51 UTC

    You might get some ideas from this recent node: Where Do I Go Next?

    Also, if you enjoy reading, the free Modern Perl book may teach you some new Perl tricks.

      Thanks, you're reply was helpful.
Re: Learn better Perl Coding
by Anonymous Monk on Feb 22, 2012 at 00:23 UTC
      Most helpful thank you for responding
Re: Learn better Perl Coding
by Anonymous Monk on Feb 22, 2012 at 02:36 UTC
    Maybe also you should ponder what "better" means to you. Consider your own thoughts carefully ... if you want to learn "from others," what prompts you to say that the people who are around you now are "hacks" ... and that you, yourself, are also a "hack?" If you want to become satisfied, first ponder introspectively what exactly it is that now makes you dissatisfied. If "exactly what you are looking for" were to walk up to you and smack you in the face, how, exactly would you recognize it for the godsend that it is? What, exactly is it that makes you step out in search of “change,” and how do you intend to identify it once you find it? Those are, actually, meant as very serious thought-questions...
      Maybe you should not assume so much, the OP appears to have a pretty good idea of areas of improvement (ood), which his current mentors can't help him with
      Jeez louise I didn't know Confucius was still alive....

        He is (maybe he forgot to log in before posting).

Re: Learn better Perl Coding
by tobyink (Canon) on Feb 23, 2012 at 08:11 UTC

    I'd say start with the Modern Perl book. If you've been programming in Perl for years, then at first it seems a little frustrating when it devotes pages and pages to the difference between scalars, arrays and hashes. I was certainly tempted to skip a few chapters, but in the end I'm glad that I did not. Because even if it's telling you stuff you already know, reading through it forces you to think about that stuff, and perhaps re-evaluate them in your head.

    Try to break code out into small logical chunks (usually modules) with clean interfaces between them. Object-oriented programming is often a good way of doing this, but it's not the only way, and sometimes not the best way.

    Learn Larry Wall's virtues of a programmer and meditate upon how you can become more virtuous.

    From the three virtues (especially from the first two), one central principle of DRY (don't repeat yourself) emerges. Avoid repetition like the plague.

    If you have the following scattered around a module:

    $self->foo; $self->bar;

    i.e. a call to foo immediately followed by a call to bar, then write a wrapper:

    sub foo_bar { my $self = shift; $self->foo; $self->bar; }

    ... and use that instead. This may seem trivial, and perhaps like it's causing you more work than it's saving. But, it makes the case where you (either intentionally or unintentionally) call bar before foo stand out like a sore thumb.

    Some people are uncomfortable doing the above. An extra sub call can make your program slower. But don't fall into the premature optimisation trap. Write your program how it makes most sense, not how you think will run the fastest. If, at the end, it runs slowly, then you can run it through a profiler and see what's really slowing it down. (It's often not what you think it will be.)

    If you find you have several wrappers like foo_bar then you're repeating yourself again, and you can eliminate repetition at another level:

    BEGIN { no strict 'refs'; my %wrappers = ( foo_bar => [qw/foo bar/], foo_baz => [qw/foo baz/], quux_xyzzy => [qw/quux xyzzy/], ); while (my ($wrapper, $methods) = each %wrappers) { *{$wrapper} = sub { my $self = shift; $self->$_ foreach @$methods; }; } }

    Here, you haven't written the wrapper subs; you've written a program to auto-generate the wrapper subs. This is often referred to as "meta-programming". One of the ultimate tools for meta-programming (in the Perl world, and probably generally) is Moose. Implement one or two projects using Moose, and it will start changing how you think about Perl. Once you're familiar with Moose, you'll find that even when you're writing non-Moose code, you can apply Moose and meta-programming ideas.

    Almost as bad as repeating yourself is repeating other people. Don't write poorly-thought out code that does X and Y when there are great Text::X and Data::Y modules on CPAN. Stand on the shoulders of giants.

Re: Learn better Perl Coding
by luis.roca (Deacon) on Feb 22, 2012 at 17:02 UTC

    If you're in Chicago maybe YAPC::NA in Madison this June would be a good idea? I have not seen anything specific about OO workshops but for about $100 you'll at least get to hear from some experienced Perl instructors.


    "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." Don Quixote
Re: Learn better Perl Coding
by tangent (Vicar) on Feb 22, 2012 at 17:05 UTC
    I did look through that O'Reilly course you mention and it does seem well laid out and covers many things you would need to know in the real world. I particularly liked the Sandbox idea. However, only 3 of the 15 lessons cover OO and it seems more geared to practical application than to design.

    Update: see this comment on O'Reilly course taken by luis.roca
Re: Learn better Perl Coding
by educated_foo (Vicar) on Feb 22, 2012 at 17:57 UTC
    Keep in mind that Perl was created to get the job done, but "Modern" Perl is almost entirely fashion-driven. Perl's built-in documentation used to be good enough that courses were unnecessary: for OO, see perltoot, perlboot, and perltooc. Sadly, these have recently been put down the memory hole in favor of some "Modern" abomination ("perlootut").
Re: Learn better Perl Coding
by Anonymous Monk on Feb 24, 2012 at 20:44 UTC
    The best book I have read on this subject is Perl Best Practices, Damian Conway, O'Reilly Media, 2005, ISBN 0596001738.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://955414]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2021-06-19 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (91 votes). Check out past polls.

    Notices?