This probably doesn't belong anywhere, but Meditations is as good a place as any I suppose
I was crawling through someone else's code today. I was supposed to go port it to use some new infrastructure of ours, but after I clawed my eyes out, we decided I should rewrite it. The clincher for me was:
for ( @data ) {
sysopen ($fh, "$log", O_WRONLY|O_APPEND);
$fh->print ("$_");
close $fh;
}
This sent me off on a rant. This sent my manager and I off into a tailspin inventing god-awful code. My final contribution is nothing short of contrived ugliness, and I wanted to share it with you, my esteemed fellow monks:
#!/usr/bin/perl
my $filename = $ARGV[0];
my @size = grep /./, map { $_ } split //, `wc -l $filename`;
my $i = '';
my $loop = 1;
while ( $loop ) {
my $d = shift @size;
if ( $d =~ /\d/ ) {
$i .= $d;
} else {
$loop = 0;
}
}
for ( 1 .. $i ) {
my $line = `head -$_ $filename | tail -1`;
print $line;
}
Since I'm dealing with the ugliness someone else unleashed on the world, somehow I feel better having unleashed that on the world, and it's better to do it here than in real code.
This isn't about obfuscation, it's about just plain god awful code that does the job (in this case a version of 'cat'). A reminder of what we strive to
not unleash on people.
So make me cringe...show me your ugliness.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.