by thamer · 6y ago · 0 comments
I can't say I understand the reason for such massive files. Surely it would be easier to maintain if it was split into a few well-defined modules?
In addition to the maintenance concerns, a JavaScript engine has quite a few parts that could be used as individual components. One good example of this is node's http-parser[1] that was extracted to a self-contained C file with associated headers and is a pleasure to use.
On the other hand, I hate finding a project that looks useful, but then the code is scattered across many files which are barely one screen long, or worse, also spread throughout different deeply nested directories. Regardless of whether the organisation makes sense, navigating directory trees is annoying.
if the LOC is similar in size, i don't see why having them in different files vs same file makes any difference at all.
Also, your IDE should be able to navigate you to definitions and usages etc. If it doesn't, it's not a good IDE. So the problem of understanding code reduces understanding the abstract structure, not how that structure is represented on file.
I don't use an IDE. In fact, I'd say it's a problem if code requires an IDE in order to work on it effectively (Enterprise Java is the most prominent example of this.) I'm nowhere near Bellard level, but would consider myself above average, and have observed that some of the most productive programmers don't either --- and their code is far easier to understand than e.g. the mostly-autogenerated, split-into-many-tiny-files projects created by those far less skilled.
And slippery slope...
I know of automatic renaming, moving parts you select automatically to another file, but full automatic refactoring to multiple modules is something I haven’t seen.
How does this tackle circular dependencies etc. I guess the IDE must parse the code, generate the syntax tree, populate symbol tables etc. and then make the refactoring.
A side point I sometimes dream of writing an emacs module which would let me to write in a single file (for easy search and edit reasons), and then cut it into several modules where I mark them with =======xyz.h========= etc.
I also want to use this in each repo where it automatically does this. I’ll hopefuly stop procrastinating and write the thing one day :).
To end with a Game of Thrones analogy, hearing about the latest developments I sometimes feel like we editor/linux/bsd/cli users are like Wildlings beyond the wall. We live in harsher conditions, but are amazed when we see large cathedrals, castles being built inside the wall. Our life is more free but also burdensome.
Why is this a good thing? The same amount of code and same number of results need to be scanned either way. With many files, you at least have the file name to give you some small amount of context without needing to read the code.
Seeing as Bellard is very prolific and has done more than you me and three others in a lifetime, there must be some merit to his approach.
My best guess is that this is more of a fun project than anything and spending too much time on such concerns would detract from the fun. I do the same with my side projects.
... one third of which is the copyright notice and license, and another third is boilerplate.
This reduces the cognitive load and gives the compiler a way to enforce separation.
In short - files in C can give you namespaces -- which are sometimes a useful way to organize code.
In newer languages like C# you can do the same. Probably works in lots of other languages too, see Rosetta Code: Nested Function:
https://rosettacode.org/wiki/Nested_functionIt could be that his workflow is to always navigate by searching function names. Then it doesn't really matter if the project is 1 file or 1000.
Personally I tend to want to split up code written by others so I can focus on the parts that go together without having to read through irrelevant parts, but I can easily navigate larger files/classes I've authored myself. I mainly split it up for the sake of future readers.
Fun to run into you, Geo!
But I stand by what I said now and nearly a decade ago, and now try to be blunt: Fabrice Bellard didn’t organise quickjs this way because he isn’t as smart as you. He did it because it makes things easier for him to write quickjs and qemu and tcc and ffmpeg and all sorts of other stuff used by all sorts of other people. And if you ever figure out how to learn from watching people who can do things you cannot, I think you could be an amazing programmer.
All the best.
We can only hope Fabrice Bellard reads it all so he can learn himself some coding.
I kinda like large files (vs splitting the code), because they are easier to navigate in vim. I have no idea about why the choice was made for QuickJS, aside from ease of inclusion into other projects, mentioned in the docs.