Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

What CPAN Modules are Good to Learn From?

by luis.roca (Deacon)
on Apr 19, 2011 at 16:10 UTC ( [id://900166]=perlquestion: print w/replies, xml ) Need Help??

luis.roca has asked for the wisdom of the Perl Monks concerning the following question:

This is from a question on comp.lang.perl in the thread: 'Learning by Example'

There's a thread I was pointed to in the CB that goes into this: What CPAN modules are "good reads"?. However it's from 2005 and I wonder if members still feel the same way about some of the advice given and/or are there any modules they would recommend?

I'll offer myself as an example. I'm pretty new to Perl and have just really started examining/working with modules. On my home node I have about a dozen listed. Currently the ones I'm studying and creating examples of in are CGI, Text::Template and Time::Piece. My feeling is that if you're going to learn from code it should be for something that addresses a goal you have. (Seems pretty obvious but, still worth mentioning) Now, as far as I know I think these are good modules to use and learn from but that's based on a few recommednations that I can't even remember now.

So I guess the question again is: What are good modules to learn from? AND How, as someone learning Perl, should one judge whether or not a module is good to use and learn from it's code?

Luis
"...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote
  • Comment on What CPAN Modules are Good to Learn From?

Replies are listed 'Best First'.
Re: What CPAN Modules are Good to Learn From?
by InfiniteSilence (Curate) on Apr 19, 2011 at 18:13 UTC

    I tried to learn Perl by reading module code once and learned (the hard way) that is is not a very a good idea for several reasons:

    • Some of the code in CPAN modules is actually not good and should not be emulated. Core modules are very good, but can be sparsely documented. Finding a good module that is clearly written and well documented would be a good idea, but read on...
    • There are LOTS of modules, many of which are very intersting and have awesome techniques that I found fascinating at the time but I have rarely (if ever) actually used.

    One of the links you added has the following quote that encapsulates what I feel is a much better approach: "The best way to learn anything, Perl included, is to use it for useful work. If you don't have a task that needs doing, you aren't going to do it, but if it needs doing, then you will be motivated to do it."

    I think that quote pretty much speaks for itself. Also, don't forget that writing up responses and trying to solve the problems of other Perlmonks is a good way to help hone your skills. You may find that you thought you had a pretty good answer to an issue only to find that your solution was exceedingly verbose, stupid (it has happened to me a few times), or was simply inferior to someone else's. You learn by trying and developing a slightly thick skin. You will need it anyway.

    Celebrate Intellectual Diversity

      As the person who suggested "Use the Core" I can affirm the value in writing up responses and trying to solve the problems of other Perlmonks is a good way to help hone your skills. You may find that you thought you had a pretty good answer to an issue only to ... Well, we have a case in point right here. And not for the first time. The write and compare has previously been useful. Learning opportunities seem to be endless.


      Be Appropriate && Follow Your Curiosity
Re: What CPAN Modules are Good to Learn From?
by toolic (Bishop) on Apr 19, 2011 at 16:22 UTC

      Thank you for the link toolic.

      Looking at that thread I notice the attention is more on CPAN authors rather than specific modules (at least in the 'Best' answer). I can definitely understand that. I know when I was first studying design I looked at examples from my favorite creatives and firms rather than seeking out specific types of work (posters, books etc). The possible problem I can see happening is that EVERYONE has done some bad work. So while it was pretty easy for me as a beginner to dismiss the poorer works of Herbert Matter, Aleksander Rodchenko or the Bauhaus I think (at least for me personally) it would be more difficult to do the same with CPAN authors without much more experience.

      I'm sure you and others have better thoughts on whether to look for good examples by module, author or a little of both. This is just my initial sense.


      "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote
Re: What CPAN Modules are Good to Learn From?
by mikeraz (Friar) on Apr 19, 2011 at 16:48 UTC

    Consider starting with the core modules included with your Perl distribution.
    After those, I would suggest the list of Recommended CPAN modules from Perl Best Practices.
    After those, ones that address goals you have and have high ratings.

    Well, that's my variable worth opinion at least.


    Be Appropriate && Follow Your Curiosity
      Consider starting with the core modules included with your Perl distribution.
      Sage advice in the right hands but taken as a broad, generic statement, this is not a good idea. I assume the OP is looking to help new Perl programmers get up to speed with current techniques but modules found in the CORE were designed up to a decade ago and do not follow "Modern" "Best Practices" for various reasons (legacy support, etc.).
Re: What CPAN Modules are Good to Learn From?
by jdporter (Paladin) on Apr 22, 2011 at 12:19 UTC

    I think it depends very much on what it is you want to learn. How to implement algorithms? How to factor code? How to do OO? How to do good internal documentation? How to make good interfaces? How to create modules specifically?

    On at least one of these, I would not recommend CGI... At least, not until you have the experience to understand why it is the way it is. It is surely a wondrous work, but (in the opinions of many, including myself), it tries to do, and be, too many things. For example, it provides both OO and procedural interfaces to all of its functions, and the functions accept both positional and named parameters. Sure, that's "nice to have" from the user's perspective, but is not a "best practice" for module writers; and certainly doesn't make CGI a "good read".

    Observe that CPAN listings of modules includes ratings. Unfortunately, none of the usual CPAN search engines provide a way to search or order modules by rating. The site where ratings are entered, CPANratings, doesn't even let you do this. I'm going to try looking at a local mirror of CPAN, maybe do a one-off search for the top-rated modules. But beware that module ratings are an imperfect indicator of quality for your purpose, as they're based at least as much on the usability of the module. But hey, it's a place to start.

    On a similar note, there is CPAN Testers. This gives lots of concrete statistics on how well modules pass their test suites, but it seems to be oriented toward answering the question of crossplatformance, i.e. "how well does CPAN — the collection of all current modules — meet the ideal of running on all platforms flawlessly?" To the extent that it lets you compare the results for individual modules, it neither distills it to a single kwalitee metric nor lets you sort by that metric. However, analysis shows the pass/fail numbers; you could easily scrape that page and do the final calculation yourself. But ultimately, this would only give you a hint of how "good" the module is. But at least you could filter out the modules that aren't "good" from a testing and portability perspective.

    AnnoCPAN, another star in the CPAN feedback constellation, only lets people add comments; it doesn't provide any kind of qualitative ranking.

    Update: Ah, LanX has remindedme of CPANTS, which does (when it's working) let you get a listing of modules ordered by kwalitee metric. But check out their relatively static Hall of Fame: 45 distributions with the most Kwalitee. I chose three modules at random from that list and perused the source code. What I saw was, I think, generally well written, perhaps even exemplary. What I didn't see was much internal documentation.

    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
Re: What CPAN Modules are Good to Learn From?
by educated_foo (Vicar) on Apr 23, 2011 at 17:02 UTC
    Large, old modules tend to be full of historical baggage and strange bells and whistles. For example, constant basically does this:
    package constant; sub import { shift; die if @_ % 2; # probably a mistake my $caller = caller; while (my ($k, $v) = splice @_, 0, 2) { *{"$caller\::$k"} = sub () { $v }; } }
    but its import function is 100 lines long and places various weird restrictions on constant names.

    If you want to learn from CPAN modules, I suggest looking at some of the newer, simpler ones, like ADAMK's ::Tiny modules.

Re: What CPAN Modules are Good to Learn From?
by chrestomanci (Priest) on Apr 20, 2011 at 20:40 UTC

    That is a wise question, another is which modules to avoid.

    Over the years I have had cause to read and understand some CPAN modules, either because I was stepping into them with a debugger, or because I was trying to discover if the bug I was seeing was mine, or came from a module I was using.

    Some modules are very readable, but others are horrible, most commonly with a very compact style of code that looks like line noise and gives us a bad reputation. I can't remember any specific examples, and even if I could I would not name them here, because as far as I m concerned, if the code works and someone else is taking responsibility for maintenance, then I don't care about the style, but for a beginner reading code and trying to learn from it, then it would be good to warn the beginner that here be dragons.

How to measure software quality
by LanX (Saint) on Apr 23, 2011 at 14:41 UTC
    We two just had a short discussion in CB about classifying CPAN-Modules like http://kobesearch.cpan.org does.

    I'd like to point - without further comment - you to this blog about CPANTS

    http://szabgab.com/blog/2008/06/1212827982.html

    and the resulting heated discussion in the comments.

    Furthermore http://cpants.perl.org/ and http://use.perl.org are down ATM.

    IMHO if you want to learn from other projects just pick projects you liked and use regularly.


    UPDATE:

    Successful coding practices have a lot to do with evolutionary processes which can't be restricted by a fixed "Intelligent design" but only probed and discussed in an ongoing process.

    Restrictions conflict with creative Perl culture, e.g. I just solved an otherwise "unsolvable" problem with goto EXPR. A metric parsing my code and eliminating this module because "goto is bad" would transform Perl into a bad Python ersatz.

    TIMTOWTDI and "Success is Sexy"!

Re: What CPAN Modules are Good to Learn From?
by Anonymous Monk on Aug 03, 2011 at 09:57 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://900166]
Approved by toolic
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-16 05:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found