Live data from Hacker News

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

austinhenley.com

211–220 of 346 posts

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

#211
post #115
post #84

Earlier quoted context omitted.

+1 I had a lot of trouble trying to explain this to juniors. The most important things is to have code that is easy to refactor when you know what you're doing (i.e. everything is working properly). Juniors I worked with had a nasty definition of a pretty code being split into a hundred files, each no longer than a screen, and each function no longer than 5 lines. The onboarding of new devs to such code was way worse…

"Flat is better than nested" - The Zen of Python I had an "everything should be broken into a hierarchy!" stage back when I was learning to code, and boy was I off track. In my defense, at the time (and this dates me) OOP was all the rage.

I find OOP spaghetti can be incredibly difficult to navigate, example: Class hierarchies 4 or 5 layers deep, some subclasses overriding the parent, others not. It can be it very difficult to follow what's actually going on.

Procedural spaghetti is more manageable, though I once had to update a C app with a 3000 line case statement. Pure madness.

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

#213
post #98

Earlier quoted context omitted.

I don’t think this dichotomy is helpful. I’m presently working at a startup that’s trying to dig itself out of a hole created by the first CTO, who in doing things “quickly” created an MVP so buggy, inefficient, crash-prone, and unmaintainable that we can’t retain customers or engineers. As always, there’s a balance to be struck, and ways to operate quickly that don’t sacrifice quality too much.

I'm kind of surprised that you can't find engineers interested in creating a new implementation of an existing application that is actually used by people. I think that might be my dream role.

Business doesn’t want us to stop the bus to change the tires - or spend so much time changing tires that the bus never reaches the destination.

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

#214
post #165

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…

What's an alternative to files that doesn't just have all the same attributes of files anyway? If it involves breaking code into multiple chunks of related functions, and possibly having these chunks act as namespaces, that sounds like what a file does.

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 have the code for HealthComponent as a part of their virtual file. And updating the HealthComponent would affect the raw file so the virtual files would have the updates automatically. Yeah you can open dozens of editor tabs or always use jump-to-definition, but just being able to scroll around or ctrl+f within a restricted set of limited files would be nice.

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

#215

I remember many years ago coming across a reimplementation of the server side for a popular MMORPG of the time, reverse-engineered from the client (which was Flash) by what was likely a teenager --- it was over 100k lines in a single file, written in Visual Basic. Global variables everywhere, short names, and not even indentation. All the account data was stored in flat files, there was no actual DB. No "best practic…

Ironically, this is a description of hacker news itself. https://github.com/shawwn/arc/blob/arc3.1/news.arc (HN has indentation, though.) It’s important to realize that this is good design. It’s hard to separate yourself from the time you live in, but the rewards are worthwhile.

This is amazing. Is there a syntax highlighting and linter kind of things for the "Arc" language? If it's possible, I would like to try that. I love how Lisp looks like.

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

#216
I always start a new project with all code in a single file then only split it out when I feel I gain more than I lose. Judgment call, and a tad subjective.

One factor in favor of mono-file is its often easier to navigate around fast and do search/replace in a single file then across many. Believe me, I understand all the benefits of mutiple files too -- not my first rodeo -- but under right conditions not always a sin to have a "fat" file.

generally after a project has left its prototype stage and become more of a stable thing, primarily under maintenance, it should certainly be split out into smaller files with sensible module boundaries. Best in long term, and plays with version control better, and large teams doing concurrent mutations on the source tree.

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

#217

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…

Your analogy is flawed. The CPU doesn't care at all about how or what code looks like, all the nice comments explaining what it does, nice naming conventions, whether its easy to understand or not. They have zero impact on the final compiled code. The executable ends up as a spaghetti of machine instructions with countless gotos in a single large file. Using bad ingredients in food, or poor quality materials in const…

No post body was provided.

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

#218

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.

I am part of a small team that maintains a legacy point of sale system that is still used by thousands of stores around the world. It started life as a DOS application written in C with some ASM bits, and has since accumulated some C++ and C#. There are functions over 5000 lines long. Files over 50000. Global all over the place. It can be a challenge sometimes, but after almost 30 years, it still brings in millions of dollars a year in maintenance and enhancements, and still processes millions of transactions for those retailers.

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

#219
My $DAYJOB task this week is beginning the process of splitting up a 14554 line C++ file. It's basically the implementation of a single class, but by way of comparison, the header file is only 743 lines, so there's a lot of code in some of those methods.

It'd be pretty unmanageable without Visual Assist (a plugin for Visual Studio that does fairly fast searching for symbols and files).

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

#220
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).

A printout of a one-file spaghetti code with gotos is the only case where I can imagine that trope of the wall of connected strings actually being a useful tool.
Post reply on HN