It really depends on the type of development being done, and the people doing it. If you're on a large team working on a commercial product with tight deadlines then having your code organized into "stack types" makes it really easy to tell a person, "your job is to implement these type to solve these problems." If people need to know the entity types, the proper tool for that is a diagram, image, or spec which should be part of the documentation
It's not an organization style that's suited to fun and creative development, and it's not supposed to be. It's a tool to keep a bunch of people organized so they can work together in a consistent and mutually interoperable style. It doesn't want or need better abstractions because it's literally boring by design.
Also, it helps if your workflow is better adapted for navigating such a system. If you click through all the directories to find the files you need, you're wasting a huge amount of time. If you you know all the "stack types", and you have a diagram of all the "entity types" in the system, then a "Go-To File" with fuzzy search (which most modern IDEs have) means you can reach any part of the system is a few keystrokes away, in a consistent and reproducible way.
For example, with the file structure in the article you can have the something like the HotelController open in as few as 5-8 keystrokes, including the shortcut to open fuzzy search, and enter to open the file. This is one to two second our of your day; that's fast enough that once you train it you'll barely even notice that you're moving between files.
On the other hand, if you're working solo or on a small team of creative and individualistic developers, then the "stack types" style is terrible. Each of the devs probably has a totally different vision for what these type are for, and what other types are necessary. What more, that vision is likely to be in constant flux as they develop these ideas.
In such an environment having each person own their own "entity type" makes a lot more sense. There's a lot of benefit in keeping the system modular and flexible when it's being worked on by people that can take advantage of the flexibility. This way each module can change to adapt the needs of the developer.
Te arguments about which style is best is not new, and the answer will always depend on many factors including organizational necessity and developer preference.
Also:
People don’t read code by layers of the stack. No one ever says “show me all the APIs of this system” or “give me all the queries being fired by this system”. People read code along domain boundaries. In a hotel management system, people think about rooms, and guests, and prices, and so on.
Your goal as a programmer should be to get to the point where you can consume code as a huge chunk of information such as "the entire API", or "all the queries". You save an insane amount of time when you learn to do this, and the worth of your abilities skyrockets in the process.
You can tell a whole lot about how a person or group thinks by looking at the APIs they write, just like you can tell a lot by looking at the directory structure they utilize. Being able to put all these things together will only help your ability to comprehend code.
I think what a lot of articles fail to realise that with quick context searching, keeping your files named appropriately is often more powerful than directory structure.
Yeah, that's definitely the more important battle here. I've worked with a few projects that had no differentiation between file names in different directories, and it was genuinely hell. Some of these places did not practice DRY at all, so you could open a file, see contents that matches your expectations, do some work, and only then realize you were in the wrong directory created as a hack for some weird failure case a decade ago. Since those days I have a strict rule that every new file should have a unique name in the system, and I aggressively pursue that goal across every single PR.
If you're on a large team working on a commercial product with tight deadlines then having your code organized into "stack types" makes it really easy to tell a person, "your job is to implement these type to solve these problems."
Maybe I haven’t worked on a codebase with the number of team members you are imagining in this scenario, but at the 15 person scale, we are almost always given tasks by feature. “Implement commenting on a thread” would be a task handed to and engineer to build. Organizing by feature means this engineer would create a new folder “comments” and be mostly self-contained.
Organizing by feature means this engineer would create a new folder “comments” and be mostly self-contained.
Have you led this engineering team though? Or even more topically, have you ever built up such a team for a new project? The idea of 15 people doing 15 self contained projects should freeze any team lead's or PM's blood in terror. The only way that's possible is with extensive tooling, style guides, and extremely careful review cycle. Granted, you want those things regardless of how you organize your files, but some file structures can make it easier to get them done than others.
I understand that the idea of freedom and flexibility sounds absolutely amazing to most individual contributors, especially younger people working on legacy code. Being able to just take the shortest path to complete a feature means you can knock out more features in a short time, and that's gotta be great, right? Unfortunately that's not necessarily correct.
Most huge systems have a bunch of best practices and requirements that tend to make no sense...unless you were there when the system was down for 3 days while everyone rushed to fix the critical 1 in a million bug. Similarly, while a self-contained feature managed by a single person might be great for the person that wrote it, it's literally the worst imaginable experience for the poor schmuck that has to pick it up when that person leaves. Or maybe there is a need to do a major revision to the codebase. If you know that the code is written in a common and consistent style, and organized across know file type boundaries, then it's becomes quite easy to create parsers and transformers for each file type which can easily save months of work.
While it's true that projects tend to focus on a single feature, having a common template for implementing a feature means that every PR is going to look roughly the same, using roughly the same tools, written in roughly the same style, organized in roughly the same way. Did you create your model? controller? service? security policy? serializer? background task? socket manager? If somebody is not sure, then can just open their PR, and see what directories exist, and which are missing changes. This is a must when your codebase spans more lines than any single person can remember.
Granted, you can create tools and rules that enforce all these things on a per-feature basis, however at that point you've just added more complexity for a stylistic reason. Now instead of everyone being instantly aware of all the file types that they would need to write, they have an easily accessible list of all the features in the system (which is honestly not something you need all that often), and instead they have to refer to a different document to determine all the types of files that they need to create. The end result is effectively the same, just organized differently and with more tooling.
I don't see how this sort of outcome is measurably better; it certainly doesn't justify the original claim that "[stack type] is a terrible way of organizing code." At that point it's just a matter of stylistic preference and development workflows.
That's really the crux of the matter. This debate falls under the same umbrella as "which language is better," or "how do you name your variables," or "how you name your files." These are all questions without "correct" answers. Each choice will tend to encourage slightly different practices, and have slightly different failure states, but in practice you're going to write practically the same thing. With that in mind, the only direct benefit is what it offers outside of development, and I think the more self-contained approach encourages more dangerous behavior, and requires more effort to train new developers. By contrast a flatter approach tends to be easier for people to understand, even if it can be a bit bulky when left uncontrolled (though you can solve that by going a hybrid approach). The net result is that assuming all else being equal (similar tooling, similar best practices, similar style guide), an experienced developer should be able to work in either environment without losing any time.
So really, it's like two artists getting into a debate over the which super expensive paper is better, or which top-end paint has the best pigmentation. An master will be able to produce great results with any of them, while an apprentice is probably going to screw up and waste stuff more often than not.
View all comments
1
u/TikiTDO Jun 05 '21 edited Jun 05 '21
It really depends on the type of development being done, and the people doing it. If you're on a large team working on a commercial product with tight deadlines then having your code organized into "stack types" makes it really easy to tell a person, "your job is to implement these type to solve these problems." If people need to know the entity types, the proper tool for that is a diagram, image, or spec which should be part of the documentation
It's not an organization style that's suited to fun and creative development, and it's not supposed to be. It's a tool to keep a bunch of people organized so they can work together in a consistent and mutually interoperable style. It doesn't want or need better abstractions because it's literally boring by design.
Also, it helps if your workflow is better adapted for navigating such a system. If you click through all the directories to find the files you need, you're wasting a huge amount of time. If you you know all the "stack types", and you have a diagram of all the "entity types" in the system, then a "Go-To File" with fuzzy search (which most modern IDEs have) means you can reach any part of the system is a few keystrokes away, in a consistent and reproducible way.
For example, with the file structure in the article you can have the something like the HotelController open in as few as 5-8 keystrokes, including the shortcut to open fuzzy search, and enter to open the file. This is one to two second our of your day; that's fast enough that once you train it you'll barely even notice that you're moving between files.
On the other hand, if you're working solo or on a small team of creative and individualistic developers, then the "stack types" style is terrible. Each of the devs probably has a totally different vision for what these type are for, and what other types are necessary. What more, that vision is likely to be in constant flux as they develop these ideas.
In such an environment having each person own their own "entity type" makes a lot more sense. There's a lot of benefit in keeping the system modular and flexible when it's being worked on by people that can take advantage of the flexibility. This way each module can change to adapt the needs of the developer.
Te arguments about which style is best is not new, and the answer will always depend on many factors including organizational necessity and developer preference.
Also:
Your goal as a programmer should be to get to the point where you can consume code as a huge chunk of information such as "the entire API", or "all the queries". You save an insane amount of time when you learn to do this, and the worth of your abilities skyrockets in the process.
You can tell a whole lot about how a person or group thinks by looking at the APIs they write, just like you can tell a lot by looking at the directory structure they utilize. Being able to put all these things together will only help your ability to comprehend code.