4 ms·
> so many programmers breaking up everything in useless classes and methods/functions/whatever just because someone wrote a blog post about doing so. This just
by raverbashing 9y ago
> so many programmers breaking up everything in useless classes and methods/functions/whatever just because someone wrote a blog post about doing so. This just makes complicated code look simple at a glance
Thank you
I've seen people create classes containing only a string or a list/array of other (existing) objects, it's not even funny anymore.
- mosselman 9y agoThis is one of the biggest reasons for code becoming unmaintainable. Many people got mad at DHH for speaking ill of TDD, but he is not alone in pointing fingers at blindly restructuring code for the sake of (unit) testing as mentioned in the article. I get why people would like to pretend that everything is made up of beautiful uncomplicated small pieces, but that is not how life works. At some point you have to understand your tax returns, mortgage contracts and communications with incoherent external APIs. Making me jump to section 4.1.2 and from there to section 7.2 in order to understand the parties mentioned under 1.1a are subject to the rules set out in Appendix A section 42.1 does not make the contract easier to understand. So why would code that feels like a legal document be easier to understand?
- discreteevent 9y agoThat's a really good example of the problems of indirection. I'll use it in future if that's ok. The thing that drives me mad about the promoters of decoupling is that they rarely talk about the downsides. The truth is that every time you decouple something there is a cost in complexity. One individual step to decouple something may seem small but the cumulative effect of many indirections in code can make it extremely difficult to navigate and understand. So when people decouple something they should understand this and make sure that the benefit outweighs the cost (which of course it does in some cases). The benefit of being able to test your code at a micro level rarely outweighs the cost.
- mosselman 9y agoThank you, yes please do. You nicely explained what I feel about this 'advice' when it is formulated compulsively like in the article. You made me think 'yes, exactly that' with regards to some people who seem to ignore the downsides of decoupling. Thank you for that, I'll refer to your comment in the future. Nice to come together like that.
- DougBTX 9y ago> I've seen people create classes containing only a string That can be a good way to improve type-checking in code that would otherwise pass around bare strings. It reduces the chances that e.g. a plain text string is confused with an HTML string. If your language supports it, an opaque type alias would be more explicit: https://flow.org/en/docs/types/opaque-types/ https://flow.org/en/docs/types/opaque-types/
- raverbashing 9y agoYes, if the auxiliary class either checks or transforms the string in some way I agree But that's in specific cases, not all cases