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
Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Yeah, I thought you were using setcontext/getcontext, or longjmp, not inline assembly mangling %rsp.

Adbot
ADBOT LOVES YOU

Macichne Leainig
Jul 26, 2012

by VG
This isn't a direct code horror, but a source control one.

The TFS build agent has locked files for check-out. So I can't check anything in, because I can't merge changes with whatever the gently caress the build agent is doing.

Someone gets paid to manage this TFS server, and they've mysteriously disappeared from their desk.

pseudorandom name
May 6, 2007

Suspicious Dish posted:

Yeah, I thought you were using setcontext/getcontext, or longjmp, not inline assembly mangling %rsp.

To be fair, the ucontext functions don't work with backtrace either. sigaltstack probably breaks it, too.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Tha Chodesweller posted:

This isn't a direct code horror, but a source control one.

The TFS build agent has locked files for check-out. So I can't check anything in, because I can't merge changes with whatever the gently caress the build agent is doing.

Someone gets paid to manage this TFS server, and they've mysteriously disappeared from their desk.

Our internal source control tool was based on the ClearCase source code, licensed long ago. It has since diverged significantly.

Do you enjoy config specs but loving hate GUI tools? Then congrats, because neither CCRC or the Windows GUI can speak our mangled version. But you sure can command line the gently caress out of some awful customized version of clear tool as you check in each file change individually.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

pseudorandom name posted:

To be fair, the ucontext functions don't work with backtrace either. sigaltstack probably breaks it, too.

I feel Apple would be less opposed to rejecting that as a bug, though.

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal
One of my coworkers was saddled with an abortion of a codebase from elsewhere in the company. Among many, many other horrors, this pattern shows up everywhere:

Java code:
Thing t = new Thing();
if(null == t)
	throw new OutOfMemoryError("Couldn't allocate thing");
and of course virtually every method has throws OutOfMemoryError on it.

This is just wrong on so many levels, but I think the reason is that the previous developers were lovely MSVC++ developers and got used to the fact that that returns null if new can't work (which, of course is against the c++ standard). Apparently learning a new language was too much for them...

McGlockenshire
Dec 16, 2005

GOLLOCKS!
The incompetent buffoons that wrote Earthlink's webmail system have it compose messages with only text/html data. No plain text fallback.

The incompetent buffoons that used to work here wrote email import code that blindly trusts HTML email if there's no plain text fallback. It then displays that HTML inline in our ticketing system. No attempt at cleaning the HTML is made. Nobody noticed until the Earthlink morons started including a <style> tag that changes the body background.

Anyone could send an email to our ticketing address right now and hijack any employee's browser, commit exploits, or even manipulate our internal systems. This has been true for eight years. I've worked here for seven. I've touched that code, I've fixed that code, but I never noticed how broken it was.

It's me. I'm the coding horror.

EntranceJew
Nov 5, 2009

McGlockenshire posted:

It's me. I'm the coding horror.

Having been in a situation like this, I have to say that it isn't exactly your fault necessarily, you should trust your codebase to some extent. You shouldn't have to keep glancing up at the ceiling to make sure there's not a gaping hole in it. This gives you plausible deniability so you can point the finger to the lack of internal security audits.

Munkeymon
Aug 14, 2003

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




I'm just surprised they're still around.

Polio Vax Scene
Apr 5, 2009



I'm the coding horror today. At least, I was. I had a list of Room objects which had lists of other objects in them that I was serializing to/from a file.

Saving the list, before: Loop through the Room list, loop through each Room's object list, serialize each object, write to stream, add 'seperator' bytes, encrypt, write to file (named after the Room), end up with dozens or hundreds of files.

Saving the list, after: Serialize Room list, write to stream, encrypt, write to single file.

Loading the list, before: Loop through each file in directory, create a room named after each file, open file stream, continue reading stream until 'seperator' bytes are detected, decrypt bytes, deserialize object from byte section, add object to room, repeat until end of stream, switch to next file.

Loading the list, after: Open single file stream, decrypt, deserialize room list. :doh:

McGlockenshire
Dec 16, 2005

GOLLOCKS!

McGlockenshire posted:

No attempt at cleaning the HTML is made.

I lied!

php:
<?
if ($contentType == 'text/html') { 
    $display['body'] = preg_replace('/<(script|iframe|frame|frameset|object)>.*?<\/\1>/','',$display['body']); 
    $display['body'] = preg_replace('/<[\/]?noscript>/','',$display['body']); 
}?>
That's objectively worse than no attempt. Witness the severe lack of case insensitivity, for example.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Now just send an email containing <scr<script></script>ipt>alert('I quit');</script> and you're good to go

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Manslaughter posted:

I'm the coding horror today. At least, I was. I had a list of Room objects which had lists of other objects in them that I was serializing to/from a file.

Saving the list, before: Loop through the Room list, loop through each Room's object list, serialize each object, write to stream, add 'seperator' bytes, encrypt, write to file (named after the Room), end up with dozens or hundreds of files.

Saving the list, after: Serialize Room list, write to stream, encrypt, write to single file.

Loading the list, before: Loop through each file in directory, create a room named after each file, open file stream, continue reading stream until 'seperator' bytes are detected, decrypt bytes, deserialize object from byte section, add object to room, repeat until end of stream, switch to next file.

Loading the list, after: Open single file stream, decrypt, deserialize room list. :doh:

I'm the horror, I don't understand the problem. Is the horror the before implementation?

WHERE MY HAT IS AT
Jan 7, 2011
Yes. Why loop through and save hundreds or thousands of individual files when you can just serialize/deserialize the whole list at once, then write/read only one file? The only reason the former would be better I guess is if you knew you would need to get just a subset of those at some point?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
OK, I thought I was just overlooking something dumb in the before vs after conversion. Thanks.

nite time dinosaur
Sep 12, 2011

this is what you get when you mess with us
this is the kind of poo poo i come across on a regular basis.

code:
private void addDealSourceId(Deal deal, PartnerProgramEnum program)
{
  String dealSourceIdStr;
  int dealSourceId;

  dealSourceIdStr = Integer.toString(DealSourceEnum.PARTNER_PORTAL.getId());

  if (dealSourceIdStr != null)
  {
    dealSourceId = Integer.parseInt(dealSourceIdStr);
    deal.setDealSourceId(dealSourceId);
  }

}
sigh. i need to find a new job.

EntranceJew
Nov 5, 2009

nite time dinosaur posted:

sigh. i need to find a new job.

At least their nonsense appears to have some sort of pattern, you could just have a grab bag of slop. I'd trade with you. :v:

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

EntranceJew posted:

At least their nonsense appears to have some sort of pattern, you could just have a grab bag of slop. I'd trade with you. :v:

That's evidence of some seriously stupid cargo-cult programming. I would not want to work with developers who write code like that. If that's how they mangle a simple method, I'd hate to see what a complex method looks like.

Macichne Leainig
Jul 26, 2012

by VG
Other than the obvious, I'm really happy ReSharper has taught me to use ternary operators in an application like this. So much less bullshit than "if null."

Having ReSharper and using lambda expressions all over the place has made me really lazy, and I don't think I could write a C++ program without being horribly frustrated anymore.

JawnV6
Jul 4, 2004

So hot ...

Tha Chodesweller posted:

I don't think I could write a C++ program without being horribly frustrated anymore.

Pretty common condition.

Macichne Leainig
Jul 26, 2012

by VG

JawnV6 posted:

Pretty common condition.

It's not a good one in my position, we do C++ at school, this semester I just had zero programming courses. :v:

Dren
Jan 5, 2001

Pillbug

Tha Chodesweller posted:

Other than the obvious, I'm really happy ReSharper has taught me to use ternary operators in an application like this. So much less bullshit than "if null."

Having ReSharper and using lambda expressions all over the place has made me really lazy, and I don't think I could write a C++ program without being horribly frustrated anymore.

Yeah I am writing C++ today it is bullshit.

Macichne Leainig
Jul 26, 2012

by VG
Just ran into this.

code:
var firstEnvironment = Environments[0];
            if (Environments != null)
            {
                ...
            }
You don't think that, y'know, that variable should go into the if statement you just wrote?

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

nite time dinosaur posted:

this is the kind of poo poo i come across on a regular basis.

code:
private void addDealSourceId(Deal deal, PartnerProgramEnum program)
{
  String dealSourceIdStr;
  int dealSourceId;

  dealSourceIdStr = Integer.toString(DealSourceEnum.PARTNER_PORTAL.getId());

  if (dealSourceIdStr != null)
  {
    dealSourceId = Integer.parseInt(dealSourceIdStr);
    deal.setDealSourceId(dealSourceId);
  }

}
sigh. i need to find a new job.

I'm the completely unused second parameter.

Rottbott
Jul 27, 2006
DMC

Tha Chodesweller posted:

Other than the obvious, I'm really happy ReSharper has taught me to use ternary operators in an application like this. So much less bullshit than "if null."

Having ReSharper and using lambda expressions all over the place has made me really lazy, and I don't think I could write a C++ program without being horribly frustrated anymore.
But C++ has lambdas...?

Vanadium
Jan 8, 2005

Rottbott posted:

But C++ has lambdas...?

Half the fun of lambdas is usually that they magically capture the lexical environment, and in C++ it's just not sufficiently magic to actually make things easier. :v:

Rottbott
Jul 27, 2006
DMC
I don't get it. They can capture from the outer scope automatically, and are certainly much easier than ye olde functors.

FamDav
Mar 29, 2008
The capture rules for c++ lambdas are even really simple, too.

raminasi
Jan 25, 2005

a last drink with no ice
C# lambdas are actually somehow more clunky than C++ lambdas because you have to spell their type explicitly. (I've had bad experiences with their auto-capturing behavior, too, although I was probably doing something I wasn't supposed to do.) C++ lambdas definitely don't have the convenient elegance that makes them fun to play with in functional languages, but C# lambdas sure the hell don't either.

e: I suppose it's only fair to note that in C# lambdas you can use type inference for the parameters, which you can't do in C++ (until C++14 apparently).

raminasi fucked around with this message at 22:47 on Dec 7, 2013

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

GrumpyDoctor posted:

C# lambdas are actually somehow more clunky than C++ lambdas because you have to spell their type explicitly. (I've had bad experiences with their auto-capturing behavior, too, although I was probably doing something I wasn't supposed to do.) C++ lambdas definitely don't have the convenient elegance that makes them fun to play with in functional languages, but C# lambdas sure the hell don't either.

I'm confused. Where do you have to specify a type when using lambdas in C#?

Sedro
Dec 31, 2008
When you assign them. e.g. you can't infer the return type of (i: int) => i.ToString() as Func<int, String>

Adahn the nameless
Jul 12, 2006

Sedro posted:

When you assign them. e.g. you can't infer the return type of (i: int) => i.ToString() as Func<int, String>

The reason for that is that the type is ambiguous between Func<int, String> and Expression<Func<int, String>>

raminasi
Jan 25, 2005

a last drink with no ice

Adahn the nameless posted:

The reason for that is that the type is ambiguous between Func<int, String> and Expression<Func<int, String>>

The fact that there's a reason for it (which I don't think anyone here wasn't aware of) doesn't make it not annoying.

EssOEss
Oct 23, 2006
128-bit approved
Then again, how often do you really need to assign a lambda to a variable? I use them every day and 99% of the time they are provided as function call arguments, e.g.

code:
std::thread([] { reticulateSplines(); }).detach();
and

code:
cities.OrderBy(c => c.Population).ToArray();

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

EssOEss posted:

Then again, how often do you really need to assign a lambda to a variable? I use them every day and 99% of the time they are provided as function call arguments, e.g.

code:
std::thread([] { reticulateSplines(); }).detach();
and

code:
cities.OrderBy(c => c.Population).ToArray();

In C#, I made an extension method to Action, and I was hoping I'd be able to do this:

(()=>Foo()).SomeFluentMethod

I couldn't, of course. I had to either cast (which is ugly) or stick it into an explicitly-provided type.

raminasi
Jan 25, 2005

a last drink with no ice

EssOEss posted:

Then again, how often do you really need to assign a lambda to a variable? I use them every day and 99% of the time they are provided as function call arguments, e.g.

code:
std::thread([] { reticulateSplines(); }).detach();
and

code:
cities.OrderBy(c => c.Population).ToArray();

I usually run into this when I'm trying to stuff some gnarly predicate into a call to Where or something and my choices are to write a ten-million-character-long line, stick a multiline anonymous function into an already-multiline LINQ chain, write the predicate as its own named function that makes absolutely no sense outside of this particular context, or store the predicate in a variable. I agree that this is a 1% case, but it does happen.

Claeaus
Mar 29, 2010
Found an old project me and a friend did at school.

Two highlights:
code:
if((GUI.listPlayers.getSelectedIndex()>0 && GUI.comboCourses.getSelectedIndex()>0) 
&& (GUI.checkPlayers.isSelected()==true && GUI.checkCourses.isSelected()==true) && 
      	GUI.players.elementAt(GUI.listPlayers.getSelectedIndex()-1)
.getMean(GUI.courses.elementAt(GUI.comboCourses.getSelectedIndex()-1).getName())!=-1)
code:
if(GUI.players.elementAt(GUI.listPlayers.getSelectedIndex()-1).result.elementAt(i).getName()
	      		.equals(GUI.courses.elementAt(GUI.comboCourses.getSelectedIndex()-1).getName())) // right?
I remember us going:
"There has to be a better way.."
"Yes."
"Do you know of any?"
"No."
"Me neither, moving on."

EDIT: It was even so horrible it broke tables

Claeaus fucked around with this message at 21:12 on Dec 9, 2013

Funking Giblet
Jun 28, 2004

Jiglightful!
Not so much a coding horror, more of a horror in code.

We have a client who exports a large chunk of product data from SAP, and we import it automatically. It's a very hands off process, and if there is a problem it's usually 99.9% the fault of the client not adhering to the spec. We do validation of all the files they send us, and usually we have some error that looks like this.
"SKU was referenced in Catalogue but definition was not found in SKU definition file (file.txt), please check your SKU export and try again".

After weeks of back and forth of him constantly asking what this meant, and us having to explain the above as "Yeah you defined a SKU id as being a part of your catalogue, but you never exported this product along with the others".

The error is now

"Hey X, remember when we said you have to export the skus, well yeah you missed SKU id Y, so go back and make sure you set it up k? Grand thanks!"

shrughes
Oct 11, 2008

(call/cc call/cc)
Recently, I saw this...

code:
#define private public
#include "header_file.hpp"
#undef private
so that some unit test code could see private member functions.

Adbot
ADBOT LOVES YOU

tractor fanatic
Sep 9, 2005

Pillbug
Is that UB if one translation unit has private functions and another has all public functions?

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