Live data from Hacker News

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

news.ycombinator.com

481–490 of 601 posts

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

#481
post #234

Earlier quoted context omitted.

It's like that in other fields of engineering too, when they are making something they haven't built before . That's the essential part: for example, a lot of construction is really just rebuilding the same thing that's already been built 100,000 times in the past 100 years. When they attempt to build something new, it often ends up like software – tremendous overruns in both cost and schedule. C.f. the only new nucl…

> It's like that in other fields of engineering too, when they are making something they haven't built before. Exactly this. I like to use an analogy of building bridges :) - OK, we have this valley and we want to drive cars over it. What do we do? - Hmm, we could just make the road along the bottom of the valley - Wouldn't that cause the cars to fall because of the steep angle? - Good point. Maybe if we built the ro…

Very interesting point.

I must admit that when I saw valley in

> OK, we have this valley

I immediately thought about SV, and then as I read

> - Maybe we could build some sort of catapult setup to throw the cars > * across the valley*

I imagined some kind of scenario happening in an alternate reality where a startup was trying to dream up a viable way to actually achieve this in SV.

It was funny because of the fact that a lot of the ideas people do come up with are probably ideologically very similar in magnitude and ridiculous impossibility.

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

#482
post #468
post #454

Earlier quoted context omitted.

The thing is, when I spend a lot of time thinking about how to make my program type-safe all of my unit tests become either useless or no-ops Integration tests easily survive refactoring, on the other hand

Unit tests are a side effect of TDD, they don't have to be the goal. I'd find value out of TDD even if I deleted all of my tests after. It sounds like your problems are around unit tests, and that is neither something required to TDD nor is it something limited to just TDD. The problem with integration tests is they are slow and grow exponentially. If they aren't growing exponentially then there's probably large chun…

No, like in some programs when I figure out how to do it correctly the unit tests are either complete tautologies or integration tests.

Then there are the "write once, never fail ever" tests. Okay, so the test made sense when I wrote the code. I will never touch that part ever again because it works perfectly. Why do I keep running them every time?

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

#483
post #377

Earlier quoted context omitted.

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.…

"job security" coupled with "I was his replacement" says that his plan worked about as well as his code...

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

#484

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…

Not exactly relevant to the overall discussion but I've been dreaming for a long time about programming an elevator such that it arrives faster and skips other floors if a user frantically pushes the call button repeatedly. Same for traffic lights with push buttons. Maybe it's a good thing that I'm not an engineer.

There are apocryphal stories about elevators that let you push/hold buttons to cancel floor selections (eg, https://www.youtube.com/watch?v=eQSdKe5kArA) or skip floors. I often forget to try them, but on the few occasions I've remembered nothing has happened.

All elevators accept a standardized fire/security key that enables "exclusive" mode that lets you tell the lift "go to this floor" and it will do so: https://www.youtube.com/watch?v=1Uh_N1O3E4E (a reasonable sink of 1hr)

As for traffic lights I'm aware (at least in Australia) that they all tie back to a realtime system that lets a control room instruct lights to turn green and so forth. (Presumably the immediate action is that the lights that are currently green immediately turn orange, then red after the normal delay.) You can get summarily fired for misusing this though. I've also heard (IIRC on a TV documentary-type show) that ambulances tie into this system with live GPS tracking such that lights turn green as they approach, but this is sufficiently fantastic that I'm waiting to trust-but-verify it before I quote it with confidence.

Under normal use some traffic lights are traffic based while others have timers. The ones that are traffic based will take into consideration whether the pedestrian crossing button has been pushed and reduce the threshold value needed for the actual traffic lights to turn red. The other timer ones - like the really annoying ones outside my local mall :) - are on a fixed timer, and I try to run for that one when I know it's about to turn green, or just accept and twiddle my fingers while I wait if I miss it.

It'd be nice if elevator simulators were satisfying to write. Although, actually... I've just realized that with Unity you could have _quite_ a lot of fun :D... (hmm, I've had GPU on my wishlist for about 15 years now, now I really want one)

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

#485
post #429
post #232

A while ago, I was tasked with maintaining production code written in R by an enthusiastic junior developer. He loved R so much that it blinded his ability to use the right tool for the job. Instead, he wrote web applications in R, instead of Python or Ruby, which my company had many developers who had expertise in, and eventually handed it over to to me. He even persuaded our bosses to invest into R Studio Server an…

> In addition, the same name would refer to different things, eg. `abc` and `Abc` and `a_bc` would mean totally different things. That's not too unusual. In Java `Camel` would usually be a class and `camel` an object, and in Prolog `Camel` is a variable wheras `camel` is an atom. Not sure about R though..? > And stuff that could be written in a simple Sinatra or Flask application were written in R Shiny. I don't know…

Well, that nomenclature works well for classes and objects, but if you use mix up cases within an object, I think we call can agree it's really bad code?

As for R Shiny, those examples all look fine, but wasn't the case with my code.

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

#486

Earlier quoted context omitted.

TDD doesn't think for you, it merely validates your own existing understanding/mental model and forces you to come up with it upfront. This is hardly a thing to be mistrustful about, unless you work with idiots.

You are right about that, but having code that passes a given test suite doesn't say anything about its secondary qualities, such as whether it can be understood. In theory, a failing test could improve your understanding of the situation, allowing you to refactor your initial pass at a solution, but I would bet that on this particular code base, the comprehension-raising doesn't go far enough, in most cases, for thi…

That seems orthogonal to testing though. Implementation code can be hard to understand with or without a test suite, at least with test, as you point out, you may be able to understand the behaviour at some higher abstraction.

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

#487
post #212

Earlier quoted context omitted.

>I found it to be especially true with testing. I've lost the count of how many times I heard "we didn't had time to write (more) tests". But testing is hard. And when given enough time, these developers don't magically start doing it "right" overnight. Bingo. It's not necessarily only skills though. It can be myriad reasons and "no time" is just the easiest excuse they can think of. In big companies I've often seen…

To even write unit tests effectively you need to write your code in a certain differently. In C# this normally means using IOC + DI. Also almost nobody I know does proper TDD. I know it is very convincing when one of the TDD evangelists shows you how to write something like a method to work out the nth number in a fibonacci sequence using nothing but just writing tests. In reality most 95% of developers that even wri…

>To even write unit tests effectively you need to write your code in a certain differently.

>In C# this normally means using IOC + DI.

I've become quite partial to functional programming in the last few years. Side effect free functions with functions as interfaces for DI lend themselves perfectly to TDD and data parallel async without worrying too much.

C# is now slowly taking over most of the good features from F#, but I think the culture won't transform so easily.

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

#488
post #280
post #210

Earlier quoted context omitted.

Except that's a really bad analogy. It's more like you set up guard rails, and every time your vehicle hits a guard rail you change the algorithm it uses for navigation until it can do a whole run without hitting a guard rail. I've experienced myself how the code quality of proper TDD code can be amazing. However it needs someone to still actually care about what they're doing. So it doesn't help with idiots.

> Except that's a really bad analogy. It's more like The response to every analogy ever made on the internet. Can we stop using them yet?

Spot on: "Analogies: Analogies are good tools for explaining a concept to someone for the first time. But because analogies are imperfect they are the worst way to persuade. All discussions that involve analogies devolve into arguments about the quality of the analogy, not the underlying situation." - Scott Adams, creator of Dilbert (I know he's quite controversial since the election, but he's on point here) in https://blog.dilbert.com/2016/12/21/how-to-be-unpersuasive/

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

#489

The worst for me was a rescue project: a site for a US tech sector Public-private partnership. Nothing too complicated: recurring donations, paid events, a small members area. They had sent it to an Indian firm to build in Drupal 7 - not a lightweight system to begin with. I would like to say "cue the stereotypes for Indian developers" and we could all have a good laugh. But no. This is more like Heart of Darkness. T…

Holy crap. You already earned yourself an upvote for this sentence:

> * Memory management. What's that? This site required 16 GIGABYTES as a PHP memory limit in order to load the front page for an anonymous user.

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

#490

At my first gig I teamed up with a guy responsible for a gigantic monolith written in Lua. Originally, the project started as a little script running in Nginx. Over the course of several years, it organically grew to epic proportions, by consuming and replacing every piece of software that it interfaced with - including Nginx. There were two ingredients in the recipe for disaster. The first is that Lua comes "batteri…

I've seen personal reality building happen in Lua several times already. It's very seductive to intelligent solo artists who are given a lot of freedom. To be fair, I've also seen it happen in C, C++, and JavaScript.

That's spot on, the guy is indeed one of the most intelligent, knowledgeable and dedicated persons I've ever met. Actually a really good guy.
Post reply on HN