Lay Out Your Code Like You'd Lay Out Your House

Frederik πŸ‘¨β€πŸ’»βž‘οΈπŸŒ Creemers on July 06, 2018

Imagine you wake up and get up to brush your teeth. You go to the "brooms and brushes" room to get your toothbrush. Then, you go to the "cleaning... [Read Full]
markdown guide

Fantastic! However, this should be paired with a well-tempered inheritance structure, so you're not repeating yourself unnecessarily. You may have seventeen types of lamp in your house, but they all implement the same common wiring and structure.

There are also some things that should be shared among rooms, such as electricity, plumbing, and so forth. No point recreating the entire electrical system for each individual room...that would just make it hard to maintain the system! Implement the common system instead.


prefer composition over inheritance - extracting non-legit abstractions is coupling your modules without bringing much benefit.


Conventions are important

A very important yet undervalued principle πŸ‘.


I have a basic crud application plus SPA with export functionalities in flask and it's almost stupid how many files you have to modify to add a single field editable by the user: the migration that modifies the db (auto-generated by the changes in the model but still...), the model itself, the server side validation forms, the server side tests, the REST API sending data to the frontend so that the user can store info in the new field, the frontend code receiving the data, the UI, the frontend tests and the export API needs to know about the new field.

The app has so little logic that I feel it's not worth refactoring to abstract a lot of this stuff but everytime the client wants a new field I have to go through the same scattered modifications.


Are There Any Frameworks That Take Advantage Of This Or A Similar Structure?


The Masonite python framework is very similar to this structure.


Yes, yes, and yes.

Just to pursue the topic, here is an article about that domain-oriented code folders with React:

It works very well for us.


Awesome post. You definitely had me hooked from the opening metaphor.


Very good, congratulations! My dad was an architect so your metaphor makes even more sense. :)


It is an absolute blessing when I don't have to ctrl + shift + f to find all implementations of a given function.

Great post Frederik! Keep up the great work.


I guess you just read chapter about bounded context in ddd book.


Amazing opening paragraph. This kind of question always comes to my head when structuring an app or a project and I never know what makes more sense. Thank you!

code of conduct - report abuse