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
chippy
Aug 16, 2006

OK I DON'T GET IT
Trying to untangle a customer's project with a view to taking it on, I just came across this delightful little nugget:

code:
catch(Exception exp)
            {
                this.lastName = exp.Message;
            }
(and no, lastName is not even printed out somewhere helpful, as if that would make it any better anyway)

p.s. the try block preceding this contained 230 lines of code.

chippy fucked around with this message at 15:46 on Aug 5, 2013

Adbot
ADBOT LOVES YOU

Sereri
Sep 30, 2008

awwwrigami

I love working on code some (probably 1st/2nd semester) CS students wrote:

php:
<?

function doTheThing($prim_id, $second_id = null){


    if($prim_id != null){

        $data = getDataViaPrimId($prim_id);

        // 50LoC doing stuff with $data

        return $data;
    }else{

        $data = getDataViaSecId($second_id);

        // exactly the same 50LoC doing stuff with $data

        return $data;
    }
}
?>

fritz
Jul 26, 2003

ReelBigLizard posted:

That is pretty much the entire document, which was a .docx.

The code is not lucid. I'd post some examples but it's under NDA, presumably to prevent merciless mocking on coding forums.

You can google that string and get a result.

Amarkov
Jun 21, 2010

chippy posted:

Trying to untangle a customer's project with a view to taking it on, I just came across this delightful little nugget:

code:
catch(Exception exp)
            {
                this.lastName = exp.Message;
            }
(and no, lastName is not even printed out somewhere helpful, as if that would make it any better anyway)

p.s. the try block preceding this contained 230 lines of code.

So the horror is that they named the Exception variable "exp" right :downs:

Pilsner
Nov 23, 2002

Amarkov posted:

So the horror is that they named the Exception variable "exp" right :downs:
Heh, I thought of that too. Other annoying variations are "exc". Or naming it when it's not even used is bad.

Amarkov
Jun 21, 2010

Pilsner posted:

Heh, I thought of that too. Other annoying variations are "exc". Or naming it when it's not even used is bad.

Can you catch exceptions anonymously in Java? I was under the impression that you can't. (But then again, lots of people are under the impression that you can't access private fields in other classes...)

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

Pilsner posted:

Heh, I thought of that too. Other annoying variations are "exc". Or naming it when it's not even used is bad.

All of my exception variable names are either "e", "ex", or an acronym for the exception like NullReferenceException becomes "nre". How else are you supposed to do it?

Pilsner
Nov 23, 2002

Amarkov posted:

Can you catch exceptions anonymously in Java? I was under the impression that you can't. (But then again, lots of people are under the impression that you can't access private fields in other classes...)
Oh, I don't know, but you can in .NET.


Factor Mystic posted:

All of my exception variable names are either "e", "ex", or an acronym for the exception like NullReferenceException becomes "nre". How else are you supposed to do it?
It's just a personal preference really, I always name them 'ex'.

Amarkov
Jun 21, 2010

Pilsner posted:

Oh, I don't know, but you can in .NET.

Well isn't dot NET fancy :mad:


fake e:

code:
private void finishRunningPls() {
    ...
}
Help dumb 4chan memes are in my code

xtal
Jan 9, 2011

by Fluffdaddy
I know a lot of memes but I'm still not catching that one. Explain it for us?

Amarkov
Jun 21, 2010

xtal posted:

I know a lot of memes but I'm still not catching that one. Explain it for us?

That's not some acronym at the end. That's "pls", as in "please" finish running, because the method doesn't guarantee that running actually will be finished at the end.

xtal
Jan 9, 2011

by Fluffdaddy

Amarkov posted:

That's not some acronym at the end. That's "pls", as in "please" finish running, because the method doesn't guarantee that running actually will be finished at the end.

That's actually what I thought, but I didn't get the meme connection. "pls" is a pretty ancient and common abbreviation. Probably was used in smoke signals at a point.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

xtal posted:

That's actually what I thought, but I didn't get the meme connection. "pls" is a pretty ancient and common abbreviation. Probably was used in smoke signals at a point.

Yeah, that's not a meme. At least not in the sense of "goddamn 4channers get off my lawn for inventing this poo poo".

Amarkov
Jun 21, 2010

Thermopyle posted:

Yeah, that's not a meme. At least not in the sense of "goddamn 4channers get off my lawn for inventing this poo poo".

Huh, really? I'd never heard it except from 4chan and redditors trying too hard to be 4chan.

nielsm
Jun 1, 2009



Amarkov posted:

Huh, really? I'd never heard it except from 4chan and redditors trying too hard to be 4chan.

I was writing "plz" and "thx" and poo poo like that in QuakeWorld Team Fortress games 15 years ago. Sorry.

Dren
Jan 5, 2001

Pillbug

nielsm posted:

I was writing "plz" and "thx" and poo poo like that in QuakeWorld Team Fortress games 15 years ago. Sorry.

Rock, no opengl plz!!!!!

EntranceJew
Nov 5, 2009

Somehow, the following code pattern was so great that my entire team implemented it into their home-rolled framework. Heavy anonymization on my part that might not make the intent of the original code clear.

PHP code:
$args = new Args();
$args->setArg('action', 'put_hotdog_on_plate');
$args->setArg('temperature', '98');
$args->setArg('condiment_mustard', 'YES');

$hot = new HotDogMeal($args);
$err = $hot->getIssues();
$res = $hot->getRes();
Code that could be as simple as:
PHP code:
$hot_dog_meal = new HotDogMeal(98,true);
$results = $hot_dog_meal->putOnPlate();
The reason for this? HotDogMeal extends a common function class that does a switch case against the action after validating (checking that arguments are defined) all of its 'args', it calls a function with a name similar to its action by reference and sets HotDogMeal's 'res'. The fun part is that the internal methods of a function refuse to pass data to one-another so I have to investigate properties that exist either within the current class (never formally [re]declared) or within the parent chain. We go the route that distrusts PHP's ability to perform a basic programming task like pass an argument so that reading code now requires me to read through every ancestor of the class chain (of which there are many) to even figure out what "function" a basic "object" is trying to do. My IDE is convinced that only slim portions of the codebase will run, I fear that it might be right.

It goes deeper, it keeps going and going and just when you think you're done, it goes some more. I was going to trace the whole thing through, but as I anonymized HotDogMeal I slowly became more and more depressed. I hope this serves as some framing device for the "ingenuity" I have to deal with daily.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I love how PHP's only data structure is basically the ideal one to use for passing arbitrary arguments to a function, but someone said "haha gently caress that!"

UxP
Aug 27, 2007

EntranceJew posted:

Somehow, the following code pattern was so great that my entire team implemented it into their home-rolled framework. Heavy anonymization on my part that might not make the intent of the original code clear.

PHP code:
$args = new Args();
$args->setArg('action', 'put_hotdog_on_plate');
$args->setArg('temperature', '98');
$args->setArg('condiment_mustard', 'YES');

$hot = new HotDogMeal($args);
$err = $hot->getIssues();
$res = $hot->getRes();
Code that could be as simple as:
PHP code:
$hot_dog_meal = new HotDogMeal(98,true);
$results = $hot_dog_meal->putOnPlate();


My co-worker wrote basically the same thing last week in Ruby, just more complicated for absolutely no reason, for a component he was gemifying.

Ruby code:
Verification.configure do |setup|
  setup.arg :foo
  setup.arg :bar
end

Verification.configure do |config|
  config.foo 'buttes'
  config.bar 'dongz'
end
Verification.configure basically just yielded an object that `define_method`ed getters and setters for the symbol passed in the "setup" pass, which then required a second pass to then set the loving variable.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
That's a very common pattern for config files in ruby.

xtal
Jan 9, 2011

by Fluffdaddy
DSLs like that are a big part of Ruby. The only horror there is that they used a yielded object instead of instance_eval, because it could be made into the (much prettier) below, a la Sinatra and a large portion of Rails.

Ruby code:
Verification.configure do
  foo 'buttes'
  bar 'dongz'
end

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
I don't have access to the code anymore, but this is a favorite story around the office:

I work at a small custom software company that mainly deals with .NET. A while back we got a call from a medical records company in a mad frenzy about a particular issue they were having. This company had a public facing API that was used by their clients to request information about patients. However, occasionally the API would send back records for the wrong person. This is bad juju for medical records considering it's a huge HIPAA violation, so this company is desperate to fix it. The original programmer of the API left the company and anyone they tried to hire to replace him quickly left, so they eventually gave up trying. When they discovered this problem they decided to contact professional devs to fix it rather than attempt to get someone in-house again. We'd find out soon why they weren't able to keep anyone around. They sent us the source code and we started to poke around.

We open the solution and find VB.NET, only one class, 70+ methods, with a file over 15000 lines long. That equates to about 200 lines per method. However, many of the methods were only a few lines long and just delegating to other methods, so it was really only about 10 methods that were contributing to the bulk of those 15000 lines. The worst offender was the method:

code:
Public Sub _w()
1     ....
.     ....
.     ....
~2500 ....
End Sub
That's right, a method called _w that took no parameters and was over 2500 lines long. Other useful method names were "_q", "get", and "shelfs"[sic]. Oh, and did I mention there were no empty lines? No vertical spacing. Just a giant wall of VB.NET. We promptly called the company back and said this would probably take a couple days and would cost $300/hr. They were surprisingly happy with that since no one else they contacted would even take the job.

The problem was passed on to one of our junior developers, because good loving luck getting one of the senior guys to do it. He combed through the code but wasn't able to find the issue, so he called another junior dev over. They comb through the code together, but are still unable to find anything at then end of a full day. The next morning, a senior dev joins the two juniors and soon after another comes by. By lunch, 4 people are crowded around the computer alternately laughing and crying at the poo poo-tacular spectacle of horrible coding. The end of day 2 is drawing near when someone finally noticed it.

code:
Public Shared _wr As XmlWriter
While scrolling between the _w and _q methods, one sharp eye spotted that line nestled between the two. It was used only once, somewhere around line 1700 in _w. No one had caught it before then because no one was very well versed in VB (anyone who was had already jumped off a bridge). For those who are lucky enough not to know VB, "Shared" is the equivalent of "static" in OOP languages. So, every single call to their API was returning XML generated by a single XmlWriter. All it took was two requests sent at the same time, and one person would see the other persons results.

At the end of it all the fix was a 6 character change - remove the "Shared" keyword. We sent the source code back, billed around $10k, and walked away with a new hatred for both VB and the people who used to use it.

Bognar fucked around with this message at 02:03 on Aug 7, 2013

Harik
Sep 9, 2001

From the hard streets of Moscow
First dog to touch the stars


Plaster Town Cop
Another fun one from the world of embedded programming. Not so much a coding horror as an API Horror.

code:
extern void do_something(unsigned char * buf, int len);

// implementation may look something like this.

void do_something(unsigned char * buf, int len) {
	struct foo_t foo = (struct foo_t *)(buf-sizeof(*foo));
	struct bar_t bar = (struct bar_t *)(buf+len);

	// do poo poo to foo and bar, trampling all over my memory
}
It's binary only, and the doxygen docs don't bother to mention this niggling little detail about the API. I know why they did it, because embedded programming can't just randomly copy buffers and they needed room for their headers. It's just that there's a few dozen much clearer ways to do this that don't involve backing up from pointers that aren't handed out by your own library. At least demand a pointer to a structure with a data member offset and not a raw char buf that you bracket.

This oddity is documented, but in a pdf guide. And it's not coupled with a giant blinking neon warning that something very unconventional is going on here, which should be mandatory.

Harik fucked around with this message at 02:48 on Aug 7, 2013

bucketmouse
Aug 16, 2004

we con-trol the ho-ri-zon-tal
we con-trol the verrr-ti-cal

Harik posted:

Another fun one from the world of embedded programming. Not so much a coding horror as an API Horror.

I've written horrible arcane castings before but this makes my head hurt. Embedded systems are scary.

nielsm
Jun 1, 2009



jQuery is the HIV causing horrible-code-AIDS to spring up everywhere.
Through uncontrolled growth we now have just short of a hundred globally registered onClick handlers in our application page, most of which aren't relevant most of the time. I believe it even grows every time a new page is dynamically loaded, and it's absolutely killing performance.
Don't blindly use the $(document).on('click', '.my [horrible=selector]', function(evt){...}) pattern, you will regret it.

Sticky Profits
Aug 12, 2011
The horror with jQuery (and to a lesser extent Javascript in general) is that because it's obviously just about swishy easing, designers feel like it's their remit. Also people are awful at Javascript.

Zombywuf
Mar 29, 2008

Currently working on some multithreaded code that crashes when I remove a debug print.

nielsm
Jun 1, 2009



Zombywuf posted:

Currently working on some multithreaded code that crashes when I remove a debug print.

Whatever you use for printing might very well have some kind of synchronisation to avoid multiple prints stepping over each other. Causing your threads to sort-of synchronise at your printing points.

Opinion Haver
Apr 9, 2007

Zombywuf posted:

Currently working on some multithreaded code that crashes when I remove a debug print.

Your code or someone else's?

Zombywuf
Mar 29, 2008

yaoi prophet posted:

Your code or someone else's?

Lets just go with "shared responsibility".

tef
May 30, 2004

-> some l-system crap ->

Zombywuf posted:

Lets just go with "shared responsibility".

Translation: It didn't crash before (but there was a bug), but I changed something now, and it's broken more.

This is how I imagine Zombywuf is on looking at my code:

Dren
Jan 5, 2001

Pillbug

Zombywuf posted:

Currently working on some multithreaded code that crashes when I remove a debug print.

You mean you get to play with gdb all day? So jealous.

qntm
Jun 17, 2009

tef posted:

Translation: It didn't crash before (but there was a bug), but I changed something now, and it's broken more.

This is how I imagine Zombywuf is on looking at my code:



Ah, yak-shaving.gif

Zombywuf
Mar 29, 2008

tef posted:

Translation: It didn't crash before (but there was a bug), but I changed something now, and it's broken more.

Nah, I've made it's behaviour more consistent. Before it only crashed sometimes, I made it crash all the time.

quote:



If anything it feels more like this

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.
So this is more silly than horror but:

public static void ಠ_ಠ(string error)
{
throw new Exception(error);
}

public static void CreateFile(string path)
{
if(File.Exists(path))
{
ಠ_ಠ("error: file exists")
}

File.Create(path)
}

Somebody's having too much fun. Works fine in C#, and php, phython and others seem to support unicode in code. Ruby does not, it looks like.

(drat, code tags remove unicode! Sorry for lovely formatting)

Zaphod42 fucked around with this message at 22:36 on Aug 9, 2013

1337JiveTurkey
Feb 17, 2005

var ┻━┻ = new WhateverException()
(╯°□°)╯︵ ┻━┻

b0lt
Apr 29, 2005

Zaphod42 posted:

So this is more silly than horror but:

public static void ಠ_ಠ(string error)
{
throw new Exception(error);
}

public static void CreateFile(string path)
{
if(File.Exists(path))
{
ಠ_ಠ("error: file exists")
}

File.Create(path)
}

Somebody's having too much fun. Works fine in C#, and php, phython and others seem to support unicode in code. Ruby does not, it looks like.

(drat, code tags remove unicode! Sorry for lovely formatting)

Right to left override mark isn't a legal character. :(

raminasi
Jan 25, 2005

a last drink with no ice
C++ code:
else {
    // TODO: Throw an exception or something.
    return result_t();
}
:rolleye:
The worst "other developer" is yourself a year ago.

Amarkov
Jun 21, 2010
code:
startup : function() {
    this._handleMatrixRows()
    this._handleMatrixColumns()
    this._handleMatrix()
}

_handleMatrixRows: function() {
    ...
    this._handleMatrix()
    this._handleMatrixColumns()
}

_handleMatrixColumns: function() {
    ....
    this._handleMatrixRows()
    this._handleMatrix()
}
Why :negative:

Adbot
ADBOT LOVES YOU

Opinion Haver
Apr 9, 2007

Haskell has Unicode variable names and custom operators:

Prelude> let ಠ_ಠ = error
Prelude> let a ^-^ b = a ++ " is more anime than " ++ b
Prelude> let a ^-^ b = a ++ " is a better anime than " ++ b
Prelude> ಠ_ಠ $ "evangelion" ^-^ "haruhi"
*** Exception: evangelion is a better anime than haruhi

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