Live data from Hacker News

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

news.ycombinator.com

61–70 of 601 posts

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

#61
Behold, academia.

The only maintainers of this code, ever, have been grad students and postdocs. I estimate there have been about 12-15 generations worth. This code has supported hundreds of publications in its lifespan.

A codebase that began life in 1987, in C. First ported to matlab in 1999. First source control was added (as SVN) in 2015. Between 2015 and 2018, there were 6 commits total, yet 3 people graduated out of the lab from it. Probably 100,000 loc total, of which I estimate maybe a third is ever used. 1400-line matlab functions are normal-ish. I've found loops nested 11 levels deep.

It's a series of psychophysical experiments. Each experiment exists in at least 4 different versions side by side in source, each named slightly different, often by incorrect datestamp of last modification. Version control across machines is not well maintained, so you have to diff everything before you can copy or move files lest you accidentally blow something away completely.

Oh, and it's mexed and wrapped for use on a mac on exactly one snow leopard machine, hardware from 2007.

edit: I think this counts as a job, not a student experience, because I am not a student. I just have to clean this mess up once in a while.

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

#62
post #18

Oracle Database 12.2. It is close to 25 million lines of C code. What an unimaginable horror! You can't change a single line of code in the product without breaking 1000s of existing tests. Generations of programmers have worked on that code under difficult deadlines and filled the code with all kinds of crap. Very complex pieces of logic, memory management, context switching, etc. are all held together with thousand…

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.

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

#63
post #58
post #46

An Angular app with ~50k LOC. Barely any tests and several hand-rolled components, some of which were merged only because the author managed to implore somebody to give them an R+ after a few sprints of the branch just sitting there. A total of 21 people were involved in creating this system and for some insane reason we still had daily standups with almost full attendance.

What's the problem with "hand-rolled components"? Isn't that pretty much the essence of building non-trivial frontend stuff? Or does this have some special meaning in the Angular world?

Not in the case of components which could easily be replaced with a well-tested and proven solution.

Notable among the ones in this project was the date picker - there's a decent number of those available and yet somebody made the decision to hand-roll it.

The result was a mess that for some reason had a 300 LOC service as a part of it. Needless to say minimal tests.

It was a waste of man-days in a project that was already over budget.

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

#64
My own CMS. Here's the function signature of the heart of it, which depending on circumstance may call itself recursively.

    function a_nodes_list_trees(
    	$site_url,
    	$base_url,
    	$mode,
    	$site_id,
    	$max_subtree_depth,
    	$nlevels,
    	$node_id = 0,
    	$tree_id = 0,
    	$nleft = 0,
    	$nright = 0,
    	$nlevel = 0,
    	$current_subtree_depth = 0,
    	$flags = 0,
    	$order = 'tree',
    	$inline = false, /* needed when loading stuff via ajax*/
    	$skipped_types = [],
    	$items_per_page = 10,
    	$min_tag_count = 2,
    	$min_author_count = 2,
    	$is_site_root = false,
    	$skip_pagination = false,
    	$ignore_404 = false,
    	$skip_display_options_and_batch_ops = false,
    	$display_bottom_pagination = true)
As you can tell from the default values, it started out having 6 arguments. And it has things like this in it:

    	$mysql_the_rest = 'FROM
    			'.DBTP.'node n
    				LEFT JOIN
    					'.DBTP.'node n2
    						ON
    							n.tree_id = n2.id
    						AND
    							n2.perm_view & ' . A_PERMS . '
    			'.$mysql_join.'
    		WHERE
    			'.$mysql_where2.'
    			'.$mysql_where.'
    			n.perm_view & ' . A_PERMS . '
    		AND
    			n.site_id = ' . $site_id . '
    		';
    	$total_count = $A->db->fetch_one_column('c', ' SELECT COUNT(*) c '.$mysql_the_rest);
.. you know? The whole CMS is 20k lines of PHP, with HTML, PHP, and MySQL all happily living together in the same files (it's not that I don't have templates, I just have plenty HTML in the PHP, too)

Yet, it works like a charm, PHP updates made it faster even, and I can use it for everything I needed so far, and use its output in a variety of ways. I still want to rewrite it, but it seems a lot of work to just shave off a few ms and have nicer code, with the same result for the visitor, and also having to write something that migrates the content. I suspect with enough content, it will slow down, and then I'll think about the next iteration. But it's still a mixture of pride, plain being happy to have it, and groaning whenever I fix a bug or add a feature.

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

#65

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…

I think it's because software is inherently easier and less critical...castles of shit actually work. Software is fairly unique in that level of quality and reliability needed to have significant economic benefit is very low, and the consequences of system failure are rarely severe. That's not the case in most branches of engineering. The complexity levels are also off the charts, in large part because economic value is so loosely coupled with quality. In many cases more turds are more profitable.

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

#66

My previous job. More than a million lines of code for a glorified CRUD app, with more than a $7 million annual budget. Accruing technical debt was a process feature. More bad code that everyone is afraid to touch means more budget for terrified developers and testers, and insane networked database design means more budget for servers and sysops. The fear leads to meetings, the meetings lead to suffering, and sufferi…

Read that last paragraph in the emperor’s voice from star wars episode 6.

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

#67

Earlier quoted context omitted.

> In my opinion, if it works, and provides the utility it was designed to bring, then it doesn't matter. If it makes money, then who really cares! This makes sense. However, if the code 1) is hard to understand (according to the developers available) and change and 2) needs to be changed, it costs money. Eg, read about the expense banks are now incurring trying to maintain COBOL systems. Whether the code is "bad" is…

Sure, but you're acting under the premise that "if we just did it 'right' the first time, we wouldn't have this mess". What I'm saying is that only under very few circumstances does it ever workout that way. Particularly with long standing systems and their software. It just builds over years, nothing you can really do about it.

> Sure, but you're acting under the premise that "if we just did it 'right' the first time, we wouldn't have this mess".

I think you're right that every long-lived code base will have warts. And I don't think that means that the original builders were wrong-headed.

But if you've got a decades-old system that nobody understands anymore, you've got a huge liability. You can't ship features to compete, you can't fix bugs, you can't comply with new regulations. You can't even rewrite confidently because you don't know what the old system does.

There must be things you can do as a code base ages to keep it maintainable, allow incremental rewrites, etc.

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

#68

As many experienced commenters below have already noted, nearly any piece of substantial, revenue-generating, long-lived code will ascend to a place full of dragons and mysticism. The more interesting debates revolve around: 1) How did it get that way, and what can we learn from that? 2) Is it inevitable that all software will end up like that? 3) How can an organization ever successfully sunset or move to a more mai…

https://www.reuters.com/article/us-usa-banks-cobol/banks-scr... describe banks struggling to maintain ancient COBOL systems as the developers who understand them are dying off.

I don't know exactly what they should have done and when, but it seems like rewrites are going to be necessary, and it sure would be nice to start rewriting a system while you still have someone who can explain what it does.

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

#70

My own CMS. Here's the function signature of the heart of it, which depending on circumstance may call itself recursively. function a_nodes_list_trees( $site_url, $base_url, $mode, $site_id, $max_subtree_depth, $nlevels, $node_id = 0, $tree_id = 0, $nleft = 0, $nright = 0, $nlevel = 0, $current_subtree_depth = 0, $flags = 0, $order = 'tree', $inline = false, /* needed when loading stuff via ajax*/ $skipped_types = []…

I feel your accounts bio perfectly matches the spirit of your posts content here haha!
Post reply on HN