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
EAT THE EGGS RICOLA
May 29, 2008

leper khan posted:

A third party is /providing/ an API, and doesn't know if it works because I haven't provided them a working client application.

If you give me the URI for it I'll write a twitter robot that tweets random information from it at Barack Obama.

Adbot
ADBOT LOVES YOU

Harik
Sep 9, 2001

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


Plaster Town Cop
Gonna have to say that this one belongs here:

$460m loss due to technical mismanagement

quote:

13. Upon deployment, the new RLP code in SMARS was intended to replace unused code in the relevant portion of the order router. This unused code previously had been used for functionality called “Power Peg,” which Knight had discontinued using many years earlier. Despite the lack of use, the Power Peg functionality remained present and callable at the time of the RLP deployment. The new RLP code also repurposed a flag that was formerly used to activate the Power Peg code. Knight intended to delete the Power Peg code so that when this flag was set to “yes,” the new RLP functionality—rather than Power Peg—would be engaged.

15. Beginning on July 27, 2012, Knight deployed the new RLP code in SMARS in stages by placing it on a limited number of servers in SMARS on successive days. During the deployment of the new code, however, one of Knight’s technicians did not copy the new code to one of the eight SMARS computer servers. Knight did not have a second technician review this deployment and no one at Knight realized that the Power Peg code had not been removed from the eighth server, nor the new RLP code added. Knight had no written procedures that required such a review.

Never pass up an opportunity to make things worse:

quote:

In one of its attempts to address the problem, Knight uninstalled the new RLP code from the seven servers where it had been deployed correctly. This action worsened the problem, causing additional incoming parent orders to activate the Power Peg code that was present on those servers, similar to what had already occurred on the eighth server.

Instead of a 1/8 failure rate, let's just make a consistent 8/8, consistency is always important.

The entire SEC report on the incident is a great read, including that they had no sanity check on orders and were happily "selling" 3.15b in stock they didn't have.

TheresaJayne
Jul 1, 2011

Amarkov posted:

C#, like Java, does not support multiple inheritance from non-interface classes. So making an empty abstract base class severely limits your ability to modify things.

C++ does support multiple inheritance, so it's not an issue. (Does C++ even have the concept of an interface, distinct from a pure virtual class?)

However if you are using TDD or something similar, then you need to have the interface to Mock, but true i guess with nothing in the interface to mock is a bit stupid.

zokie
Feb 13, 2006

Out of many, Sweden

TheresaJayne posted:

However if you are using TDD or something similar, then you need to have the interface to Mock, but true i guess with nothing in the interface to mock is a bit stupid.

To test stuff like that use inheritance, I was blown away by the TestableBar : Bar that overrides the virtual method Foo GetFooDependency to test.
Art of Unittesting owns!

1337JiveTurkey
Feb 17, 2005

zokie posted:

To test stuff like that use inheritance, I was blown away by the TestableBar : Bar that overrides the virtual method Foo GetFooDependency to test.
Art of Unittesting owns!

If you're using dependency injection (I don't know what .NET frameworks exist but I'm sure they exist) then you can keep the Bar class the same as it was before. In that case there's a SetFooDependency method that serves as a marker for whatever's providing the Bar that the Bar also needs a Foo. The difference between the test case and the actual code is that the provider used creates a Foo or MockFoo depending on the circumstances.

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
This is more of a development bumblefuck than an actual horror of coding, but whatever.

Basically I've worked myself out of stuff to do for my features of $PROJECT. So, I was told to go through a big rear end list of services exposed by $CLIENT for $PROJECT to consume, and a list of $CONTROLS for $PROJECT which make use of those services. Nothing was documented, and nobody could tell me poo poo except have fun and good luck. They said $RELATEDPROJECT used these services and my project's $CONTROLS will copy what $RELATEDPROJECT did, and to look in their source and talk to the guys in the shared office who work on that. Whee!

One of the first things I found out is that we don't have documentation for these services that both $PROJECT and $RELATEDPROJECT consume. Then I found out that I needlessly replicated something that was already done, but since nobody knew it was done, it just sorta sat there in the ether.

I then find out "Oh, $GUYWHOLEFT was doing all that stuff." Too bad nobody kept track of what he was doing and he didn't write anything down.

Oh, and these $CONTROLS are a nice heady mix of Razor, jQuery, knockout, and server side generated html.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

That's a project management horror.

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
Oh yeah we switched team leads around the time the guy who did undocumented stuff left :haw:

IMlemon
Dec 29, 2008
Java code:
private boolean hasVesselChildren(Vessel vessel) {

  if (vessel.getName() != null)
    return true;

  if (vessel.getGearCode() != null)
    return true;

  ArrayList<RecordTracker> children = new ArrayList<RecordTracker>();

  return children.size() > 0;
}
This is used all over the place. Every day I'm surprised that this application actually works.

Java code:
public void dispose() {
  logger.debug("DIPOSED");
}

This is called when window or whatever is closed and ends up taking 60% of the log file. At least it's funny.

Jewel
May 2, 2009

PHP.net was comprimised with a javascript injection exploit of some kind and blocked by google :allears:

Jewel fucked around with this message at 16:49 on Oct 24, 2013

Kalenden
Oct 30, 2012
Does anybody know a good list or website about coding horrors or funny coding constructions?

Lately a friend sent me some over and I'm having fun in guessing what the result will be.

For example (in Python):

quote:

x = 1
def test():
global x
try:
return True
finally:
x = 2

print str(test())
print x


(Allegedly) gives true2.

Or (Java):

quote:

class A {
public void m(A a) { System.out.println("1"); }
}
class B extends A {
public void m(B b) { System.out.println("2"); }
public void m(A a) { System.out.println("3"); }
}
B b = new B();
A a = b;
a.m(b);

prints out 1 (if I remember correctly).

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

for the love of god use [code] tags

qntm
Jun 17, 2009
Those are both incredibly obvious, but very small changes could be made to make them far less predictable.

In the Python example, return x instead of True.

In the Java example, call b.m(a) instead of a.m(b).

ManoliIsFat
Oct 4, 2002

Kalenden posted:

Does anybody know a good list or website about coding horrors or funny coding constructions?

http://thedailywtf.com/

Kalenden posted:

Does anybody know a good list or website about coding horrors or funny coding constructions?

Lately a friend sent me some over and I'm having fun in guessing what the result will be.

For example (in Python):



(Allegedly) gives true2.
Of course, as that's what finally does. It returned true, then set the value of x.

ManoliIsFat fucked around with this message at 23:24 on Oct 24, 2013

Thermopyle
Jul 1, 2003

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

Kalenden posted:

Does anybody know a good list or website about coding horrors or funny coding constructions?

Here.

That python one you shared won't even work since Python is whitespace-sensitive.

crazypenguin
Mar 9, 2005
nothing witty here, move along
And the java one will print 3, and I'm not sure why anyone would think otherwise?

Posting Principle
Dec 10, 2011

by Ralp

crazypenguin posted:

And the java one will print 3, and I'm not sure why anyone would think otherwise?

Because a similar program in C++ will print 1.

return0
Apr 11, 2007

crazypenguin posted:

And the java one will print 3, and I'm not sure why anyone would think otherwise?

I maybe have my retarded goggles on but why 3 - is Java method overloading weird?

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

crazypenguin posted:

And the java one will print 3, and I'm not sure why anyone would think otherwise?

Because you're passing in a B (not up-cast), so it should print 2?

return0
Apr 11, 2007

Kilson posted:

Because you're passing in a B (not up-cast), so it should print 2?

I think so too but dont really do much java

Don Mega
Nov 26, 2005
I use to work for this lovely company. There was literally nothing about that place that was not a coding horror. No source control, tests or qa, separate development environment, or sql sanitation. I could go on all day. Thankfully, I have found a much better place to work for since then.

Sedro
Dec 31, 2008

return0 posted:

I maybe have my retarded goggles on but why 3 - is Java method overloading weird?
It is the combination of overloads and overrides. Overloads happen at compile and overrides happen at runtime.

Java decides which overloaded method signature to use based on the compile-time types:
Java code:
A a = ...
a.m(b);
The compiler just sees you calling a method on A. The method call resolves to A.m(A) since that is the best overload available on type A (there is only one choice).

When a method is overridden, the JVM always calls the override on most specific runtime type. The runtime type of (variable) "a" is (class) "B":
Java code:
B b = new B();
A a = b;
...
The JVM has the choice of calling A.m(A) or B.m(A), so it calls B.m(A) because B is more specific than A.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Posting Principle posted:

Because a similar program in C++ will print 1.

Not if you include the implicit virtual keyword.

Kilson posted:

Because you're passing in a B (not up-cast), so it should print 2?

But A doesn't have an overload that takes B. Java is single dispatch.

return0 posted:

is Java method overloading weird?

No, it's pretty normal. Double dispatch implies a non-trivial run-time overhead cost.

Zhentar fucked around with this message at 00:51 on Oct 25, 2013

Posting Principle
Dec 10, 2011

by Ralp

Zhentar posted:

Not if you include the implicit virtual keyword.


lmao i'm a loving idiot welp. public nonstatic Java methods are implicitly virtual

Posting Principle fucked around with this message at 00:54 on Oct 25, 2013

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Sedro posted:

It is the combination of overloads and overrides. Overloads happen at compile and overrides happen at runtime.

Java decides which overloaded method signature to use based on the compile-time types:
Java code:
A a = ...
a.m(b);
The compiler just sees you calling a method on A. The method call resolves to A.m(A) since that is the best overload available on type A (there is only one choice).

When a method is overridden, the JVM always calls the override on most specific runtime type. The runtime type of (variable) "a" is (class) "B":
Java code:
B b = new B();
A a = b;
...
The JVM has the choice of calling A.m(A) or B.m(A), so it calls B.m(A) because B is more specific than A.

Well how about that. I figured it found the specific runtime type first (being B), and only then applied the arguments, which would have caused it to print 2. Thanks for teaching me a new thing!

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Kilson posted:

Well how about that. I figured it found the specific runtime type first (being B), and only then applied the arguments, which would have caused it to print 2. Thanks for teaching me a new thing!

Remember internally overloads are actually getting name mangled as slightly different methods, so at compile time its determined which is being called. You can then override it at runtime, but its going to be looking for that specific parameter signature because the overloaded methods are actually different.

Something like m_b(B b) and m_a(A a), though not so trivial.

As Zhentar said it would require double dispatch to check parameter typing at runtime, an extra vtable lookup, so you don't want that for every case. But you can write a method to do the lookup manually when needed.

Zaphod42 fucked around with this message at 16:03 on Oct 25, 2013

IronDoge
Nov 6, 2008

Not really specific code, but I found out today the website manager for my fire company's website is all in flash for some godforsaken reason. Simple things like editing a news feed takes like 30 minutes for one little article because every edit I do has a 3 second lag. :shepicide: I'm definitely going to rebuild this site, but goddamn WTF ever thought a flash backend was a good idea?

PhonyMcRingRing
Jun 6, 2002

dwazegek posted:

code:
public bool IsNumeric(object numberString)
{
  char[] ca = numberString.ToString().ToCharArray();
  for (int i = 0; i < ca.Length; i++)
  {
    if (!char.IsNumber(ca[i]))
      if (ca[i] != '.')
        return false;
  }
  if (numberString.ToString().Trim() == "")
    return false;
  return true;
}
I guess it's not the worst piece of code in the world, but still...

If you think that's fun, check out some of the code for the Microsoft.VisualBasic library. The amount of crap they did just to make VB6 transitions to VB.Net is ridiculous.

Molten Llama
Sep 20, 2006

Ironsights posted:

I'm definitely going to rebuild this site, but goddamn WTF ever thought a flash backend was a good idea?

Rich Internet Applications was a horrible thing Macromedia threw their then-tremendous weight behind.

If it's any consolation, it was probably at least as painful to develop as it is to use.

Neurion
Jun 3, 2013

The musical fruit
The more you eat
The more you hoot

PhonyMcRingRing posted:

If you think that's fun, check out some of the code for the Microsoft.VisualBasic library. The amount of crap they did just to make VB6 transitions to VB.Net is ridiculous.

It's been forever since I used VB6, and now you've got me curious what they did. Mind filling us in?

ikanreed
Sep 25, 2009

I honestly I have no idea who cannibal[SIC] is and I do not know why I should know.

syq dude, just syq!
Short but sweet
code:
if(x.contains("|") && !string.IsNullOrEmpty(x))
{
	Something about emails, who cares
}

ToxicFrog
Apr 26, 2008


I work with some seriously smart people. But I also work on a huge codebase that has evolved over many years and, occasionally, been exposed to the tender ministrations of interns. And the smart people are sometimes pressed into service on technologies they are unfamiliar with.

So every once in a while, I find something horrifying. Like today! See, we have an internal service. And we have a small, Django-based web interface for monitoring the status of this service. Today, I was asked to add a feature to this interface.

What I expected to find:
  • Server code reads status information from service.
  • Information is rendered into page.

What I found:
  • Server code reads status information from service.
  • Information is converted into a bunch of blocks of JSON.
  • Page is rendered. The template is extremely terse, basically just splicing the JSON in and then handing it over to...
  • ...a shitload of JavaScript, which parses the JSON, and then...
  • ...invokes a bunch of factory methods, which painstakingly reconstruct all the data that was already available in python, before...
  • ...stuffing it into a giant pile of arrays, which are then iterated in order to...
  • ...populate the page with the data that could have been rendered straight into it from Python to begin with.

:gonk:

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

ikanreed posted:

Short but sweet
code:
if(x.contains("|") && !string.IsNullOrEmpty(x))
{
	Something about emails, who cares
}

Let's hope x is never actually null!

abraham linksys
Sep 6, 2010

:darksouls:

ToxicFrog posted:

  • Server code reads status information from service.
  • Information is converted into a bunch of blocks of JSON.
  • Page is rendered. The template is extremely terse, basically just splicing the JSON in and then handing it over to...
  • ...a shitload of JavaScript, which parses the JSON, and then...
  • ...invokes a bunch of factory methods, which painstakingly reconstruct all the data that was already available in python, before...
  • ...stuffing it into a giant pile of arrays, which are then iterated in order to...
  • ...populate the page with the data that could have been rendered straight into it from Python to begin with.

:gonk:

:confused: This is basically "client-side templating 101." Though really, "reconstruction of data" shouldn't be needed if you have an API that's spitting out a format your JS/templates consume, and it can get ugly if it's an ad-hoc implementation and not based on one of many libraries that do this.

It's done so that no duplication of effort is required when making web applications that have lots of front-end interaction. You generally don't want to have to have both server- and client- side templates doing the same thing.

(of course if this is a mostly static page with no rich interactivity then yeah it's way more effort than it's worth :v:)

My Rhythmic Crotch
Jan 13, 2011

code:
select '<tr><td>' || first_name || '</td><td>' || last_name || '</td></tr>' from people;
Now imagine an entire webapp made with that. Just pages and pages of it. I didn't even know that was valid syntax!

My Rhythmic Crotch fucked around with this message at 05:34 on Oct 26, 2013

it is
Aug 19, 2011

by Smythe
I'm confused by the </tr> without <tr>

Does that return a table full of first_name last_name?

My Rhythmic Crotch
Jan 13, 2011

I forgot the <tr>. It returns this:
code:
 <tr><td>bob</td><td>smith</td></tr>
 <tr><td>sally</td><td>jenkins</td></tr>
I can't remember exactly how he was doing the <table>, <thead> etc.

Qwertycoatl
Dec 31, 2008

At a previous job, this is what the system did to look up a user's email address stored in a database:

1) In another database, look up the application ID in a different database to find the location of the database with the user information in it.
2) Convert the request to XML, and http post it to something running ASP.NET on the same server
3) The asp.net page converts the XML request into a different format of XML, and looks up the application ID in a database to find out what port the application is listening on.
4) asp.net does an http post back to the original application with the XML request.
5) The application reads the database information and request out of the XML, and retrieves the email address from the database, and packages it up in XML top send back to asp.net
5) asp.net converts the response XML into different XML, and returns it to the application.

I'd been asked to look into why the system was too slow. I replaced all that with a function call.

pigdog
Apr 23, 2004

by Smythe

My Rhythmic Crotch posted:

code:
select '<tr><td>' || first_name || '</td><td>' || last_name || '</td></tr>' from people;
Now imagine an entire webapp made with that. Just pages and pages of it. I didn't even know that was valid syntax!

Are these names entered into the database from a controlled source? How many customers do you have whose name is <script src="http://some.evilsite.ru/exploit.js"/> ?

Adbot
ADBOT LOVES YOU

My Rhythmic Crotch
Jan 13, 2011

It's for an internal application, thankfully. It's easy to inject SQL into it though. In fact other developers needed to get information out of that app, and just about the only way to do it was SQL injection.

I built an API for it though, so it's all good now. Well, my API is okay, the old site is still as crufty as ever.

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