Six tips for approaching Legacy Code
At Magma, we are frequently approached by organisations with legacy systems, which have been written by engineers who are no longer with the organisation. We regularly speak to organisations that tell us it takes too long to implement a new feature because the code base has become too complicated and they dare not touch it in case it breaks.In the ideal world, all code would be written in a way that would enable any engineer to easily interoperate and master very quickly. Software unfortunately is not an ideal world and software languages and standards go in and out of style continually, therefore our software engineers are left to decipher and unravel code which is often referred to as “spaghetti code”
How do our engineers at Magma tackle that code?
1. Not be too judgemental – it is very easy at the first glance of legacy code to assume the worst and decide it’s a total re-write. During that initial period, we try to understand the client’s business logic and suddenly we realise whilst it may not be the best code it does actually make sense.
2. Bite-size pieces – getting started on a legacy system can feel like walking blind into the unknown and engineers become afraid of changing the code and developing new features. Initially we begin by working on smaller files and simple bug fixes to help us find our way around the system and understand the business logic.
3. Develop a knowledge of multiple coding languages – at Magma whilst we specialise in PHP, we have a good working knowledge of most coding languages and frameworks. We pride ourselves on our ability to understand and work with almost any code which is given to us.
4. Reducing the risk – at Magma at least two engineers must sign off another engineer’s code before it is deployed. We apply the same principles to legacy adoption as often in our experience it takes two people to agree that the code has no logic or doesn’t make any sense. With any system, we build or adopt in the case of legacy, we always work on the “bus count basis” How many of the Magma engineering team would need to be hit by a bus before the team are in difficulty, we continually plan to ensure our bus count is as high as possible.
5. Follow convention – most software languages have their own set of conventions or frameworks, any code written or modified following these will be much easier to work with and handover to the client’s team in the future. At Magma, we always write code to a high standard with minimum technical debt and following best practice and conventions.
6. Testing – apply as many tests as you can, initially we request system documentation and where this is lacking which is typical of most legacy systems; inorder to understand the business logic and functionality of the system the best strategy is to test. By applying functional tests every time we add new code, we are able to confidently build and implement new features to the system.
Working with code written by someone else can be difficult and sometimes disastrous, at Magma we are very experienced in the adoption and improvement of legacy code and enjoy the challenge.