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
Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The names suggest that it's a public method which calls a method on a private member, so unless you're horribly opposed to encapsulation there's nothing wrong with the function existing.

Adbot
ADBOT LOVES YOU

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

tef posted:

yes newline

Man I'm dumb. I'll file that away. It'll come in useful one day.

king_kilr
May 25, 2007
Hey guys, we're on reddit: http://www.reddit.com/r/programming/comments/a4f97/coding_horrors_code_that_makes_you_laugh_or_cry/

ton1c
Apr 30, 2005
You know it's funny, a good number of people reading this thread and that reddit thread would probably be guilty of a number of things in this thread. Programming should be more like music, where you compete against yourself rather than bash those who suck, but then nothing would get done.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

ton1c posted:

You know it's funny, a good number of people reading this thread and that reddit thread would probably be guilty of a number of things in this thread. Programming should be more like music, where you compete against yourself rather than bash those who suck, but then nothing would get done.

I don't understand. There are musical pieces that everyone, even those who don't know a thing about musical theory, can agree are loving terrible.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

ton1c posted:

You know it's funny, a good number of people reading this thread and that reddit thread would probably be guilty of a number of things in this thread. Programming should be more like music, where you compete against yourself rather than bash those who suck, but then nothing would get done.

And nobody should ever listen to each others music, we'll all just whittle our own instruments and play holed up in our rooms and never speak of it again. Most importantly, we'll never critique one another's music. This will guarantee all but one of us are stuck at the beginner level, and we'll all be happy.

tef
May 30, 2004

-> some l-system crap ->

ton1c posted:

You know it's funny, a good number of people reading this thread and that reddit thread would probably be guilty of a number of things in this thread.

I'm pretty sure some of the posts have been people outing some of the horrible code they've written. It's rather cathartic.

quote:

Programming should be more like music, where you compete against yourself rather than bash those who suck, but then nothing would get done.

Hackers and Composers eh? I'm not sure you can attribute the desire to code to a competitive element alone, nor any progress to such a poor motive.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Factor Mystic posted:

It's indicative of 1:1 mental modelling to code, and shows that to him the code only makes sense if it explicit returns "true" somewhere and "false" somewhere else. There's no jump to the higher order of thinking where the return value of the call can be returned, or once you've achieved that, possibly scrapping the helper function altogether because you realize the inner call does everything you need.

Another possible explanation is that at some point, the code actually did more work itself. Later, the manual code was replaced with a call to the other method, and the rest was left alone.

poopgiggle
Feb 7, 2006

it isn't easy being a cross dominate shooter.


tef posted:

I'm pretty sure some of the posts have been people outing some of the horrible code they've written. It's rather cathartic.

Hi, my name is poopgiggle and I have written horrible code. (*Hi poopgiggle!*)

When writing quick text-munging Perl scripts for work I have been known to wrap error-prone code in "eval" blocks rather than fixing boundary conditions in order to get something to work quickly.

I have left code entirely undocumented except for one comment at the top, reading "documentation left as an exercise to the reader."

I have authored regular expressions which were about 4" wide on the screen.

There's probably more.

king_kilr
May 25, 2007

poopgiggle posted:

I have authored regular expressions which were about 4" wide on the screen.

http://github.com/brosner/everyblock_code/blob/master/ebdata/ebdata/nlp/addresses.py

I hope this makes you feel tiny.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

While we're at it:

quote:

Mail::RFC822::Address: regexp-based address validation

Mail::RFC822::Address is a Perl module to validate email addresses according to the RFC 822 grammar. It provides the same functionality as RFC::RFC822::Address, but uses Perl regular expressions rather that the Parse::RecDescent parser. This means that the module is much faster to load as it does not need to compile the grammar on startup.

Download Mail::RFC822::Address-0.4.tar.gz or read the documentation.

The grammar described in RFC 822 is suprisingly complex. Implementing validation with regular expressions somewhat pushes the limits of what it is sensible to do with regular expressions, although Perl copes well:

code:
(?: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?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[
 \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*
)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)
*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+
|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r
\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:
\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t
]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031
]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](
?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?
:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?
:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?
:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?
[ \t]))*"(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?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\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[
\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t
])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t
])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?
:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|
\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:
[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\
]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)
?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["
()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)
?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>
@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[
 \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,
;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t]
)*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\
".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?
(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".
\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:
\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[
"()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])
*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])
+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\
.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(
?:\r\n)?[ \t])*))*)?;\s*)

Pardot
Jul 25, 2001




Janin posted:

Mail-RFC822-Address

If you break it down part by part and combine the regexes, it's not so bad. Datamapper does a good job of that, see: http://github.com/datamapper/dm-more/blob/master/dm-validations/lib/dm-validations/formats/email.rb

king_kilr
May 25, 2007

Janin posted:

While we're at it:

As I recall this doesn't actually perfectly parse emails, RFC822 allows infintely nested comments, this just allows REALLY nested comments. regex aren't powerful enough to parse 822.

newsomnuke
Feb 25, 2007

My most infamous moment of retarded coding was when I was trying to figure out an algorithm for automatically placing wall pieces around a set of rooms in a game. There were a total of 256 different combinations of wall pieces that were needed to cover all possibilities.

I thought for ages over the algorithm, but just couldn't make any headway, it really was just too tricky. So I gave up, and started writing a switch statement to manually handle all 256 cases. I knew it was terrible, but I just couldn't figure out how to do it algorithmically. I got to about case 80 before realising that if I changed my data structures a bit, I could write the algorithm in about 5 lines.

Zombywuf
Mar 29, 2008

poopgiggle posted:

I have authored regular expressions which were about 4" wide on the screen.
I once wrote one 4 screens wide:
code:
<flight>\s*<[^>]+>\s*(?:sun|mon|tue|wed|thu|fri|sat)\s*(\d+)\s*(\w{3})\s*(\d{4})\s*-\s*(?:sun|mon|tue|wed|thu|fri|sat)\s*(\d+)\s*(\w{3})\s*(\d{4}).*?outradio=([^&]+)&.*?</a>([^<]+)<b>\s*total\s+\((\w+)\)[^<]+</b>[^<]*<b>[^<]*</b>\s*\w{3}\s*\1\s*\2\s*\3\d{4}-\d{4}([a-z]+\d+)([^<]+)<b>[^<]+</b>\s*<b>[^<]+</b>\s*\w{3}\s*\4\s*\5\s*\6\d{4}-\d{4}([a-z]+\d+)([^<]+)<b>[^>]+</b></flight>

tef
May 30, 2004

-> some l-system crap ->

Zombywuf posted:

I once wrote one 4 screens wide:

As someone else who was paid to write a series of regular expressions to translate html into well formed xml I would like to say :smithicide:

Opinion Haver
Apr 9, 2007

Janin posted:

While we're at it:

I think my favorite parts are lookaheads nested inside lookaheads inside other lookaheads.

xarph
Jun 18, 2001


nbv4 posted:

I think someone doesn't know what "release candidate" means...

The inflation of software release milestones: http://technet.microsoft.com/en-us/magazine/2008.03.windowsconfidential.aspx?pr=blog

Captain Capacitor
Jan 21, 2008

The code you say?

yaoi prophet posted:

I think my favorite parts are lookaheads nested inside lookaheads inside other lookaheads.

If there's ever been a 'Yo Dawg' of Regexes, it would be this one.

This is from an assignment I had to write for my compilers class. I had reached a point of frustration with JavaCC and submitted this chunk of code amongst my actual answers:

code:
TOKEN :
{
  < RAGE : ( <F> )+ ( <U> )+ >
  | < #F: "F" >
  | < #U: "u" | "U" >
}

Amish Ninja
Jul 2, 2006

It's called survival of the fittest. If you can't slam with the best, jam with the rest.
Where I work, there's a bunch of php legacy code that's just so fuckin' bad. It's worse than the worst stuff I ever wrote while in school learning the basics of programming. It's as if the programmer went out of his way to break the DRY rule at every possible turn, while having includes that made no sense and did no favors in terms of code readability. I'm going to be rewriting some of it before the end of the year, and I can't wait, because maintenance of the old crap is horrible and makes me want to hurt people.

I'll post some true eyesores a bit later.

Vanadium
Jan 8, 2005

code:
dcopid=$1

euro=0;
cent=0;
for line in `dcop $dcopid KommanderIf text snack_scanfield|sed -e :0 -e s/".("/"("/ -e t0 -e s/"("// -e s/")"//`; do
if [ "x$(echo $line|cut -d- -f1)" == "x" ]; then
multiplier="-"
else
multiplier="+"
fi
euro=$(($euro $multiplier `echo $line|cut -d\. -f1|sed -e s/"-"//`))
cent=$((`echo $line|cut -d\. -f2|sed -e s/"^[0]*"//` $multiplier $cent))
done
echo $cent;
while [ $cent -ge 100 ]; do
euro=$(($euro+1))
cent=$(($cent-100))
done
while [ $cent -le -100 ]; do
euro=$(($euro-1))
cent=$(($cent+100))
done
if [ $cent -lt 0 ] && [ $euro -ge 0 ]; then
euro=$(echo -$euro)
cent=$(echo $cent|sed -e s/"-"//)
fi

if [ $cent -gt 0 ] && [ $euro -lt 0 ]; then
euro=$(($euro + 1))
cent=$((100 - $cent))
fi

dcop $dcopid KommanderIf setText snack_bookingprice "$euro.`printf %02d $cent`"
unix programming is the best programming :allears:

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


Vanadium posted:

unix programming is the best programming :allears:

I could post some shell scripts that would make your eyes bleed. No one I work with understands sourcing or how to pass arguments so there's a lot of duplicated information which leads to lots of inconsistencies as well as directories filled with things like:

code:
shutdown-admin.sh
shutdown-all-fast.sh
shutdown-all-slow.sh
shutdown-app1.sh
shutdown-app2.sh
shutdown-app3.sh
shutdown-app4.sh
shutdown-app5.sh
shutdown-app6.sh
shutdown-app7.sh
shutdown-app8.sh
shutdown-clust1.sh
shutdown-clust2.sh
shutdown-clust3.sh
shutdown-clust4.sh
shutdown-clust5.sh
shutdown-graceful-all.sh
shutdown-graceful-app1.sh
shutdown-graceful-app2.sh
shutdown-graceful-app3.sh
shutdown-graceful-app4.sh
shutdown-graceful-app5.sh
shutdown-graceful-app6.sh
shutdown-graceful-app7.sh
shutdown-graceful-app8.sh
shutdown-graceful-clust1.sh
shutdown-graceful-clust2.sh
shutdown-graceful-clust3.sh
shutdown-graceful-clust4.sh
shutdown-graceful-clust5.sh

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Does this:
php:
<?
if(is_numeric($extid))
   $sql .= "us_extid=$extid";
else
   $sql .= "us_extid='".$extid."'";
?>
count? No? How about when the us_extid column is always a varchar column? Still no? How about when PHP sees a value of '0######'* in $extid and flips a loving coin to decide whether its a number or not? It's probably also because our poo poo pile software treats that variable as either a number or a string depending on how the original programmer was feeling the second he happened to be writing any one of the 200 preceding lines in this function, so maybe it's not 100% PHP's fault, but PHP's inconsistent type guessing is the enabler here. gently caress, I had the most frustrating morning.

*that's a 6-digit number with a leading zero, fyi

Sprawl
Nov 21, 2005


I'm a huge retarded sperglord who can't spell, but Starfleet Dental would still take me and I love them for it!

Munkeymon posted:

Does this:
php:
<?
if(is_numeric($extid))
   $sql .= "us_extid=$extid";
else
   $sql .= "us_extid='".$extid."'";
?>
count? No? How about when the us_extid column is always a varchar column? Still no? How about when PHP sees a value of '0######'* in $extid and flips a loving coin to decide whether its a number or not? It's probably also because our poo poo pile software treats that variable as either a number or a string depending on how the original programmer was feeling the second he happened to be writing any one of the 200 preceding lines in this function, so maybe it's not 100% PHP's fault, but PHP's inconsistent type guessing is the enabler here. gently caress, I had the most frustrating morning.

*that's a 6-digit number with a leading zero, fyi


Can't you typer your variable before you put stuff into it?

And 1 quick google found this.

quote:

Comparing a non-numeric string to the integer 0 by using == will return true, since the string will be casted to integer - which will be zero. If your string starts with a number, it will be castet to an integer with the number as value.

To avoid the described behavior, you should use === instead of ==.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Sprawl posted:

Can't you typer your variable before you put stuff into it?

And 1 quick google found this.

Strict typing would require about a week of work for rewriting and testing while this had to be done today. Also, I don't see how the behavior of == makes any difference to is_numeric, which quite clearly changed its behavior when acting on the same data as I tapped F5 a few times earlier today.

wrok
Mar 24, 2006

by angerbotSD
Defined in a base class
code:
protected const char SPACE = ' ';
Child class :saddowns:

code:
private string blank1 = new string(SPACE, 4); //char 4-7
private string blank2 = new string(SPACE, 2); //char 55-56
private string blank3 = new string(SPACE, 1); //char 57
private string blank4 = new string(SPACE, 18); //char 63-80

later...

public override string GenerateThisThing()
{
    StringBuilder sb = new StringBuilder();
    sb.Append(someString);
    sb.Append(blank1);
    sb.Append(sumString);
    sb.Append(someString);
    sb.Append(sunNumber.ToString());
    sb.Append(someString);
    sb.Append(someString);
    sb.Append(someCode);
    sb.Append(someDate.Date.ToString());
    sb.Append(blank2);
    sb.Append(blank3);
    sb.Append(someNumber.ToString());
    sb.Append(blank4);
    return sb.ToString();
}
:psyduck:

Just-In-Timeberlake
Aug 18, 2003
Not really code but my coworker told me that some of our customers want their automated reports emailed to multiple recipients and that he was just going to add some more email field columns to the customer table.

I looked him square in the eye and said "you know drat well the right thing to do is create a new table linked to the customer table". He sighed and said "yeah, was trying to avoid that".

He's actually a very good database guy, just lazy sometimes.

Sprawl
Nov 21, 2005


I'm a huge retarded sperglord who can't spell, but Starfleet Dental would still take me and I love them for it!

golgo13sf posted:

Not really code but my coworker told me that some of our customers want their automated reports emailed to multiple recipients and that he was just going to add some more email field columns to the customer table.

I looked him square in the eye and said "you know drat well the right thing to do is create a new table linked to the customer table". He sighed and said "yeah, was trying to avoid that".

He's actually a very good database guy, just lazy sometimes.

Make a Text blob and use , to separate them since that's how you would multi-mail it anyways.

Zhentar
Sep 28, 2003

Brilliant Master Genius

golgo13sf posted:

He's actually a very good database guy, just lazy sometimes.

Who isn't? That's what you have code review for.

Zombywuf
Mar 29, 2008

Sprawl posted:

Make a Text blob and use , to separate them since that's how you would multi-mail it anyways.

Not forwards compatible with Wave.

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock
I just spent an hour or so helping a friend with tracking down a bug after he migrated some PHP scripts to a new server. The culprit?

Let me just quote http://www.php.net/manual/en/function.gd-info.php:

quote:

Previous to PHP 5.3.0, the JPEG Support attribute was named JPG Support.

Stay classy, PHP team.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Out of curiosity, Broken Knees Club, did you ever find out what makes GCC die without this define in your codebase?

Broken Knees Club posted:

So while messing around in an old codebase I stumbled on this:
code:
#define HEREBEDRAGONS //do not comment out!!! crashes gcc
I could not find a single reference to the flag. GCC did, in fact, crash if you commented it out. How does that even work? :psyduck:

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

Ledneh posted:

Out of curiosity, Broken Knees Club, did you ever find out what makes GCC die without this define in your codebase?

That's so weird that I'm not sure normal logic can be applied to it, but wouldn't it make sense to diff the preprocessor output with and without that #define statement to see what changes? If you can't find the flag itself, I doubt that would help, but it seems like it could be worth a try.

ZorbaTHut
May 5, 2005

wake me when the world is saved

ultra-inquisitor posted:

My most infamous moment of retarded coding was when I was trying to figure out an algorithm for automatically placing wall pieces around a set of rooms in a game. There were a total of 256 different combinations of wall pieces that were needed to cover all possibilities.

I thought for ages over the algorithm, but just couldn't make any headway, it really was just too tricky. So I gave up, and started writing a switch statement to manually handle all 256 cases. I knew it was terrible, but I just couldn't figure out how to do it algorithmically. I got to about case 80 before realising that if I changed my data structures a bit, I could write the algorithm in about 5 lines.

I was writing minimap code a while back for a randomly generated level. The level fragments consisted of a bunch of tiles, any of which could be rotated 90 degrees to slot into the game itself. To save on memory I'd done a bunch of heuristics to combine "similar" tiles in the minimap-fragment texture, so a 2x2 round room would end up represented by a single 90-degree arc which was then pointed to four times, with optional rotation flags.

Wait, did I say "rotation"? My mistake. For the sake of rendering speed it was actually represented as a series of three flips, horizontal/vertical/diagonal. Some segments of the codebase did these in a different order, and none of us could ever remember which order we were "supposed" to be using.

So: take HVD flips, then try to algorithmically generate a 90 degree clockwise rotation.

Solution: build a tiny interface to allow me to just jam rotations into the game engine and see what it looked like, then sit in front of the console for three minutes with a scrap of paper, bruteforcing the rotation matrix by hand.

End result:

code:
const int rotations[8] = {4, 2, 1, 7, 0, 5, 3, 6}; // generated by hand, touch and die, even I don't know whether this is HVD or DHV
(numbers made up, I don't have access to the originals anymore)

Zombywuf
Mar 29, 2008

Not a horor, a response to a horror from a co-workers blog that I found amusing:

quote:

Digression: Adverts are the bane of my life. If you want to include banner ads on your site, an ad network will typically give you a piece of JavaScript to insert on your page wherever you want the ad to appear. This JavaScript will typically be some of the most hideously tortuous code you have ever seen. It will reveal a positively Lovecraftian chain of document.write() calls, eval() statements, and nonsensical browser hacks that eventually result in a 2MB Flash file being pulled over a 28.8kbps network connection from somewhere in Kazakhstan. Advert code is the closest thing modern science has to the Berryman Logical Imaging Technique. I hear that the CIA used to teach terrorist suspects JavaScript just so they could expose them to advert code, and break their wills.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:
New release of my favourite software!

Required changes to existing files:

-Insert this code (in multiple places):
php:
<?
$text = str_replace('à','//acute//',$text);
$text = preg_replace('{[ \s]+}', ' ', $text);
$text = str_replace('//acute//','à',$text);
?>
*Note. "à" is not an acute-accented "a". Not that it would matter.

-Edit existing code, to replace with this:
php:
<?
$str = preg_replace("/(<br>|<BR>|<br \/>|<BR
\/>|&amp;lt;br&amp;gt;|&amp;lt;BR&amp;gt;|&amp;lt;br \/&amp;gt;|&amp;lt;BR
\/&amp;gt;)/"," //br// ",$str)." ";
?>
:wtc:

anonumos
Jul 14, 2005

Fuck it.

Surge Strip posted:

So many things wrong. He even got an error that Uppercase was already defined, and so he misspelled it.

We got a lot of this. I'm a tester for a company making truss design software. A few years ago they outsourced the creation of an automated testing suite, along with some of their actual programming hours.

The inevitable result was a 50 person team of Indian programmers triple spacing their code, misspelling common words as variables and a lot of scoped variable, function, object, class, and method re-declarations. It's not difficult to find examples of a window declaration in our testing suite's coding language, mirrored by another declaration with a single letter missing or some other retardation:

  • LayoutSettings and LyoutSettings
  • string sUserNme or string sUsrnme
  • etc.

They also completely ignored any error/exception trapping, even though there is a convenient do/except (essentially a try/catch) functionality built into the testing suite language. Instead of trapping exceptions they used a universal error code system consisting of an integer variable "iStatus" that could be 0, 1, 2, or 3. These error codes were made into constants called AEP_ERROR, AEP_FAILURE, AEP_SUCCESS, and something else I can't really bring myself to remember now.

Every single function or method was typed int and would return one of the constants depending on the success of the function. So they would call a function, assign its return value to iStatus and immediately test the value of iStatus after the function call.

code:
	[ ] iStatus = ProBase_LumberEditor.MSelectLumberInvItem( sLumberInvDel ) 
	[-] if ( iStatus == AEP_ERROR )
		[ ] LogError("Could not select '{sLumberInvDel}' in the Lumber Editor grid.")
		[ ] return AEP_ERROR
The funny thing is they did use the do/excepts, but the code shows no attempt to make use of the exception class, relying completely on the error code constants.

Here's one of their functions:
code:
[-] INTEGER fncCopyLumberInvItems( STRING sCopyName )  
	[ ] 
	[ ] 
	[-] do
		[ ] 
		[ ] 
		[ ] ProBase_LumberEditor.SetActive()
		[ ] 
		[ ] 
		[ ] ProBase_LumberEditor.pbtCopyAs.Click()
		[ ] 
		[ ] 
		[ ] ProBase_LumberEditorCopyAs.txtEnterNewLumberInvName.SetText( sCopyName )   
		[ ] 
		[ ] 
		[ ] ProBase_LumberEditorCopyAs.pbtOK.Click()
		[ ] 
		[ ] 
		[ ] ProBase_LumberEditor.pbtOK.Click()
		[ ] 
		[ ] 
	[ ] 
	[ ] 
	[-] except
		[ ] 
		[ ] 
		[ ] fncLogMsg ( "Error",  
    		    "Error in Copying the Lumber Inv Items" )
		[ ] 
		[ ] 
		[ ] return (AEP_ERROR)
		[ ] 
	[ ] 
	[ ] 
	[ ] return (AEP_SUCCESS)
	[ ] 
I'm no crack programmer. I took just enough semesters to qualify for a Comp. Sci. secondary concentration at a liberal arts school. But I have come close to meltdown with the stuff that assaults my coding sensibilities.

And that's after I grew resigned to spending 5 minutes of cleanup each time I crack open a testcase to troubleshoot. We've practically halved the lines of code in the last year, just by removing duplicate functions and the extra spaces. We haven't even been able to estimate the manhours to strip out the iStatus error codes and replace it with real raises and exception objects.

jandrese
Apr 3, 2007

by Tiny Fistpump
Every time I see a regex horror I have to remind myself that few people know about the /x flag for Regexes. If you're doing anything even mildly complicated with regexes, you're perpetuating a horror unless you use the /x flag and spread it out across a few lines, possibly with some comments in the particularly "clever" sections.

Zombywuf's horror a few posts back could have been:

code:
qw{
  <flight> \s*
  <[^>]+> \s*
  (?:sun|mon|tue|wed|thu|fri|sat) \s* (\d+) \s (\w{3}) \s* (\d{4})
  \s* - \s*
  (?:sun|mon|tue|wed|thu|fri|sat) \s* (\d+) \s* (\w{3}) \s* (\d{4})
  .*?
  outradio=([^&]+)&
  .*?
  </a> 
  ([^<]+) <b>\s* total \s+ \((\w+)\) [^<]+ </b>
  [^<]* <b> [^<]* </b> \s*
  \w{3}\s*\1\s*\2\s*\3\d{4} - \d{4}
  ([a-z]+\d+)
  ([^<]+)<b>[^<]+</b> \s* 
  <b>[^<]+</b> \s*
  \w{3}\s*\4\s*\5\s*\6\d{4} - \d{4}
  ([a-z]+ \d+ )
  ([^<]+)<b>[^>]+</b>
  </flight>
}x
You can even toss in a few comments explaining exactly what each particularly difficult line is matching like
code:
(?:sun|mon|tue|wed|thu|fri|sat) \s* (\d+) \s (\w{3}) \s* (\d{4}) # match the date in 'dayweek day month year' form
When whatever screen this is scraped off of changes, you can go back and quickly find the part that changes and fix it. The syntax still looks nightmarish, but that's pretty much unavoidable when you're hitting regexes hard, and despite that it's not as hard to read as it looks at first anyway, given that you're really only using a handful of different expressions over and over again.

jandrese fucked around with this message at 19:43 on Nov 26, 2009

Zombywuf
Mar 29, 2008

jandrese posted:

Zombywuf's horror a few posts back could have been:
You're making some assumptions about the software that regex was fed to that are incorrect.

Number one is that the application was not written in vb6.

Adbot
ADBOT LOVES YOU

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
From the helpful comments department:

code:
#include <assert.h>                                       // assert
#include <map>                                            // multimap container
#include <string>                                         // string class
#include <iostream>                                       // C++ I/O
edit: Wow, I've never seen this one before. Right-aligned asserts with left-aligned code!

code:
void action() {
	                                                assert( !thing.empty() );
	                      assert( (*thing.begin()).first == thinger->now() );
	Foo f = (*thing.begin()).second;
	// everything else is left-aligned
}

pokeyman fucked around with this message at 00:25 on Nov 27, 2009

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