News for hackers. Stuff that matters.
Re:A project with a single 11,000-line code file by userbinator on Sunday April 03, 2022 @05:02PM (#30900614)
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 practices" at all. Yet, not surprisingly, it worked pretty well and was actually not difficult to modify --- Ctrl+F would easily get you to the right place in the code.

I guess the moral is, never underestimate what determination and creativity can do, and always be skeptical when someone says there's only one best way to do something.

Re:A project with a single 11,000-line code file by sillysaurusx on Sunday April 03, 2022 @05:21PM (#30900789)
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.

Re:A project with a single 11,000-line code file by gfunk911 on Sunday April 03, 2022 @06:32PM (#30901396)
This is a good point, but there's also a key difference.

There's a big difference between "code being in one file" and "code being in one function." It sounds like the OP had something reasonably close to "one function," whereas the HN code has a lot of (what appear to be) small well designed methods.

Re:A project with a single 11,000-line code file by saila on Sunday April 03, 2022 @08:31PM (#30902228)
I'm not seeing the irony. The file you linked to is only ~2600 lines of code and seems to be well-modularized and fairly well commented. Assuming that's the whole site, I think that's pretty reasonable.
Re:A project with a single 11,000-line code file by exdsq on Sunday April 03, 2022 @06:20PM (#30901308)
The only readability issue I have with that is the functions expected arguments. Add some types and I’d be very happy to work on it. I believe Facebook uses a single directory of files now as best practice? With the file names including namespaces. That was an HN comment from ages ago so could be wrong or misinterpreted.
Re:A project with a single 11,000-line code file by sillysaurusx on Sunday April 03, 2022 @06:44PM (#30901499)
pg's new lisp, Bel, has something close to typed arguments:

  (def add1 (x|int)
    (+ x 1))
http://www.paulgraham.com/bel.html

I've been implementing it for a couple years now, though not seriously till the past couple months. There are some interesting (and overlooked) ideas in Bel.

Bel is sort of the limit case of generality. For example, you might expect the "type" above to be a separate kind of object, the way that types are separate kinds of things in TypeScript.

But in fact, it's simply a function that receives the argument and can throw an error. So for example, you can do something like:

  (def positive (x)
    (if (< x 0) (err 'negative) x))

  (def sqrt (x|positive)
     ...)
I just wish he'd solved keyword arguments as thoroughly as every other kind of argument. There are hints that it was always in the back of his mind. Though it's true he never needed them, so that's probably why he never made them.
Re:A project with a single 11,000-line code file by exdsq on Sunday April 03, 2022 @07:33PM (#30901853)
It's nice to have invariants - I believe I've seen them in Rackets contracts but I'm a little away from that stuff in my Lisp journey :)
Re:A project with a single 11,000-line code file by CornCobs on Monday April 04, 2022 @12:37AM (#30903342)
That doesn't really allow for type checking which is a major purpose of types. It's more of just some nice sugar for runtime assertions
Re:A project with a single 11,000-line code file by klibertp on Monday April 04, 2022 @08:50AM (#30906010)
Well, you can interpret the predicate function body as a set of constraints on the type. Of course, such predicate function would need to be restricted to what your type system can handle. Typed Racket does this, by allowing you to implement type refinements[1]. As long as the predicate only uses operations listed there, it can be used for type checking. Idris also lets you write functions that operate on types and that are used for type checking.

[1] https://docs.racket-lang.org/ts-reference/Experimental_Featu...

Re:A project with a single 11,000-line code file by lupire on Sunday April 03, 2022 @06:14PM (#30901248)
2600lines is not 100k lines.
Re:A project with a single 11,000-line code file by fatih-erikli on Sunday April 03, 2022 @08:05PM (#30902065)
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 by sillysaurusx on Sunday April 03, 2022 @08:22PM (#30902175)
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 run. Try this one:

https://github.com/tensorfork/tlarc

I believe you can simply install racket, then run make && bin/arc and be dropped into a repl. From there you can follow the arc tutorial, whose link I’ll dig up after I’m finished driving home.

EDIT: That fork is actually a lot different from arc3.1 proper. I’ll try to locate a more faithful one.

EDIT 2: Unfortunately it's quite a lot of work to remove the mzscheme dependency from the old arc3.1 codebase. And I'm not sure it's even possible to install the mzscheme lib on the latest racket (e.g. `brew install racket` doesn't seem to have it).

So the above instructions are the best I can do for now.

Re:A project with a single 11,000-line code file by fatih-erikli on Sunday April 03, 2022 @08:26PM (#30902200)
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?

Re:A project with a single 11,000-line code file by sillysaurusx on Sunday April 03, 2022 @09:18PM (#30902479)
> 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".

Re:A project with a single 11,000-line code file by FpUser on Sunday April 03, 2022 @08:55PM (#30902350)
Looks totally fine to me. I'd say it is written very well.
Re:A project with a single 11,000-line code file by KSPAtlas on Monday April 04, 2022 @03:54PM (#30911266)
Wait, hn is written in Lisp?
Re:A project with a single 11,000-line code file by gofreddygo on Sunday April 03, 2022 @05:19PM (#30900775)
Funnily enough, I have recently had great success by reversing the "best practices" on a distributed "micro services" architecture application into a single big Java file.

Best practices were the usual suspects DRY, IOC, SQL + NoSQL, separation of concerns, config files over code, composition over inheritance, unexplainable overlapping annotations, dozens of oversimplified components doing their own thing, and some $something_someone_read_on_a_medium_post

The Single Java File was around 500 lines no db, lots of globals, a dozen or so classes and some interfaces, Threads for simulating event based concurrency, generous use of Java queues and stacks but i specifically made it static with Zero dynamic hashmaps.

It actually runs in my IDE, I can understand what the hell the product is supposed to do what component is doing more than it should and more valuable was to predict what could break if I change that value in the helm chart from 5.0 to 5.1.

It is quite useful and pleasing, I can actually reason about things and I have new found use and appreciation for Type Systems and compile errors. And I can write tests that run in under 3seconds.

Re:A project with a single 11,000-line code file by teaearlgraycold on Sunday April 03, 2022 @05:34PM (#30900911)
Having the whole project actually in one project is critical. I think some of these “best practices” are actually very useful when applied with caution. But you sometimes need to break the rules. Everything should be optimized for developer convenience. Convenience in deployment. Convenience in debugging. Convenience in refactoring. Only do what HN and FAANG says is “right” when you need to.
Re:A project with a single 11,000-line code file by KwisaksHaderach on Monday April 04, 2022 @01:35AM (#30903587)
This application must be really really simple ;), so no database?
Re:A project with a single 11,000-line code file by smaudet on Monday April 04, 2022 @01:15PM (#30909238)
You'd be surprised the garbage overhead brings into an app architecture...

These best practices really only make sense in large organizations, i.e. Conways law.

After all, you can't really ask 100 developers to all add code to one file in a couple weeks - they will spend a month or so just resolving conflicts...

100 file repos are designed so that 100 developers can edit them (in theory), and have relatively few conflicts, not because its better code.

As another anecdote, I find whenever I do solo code I can easily spin out thousands of lines of code within a week (includes testing), when doing code on a project with many other devs my rate drops into the range of maybe 200 a week, just because so much time is spent interlinking other code, finding fixing bugs and tests strewn across many files...

Re:A project with a single 11,000-line code file by gofreddygo on Monday April 04, 2022 @11:09AM (#30907551)
No and no.
Re:A project with a single 11,000-line code file by tokamak-teapot on Sunday April 03, 2022 @05:23PM (#30900809)
Presumably VB.NET? Because the VB6 IDE wouldn’t let you write more than 65534 lines [1]. Don’t ask how I discovered this.

[1] https://docs.microsoft.com/en-us/previous-versions/visualstu...

Re:A project with a single 11,000-line code file by vsareto on Sunday April 03, 2022 @06:51PM (#30901554)
>Don’t ask how I discovered this.

Like most of the world at one point, it ran on Excel 2003

/s

Re:A project with a single 11,000-line code file by Forge36 on Sunday April 03, 2022 @05:48PM (#30901052)
I too learned this lesson the hard way.
Re:A project with a single 11,000-line code file by cbanek on Monday April 04, 2022 @03:25AM (#30904107)
Came here looking for this. <3
Re:A project with a single 11,000-line code file by formerly_proven on Sunday April 03, 2022 @05:49PM (#30901060)
It always seemed surprising to me how some of the big Oblivion and Skyrim mods would get by with fairly few bugs despite there being no way to have automated tests and some of them having 10k lines of scripting (or much more in some cases) spread around dozens or hundreds of quests (quests in the CE engine are not just the quests you as a player see, but also a huge number of invisible quests because quest state machines and associated scripting is how scripting works).
Re:A project with a single 11,000-line code file by theobeers on Sunday April 03, 2022 @06:19PM (#30901293)
I think it makes sense. Modders get a kind of obsessive testing from their communities (including themselves) that devs in most commercial contexts couldn’t dream of. Skyrim mods are, if anything, correcting for bugs in the game.
Re:A project with a single 11,000-line code file by pnt12 on Monday April 04, 2022 @09:06AM (#30906165)
For a single modder, it may have to do with being a single developer, working on it over a long period of time and being a passion project.

For a while, I was the only developer working in a small module of a bigger project: I started the code base, discussed requirements with clients, implemented the needed features, tested the whole product end to end. I developed a very good instinct about it and about what any change would do, much better than any other project. My theory is that the code base matched my way of thinking, so thinking about it was pretty easy.

Re:A project with a single 11,000-line code file by smaudet on Monday April 04, 2022 @01:56PM (#30909823)
Fewer (in charge) developers makes for a more stable product - even open source products fair better when they have a long term maintainer versus ownership changes frequently.

The other thing is style - when used well, state machines don't require testing. There's nothing to test - either your machine works or it doesn't, there is no point testing state transitions because that is the fundamental job of the state machine. You may as well test that addition works.

Ofc, they must be used well - problems may be difficult or overly complex to model as a state machine or even set of state machines - the pattern excels for small problems, less for large ones.

Re:A project with a single 11,000-line code file by MauroIksem on Monday April 04, 2022 @12:56PM (#30908963)
This description has been life the last 4 years.
Re:A project with a single 11,000-line code file by Breza on Tuesday April 12, 2022 @10:29AM (#31003228)
What are you working on?
Re:A project with a single 11,000-line code file by lenkite on Wednesday April 06, 2022 @04:58AM (#30929955)
I have observed that bugs tend to be introduced when you have more than one person working on a project. Single person projects have very low bugs especially if the coder is experienced and follows simplicity + structured programming.
Re:A project with a single 11,000-line code file by wefarrell on Sunday April 03, 2022 @05:23PM (#30900800)
You can get away with a lot on a single developer project and best practices aren’t in place solely to make code functional.

That application would likely fall apart if multiple developers of with diverse backgrounds had to maintain it and add new features.

Re:A project with a single 11,000-line code file by userbinator on Sunday April 03, 2022 @05:38PM (#30900941)
I don't know what you mean exactly by "diverse backgrounds" and it doesn't matter in this case either, because there were definitely multiple people working on it (although the initial version was the work of one.) They effectively used a forum thread as source control, and just attached their modified versions to the posts.
Re:A project with a single 11,000-line code file by suifbwish on Sunday April 03, 2022 @05:45PM (#30901024)
To be fair even with using best practices, code can still fall apart with multiple developers from diverse backgrounds.
Re:A project with a single 11,000-line code file by Dudeman112 on Monday April 04, 2022 @04:39AM (#30904481)
The conclusion, of course, being that if you need multiple developers the code is less likely to fall apart if they have similar backgrounds ;)
Re:A project with a single 11,000-line code file by KwisaksHaderach on Monday April 04, 2022 @01:39AM (#30903604)
Re:A project with a single 11,000-line code file by juancampa on Monday April 04, 2022 @10:58AM (#30907410)
Came to say this. I actually find QuickJS pretty easy to understand and modify, in part because everything is one file and it's easy to search, using vim's `#` and `*` keys, for example.

When working on projects by myself, I like putting everything in one big file too. Trying to find the "right" place for something is some unnecessary overhead, not to mention the navigation cost. It's a different story when a team is involved though.

Re:A project with a single 11,000-line code file by yoursunny on Sunday April 03, 2022 @08:47PM (#30902311)
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 by rezonant on Sunday April 03, 2022 @07:43PM (#30901901)
I suspect the game was Runescape. My brother used to be a fan of these custom servers.
Re:A project with a single 11,000-line code file by RTFM_PLEASE on Sunday April 03, 2022 @09:39PM (#30902566)
A likely guess, although RuneScape isn't Flash based (Java & RuneScript).
Re:A project with a single 11,000-line code file by rezonant on Monday April 04, 2022 @05:55AM (#30904847)
Oh right.
Re:A project with a single 11,000-line code file by elvennn on Monday April 04, 2022 @06:47AM (#30905107)
I think the game is Dofus, a French MMO ;)
Re:A project with a single 11,000-line code file by swayvil on Sunday April 03, 2022 @05:24PM (#30900814)
Ah, that takes me back. Commodore 64 freeware games written in Basic.

Ya, you could just go in there and mess with the code all over the place.

Re:A project with a single 11,000-line code file by weq on Tuesday April 05, 2022 @02:18AM (#30915841)
me when i look back at the code i pumped at as a 15yr old writing a java servlet web app that could admin a quake1 tf server game