Live data from Hacker News

Ask HN: What's the largest amount of bad code you have ever seen work?

news.ycombinator.com

371–380 of 601 posts

Re: Ask HN: What's the largest amount of bad code you have ever seen work?

#371
post #296

Earlier quoted context omitted.

Tests that run for 30 hours is an indication that nobody bothered writing unittests. If you need to run all tests after changing X, it means X is NOT tested. Instead you need to rely on integrations tests catching Xs behavior.

> Tests that run for 30 hours is an indication that nobody bothered writing unittests. Yes, they were not unit tests. There was no culture of unit tests in the Oracle Database development team. A few people called it "unit tests" but they either said it loosely or they were mistaken. Unit test would not have been effective because every area of the code was deeply entangled with everything else. They did have the con…

I'm amazed that it had that many tests that took that long, but ONLY had 80-95% coverage. I understand the product is huge, but that's crazy.

Re: Ask HN: What's the largest amount of bad code you have ever seen work?

#372
I wanted to tackle a rewrite of a legacy LISP program, used by AutoCAD, to take in a list of 3D coordinate points, and output a DWG of a 2D projection (from which to create a jig on which to assemble a prototype). Cool stuff, right? My intent was to create a "proper" script in AutoCAD to actually create 3D objects from the input data, and let the program do the projection to a 2D drawing. (I'm still not sure if that would have been possible; I never got that far.)

I had never written in LISP before, so I bought a book!

I was having trouble reading the program on the computer, so I printed out the roughly 15,000 lines. Not a lot, I know, but it was about an inch and a half thick stack of paper. I started going through it.

It consisted of LOTS of subroutines. Thousands. Each one neatly formed; no more than a couple hundred lines. It gave me hope.

It read in the text file, created a blob of a string, and then passed that blob to the first subroutine. Then it passed to the next subroutine. And then the next, and so on. As far as I could tell, it never called a subroutine a second time, and it never returned to the starting method. Given the strangeness of LISP, I couldn't figure out what it was doing, or why.

The guy who wrote it had retired, and we didn't get along anyway, so I didn't try to chase down what his thinking was.

I gave up.

To my knowledge, they're still using that program 17 years later.

Re: Ask HN: What's the largest amount of bad code you have ever seen work?

#373

Earlier quoted context omitted.

Tests that run for 30 hours is an indication that nobody bothered writing unittests. If you need to run all tests after changing X, it means X is NOT tested. Instead you need to rely on integrations tests catching Xs behavior.

Always test "outside-in", i.e. integration tests first, then if you can afford it, unit tests. Integration tests test those things you're going to get paid for... features & use-cases. Having a huge library of unit tests freezes your design and hampers your ability to modify in the future.

For those who want to know more about this approach: see Ian Cooper - TDD, Where Did It All Go Wrong https://www.youtube.com/watch?v=EZ05e7EMOLM

I post this all the time, it's like free upvotes :)

Re: Ask HN: What's the largest amount of bad code you have ever seen work?

#374

We have absolutely no idea how to write code. I always wonder if it's like this for other branches of engineering too? I wonder if engineers who designed my elevator or airplane had "ok it's very surprising that it's working, let's not touch this" moments. Or chemical engineers synthesize medicines in way nobody but a rockstar guru understands but everyone changes all the time. I wonder if my cellphone is made by mac…

We have plenty of ideas on how to write code well. The catch is that they all make development slower and more expensive (at least up front, maybe the technical debt will come back to bite, maybe not).

Re: Ask HN: What's the largest amount of bad code you have ever seen work?

#375
post #60

Ten years ago I was called in to remediate a new web application which had been subcontracted to an Indian development company. The PHP developers who'd put it together evidently didn't know about classes, and each page in the application was hundreds, sometimes thousands, of lines of spaghetti code, most containing the same duplicated (but subtly changed) blocks providing database connectivity etc. Security had not…

10 years ago PHP didn't have classes

PHP 5 was released 14 years ago in July, 2004. One of its new features was OOP. Classes were supported at that time. In fact, a comment from 14 years ago shows an example class [1].

[1]: http://php.net/manual/en/language.oop5.php#46290

Re: Ask HN: What's the largest amount of bad code you have ever seen work?

#376

Earlier quoted context omitted.

What sorts of techniques did they use? I'm very curious to see/hear examples.

function isTrue(v) { var result; result = v; if (!isFalse(result == true)) { return result; } else { return isFalse(result); } } function isFalse(v) { var result; result = v; if (!isTrue(result == true)) { return isFalse(result); // Tail recursion so this is fine. } else { return result; } } if (isTrue(myBool) == true) { // TODO: Could this be refactored to isTrue(isTrue(myBool))? return true; } else if (isTrue(isFal…

i hope to god that this is just code you made up to be facetious.

Re: Ask HN: What's the largest amount of bad code you have ever seen work?

#377
post #187

I took over a Perl project where every SQL call was an exec to a java program which would make the query. The largest madness was a J2EE mess where persistence was achieved by taking your current object, sending a message bean to the server, it would touch the database and return the result which was being polled for (making it synchronous). The amazing thing is that the client and the server were the same J2EE insta…

Was there a reason they did not use DBI to call the code ?

I had been told he bragged about it being "job security" since nobody could understand what he had written. I never spoke to him directly as I was his replacement...

The java mess was a pattern copied from within the company where it was used correctly. The main product of the company was built around some very complex scheduling software. It was a black box and communication was entirely through inter-server beans. This was copied to intra-server, which makes no sense at all, and it was used everywhere.

Re: Ask HN: What's the largest amount of bad code you have ever seen work?

#378
Not the largest, but the most insane.

At an old employer there were 15,000 lines of batch script across 14 .bat files on a Windows laptop. Old director of IT used it to onboard new customers. It basically copied a DB and turned "CHANGE ME" in some columns to the client's name.

It had it all. 5k lines of date validation, 3k lines of "UI", 400 goto statements, hard-coded passwords, versioning by incrementing the file names (leading to a bunch of code that was never called), and to top it off a static IP granted to the laptop that used as a part of authentication.

Took me two weeks to unravel it and replace with ~20 lines of Ruby.

Later, all of my complaining on Facebook led an old professor to invite me back to give a talk on the importance of code quality!

Re: Ask HN: What's the largest amount of bad code you have ever seen work?

#380

Earlier quoted context omitted.

Love the idea of this. In my experience it's far easier to introduce testing by focusing on unit testing complicated, stateless business logic. The setup is less complex, the feedback cycle is quick, and the value is apparent ("oh gosh, now I understand all these edge cases and can change this complicated code with more confidence"). I think it also leads to better code at the class/module/function level. In my exper…

In general, I test those things that relate to the application, not those about the implementation. i.e. Test business logic edge-cases, don't test a linked-list implementation... that's just locking your design in.

Right, like I said "complicated business logic". I agree completely, I have no desire to test a library or framework (unless it's proven to need it).
Post reply on HN