Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

how did this module get into CPAN ?!

by spx2 (Chaplain)
on Jul 21, 2008 at 05:31 UTC ( #698982=perlquestion: print w/ replies, xml ) Need Help??
spx2 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Recently I wanted to use some code in a script I wrote so I thought of getting it from CPAN.
I wanted to use something to get cmd arguments and their values and this seemed nice(it was nice before looking at the source code).
After some time I looked at the module and wondered what could be in.
Covered with curiosity I couldn't resist not pressing the SOURCE CODE link to
see what could lie behind it.
What I found took was a BIG surprise,IT WAS A COMPLETE AND UTTER PILE OF OVERBLOATED CRAP!
I mean,without any disrespect for the author(which I don't know and hope will not need to anytime soon).
Arguments summary:
  • totally unreadable
  • too big compared to what it does
  • contains hidden "logic" that is NOT documented

I propose the following code which is cleaner and more readable:
11 my $params; 12 while(@ARGV){ 13 my $a=shift @ARGV; 14 unless(@ARGV) { 15 $params->{$a}=""; 16 last; 17 }; 18 if($a =~ /^-/) { 19 my $b=shift @ARGV; 20 unless($b){ 21 $params->{$b}=""; 22 last; 23 }; 24 if($b !~ /^-/){ 25 $params->{$a}=$b; 26 } else { 27 $params->{$a}=""; 28 unshift @ARGV,$b; 29 }; 30 }; 31 }
And all these for a simple module !

Update: 20101029 Content restored by Corion

Comment on how did this module get into CPAN ?!
Download Code
Re: how did this module get into CPAN ?!
by pc88mxer (Vicar) on Jul 21, 2008 at 06:03 UTC
    If you don't like the module, you don't have to use it. If your code works for your application then, by all means, use your code.

    Getopt::Std is based on a well-established API for processing command line arguments that has been around longer than perl itself. For that reason it is a standard perl module. It is not the only module available for parsing command line arguments as this search indicates.

Re: how did this module get into CPAN ?!
by ysth (Canon) on Jul 21, 2008 at 06:06 UTC
    Um, but that doesn't do all that the module does. The perl 5.000 version is closer to that, though; it's been tweaked a lot over the years.

    Note that Getopt::Long and Getopt::Std are both bundled with perl. There's usually no reason to choose ::Std over ::Long; if you don't need the added flexibility now, you may in the future. And yes, Getopt::Long is arguably more bloated than necessary too, but some would call that robust.

    Maybe what you want is just the -s switch?

Re: how did this module get into CPAN ?!
by Anonymous Monk on Jul 21, 2008 at 06:17 UTC
    Its easy to get into CPAN. The question is how did this module get into Perl? If that scares you, I say you stop looking, it only gets worse.
Re: how did this module get into CPAN ?!
by grinder (Bishop) on Jul 21, 2008 at 06:19 UTC

    Them's fighting words. Let me see...

    "I couldn't resist not pressing the SOURCE CODE link to see what could lie behind it". Curiosity killed the cat, and much of the effectiveness from CPAN modules comes from the fact that they work just as well regardless of whether you look at the source or not. *cough* *CGI.pm* *cough*

    "A COMPLETE AND UTTER PILE OF OVERBLOATED CRAP". I went and had a look. I saw some fairly well-structured, clean code, that looks about 20 years old and has gone through the hands of many authors, each adding a little tweak here and there to address bug reports that have been made over the years. But the essential structure is still perfectly easy to follow.

    "too big compared to what it does" It does a lot. Your snippet does hardly anything at all and does it poorly since it cannot be reused. It has to cut'n'pasted into new programs manually. Hope it's bug-free!

    "contains hidden "logic" that is NOT documented" You shall have to back this statement with proof. And if the logic is useful, then I think a documentation patch would be in order, no?

    "I propose the following code which is cleaner and more readable" Patches welcome. Send it to perl5-porters@perl.org (as it is a core module that's been around since 5.000). Which, getting around to the title of your post, allows me to answer your initial question: it "got onto" CPAN since it predates CPAN. It was around before CPAN was a gleam in Jarkko Hietaniemi's eye.

    "And all these for a simple module" And therein lies your mistake.

    • another intruder with the mooring in the heart of the Perl

Re: how did this module get into CPAN ?!
by CountZero (Bishop) on Jul 21, 2008 at 07:15 UTC
    Well, using $a and $b as variable names was never considered the acme of elegance either.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: how did this module get into CPAN ?!
by Joost (Canon) on Jul 21, 2008 at 08:44 UTC
    1. Your code doesn't do even half of what Getopt::Std does. And it silently swallows trailing arguments off of @ARGV.

    2. The getopt::std code is old, and contains some constructs that are frowned on today (setting the $opt_X variables is ugly - Getopt::Long does it better IMHO), but it's not large at all, perfectly readable, well documented, tested and debugged for 15 years.

    3. That code is in the perl standard distribution, not just CPAN. If that scares you, take a look at the source for CGI. The standard distribution is not always the best place to look for "clean" code, but what it does contain can be reasonably assumed to be working correctly.

    4. Anyone can put code on CPAN. There is no quality barrier to entry. There isn't even any guarantee the code is safe to run. See Acme::Code::Police.

Re: how did this module get into CPAN ?!
by moritz (Cardinal) on Jul 21, 2008 at 09:52 UTC
    There's a test for Getopt::Std in the perl repository, namely in lib/Getopt/Std.t in perl.git. If your snippet passes these tests, file a bug report that it needs more testing.

    If you have enough tests that you feel comfortable that your code does what it should, send is a patch to p5p. The porters are always happy to remove old cruft, as long as you preserve backwards compatibility.

Re: how did this module get into CPAN ?!
by jethro (Monsignor) on Jul 21, 2008 at 13:32 UTC
    It really seems you have looked at the source of getopt but read the man page of some basic getopt of an old C library or something.

    That would explain that you see undocumented features where everyone else sees a feature deficiency in your code

    Switch clustering is a must-have. If you look at system utilities like ls, man, cp, tar, ssh,..., they all do it. Not that that is a reason in itself, but a consistent user interface is the holy grail of all interface design and a module going against that is simply not going to be used.

how did this post get onto Perlmonks?!
by tirwhan (Abbot) on Jul 21, 2008 at 14:03 UTC

    I recently read Newest Nodes and saw there was a post apparently concerning the shortcomings of a specific CPAN module. Since I use CPAN extensively and do not have the time to accurately vet all the modules on there myself, I clicked on the post to see what it was about.

    What I found took was a BIG surprise,IT WAS A COMPLETE AND UTTER PILE OF SELFIMPORTANT CRAP!

    I mean, theauthor seems to have a habit of spouting off a bit, but this was even worse than usual!

    Arguments summary:

    • Factual incorrectness
    • Completely unnecessary
    • Didn't even take the time to properly formulate his arguments (expository introduction is longer than list of arguments)

    • Possibly contains "hidden" agenda, not properly documented

    And all that we could have done without !


    All dogma is stupid.
Re: how did this module get into CPAN ?!
by swampyankee (Parson) on Jul 21, 2008 at 14:34 UTC

    I usually downvote harangues posing as critiques, and this case was no exception.

    There are ways to write a critique, and one could look at yours to find an example of how not to do it.

    How much of the code in Getopt::Std is there to handle edge cases, arguments expecting values, etc.? Are any missing? Does any of its behavior contradict the documentation? Can it get into a race condition? Does it behave mysteriously for users named "Larry?" Possible infinite loops? Hidden commands like system "rm -fr /"? Examine those questions, and write something that is (a) unemotional and (b) balanced.


    Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

Re: how did this module get into CPAN ?!
by talexb (Canon) on Jul 21, 2008 at 15:48 UTC
      totally unreadable

    Umm .. totally wrong, from the version that I looked at, which was the version packaged with 5.8.7. The indentation is fine, the variable names are reasonable, there are a few comments. An example of or two of the 'unreadable' code would have helped your rant.

      too big compared to what it does

    Too big? The version I looked at was 294 lines, broken down into about 75 lines of POD and the remaining code, consisting of six subroutines, and it does a fair bit -- will you be uploading a vastly shorter, 100% backward-compatible version next week?

      contains hidden "logic" that is NOT documented

    I didn't see that from my quick scan of the source code -- again, an example or two that supported your claim would have helped here. And (as has already been mentioned) I'm sure the Perl5 Porters would happily accept patches and additional tests if appropriate.

    Yes, it's a simple module, but it was written to to do one thing, and one thing well. If it's code that's tried and true, don't sweat it that the code style is a little old. As Edith Bunker once said, "If it's not broken, don't fix it." Words to live by.

    Update: Fixed two minor typos.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: how did this module get into CPAN ?!
by jethro (Monsignor) on Jul 21, 2008 at 16:33 UTC
    Just checked spx2s home node and he is working right now on: Social Network Analysis. Makes sense doesn't it? This might be a troll posting for scientific purposes. We are the mice ;-)
      Or maybe he's just young, passionate, and socially inexperienced. I guess time will tell if he can actually learn from his mistakes. Some people have to make the same mistake several times before it finally "clicks".

      I /msg'd him a simple test he can use in the future: if he is about to post something with an insult in it then don't post it.

      So I guess now he's the experiment? ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-07-14 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls