Reviewing CPAN modules

56
Reviewing CPAN modules Neil Bowers 1

Transcript of Reviewing CPAN modules

Page 1: Reviewing CPAN modules

1

Reviewing CPAN modules

Neil Bowers

Page 2: Reviewing CPAN modules

2

• Apparently there are 1,900+ Torch/Flashlight apps…

Page 3: Reviewing CPAN modules

3

Page 4: Reviewing CPAN modules

4

What is CPAN?

• Something like a university library?• Lots of useful items, nicely catalogued, easily found

A toolchest full of precision instruments that good programmers can wield to make great things

- chromatic

Holy crap, I forgot about [that module that I wrote].- Andy Lester

• I think more like Rube Goldberg's workshop:• A bunch of useful things, some half-finished ideas, practical jokes, stuff

that no longer works, items that shouldn't be there, forgotten things in the corner

Page 5: Reviewing CPAN modules

5

Review #1Generating passwordsModules that can be used to automatically generate passwords, either random sequences of characters or pronounceable pseudo words

Page 6: Reviewing CPAN modules

6

Modules for generating passwords

Page 7: Reviewing CPAN modules

7

Generating random char strings

• 100,000 passwords

Page 8: Reviewing CPAN modules

8

Structure of reviews

Page 9: Reviewing CPAN modules

9

After doing the review

• I'm now using Crypt::YAPassGen• v0.02 released 2004-05-30

• App::Genpass is good• I've submitted changes to add features I liked in other modules

• I've ended up using Data::Random elsewhere• Because I was aware of it having done this review

• Hoping to finally release fix for Crypt::RandPasswd• I was granted co-maint yesterday (23rd Nov 2012)

Page 10: Reviewing CPAN modules

10

Review #2Looking up location of an IP addressModules that can map an IP address to ISO country code,and possibly return additional info like language, county/state, etc

Page 11: Reviewing CPAN modules

11

Modules for getting IP locationco-maint to release fixes and doc updates

Page 12: Reviewing CPAN modules

12

Notes

• A number of these are 'commercial'• Pay for full data set, or to get unthrottled access to backend service

• Performance & coverage tests took the most time• In particular it's hard to test for correctness

• A number of good options• Competition keeps them on their toes?• Which one you use might depend on what other info you want for an IP

• Ended up not having the need, so not using any• But have used them occasionally, now I know about them

Page 13: Reviewing CPAN modules

13

Review #3Spelling out a number in EnglishModules for converting 327 to "three hundred and twenty-seven",-3.25 to "minus three point two five", etc

Page 14: Reviewing CPAN modules

14

Modules for spelling out numbers

Page 15: Reviewing CPAN modules

15

Notes on review #3

• Fewer modules meant more time to 'play'• I had fun writing a script to automatically compare results between

modules for 1 .. N

• First time I hit a module that just doesn't work

• Lingua::EN::Numbers• The first module where I remember looking at the code and thinking

"hey, nice"• I took over maintenance from Sean Burke to release fixes• And have a todo-list, adding ideas that came up during the review

Page 16: Reviewing CPAN modules

16

My rules of engagement

• Treat authors and their code with respect• This might be someone's first tentative steps at code sharing

• Report all bugs I find• If I can see how to fix them, then submit a fix

• Fix and improve documentation• Especially if I had to look at the code to work out how to use it

• If appropriate, try and get co-maint to release fixes• Because CPAN is forever• This can be to just mark a module as deprecated & update SEE ALSO

• If there are four or more modules for something• It goes onto my backlog of potential reviews

Page 17: Reviewing CPAN modules

17

Observations based on the rules

• What encourages me to submit fixes?• Github• Makefile.PL (or more accurately: not dist.ini)

• Getting co-maint is relatively costly• People disagreed when I said this at LPW 2011 ("You're doing it

wrong")• I still think this (getting co-maint to fix doc is relatively costly)

• I'm toying with writing a tool to manage this• I might submit bugs or send email on 10 different modules in a review

Page 18: Reviewing CPAN modules

18

Review #4Parsing User-Agent stringsModules for extracting and inferring information from HTTP User-Agent strings.

Eg to tell how many of your site's users are using IE vs Chrome vs Firefox

Page 19: Reviewing CPAN modules

19

Modules for parsing User-Agent

Page 20: Reviewing CPAN modules

20

Review structure: module section

Page 21: Reviewing CPAN modules

21

ComparisonCoverage (test corpus)

Speed

Review-driven development!

Page 22: Reviewing CPAN modules

22

Curation

• Requirements for these modules• Continuing good coverage of (versions of) browsers, bots, libraries, etc• Good enough performance (processing large log files)• Identifying other things (is it a mobile? what's the screen size?)

• Working with Olaf Alders on "complete solution"• Currently at the R&D stage

Page 23: Reviewing CPAN modules

23

Review #5Defining constantsModules for defining constants and immutable variables

Page 24: Reviewing CPAN modules

24

Modules for defining constants

Page 25: Reviewing CPAN modules

25

Some firsts with this review

• I was prompted to look at the Perl source• To make sure I understood SvREADONLY

• Emailed an author for help understanding his code

• Enough modules to prompt me to map them out

Page 26: Reviewing CPAN modules

26

Observations

• I had been using Readonly• But I clearly hadn't read all the documentation before

• Now I use Const::Fast• Latency: all those modules using Readonly …

• Surprising variety of designs / approaches• I learned a lot looking at the code for all these modules

• But quite a few experiments• "I wonder if you can …"

Page 27: Reviewing CPAN modules

27

Review #6Getting module dependency infoFinding out what modules (and dists) are used by a module or modules

Page 28: Reviewing CPAN modules

28

Tried a new approach

• Previously I only published after a lot of work• But I still missed plenty of modules

• Decided to experiment with a more lean approach• Found 6 modules, none did what I wanted, so wrote my own• Wrote a quick sketch review and published it• More modules came out of the woodwork every time I updated

• I was looking at dependencies for my next review• But ended up pushing this one out sooner

Page 29: Reviewing CPAN modules

29

Modules for getting dependencies

Page 30: Reviewing CPAN modules

30

Module Author

• But META.json says:

• I had a "bug" reported – author is listed as:

• End result was PAUSE::Permissions

Page 31: Reviewing CPAN modules

31

Notes

• The 23rd module nearly matched mine!

• Very much still in progress

• Curation needed:• There are 5 or so distinct module types (out of 26 so far)• But lots of different variations on each theme

Page 32: Reviewing CPAN modules

32

Why so many modules?

• Whipupitude

• Low barrier to entry for CPAN

• Hard to find (all) appropriate modules

• Easier to upload than contribute or take over

• Playing with Perl is fun (eg constants, dependencies)

Page 33: Reviewing CPAN modules

33

Review #7Making HTTP requestsModules for making HTTP requests (GET, POST, PUT, DELETE, etc)Excluding higher-level modules like WWW::Mechanize

Page 34: Reviewing CPAN modules

34

Modules for making HTTP requests

The only module I've given up on

Page 35: Reviewing CPAN modules

35

Performance on GET requests

Page 36: Reviewing CPAN modules

36

Runtime dependencies

Require a C library

Requires a C library and Moose!

Page 37: Reviewing CPAN modules

37

What module to use?

Page 38: Reviewing CPAN modules

38

Review #8LUHN checkModules for checking credit card numbers

Page 39: Reviewing CPAN modules

39

Modules for checking CC numbers

Page 40: Reviewing CPAN modules

40

Performance of LUHN modules

Moose?

Page 41: Reviewing CPAN modules

41

Review #9Getting a module's pathModules for finding where a module has been installed locally,preferably without having to load the module

Page 42: Reviewing CPAN modules

42

Modules for getting a module's path

Page 43: Reviewing CPAN modules

43

Comparison

Nearly three orders of magnitude

Page 44: Reviewing CPAN modules

44

Feature matrix

Page 45: Reviewing CPAN modules

45

Features vs Dependencies

Page 46: Reviewing CPAN modules

46

Appropriate # of dependencies

Page 47: Reviewing CPAN modules

47

Observations

And some mild venting

Page 48: Reviewing CPAN modules

48

What do people use CPAN for?

• Sharing code with others!

• Configuration management

• A cloud-based store for configuration (Task::BeLike::*)

• A transport mechanism

• A todo list (eg Business::BankCard)

• A blog / dumping ground for ideas

• None of the above (ACME::*)

Page 49: Reviewing CPAN modules

49

Version numbers

• Version numbers should be designed for humans• PAUSE just wants them to be monotonically increasing

• All modules in a dist should have• A version number• The same version number

• Don't be afraid of 1.x• 73% of dists on CPAN are version 0.*

• our $VERSION = '0.01';

0.010.004

1.1216600.0.200.6.1

50.000

0.001005v0.0.3

2.46632

2011121001

Page 50: Reviewing CPAN modules

51

How can you tell a good module?• Version number

• But see Net::HTTP::Tiny v0.01

• Recently updated• Some modules are 'finished'

• Volume and/or quality of documentation• See Crypt::RandPasswd

• Number of bugs• Some big hitters have a long list though…

• Number of dependent modules• from different authors

• Ratings / +1's

• Perl::Critic

• Author

• All of the above, and more

Page 51: Reviewing CPAN modules

52

How have I changed as a result?• I've learned new things, & new ways to do things, & …

• I do developer releases & pay a lot more attention to CPAN Testers

• I'm more paranoid

• I benchmark and profile

• I use IRC, and have had only positive experiences

• How I export functions (thank-you Zefram)

• How I think about dependencies

• Moose / Mouse / Moo

• I'm a lot more circumspect about releasing code to CPAN

• Beginner's mind

Page 52: Reviewing CPAN modules

54

My review process

• Quickly skim and find initial set of modules

• Start writing sections for each module• Write generic SYNOPSIS style example, and evolve it as I go along

• Report bugs and documentation issues as I go

• First sketch at benchmarking & comparing

• More thorough search for modules to include

• Email the authors, give them a chance to comment

• Publish first version• Iterate as people point out modules that I've missed

Page 53: Reviewing CPAN modules

55

It's easy – why not give it a go?% mkdir json% cd json

% cat > module-list.txtJSONJSON::DWIWJSON::JOMJSON::ParseJSON::SyckJSON::TinyJSON::UtilJSON::XSJSON::YAJLJSON::Streaming::ReaderJSON::Streaming::WriterMojo::JSONPegex::JSONTest::JSON^D

% cpan-review

Page 54: Reviewing CPAN modules

56

What do I want you to do?

• Stop and search CPAN before writing code• Ok, I accept it's hard to find (all of the) relevant modules for a task

• Just because you wrote it, you don't have to upload it• Only release if it's needed for another module, or another user• Put it on github• Write an article about it on blogs.perl.org

• Add links to similar modules in SEE ALSO• MetaCPAN will include those in search results• It's helpful for users• You'll make my life easier

• Write a helpful ABSTRACT in your NAME section• "a perl interface to foolib"• "the hardest working two letters in Perl"

Page 55: Reviewing CPAN modules

57

Review-related todo list

• Related to existing reviews• Fix Crypt::RandPasswd• Configurability for Lingua::EN::Numbers• User-Agent module with Olaf• New constant module: Exporter::Constants• Dependencies: +5 modules to review, my module, curation• HTTP requests: Mojo::UserAgent, async request modules• Changes to Business::CCCheck

• New reviews in progress• Hash objects• JSON• Module loading

Page 56: Reviewing CPAN modules

58

Finding modules is hard

• Thinking about trying automatic clustering

• Help identify groups of modules for review

• Possible contribution to MetaCPAN

• Automatic tagging of modules• Use keywords field in metadata