Ask HN: Alternatives to organizing code in files and folders?
I realize I spend a lot of time organizing code into files and folders. And usually, it's organizing packages, modules, functions and classes into matching files/folders, and then updating package/module import statements. That is, it's simply a chore.
A barrier to change is our current tools such as IDEs and VCS/Github are tightly tied to the files and folders paradigm.
Though, every tool that doesn't map 1-1 with the filesystem I have always hated the experience. Think: XCode, Visual Studio. But maybe it just hasn't been done right.
What are your thoughts on alternatives? Drawbacks to change?
23 comments
[ 4.3 ms ] story [ 67.8 ms ] threadI wonder if there is already a modern tool/suite for Node/Python inspired by Smalltalk...
There is LivelyKernel [2] but some versions are more file-oriented (like Lively 4 [3])
[1] https://pharo.org/
[2] https://lively-kernel.org/
[3] https://lively-kernel.org/lively4/lively4-jens/start.html
Interesting. Just made me think of using a custom filesystem to navigate a codebase. Similar to: https://github.com/osnr/TabFS. I wonder if anyone has done this.
Hierarchical structure has been criticized a lot in recent years, and rightly so as for the naive view which insists that there is One Right Way to categorize things. But the not-so naive view acknowledges that any hierarchy is artificial and ultimately arbitrary, while it at the same time asserts that it can also be useful. Think of a library: which one is more useful to your most frequent use cases, one that keeps books ordered in divisions and subdivisions of subjects on the shelves, or one that keeps books in random order? I think it is the first. You'll still need one or more catalogs and one can still debate where that book on maths for the engineer goes (maths, engineering, or text books); that doesn't mean the hierarchy of the books on the shelves is useless.
When I need one of these packages, I search Google, and typically read their API on Github. I never navigate a hierarchy to find them.
When we make our own code flat, we have problems because we don't have an easy way to search. Another argument would be that hierarchies can help contain dependencies - i.e. don't depend on code outside of a directory.
> that doesn't mean the hierarchy of the books on the shelves is useless
I just think the hierarchy should be virtual/automatic, and the focus should be on tracking dependencies between components. I think very few people would look at dependency graphs of their codebase...there's just not good tools.
As long as the code is easy to find and doesn't have similar naming as other code you should be good to organize however you want. If you work on a team then make some decisions as a team on how to organize files. I work with Rails which has an opinionated view on folder/file structure which is great because I don't have to spend time thinking about it and can focus on getting things done.
While they are based on the same concept, putting things inside of things (in hierarchies) is a pretty solid way of sorting stuff.
There are other ways as well, such as labels/tags. But regardless of technology I feel like folders (in one way or another) is one of the tools you would reach for.
Were you thinking of this Monty Python skit when you wrote that?
https://youtu.be/LFrdqQZ8FFc
I think folders and sub folders makes sense for run times and IDE’s to “know where to look”.
Yeh this seems to be the primary problem. You would basically use uuids and end up with your files in a sort of database.
I think this often scares people because they don't know where something definitively lives anymore...and you rely on a tool to access your stuff.
Some people actually prefer a definitive location for things...in order to build a mental map to come back to things. When I am coding I know where to find things quickly based on the shape of the folder structures I browse. Folders just seem natural with many analogies to the physical world...whereas graph clouds such is with tagging are rare.
But I think we must remember that the file system is essentially a database with a tool that one relies on to access the underlying bytes on disk.
If some alternate reality existed, based on some other data structure / schema... I guess some other set of tools and workflows would be needed to find and move whatever the new name for blobs of bytes (files) would be...
If every exported variable or function was in a separate file, that would eliminate most of my problems. But it’s just a pain to write code that way…
I wonder if something that automatically organises your code into separate files would help...and fixes all the imports for you. A cli tool that would _lint/autofix_ your code organization. And then you would just need:
- IDE plugin (VSCode, IntelliJ) to show an organized IDE file tree
- cli tool to allow browsing organized code from terminal
- perhaps a custom fs for viewing your project in Finder/terminal and easily browsing in other tools
- git wrapper to show correct file names in diff/status
- chrome extension for Github to show flat files in a structured way
- auto-generated file names are gross. - 50+ imports in each file with bogus file names is gross
The FileSystem itself is a gross way to organize code after all.
I may want to organize my code in multiple different overlapping views. I may want to organize by behavior (state, actions, etc) or by feature (login, comment, etc).
My suggestion is an IDE that hides files from the user entirely. Something a little more akin to SmallTalk.
They do it by auto renaming and something else.
0. http://cs-www.cs.yale.edu/homes/freeman/lifestreams.html
It is an interesting exercise, and with a good typesystem it can go a long way.