Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Horrors abound

by htoug (Deacon)
on Nov 25, 2004 at 23:59 UTC ( #410487=note: print w/ replies, xml ) Need Help??


in reply to Pearls (not really) of Perl programming

I just fell face forward into this earlier today (sorry for the extremely long lines):

use vars qw/ + + $AllowFullYearView + + $LevelForRobotsDetection $LevelForWormsDetection $LevelForBrowsersDete +ction $LevelForOSDetection $LevelForRefererAnalyze + $LevelForFileTypesDetection $LevelForSearchEnginesDetection $LevelForK +eywordsDetection + /; ($AllowFullYearView, $LevelForRobotsDetection, $LevelForWormsDetection, $LevelForBrowsersD +etection, $LevelForOSDetection, $LevelForRefererAnalyze, $LevelForFileTypesDetection, $LevelForSearchEnginesDetection, $LevelF +orKeywordsDetection)= (2,2,0,2,2,2,2,2,2); use vars qw/ + + $DirLock $DirCgi $DirConfig $DirData $DirIcons $DirLang $AWScript $Arc +hiveFileName + $AllowAccessFromWebToFollowingIPAddresses $HTMLHeadSection $HTMLEndSec +tion $LinksToWhoIs $LinksToIPWhoIs + $LogFile $LogType $LogFormat $LogSeparator $Logo $LogoLink $StyleSheet + $WrapperScript $SiteDomain + $UseHTTPSLinkForUrl $URLQuerySeparators $URLWithAnchor $ErrorMessages +$ShowFlagLinks + /; ($DirLock, $DirCgi, $DirConfig, $DirData, $DirIcons, $DirLang, $AWScri +pt, $ArchiveFileName, $AllowAccessFromWebToFollowingIPAddresses, $HTMLHeadSection, $HTMLEnd +Section, $LinksToWhoIs, $LinksToIPWhoIs, $LogFile, $LogType, $LogFormat, $LogSeparator, $Logo, $LogoLink, $Sty +leSheet, $WrapperScript, $SiteDomain, $UseHTTPSLinkForUrl, $URLQuerySeparators, $URLWithAnchor, $ErrorMessa +ges, $ShowFlagLinks)= ('','','','','','','','','','','','','','','','','','','','','','','' +,'','','','');
etc for several pages, followed by:
#--------------------------------------------------------------------- +--------- + # Function: Write on ouput header of HTML page + + # Parameters: None + + # Input: %HTMLOutput $PluginMode $Expires $Lang $StyleS +heet $HTMLHeadSection $PageCode $PageDir + # Output: $HeaderHTMLSent=1 + + # Return: None + + #--------------------------------------------------------------------- +--------- + sub html_head { my $dir=$PageDir?'right':'left'; if (scalar keys %HTMLOutput || $PluginMode) { my $MetaRobot=0; # meta robots + + my $periodtitle=" ($YearRequired".($MonthRequired ne 'all'?"-$Mont +hRequired":"").")"; # Write head section + + if ($BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml') +{ if ($PageCode) { print "<?xml version=\"1.0\" encoding=\"$PageCode\"?>\n"; } else { print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"; } ; if ($FrameName ne 'index') { print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//E +N\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; } else { print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset/ +/EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n"; } print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$ +Lang\">\n"; } else { if ($FrameName ne 'index') { print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitio +nal//EN\">\n\n"; } else { print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset/ +/EN\">\n\n"; } print "<html lang='$Lang'".($PageDir?" dir='rtl'":"").">\n"; } print "<head>\n"; print "<meta name=\"generator\" content=\"AWStats $VERSION from co +nfig file awstats.$SiteConfig.conf (http://awstats.sourceforge.net)\" + />\n"; if ($MetaRobot) { print "<meta name=\"robots\" content=\"".($FrameName eq 'mainlef +t'?'no':'')."index,nofollow\" />\n"; } else { print "<meta name=\"robots\" content=\"noindex,nofollow\" />\n"; }
and so on for more than 10,000 lines - in one file.

Note the way arguments are passed to a function: in global variables, and the neat way of printing just one line per print statement (OK: in all fairness later the author has discovered here-docs, but he has not refactored).
And of course it is a CGI program, but does not use CGI;.

I was trying to find a web-log-analyser tool with nice pictures for the PHBs, and google pointed me towards a site on sourceforge, where a well-documented tool was available in perl, with all the nice graphs management likes.

I recoiled in horror on looking inside the code and discovering a true treasure-trove for the perlmonks Pearls (or not) - a sample of which I just had to share.
I will now go on my way and find something better or (yuck) do it myself. Pity - it did look promising, and I am lazy and impatient.

All names withheld to protect the unnamed author.


Comment on Horrors abound
Select or Download Code
Do Open Source programs have to be pretty inside?
by Thilosophy (Curate) on Nov 28, 2004 at 07:48 UTC
    This is an interesting point you raise here: Do Open Source programs have to be pretty inside? Sometimes you have a really capable program, which does its job very well, you use it, recommend it to others, but you better not look under the surface, as the source could make you blind.

    I know which project you are talking about here, because I use it frequently, and when I wanted to replace the home-spun referrer-scanning logic for my blog (code I have to update all the time to keep up with all the different search engines) with something more complete, I looked at above source to see if I could use some of their code for that purpose. And yes, I also recoiled in horror (and gave up). Totally monolithic, horrible from a software engineering stand-point.

    Would this be a better project if its code was more modular, with components useful outside its primary application? Yes. But is the reverse also true? Does a useful program become less useful because the implementation is ugly?

    I was trying to find a web-log-analyser tool with nice pictures for the PHBs, and google pointed me towards a site on sourceforge, where a well-documented tool was available in perl, with all the nice graphs management likes.
    I will now go on my way and find something better or (yuck) do it myself. Pity - it did look promising, and I am lazy and impatient.

    I would not do that, especially when you are lazy and impatient. Your PHB is not going to look at the source, the project is, as you say, well-documented, popular and works as advertised. Just treat this open-source project as closed-source (for your own safety).

      I agree - it will probably be best to accept the project just as any other shrink wrapped system we buy.

      I is a terrible shame though that all the effort that has gone into this project has ended with such a poor result. If it had been done according to 'proper' software engineering methods, it could have been augmented with you referrer-scanning logic and my additions.

      It does make the program less useful because you and I have had to do something else, and thus we have had to spread our tuits. The program could have saved us valuable time for something vital (like playing with the dogs) instead of having to do something that has beeen done many times already. If the implementation is 'nice' (from an engineering point of view) it adds considerable value. OK: it does as advertised, but extra value can be had if it is possible to reuse parts of it in new and unforseen ways. I think that perl (and Perl) is a good example of this.

      Does a useful program become less useful because the implementation is ugly?

      Yes, I would say so. A less maintainable program results in longer development times for bug fixes and security patches. A less maintainable program also has a greater chance of having a bug introduced whenever the program is changed.

      I guess that any kind of obfuscation is, in a way, against OpenSource. Who would dare to help if understanding such criptical code would consume most of someones' spare time?

      .{\('v')/}
      _`(___)' __________________________
      Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-07-11 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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








    Results (224 votes), past polls