Re: What is the best code on the CPAN?

2012-02-08 Thread Michael G Schwern
On 2012.2.7 6:29 PM, Jeffrey Thalhammer wrote:
 I'm working with a group of Perl developers with various backgrounds and 
 skill levels.
 We have instituted a fairly effective code inspection process, but we still 
 get
 bogged down in debates over what good code is.   Unfortunately, the
developers work
 in isolated silos and spend the vast majority of the time looking only at
their own code.
 So they rarely have an opportunity to see what good (or just better) code
might actually
 look like.

If the silos are eliminated and people have to cooperate and work with each
other, you'll find that the discussions about what is good code become far
more practical and people's attitudes become less provincial.


 So in your opinion, which distribution on the CPAN best demonstrates these 
 qualities?
 Or do you think there are other more important qualities that I should be
looking for?
 I realize there is more than one way to do it, so I don't really expect to
find the
 best code.  I just want something I can hold up as strong example that 
 people
 (including myself) can learn from and aspire to.

At the risk of sounding immodest, with the exception of failing to use other
CPAN modules, because it can't, Test-Simple 1.5 matches your criterion pretty
well.
http://search.cpan.org/~mschwern/Test-Simple-1.005000_002/


-- 
91. I am not authorized to initiate Jihad.
-- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army
   http://skippyslist.com/list/


Re: What is the best code on the CPAN?

2012-02-08 Thread Greg Sabino Mullane
On Tue, Feb 07, 2012 at 06:29:04PM -0800, Jeffrey Thalhammer wrote:
...
 which distribution provides the best example
...
 Perl::Critic compliance (any set of Policies will do).

I think Perl::Critic itself is a good example.

-- 
Greg Sabino Mullane g...@endpoint.com
End Point Corporation
PGP Key: 0x14964AC8


pgpRwLqBe74B1.pgp
Description: PGP signature


Re: What is the best code on the CPAN?

2012-02-08 Thread Ovid
Hi Jeffrey,

While the Perl::Critic and TB2 examples may be good code, I submit that they're 
also complicated enough that it may be very hard for a new developers to really 
understand them due to their sheer size. Even for experienced developers, they 
may be nerve-wracking as a learning experience. For smaller problems, though, 
they may not have enough of the characteristics you list to qualify as best.

Perhaps you can find smaller examples of code which fit interesting problem 
spaces and are well-designed? For example, I think you'll find my 
HTML::TokeParser simple is reasonably well designed, even though it's a 
disguised factory which inherits from an awkward interface. It was written in 
the pre-Moose days, so it doesn't fit your criteria.

However, it shows good use of inheritance (a tricky thing to do!) because base 
classes I wrote are abstract and its polymorphism is effective in making many 
methods simply a single line of code. On top of that, it also obeys Liskov 
because you can drop it into a code which uses HTML::TokeParser and it will 
still magically work, even as you gradually replace stuff like this:

    my $text = $token-[0] =~ /^(?:S|E|PI)$/ )
      ? $text = $token-[-1]
      : $text = $token-[1];

With this:

    my $text = $token-as_is;

(get_text() is a better name, but the base class used it for something else and 
overriding a method to provide semantically different behavior is a Bad Thing)

For bonus education points: grab the older versions from the Backpan and watch 
how it evolved from a steaming pile of ones and zeros to something tolerable 
(for its time -- today I would be tempted to rewrite with Moose, but why 
rewrite working code?)

TL;DR: Matching of your criteria would be hard in a code base small enough to 
get your head around easily but maybe something smaller helps?

Cheers,
Ovid
--
Live and work overseas - http://overseas-exile.blogspot.com/
Buy the book   - http://www.oreilly.com/catalog/perlhks/
Tech blog  - http://blogs.perl.org/users/ovid/
Twitter- http://twitter.com/OvidPerl/



 From: Jeffrey Thalhammer j...@imaginative-software.com
To: Perl QA perl-qa@perl.org 
Sent: Wednesday, 8 February 2012, 3:29
Subject: What is the best code on the CPAN?
 
I'm working with a group of Perl developers with various backgrounds and skill 
levels.  We have instituted a fairly effective code inspection process, but we 
still get bogged down in debates over what good code is.   Unfortunately, 
the developers work in isolated silos and spend the vast majority of the time 
looking only at their own code.  So they rarely have an opportunity to see 
what good (or just better) code might actually look like.

I want the team to see how to do things right, rather than debating all the 
ways to do it wrong.  So for our next code inspection, I want them to study 
some good code from the CPAN.  So the question is, which distribution 
provides the best example.  These are the things I think I want in such an 
example (in no particular order):

Object-orientation using Moose.
Prudent use of Perl idioms without being overly clever.
A discernible architecture and clear separation of concerns.
Strong examples of encapsulation / inheritance / polymorphism.
Demonstrates inversion-of-control principles.
Well named variables and subroutines.
Well factored code with minimal complexity.
A clear pattern for extension and reuse.
Useful documentation (e.g. POD, comments).
High-value tests at the functional and unit level.
Perl::Critic compliance (any set of Policies will do).
Effective use of other CPAN modules for routine tasks. 
Effective error handling.
Effective use of Roles.
Self-documenting code.
Robust and consistent API.

So in your opinion, which distribution on the CPAN best demonstrates these 
qualities?  Or do you think there are other more important qualities that I 
should be looking for?  I realize there is more than one way to do it, so I 
don't really expect to find the best code.  I just want something I can hold 
up as strong example that people (including myself) can learn from and aspire 
to.

-Jeff






What is the best code on the CPAN?

2012-02-07 Thread Jeffrey Thalhammer
I'm working with a group of Perl developers with various backgrounds and skill 
levels.  We have instituted a fairly effective code inspection process, but we 
still get bogged down in debates over what good code is.   Unfortunately, the 
developers work in isolated silos and spend the vast majority of the time 
looking only at their own code.  So they rarely have an opportunity to see what 
good (or just better) code might actually look like.

I want the team to see how to do things right, rather than debating all the 
ways to do it wrong.  So for our next code inspection, I want them to study 
some good code from the CPAN.  So the question is, which distribution 
provides the best example.  These are the things I think I want in such an 
example (in no particular order):

Object-orientation using Moose.
Prudent use of Perl idioms without being overly clever.
A discernible architecture and clear separation of concerns.
Strong examples of encapsulation / inheritance / polymorphism.
Demonstrates inversion-of-control principles.
Well named variables and subroutines.
Well factored code with minimal complexity.
A clear pattern for extension and reuse.
Useful documentation (e.g. POD, comments).
High-value tests at the functional and unit level.
Perl::Critic compliance (any set of Policies will do).
Effective use of other CPAN modules for routine tasks. 
Effective error handling.
Effective use of Roles.
Self-documenting code.
Robust and consistent API.

So in your opinion, which distribution on the CPAN best demonstrates these 
qualities?  Or do you think there are other more important qualities that I 
should be looking for?  I realize there is more than one way to do it, so I 
don't really expect to find the best code.  I just want something I can hold 
up as strong example that people (including myself) can learn from and aspire 
to.

-Jeff




Re: What is the best code on the CPAN?

2012-02-07 Thread David Golden
On Tue, Feb 7, 2012 at 9:29 PM, Jeffrey Thalhammer
j...@imaginative-software.com wrote:
 So in your opinion, which distribution on the CPAN best demonstrates these 
 qualities?

Dist::Zilla

Leaving aside the fact that I don't think your full wishlist actually
exists in any single thing on CPAN, I would nevertheless point you to
that as a good example of almost all the things on your list.

-- David


Re: What is the best code on the CPAN?

2012-02-07 Thread Mike Doherty
Dist::Zilla is also something you might want to actually /use/ :D

-Mike


On 12-02-07 09:34 PM, David Golden wrote:
 On Tue, Feb 7, 2012 at 9:29 PM, Jeffrey Thalhammer
 j...@imaginative-software.com wrote:
 So in your opinion, which distribution on the CPAN best demonstrates these 
 qualities?
 
 Dist::Zilla
 
 Leaving aside the fact that I don't think your full wishlist actually
 exists in any single thing on CPAN, I would nevertheless point you to
 that as a good example of almost all the things on your list.
 
 -- David