Live data from Hacker News

A project with a single 11,000-line code file

austinhenley.com

261–270 of 346 posts

Re: A project with a single 11,000-line code file

#261
post #253

Earlier quoted context omitted.

Restaurant industry version: I was so afraid to cook in a dirty kitchen, I ended up not cooking at all. This thread made me realize that's better to sell food prepared on dirty surfaces with unrefrigerated ingredientes half-eaten by rodents and roaches that makes people sick, than fresh food prepared on clean surfaces with clean utensils. I'm glad I read this. This is a restaurant worker story. Construction industry…

If you're writing code that controls radiation therapy machines or trains or autoclaves or something, yah, maybe there should be some regulation and potential jail time for negligence. But 95% of all software written ( especially if it's the first version of new software) isn't life or death. If the next social media startup or saas-for-painters is spaghetti code it's not going to hurt anyone. Failure is cheap in our…

[deleted]

Re: A project with a single 11,000-line code file

#262
post #110
post #29

The payroll check printer for my employer was once a couple thousand lines that generated raw PCL to be sent to a LaserJet that used magnetic toner to produce checks that had a working MICR number. It was rendered into spaghetti by multiple GOTOs that jumped to helpful labels like "666", and calls into other helper programs to generate more PCL that did things like change fonts and draw graphics. Of course none of it…

Reading your process I have that stereotypical TV series image in my mind of a person so deep into the subject matter that plaster every wall with notes and pull string all across the room at head height to hang up ever more notes kinda like that one NCIS episode (S8 E6 "Cracked"): https://img.sharetv.com/shows/episodes/standard/616591.jpg (although that image is only a small part of that whole view).

We call that a Murder Board in my office.

Here's a TV Tropes article on the cliche: https://tvtropes.org/pmwiki/pmwiki.php/Main/StringTheory

Re: A project with a single 11,000-line code file

#263

So afraid to write bad, spaghetti code, I ended up writing no code at all. This thread made me realize that it's better to have a working profitable project with bad code, than a perfect unfinished project, with meticulously chosen design patterns. Afraid of being judged for bad code, I could not start until I had the right architecture. I'm glad I read this. This is developers therapy.

happy medium: write shitty code with strong API boundaries. at least the damage is localized and every so often you can go back and clean up or replace components independently. or more likely, just leave it that way and make more poorly implemented features that make money.

Re: A project with a single 11,000-line code file

#264
post #55

I learned that not all text editors go to the effort of loading the file data very carefully with careful underlying data structures when I tried to open a 67K LOC COBOL file on a 32bit system, a while back. (Sidenote: COBOL has a 999,999 LOC hard limit in the compiler spec.) So very many editors just couldn't open it. Some would use so much memory that the system would either freeze, or the OS would kill them. Some…

What editors ended up working?

Re: A project with a single 11,000-line code file

#265
I worked at a large ecommerce company on their Android app. I was tasked with using the Sonar tool to analyze the source code of their app. A bad cyclomatic complexity is 30, at which point it is difficult for an experienced engineer to follow the code paths.

There was a file in that source that had over 900 cyclomatic complexity.

The reason was that at that point Android had a limit on their method count. Called the dex limit. You could only have 64k methods, before multidex was introduced.

The engineers couldn't add more methods, so they had to jam code into existing methods. No DRY. No refactoring.

It was fucking impossible to understand at the code level. You had to just use the app for years to understand it.

That analysis got a bunch of us targeted by the senior developers because it made them look bad. They fired multiple people, including me, who pointed this out. We said it made it impossible for new engineers on the project to succeed, and the incumbents didn't want that to be known, less they lose their bonuses.

Re: A project with a single 11,000-line code file

#266

Earlier quoted context omitted.

Maybe it's the editors that need updating. It would be pretty neat to have the chunks of functions / namespaces model as lots of tiny separate files on the disk, but a sort of view-layer so that you can view all the related ones in one virtual file. You could even then have multiple virtual files that include the same raw files. For example in a video game your player, monsters, health potions, and attacks could all…

Look up "class browser", in particular "smalltalk class browser" to see examples, current and historic, of editors supporting that kind of approach to navigating codebases.

Something like this https://tibleiz.net/code-browser/ maybe?

Re: A project with a single 11,000-line code file

#267

I worked on Word for years. Office has thousands of files over 10,000 lines with, uh, various degrees of test coverage and comprehensibility. After some time and experience, your mental model of the architecture ends up being way more important than simple metrics on source code organization. IMO, organizing source code in files seems archaic. E.g. tracing the history of a function moved across files can be tedious e…

Give https://www.unison-lang.org/learn/tour/ a read. The Unison language stores code as hashed syntax trees.

Re: A project with a single 11,000-line code file

#268

Earlier quoted context omitted.

Try debugging a single 10k loc file versus fifty small modules where each takes care of a distinct part of the logic.

As someone who did a bit of enterprise Java, I much prefer the former. Jumping around between lots of tiny files and not being able to see where the actual work happens because it's spread everywhere is a debugging nightmare.

I think you need a better IDE.

Re: A project with a single 11,000-line code file

#269
post #29

The payroll check printer for my employer was once a couple thousand lines that generated raw PCL to be sent to a LaserJet that used magnetic toner to produce checks that had a working MICR number. It was rendered into spaghetti by multiple GOTOs that jumped to helpful labels like "666", and calls into other helper programs to generate more PCL that did things like change fonts and draw graphics. Of course none of it…

I went through something similarly during my PhD when my advisor printed the main code of the program that we were going to work on. At first I thought he was kidding (he's a very chill guy) but... Heck, after a few hours of "paper debugging" we discovered a lot of nasty issues, got new ideas and found redundant and spaghetti code that we didn't find when we debugged digitally (obviously, we were not a team of CS students/coders. Just a bunch of chemists kinda newbies to coding). It was a really useful and funny approach.

Re: A project with a single 11,000-line code file

#270
10 years back when I was first starting my company, we wanted to build a phone IVR system with Twilio to book tables at restaurants. It was fairly complex; it to track many different aspects of call state, including client being able to enter things like date/time/party size etc. with push-dial, and call our internal APIs. I assigned a recent college grad to the task.

In a week, she came back and said "OK I've finished the prototype." I thought no way and I asked her to demo. Try X, try Y, try X + Y, etc. -- it all worked.

Then I looked at the code.

She had written the API handler as a one gigantic function, presumably because Twilio gives you a single API callback on an incoming call. It was a maze of nested if-statements going 10+ levels deep, subroutines relentlessly copy-pasted inline throughout the whole thing. Then she manually tested by dialing the phone 100s of times, putting in hacks throughout the if-tree.

Her prototype ended up being pretty easy to refactor and was ultimately the basis (at least logic-wise) of what we put into production.

Post reply on HN