You can tell a lot about a professional developer through the code that he or she writes. Their thinking is laid out in front of you and their level of care is immediately evident. Writing maintainable, clean code is achievable with the right knowledge and effort. Jumar’s Senior Technical Architect, Paul Graves, gives us some top tips on how to write better code for the future.
DON’T OVERLOAD NAMES FOR DIFFERENT CONCEPTS
Imagine that you are writing instructions to bake a cake; verbs are needed to know what actions to take, and nouns are needed to know what those actions affect. If the business terminology exists then speak the same language. That way the concepts are understood by both fellow developers or testers. If you do this you will naturally write code that is more easy to understand and less cluttered with technical details that obscure the overall intent.
BE MINDFUL OF YOUR DEPENDENCIES
Code dependencies can very easily over complicate your project. Watch how you organise your dependencies and strive for singular-direction. Although it’s impossible to avoid bi-directional dependency altogether, one-directional dependencies are much easier to manage.
One of the common reasons code is difficult to update is convoluted dependencies. Your code becomes complicated once your dependencies start going in multiple directions. What could be a small change turns in to hours of coding hell as there are multiple dependencies on that change. The best way to minimise dependencies is to expose to other code only the details you need to for it to call you or get your results. Don’t let the outside world know your inner data structures or algorithm though it is tempting to do so as a shortcut!
REORGANISE AS YOUR CODE GROWS
It’s difficult to know how your project is going to grow when you write the first few lines. However, it’s important that you reorganise and improve your structure as you add features and re-architect. Whether it’s lines of code, software architecture, directory structure, or even the project platform version, everything needs to iteratively improve its organisation as you start changing your project. If you neglect this because “we are too busy at the moment” it will become absolutely necessary at some other point at which it will be even more inconvenient than the current time!
Clean Code: A Handbook of Agile Software Craftmanship – Robert C Martin
This one’s a must read by the man himself, Robert Martin AKA Uncle Bob. It’s split into three parts – the principles of clean code, clean-up case studies, and the lessons learnt from the case studies.
Code Complete – Steve McConnell
If you’re looking for the next step in your career contact Jumar today on 0121 788 4550 or upload your CV here.