Where I work developers are always telling me that "I added this just in case for the future" or "I think it's a good idea to do this because they'll probably want it some day". I think it's great that they're proactive in trying to anticipate future changes but I can't help thinking that it's unnecessary and risks writing code that may never be needed and therefore unproductive (I also think that some developers just want to try out something new for the sake of it). Are the arguments for future proofing invalid if you just write good, clean organised code?
|
|
Well first of all, there are some things that need clarification:
This means is that writing "future proof" code, is ensuring that the code is written in a loose coupled manner, sufficiently abstract, but also code that does not completely hide abstraction levels, so there's always a way to go to the lower abstraction levels if necessary. Writing future proof code is an art by itself and is tightly coupled with solid practices for component versioning, separation of concerns, layering and abstractness of functionality. Future proofing has nothing to do with adding features ahead of time, but with making sure you can add features in the future in a non breaking manner, through the good design of existing code/libraries. My 2c |
|||||||
|
|
Do not write code that will not be used for a long time. It will be useless as it most likely will not fit the needs at that time (which you by definition do not know yet). Make the code robust against unexpected problem situations allowing for graceful recovery or fail-fast, but do not write code for possible future uses. A good way to ensure that, is to use test driven design and development. Test cases are derived from the specification and use cases. All code must make a test pass. Unneeded code should not be written. By doing it this way it is simple to determine if it is needed or not. |
||||
|
|
It is important to realise that making code future proof, and writing code in case it is needed in the future are two very different things. The former is crucial to a good application, the lesser is usually not good coding practice.
So, by all means, make code future proof (NASA still send spaceships up using Fortran), but dont write code 'just in case'. |
|||||||||
|
|
Think about how many time you have enabled a piece of code down the line in a production environment and thought, "Thank god I wrote that 2 years ago!". Code should be modifiable / extendable easily. Don't add code that isn't immediately necessary, because this gives a very false sense of security and wastes dev/test resources in a world of changing requirements. |
|||||||||||||||||
|
|
Good, clean, well-organized code is future-proof in the sense that it makes changes and additions easier to implement correctly. |
|||
|
|
|
A lot of the other answers address kind of larger design issues, or are rather abstract. If you think in terms of what will happen in the future you can define some clear techniques to help future-proof the code. Primarily think that in the future somebody will try to add a feature to the code, or will attempt to reuse your code somewhere else. They may also try to fix a feature in the code. Obviously just having good clean code is a required starting point, but there are also some specific techniques that can be done. Defensive Programming: Do input checking beyond what you current application actually needs. Whenever you call APIs be sure sure to check that their input is something that you would expect. In the future people will be mixing new versions of code together, so the scope of errors and API returns will change from what it is now. Elliminate Undefined Behaviour: A lot of code has behaviour which just kind of evolves from nowhere. Certain combinations of input lead to certain output which nobody really intended, but just so happens. Now inevitably somebody will rely on that behaviour, but nobody will know about it since it isn't defined. Anybody attempting to change the behaviour in the future will inadvertently break things. Use safety checks now and try to remove/block all undefined uses of the code. Automated Test Suite: I'm sure you can find volumes written about the need for unit tests. In reference to future proofing however this is a critical point in allowing somebody to refactor the code. Refactoring is essential to maintaining clean code, but if lack a good suite of tests you can't safely refactor. Isolation and Segregation: Encapsulation and proper modularization is a good design principle, but you need to go beyond that. You'll often find that you need to use a library, or API, or product, which may have a questionable future. Maybe due to quality concerns, licensing problems, or continued development by the authors. In these cases take extra time to put a layer between you and this code. Slice down the API to just what you need so the coupling is very low to allow easier replacement in the future. |
|||
|
|
|
"Future Proof" at best means "loosely-coupled design". 80% of the time people mean "flexible" when they say "future proof". Sometimes they say it to try and sound cool. But at least they're delivering something on time that works. "Future Proof" at worst is meaningless. 20% of the time, it's an excuse to waste time researching alternative technologies instead of simply delivering something. They're not delivering anything (or what they're delivering is too complex for the problem at hand.) There are two edge cases.
|
|||
|
|
|
YAGNI = You Aren't Gonna To Need It. Your instincts are correct their code is superfulous, adds a burden of maintanence and testing and wastes time on things that don't have a concrete business value. See Also: Gold Plating. |
|||
|
|
|
Ignoring the title of the question, and sticking the main point about "putting stuff in because somebody might want it some day"... The answer is NO. Never. Don't write a stitch of code you don't need today. Here's why:
I think the first point is the most important. If you've ever worked with a system that's riddled with generic code for different customers, or full of feature bloat with stuff you don't need then you know just how much extra time and effort it takes to maintain or extend the functionality because of that. So avoid at all costs. |
|||
|
|
