←back to thread

361 points mmphosis | 4 comments | | HN request time: 0.243s | source
1. tegiddrone ◴[] No.42167934[source]
> 5. If a particular function doesn't fit anywhere, create a new module (or class or component) for it and you'll find a home for it later.

I worked at a place that did this with their frontend app. Devs rarely knew where anything should go and so for any given Component/Module, there was usually some accompanying `MyComponent.fns.ts` file. Homes were NEVER found for it later. Code duplication through the nose and lots of spaghetti coupling.

Edit: i'm definitely blowing off some steam. That said, I think there is good virtue in this "habit" so long as there is good reason that it "doesn't fit anywhere" ... and when another module starts referencing the temporary home module, it is a smell that the time is now to give it a proper home.

replies(3): >>42168380 #>>42168425 #>>42170223 #
2. atodorov99 ◴[] No.42168380[source]
I also disagree with that advice and believe it to be an anti pattern. Code readability can suffer massively from multiple modules. It depends on the use case and particilar function so this kind of advice should not be a general rule but rather a unique decision should be made for each different situation.

Very uncomfortable truth (imo) for many developers who prefer to find abstractions and general all encompassing advice. I have found that the correct placement of functions in files/classes is a "sense" that is improved solely with experience and is never truly complete. It is after all about communicating intent to other human beings for which there are no hard rules.

3. stoperaticless ◴[] No.42168425[source]
Other end of this spectrum is ever growing “utils” package.
4. skydhash ◴[] No.42170223[source]
I used to do the utils file, but now it's either a local function (same file, close to usage) or I find a proper home for it (even if it's a rudimentary module).