[Purdue-pm] False Hubris code example

Michael Gribskov gribskov at purdue.edu
Tue Aug 18 06:37:32 PDT 2009

I would never consider a person's code to be bad, only particular code.  
IMO, if it takes an experienced programmer a significant amount of time 
to just figure out what it does AND there is no over-riding need for 
efficiency, I consider it to be bad.  Preferably, code should be as easy 
to understand as a written sentence.  Almost all the effort in software 
development is in the maintenance phase of the life cycle, code that 
shows your programming chops by using obscure but  "very idiomatic" 
parts of the language that require "deep understanding" make maintenance 
more difficult.  the slurp code below definitely meets Wall's definition 
of false hubris == "unnecessarily dense, unreadable code".

what i specifically don't like:
1) assigning value to @ARGV, which is, after all, supposed to represent 
the command line
2) assigning value of undef to $/ as a side effect of unbalanced left 
and right hand sides of assignment
3) by my timing with NYTProf, the compressed code is actually a little 
over 20% slower than the following

    local $/ = undef;
    open( IN, "<$file" );
    $text = <IN>;
    close IN;


4) the compressed code is 52 characters, the more understandable (IMO) 
code above is only 70. Why make it difficult to understand to save 18 
characters of typing

> Hash: SHA1
> Michael Gribskov wrote:
>> Why do people consider code like this to be "good"??
>> my $text = do { local( @ARGV, $/ ) = $file ; <> };
>> while it is compact, it is to my mind obscure and uneccessarily
>> difficult to understand, succeeding by side effects of the overt code. 
>> A whole program written like this is a nightmare. IMO of course
> Do you consider the rest of chromatic's program "bad" then?
> I would probably just use File::Slurp unless some constraint wouldn't
> let me. The one line is very idiomatic perl. Just some very deep
> understanding of what perl can do.
> joe
> Version: GnuPG v1.4.5 (GNU/Linux)
> Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org
> iD8DBQFKgY3Eb0mzA2gRTpkRAni8AKCh/zbPI84hZVAQlJi3ZM4h/GtYOwCgjIY5
> =VL6K
> _______________________________________________
> Purdue-pm mailing list
> Purdue-pm at pm.org
> http://mail.pm.org/mailman/listinfo/purdue-pm

Michael Gribskov
Professor of Biological Sciences
Purdue University
Lilly Hall of Life Sciences
915 W. State Street
West Lafayette  IN  47907-2054
gribskov at purdue.edu
vox: 765.494.6933     fax: 765.496-1189
<A HREF=http://sapporo.genomics.purdue.edu/webcal/wcal.pl?c=get&ls=0&w=Gribskov>Calendar</A>

More information about the Purdue-pm mailing list