Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.
I came across something like this today, in some older code written by one of our more senior programmers that's still being used for live, production work:
Perl code:
@somearray = ( "this work has been updated", "updated",
               "this work hasn't been updated", "same",
               "this work is new", "new"
               # and so on
              );

$somearray_len = @somearray;
$counter = 0;

while ($counter < $somearray_len){
    my $var1 = $somearray[$counter];
    $counter++;
    my $var2 = $somearray[$counter];
    # do stuff
}
This was, by far, the sanest and most comprehensible part of the program.

Adbot
ADBOT LOVES YOU

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

pigdog posted:

Came for awesome perl horrors, left slightly disappointed. Sure he could have just gone for %somehash = @somearray and worked it from there, but hey, TMTOWTDI. Sane and comprehensible is a tall order for Perl programs in the first place.
He could also have just used a hash in the first place--he didn't use it for anything that wouldn't have been easier with a hash. Probably also worth noting that @somearray and $var1/$var2 are the actual variable names (there's also a $thing that recurs infrequently throughout the program).

Anyway, probably more impressive in the program were the ~200 regular expressions, all trying to match variations of the same relatively simple string. Stuff like:
Perl code:
@regexes = (
    "[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}",
    "[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}",
    "[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}",
    "[0-9]{1,2}\.[0-9]{1,2}",
    ## and so on for another 200-something lines
    );
foreach $r (@regexes){
    if input =~ m/$r/ {
        ...
    }
}
Slightly more complex than that, and probably complex enough that you'd want to use 2 or 3 regexes, just to make it easier.

But I may be being overly harsh on his code because the program doesn't really work at all, and the fact that it doesn't work creates probably an extra few day's worth of incredibly tedious work a month for a couple unlucky people (though not me, anymore).

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

quiggy posted:

Smart people use whitespace like this. Dumb people use whitespace like this.
I wish I could dump large bits of my company's codebase on here, because I could demonstrate quite clearly the ways in which dumb people use whitespace.

It doesn't really have anything to do with tabs vs spaces, though--at least where I work, it seems to be more "this script won't run, so I'll just add more braces at the end until it will" kind of stuff.

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

fritz posted:

ETA: queryTile is called in only one location, and checklist is always a 1-element list.

It's better than that:
Python code:
        checklist = ['Shrubland','Heathland','Marshland','Cacti Forest','Broadleaf Forest','Deciduous Forest','Mixed Forest', \
                     'Coniferous Forest','Evergreen Forest','Tropical Forest','Swamp','Desert','Cave','Beach','River','Highland', \
                     'Mountain','Plain','Tundra','Savannah','Glacier','River Bank','Pond','Ocean','Lake','Lakeshore']
...
        for check in checklist:
            vars()[check] = []
            for x in range(MAP_WIDTH):
                for y in range(MAP_HEIGHT):
                    if queryTile(x, y, [check]):
...
The elements in checklist are all of the conditions he's checking for in queryTile. So he's calling the function for every possible condition on every map square, and then checking again for every possible condition on that map square every time.

Extortionist fucked around with this message at 07:24 on Sep 24, 2013

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

Ender.uNF posted:

ClearCase.

So just shut up about git, ok? I'd kill for git.

RCS.

In the rare case we have to share code with corporate, we have the luxury of using ClearCase. All local stuff is in RCS--and even then, a lot of production-critical code hasn't ever even been checked in.

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.
Perl code:
close STDERR;
open STDERR, "> /dev/null";

open SQL, "| /informix/bin/dbaccess" 
    or die "Unable to open SQL handle: $!\n";

print SQL $sql;
The path to dbaccess was recently changed.

Not pictured: capturing STDOUT in a variable, then using regex matches to parse out the information that was queried from the database.

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.
We have an xml product that contains records of votes on certain pieces of legislation, breaking the totals out into Democrats/Republicans/etc. But Republicans was spelled "republicians", and we can't fix it now because it would break innumerable downstream workflows.

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

Edison was a dick posted:

Offer an alternative "version 2" feed that has the typo fixed and threaten to deprecate the old one.

If I worked in a place with anything approaching sensible practices I might consider it. This is actually a project our group had to rewrite from scratch to replace another group's product--the typo was theirs and we had to replicate it, the downstream teams wouldn't give a minute's effort to fixing anything.

But even if I did that a) no one would pay attention, the old one would be deprecated and the new one would still break everything, and b) no one would notice anything was broken until some day I'd just end up with a many-times-forwarded e-mail originating from an loc.gov address in my inbox asking why in the world this feature was broken and I'd have to go and change it back anyway.

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

Thermopyle posted:

Coding horror: web scraping

I've got maybe 20 hours over the past couple months into writing a scraper for a site just for fun and personal enlightenment.

Today the site unveiled a complete redesign after looking the same for 5 years.

:negative:
A huge part of my and my team's job is scraping a few thousand sites, with the expectation we turn the scraped data around (with a lot of additional work done on the parsed data) within a few hours of the site posting.

The business's requirements don't change when a site does.

So, yeah, I also feel your pain.

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.
I don't know if this counts, but a warning from ghostscript working on a pdf:

code:
**** File has circular references in resource dictionaries.

**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Adobe Acrobat Pro Extended 9.4.5 <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.

Adbot
ADBOT LOVES YOU

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

PhantomOfTheCopier posted:

PDf is a horror. Please use PostScript for printable document content, and HTML for on-screen content.

Believe me, I'd use just about anything else but we have zero control over the input. The goal of the whole project is turning these hideous pdf documents into structured machine-readable documents (like xml, except if it were an awful 40 year old proprietary format).

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply