Re: New Perl user looking for code to study
by matthewb (Curate) on Apr 23, 2005 at 19:24 UTC
|
You're looking for CPAN
Happily, however, the journey is ongoing. As you come to understand more of what you encounter the urge to read code will become stronger and you'll find yourself skipping to the source before you read the documentation.
Note that it can be just as useful to read bad code as it is to read good, what's important is to keep interested in self-improvement.
There are loads of examples of funky Perl code out there but if you're looking for real-world good stuff, here are a couple of favourites:
-
When I browse the source for Template Toolkit I am always in awe, thinking “man, that is so much more organised than my code!”.
-
Newcomer CGI::Prototype is almost enough to make me give up coding altogether in how infuriatingly sensible it is (instead, I decided to use it as the basis for my latest project).
And look at the whizz-kids here. Perlmonks isn't like other forums1, there are regular contributions from some of the best minds in the business that frequently question how [id://matthewb|this] little contractor writes his code.
[1]. Kidding about that link ;)
| [reply] |
|
Newcomer CGI::Prototype is almost enough to make me give up coding altogether in how infuriatingly sensible it is
{blush}
I suppose the real thing that drives my coding for stuff like that is the sensible "Smalltalk Best Practice Patterns" by Kent Beck, an excellent book for basic object oriented programming, even though it is focused on Smalltalk. (And supports my idea that you really can't say you "do OO" until you've practiced in Smalltalk at least for a short while.)
| [reply] |
Re: New Perl user looking for code to study
by tlm (Prior) on Apr 23, 2005 at 19:19 UTC
|
| [reply] |
Re: New Perl user looking for code to study
by ddam (Initiate) on Apr 23, 2005 at 19:48 UTC
|
Thanks all. Good advice here. This place is fantastic. With the tutorials and code sections, I think I'll be well on my way.
This is why I chose to learn Perl. Great community, great docs, loads of examples. | [reply] |
Re: New Perl user looking for code to study
by bofh_of_oz (Hermit) on Apr 23, 2005 at 18:57 UTC
|
I would say that from my point of view, the main best practices are:
1. document your code
2. use strict and warnings (at least when writing and testing the code)
3. before creating something big, look around - chances are, someone already did something similar, so you can reuse the code
As for the links to a "good" code, I would advise to look in the Code Catacombs - the approved code from the hardworking monks :)
--------------------------------
An idea is not responsible for the people who believe in it...
| [reply] |
Re: New Perl user looking for code to study
by ghenry (Vicar) on Apr 23, 2005 at 20:49 UTC
|
I actually find that PM has a lot of excellent code. Just look in just about any section.
After about spending a month or two on here, you will see a lot of great code, but just not from me ;-)
Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!
| [reply] |
Re: New Perl user looking for code to study
by bradcathey (Prior) on Apr 23, 2005 at 18:59 UTC
|
| [reply] |
|
| [reply] |
|
Writing obfuscated code is fun, and certainly a challenge, but it's really a very specialized niche. Learning how to do it may teach you a lot of Perl features, but it really doesn't teach you how to use them well. I think the latter is more important than the former, and hopefully you'll agree that obfuscation is not the best example of it.
| [reply] |
|
I agree, the camel is not a practical example of nice structured code. But it still is an amazing thing of beauty, which was my point. And if you can do that, you know you can probably do the day-to-day stuff well.
—Brad "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
| [reply] |
Re: New Perl user looking for code to study
by TedPride (Priest) on Apr 24, 2005 at 08:12 UTC
|
Try to section your programs into stand-alone chunks. Turn these chunks into subs; try to test each for all possible inputs and behaviors. Once a sub works, you can use it as part of bigger and bigger sections of your program, each of which should be tested in turn.
As far as standard formatting goes, always write your programs for use strict and use warnings; define all variables at the top of the section that uses them; insert comments wherever you're likely to have problems remembering the mechanics of your code later. Use some sort of standard naming scheme for variables and subs that avoids case sensitivity problems and name collisions.
Read through the posts here every day and try to solve the algorithmic problems on your own. Then compare to posted code. My code formatting got worlds better within a week or two of doing this. | [reply] |