Live data from Hacker News

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

austinhenley.com

231–240 of 346 posts

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

#231

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

The world runs on software like that. Hard to maintain “crappy” code that makes $ beats clean pure “perfect” code that makes zero $ every time.

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

#232

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…

Circa 2006, I was in college, and I got hired to write a webapp for a college department. I didn't know JavaScript could have classes and capture variables, so I made the app with entirely global variables and plain functions combined with `eval`. It's over 2000 lines, and nobody after me could understand it.

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

#233

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.

Looks totally fine to me. I'd say it is written very well.

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

#234
The size of a code file doesn’t matter. What matters is the amount of state the code in the file manipulates. For example, a 100k line code file with 500 pure functions not using any global state is fine. It is simple. However a 100k line code file with 500 functions that all manipulate 1000+ global variables is extremely complex and hard to maintain because of the undocumented global state invariants and hidden side effects.

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

#235

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.

The Player controller from the game Celeste is a single 5600 line file that includes things like systems only used in the tutorial. I honestly don't think it's as bad as some of the criticism it got when the code was released makes it seem, but it certainly could be better looking code. But ultimately, Maddy Thorson isn't selling a block of code. They're selling a game and it has extremely satisfying control of the c…

I remember sharing that Player.cs code from Celeste in the gamedev subreddit, and getting all kinds of weird novice comments about how the code doesn't adhere to 'OOP Principles' or 'there isn't any unit tests' or 'you should split it into multiple files with 100 lines each' or 'you should use an ECS to make a real game'.

Laster on Noel Berry did give a response explaining the various design choices behind their code:

https://github.com/NoelFB/Celeste/tree/master/Source/Player

Anyways, kudos to the team sharing their code even if it's a bit messy.

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

#236

Earlier quoted context omitted.

The sad reality of tech companies is that there is little incentive or bonuses for improving the situation. You won't get a bonus for cleaning up the code or for rewriting rotten code. Hack at the code for 4 years, collect your options and leave the mess to someone else. To be honest, a hacky codebase written fast is not the worst codebase to deal with. The worst type is when someone had the time to overarchitect and…

> The worst type is when someone had the time to overarchitect and overengineer things. I concur. Refactoring should be as much about removing unneeded abstraction and features as it is about adding same. > there is little incentive or bonuses for improving the situation. Yeah, I just can't seem to believe this in my soul. I just want to fix ugly code and can't stop myself. I get huge satisfaction from speeding up, t…

Just do it. Don’t ask for permission. You will end up more productive not less.

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

#237

I've refactored monolithic code several times in my career. It starts with a thorough going-over, making notes, identifying the state machines and drawing what was handled and what was not. Then, reimplement as a simple state machine but this time, fill in all the transitions (event+state => new state + action) One was an Infiniband code base from the vendor - a 'computer scientist' had written several layers to do w…

I like your approach. Having a clear understanding that all software is just state machines is a great way to solve hard problems.

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

#238

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.

let me recommend one of my favourite programming blog posts: https://prog21.dadgum.com/21.html

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

#239

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.

Getting something working and out there is 90% of the battle, especially on small or single person teams. I wrote a saas php app with vanilla html and JS that ran without issue for 8.5 years for a fortune 1000 company. About twice a year I would return to it to add or modify a feature and I had no idea how a lot of it worked and even had duplicated or redundant files that I was too afraid to delete. It worked though and I got paid every month for a very long time. Sometimes delivering a product is all it takes and getting trapped in delivering 'clean' code is just a blocker. Not often, but sometimes :)

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

#240

Earlier quoted context omitted.

Indeed there is. I've been using this vim plugin for over a decade: https://www.vim.org/scripts/script.php?script_id=2720 Which IDE do you like? I'll see about getting some highlighting for it. As for actually running arc, it’s hard to run the original arc3.1 due to racket updates. I’ve made a few branches over the years that try to preserve the original spirit of arc (no significant changes) while making it easy to…

I use Visual studio code, I couldn't find it in Extensions. I'm just asking out of curiosity, What do you develop with Arc usually? I like how the "html" and "css" part was embedded in that "news.arc" file. Do you think that VIM script will highlight and lint the "css" part of an "arc" file?

> What do you develop with Arc usually?

I try to use Arc for as much as possible. We wrote our TPU monitoring software in it: http://tensorfork.com/tpus

Eventually I became frustrated with Racket's FFI. So I eventually made my own arclike language called elflang: https://github.com/elflang/elf

... which itself is a fork of Lumen (https://github.com/sctb/lumen) by Scott Bell.

The performance is good enough to run a minecraft-style game engine: https://i.imgur.com/iyr0YrB.png which was satisfying.

Nowadays I've been trying to implement Bel, mostly for the challenge of it than for any practical reason.

> I like how the "html" and "css" part was embedded in that "news.arc" file. Do you think that VIM script will highlight and lint the "css" part of an "arc" file?

Nope. https://i.imgur.com/o9aUG6j.png

But it has one very important feature: it can properly highlight atstrings: https://i.imgur.com/wO4f742.png

It's probably hard to tell, but the "@(hexrep border-color*)" would normally be highlighted as if it were a string. Arc has a feature called atstrings, where you can use @foo to reference the enclosing variable "foo". It can also call functions, e.g. "The value of 1 plus 2 is @(+ 1 2)" will become "The value of 1 plus 2 is 3".

Post reply on HN