Live data from Hacker News

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

news.ycombinator.com

351–360 of 601 posts

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

#351
post #62

Earlier quoted context omitted.

A sentiment among members of a former team was that automated tests meant you didn't need to write understandable code - let the tests do the thinking for you. This, and stuff like your story, are why I don't trust people who promote test-driven development as the best way to write clean APIs.

Rich Hickey called it guard rail driven programming. You'll never drive where you want to go if you just get on the highway and bump off the guard rails.

Nice imagery. I like it.

The other commenters made me think of the kids game Operation. https://en.wikipedia.org/wiki/Operation_(game)

How about shock collar programming? Or electric fence programming? Or block stacking (Jenga) programming.

Good times.

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

#353
My first job out of university was to program IVR systems for a telecom company using an in-house developed framework.

An IVR application would typically play a recording to the user, then wait for the DTMF signal, then maybe take the user to a sub-menu, prompt the user to choose another option and do a database query and then play another recording and so on.

The IVRs had to repeat a menu if the user made an invalid selection, and "press 'star' to return to the main menu" and so on.

So most of the applications I maintained were thousand line C++ functions that looked something like this (paraphrased):

  void ivr_main(int ch) {
  main_menu:
    play("mainmenu.vox");
    d = get_dtmf(ch);
    if(user_hung_up(ch)) return;
    switch(d) {
    case '1' : goto menu_1;
    case '2' : goto menu_2;
    case '3' : goto menu_3;
    case '4' : goto menu_4; 
    }
    goto main_menu;
  menu_1:
    play("menu1.vox");
    d = get_dtmf(ch);
    if(user_hung_up(ch)) return;
    switch(d) {
    case '1': goto menu_1_1;
    case '2': goto menu_1_2;
    case '*': goto main_menu;
    }
    goto menu_1;
  // etc...
  }

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

#354
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…

Why didn’t you rewrite it from scratch and then just replace the codebase in 1 giant commit ? Seems doable if you have the balls

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

#355
A nested if statement approximately 75 levels deep all because the author didn't understand that an ID can be unique. So he manually checked the value (which meant it could never be changed without a code change).

He did't understand the concept of a join. So he'd nest queries in VBScript with join key supplied from the outer query to the inner. Row by row. Essentially, a manual cursor.

Same programmer wrote an ASP portal app. The login of which got most of its security because they didn't know how to iterate over a returned dataset. Same code would set a cookie for access IN THE PRESENCE of a password. It could be wrong, you would still get access. Worse, the logout function didn't delete the access cookie, it just redirected you to the login page. Meaning you could impersonate anybody if knew thier username. Included admin.

I once corrected bug, by using a view. I sent him the view. He had no concept what a view was "That's like a stored procedure right?'. I'm shocked he knew what a stored procedure was.

He's still in business and the software is deployed worldwide. He refuses to fix it. He's a multi-millionaire.

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

#356

As a budding programmer (hobbyist), what can I do not to fall into the mistakes others talk about in the comments? Is there any particular set of mental habits that could lessen the chance of spaghetti occurring, or is it just a matter of when rather than if?

In practice, it's more a matter of mentality and willingness, than any specific knowledge regarding code maintanence. All you need is a couple of articles or a single book about writing clean, maintainable code - after that, the majority of the benefit comes from simply trying to maintain the long term thinking and not getting into a "let's just get this frigging done and go for a beer" mentality. Yes, there's always more you can learn to better structure your code, but simply being aware and _wanting_ to write readable code consistently takes you above 75% of the code out there.

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

#357
post #176

The worst program I ever worked on was something I was asked to maintain once. It consisted of two parts. The first was a web application writen in ASP. The second portion was essentially Microsoft Reporting Services implemented in 80,000 lines of VB.NET. The first thing I did was chuck it into VS2010 and run some code metrics on it. The results were, 10 or so Methods had 2000+ lines of code. The maintainability inde…

When I do code necromancy, instead of understanding the code, I try to understand what it does, how it interacts with the world, and then recreate that behavior.

Meaning I capture all the I/O and recreate it. SQL, HTML, PDF, CSV, whatever. Serialize everything, before and after. And then do diffs on the outputs to see if new code reproduces expected behavior.

Much easier than dead code removal, code deduping, incremental changes, backfilling tests, etc.

Once someone captures, documents what the code is actually doing, the real refactoring begins. Removing unnecessary queries. Grooming data. Simplifying schemas. Aligning the app with the biz. Etc.

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

#358
post #172

Earlier quoted context omitted.

In reality there often isn't time. Getting it done > Getting it done properly as far a management is concerned.

Ever had this discussion with a coworker? Coworker: "I hadn't enough time to do it right" You: "Given enough time, how would you do it differently?" Coworker: "............" (crickets) IMHO it's not related to deadlines only ; the "not enough time" argument is often a comfortable fallacy, keeping us from facing the limits of our current skills. I found it to be especially true with testing. I've lost the count of how…

The one that gets me is when you've designed something as simple as possible and then to make it "simpler" people insist on making it less general and paradoxically more complex in a small way.

Related to that is the "obvious performance fix" that doesn't perform faster that keeps burning up time for years long after it was proven to not be faster because freshers never found out about it and the oldsters forgot.

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

#359

When I took over my current job a outsourcing company who employed developers based in Islamabad (Pakistan) wrote most of the code. It's C#, they didn't understand the concept of null, by ref or by value. It was interesting. The database was Mongo and they had some horrible Entity Framework port that they forked on Github and used which wasn't maintained and at the time in 2015, 3 years old. The data layer had busine…

C# 8 just announced optional nullability as a feature

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

#360
post #176

The worst program I ever worked on was something I was asked to maintain once. It consisted of two parts. The first was a web application writen in ASP. The second portion was essentially Microsoft Reporting Services implemented in 80,000 lines of VB.NET. The first thing I did was chuck it into VS2010 and run some code metrics on it. The results were, 10 or so Methods had 2000+ lines of code. The maintainability inde…

When I do code necromancy, instead of understanding the code, I try to understand what it does, how it interacts with the world, and then recreate that behavior. Meaning I capture all the I/O and recreate it. SQL, HTML, PDF, CSV, whatever. Serialize everything, before and after. And then do diffs on the outputs to see if new code reproduces expected behavior. Much easier than dead code removal, code deduping, increme…

This is often the only sane thing to do.

It’s my default approach with thorny scientific code: get everyone to agree on what output should be for a bunch of relevant inputs, get the original systems output, hash it, and then write a bunch of tests in a new project that all assert that these inputs produce outputs whose hashes are as follows..

then never look at the guts of the horror again.

Post reply on HN