Hacker News new | past | comments | ask | show | jobs | submit login

Sure it lives a single file, but considering the length, wouldn't it actually be better to split it into multiple files? I'm not that familiar with C, it seems to be a "thing" in C to just have giant files.



I've been thinking about this a lot recently. For most of my career I've been a Java programmer and for the majority of projects, each class is put in its own file. The amount of jumping (between files / following method calls) can get really tedious when you're trying to grok a code base. I've been working on Typescript projects recently where the standard has been to have slightly larger files -- possibly containing a class definition, but more often it's an entire module -- and it's actually been kind of nice to just read the entire thing top to bottom in one go. I've looked for studies on "locality" of source code, but haven't really found anything.


Yes, it can be really jarring to have to constantly move between several small files.

I mostly use C#, and a while back I settled on a middle ground, where closely-related classes and interfaces are grouped together in a single file.

When I'm working on web apps/APIs, I usually follow the "feature folder" concept too, where all the most central parts are together in the same file.


SQLite is actually maintained in many files, but they are concatenated into one file for distribution. Here is the reasoning: https://sqlite.org/amalgamation.html




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: