5 ms·
The number one attitude that leads to maintainable code for me, is to not worry about problems I don't actually have. That is, solve the problem I am trying to
by taeric 10y ago
The number one attitude that leads to maintainable code for me, is to not worry about problems I don't actually have.
That is, solve the problem I am trying to solve. Do not go out of the way to solve other problems. They will have their time, or they were not important.
Obviously, it took some time to get so that I could write code that wasn't a disaster on its own. I would argue I haven't gotten past that point, actually. Which is all the more reason that the less I touch to solve a problem, the better.
- a-priori 10y agoThere's a line to tread here: solving future problems isn't a good idea, as you say, but neither is closing off future options by being too specific about your current needs. You don't want to create extra problems for future you to solve.
- taeric 10y agoAgreed. This is what I was referring to with my code not being a problem on its own. Ideally, you don't write things that wall you off from future options. But, neither should you try to anticipate all things.
- pklausler 10y agoDisagree. You don't want to solve just the specific problem at hand in a way that will be hard/expensive/buggy to extend. And you don't want to implement the most general conceivable solution library, either. The best solutions are in the middle ground, viz. those that solve the immediate problem in a way that anticipates and facilitates the future as well.
- taeric 10y agoIf something puts itself in the way of the work I am doing already, then I will attempt to solve it. But, you have to exercise caution and prioritize. Otherwise, you'll just find yourself in the "Hal fixing a lightbulb"[1] cycle. [1] https://www.youtube.com/watch?v=RHpJFROEOmg https://www.youtube.com/watch?v=RHpJFROEOmg
- gentleteblor 10y agoI'm not sure how I feel about this. What has worked for me is embracing change. Requirements will change, third party integrations will change, front end frameworks, use cases, service providers etc. Everything will change so write (really build) code that tolerates change (IOC, interfaces, etc. Any form of loose coupling you can get away with cleanly). There are of course situations when the one line fix is the right one. But in general, this outlook on short term vs long term changes (knowing when the concrete should become the abstract) is one of the differences between being a programmer and a software engineer (or being a senior and a junior).
- mrec 10y ago> Everything will change so write (really build) code that tolerates change (IOC, interfaces, etc. Everything might change. Not everything will change. I think the problem I have with your principle is that many of the techniques to accommodate change (the "IOC, interfaces, etc" you mention) can have a real and immediate cost when it comes to understanding a codebase, and that's the fundamental sin when it comes to maintainability. Abstraction and indirection have value, obviously, but on balance I'm with GP; don't add 'em until you actually need 'em. In particular, don't add an interface and a factory and whatnot until you actually have more than one implementation. This may depend on your languages and dev environment; something like IDEA where large-scale but mechanically trivial refactorings can be accomplished quickly and safely are more suited to KISS than e.g. dynamic languages where tooling is much much weaker.
- AstralStorm 10y agoAdding a proper interface is much more expensive than removing it if it proves worthless. Designing a good interface and especially components or other means of compartmentalization removes a huge source of mistakes. Especially the last part is critical - if there is no abstraction or some other kind of tight binding between components you've already lost.
- mrec 10y agoI think we may be miscommunicating; a lot of these words mean different things to different people. Designing a good and minimal "interface" for a class or module, in the sense of how it exposes its functionality to the rest of the world, is absolutely important, yes. Deciding that mentioning classes anywhere in a signature is Evil, and that everything must implement a separately-defined interface in the Java/C# sense, is IMHO not at all useful. Not because it's "expensive" - it just takes an already-designed class API and copypastes it into an interface - but it's pure busywork. More code (which some people treat as a plus), harder to understand (because now there's always extra ambiguity at a call site as to which implementation is being called), adds nothing. This type of thinking - taking a useful tool or rule of thumb and turning it into dogma - seems far more prevalent in Java-land than in any other language I've worked in; I've never really understood why.