4.9.2014

Working (with) Legacy Code

First of all: never (ever) assume you're confronted with bad code.

People that wrote it are probably as smart as you are – maybe even smarter, since they (sometimes) wrote code that make a product that sells pretty well over a couple of decades.

So here we go (and I have just two points):

  • Don't change code only because you assume that it has faults.

    You have to prove that, first (using debugger / profiler). We are not in a beauty contest, here.

  • Don't change interfaces.

    Changing the behavior of a Class / Method is no problem, if that Class / Method is used in a precisely defined, local context. Changing interfaces of Classes / Methods that are wildly used in a complex application are a no-go even in the context of a quasi-automated Refactoring.

    Don't do that. Use the Compiler to unveil your errors: rename a Class / Method that needs a new behavior, and let the Compiler's errors lead your way thru.


  • Sidenote:

    If some code doesn't do what you assumes it should do, that doesn't mean someone else shares your assumptions (and your reasons for changing it's behavior).

    She might rely on some assumptions that might seem stupid to you, but she might rely on them for good reasons (even if those reasons are founded on a reality that goes decades back).

    (Kommentarfunktion z.Zt. deaktiviert.)
    Array 46.229.168.151&&15:32 - 10.12.&&2&&(unknown)&&&&Mozilla/5.0 (compatible; SemrushBot/2~bl; +http://www.semrush.com/bot.html)&& 109.40.67.182&&15:33 - 10.12.&&1&&(unknown)&&https://www.google.de/&&Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1&&