There’s an important property that your code base should have — it should be easy to do the right thing, and hard to do the wrong thing. The codebase should be clean, and it should be easy to keep it so. One of the things necessary to achieve this is making sure that all code has a designated home. It’s the same with keeping a house clean, having designated places for all items that you own makes cleanup a trivial exercise, and not having designated places can turn it into a high-barrier, stressful one.
Typically there will be a few “classes” of code files. In a front-end app, perhaps this is “components”, “services”, “data types”, “filters”. Orthogonally, these may be organized into libraries, e.g. something like lib-client
may have code of each of these classes shared between multiple apps, and client-my-app
will have the code specific to the leaf-node app. For any new unit of code you want to add, you should ask “what class of code is this?” and “at what level in the sharing hierarchy does it belong?”. This will pin-point the right place to put the code.
A corollary of this is that your code base should not have a utils
directory. Make one, and it’s certain to become a dumping ground for code whose authors were too lazy to ask or answer the aforementioned questions.
There will be times when a new class of code comes up, one you haven’t identified in the original directory structure setup. This should be easy to identify — the answers to the “what class of code is this?” doesn’t come easy. If that is the case, reexamine your classes from scratch, see why the new unit of code doesn’t fit, and come up with a structure that accommodates it.
Finally, sometimes you’re just hacking, or stubbing something out temporarily, and need to drop in some unrelated code in the file you’re doing the rest of your work in, in the interest of getting to runnable code and staying there. In that case, sure, drop the code where you are, but be sure to communicate intent by leaving a comment along the lines of
// TEMP putting the code here for now to get started,
// move to the right home before merging into master
Comments
Post a Comment