Paul will talk about the challenges of inheriting someone else’s code. Paul will discuss 5 tips: Use an IDE, Variable Usage, Jump To Implementation and Declaration, Global Search, and Inspection.
I’ve spent the past few weeks updating software. I was not the primary developer, mostly I was working with other people’s code. I ran into several challenges, here are some tips for when you are in this situation:
- Use an IDE – My project is Python, so I chose to use PyCharm. I am a hardcore Vim user, however, I use Vim emulation and it works good enough. There are several advantages to using an IDE vs. a command line text editor
- Variable Usage – The editor will highlight variables that are unused and those that are undefined. Handy for making updates to code you are not familiar with.
- Jump To Implementation and Declaration – This is super handy as you are likely not familiar with the application flow or the code base. You can right click on anything and follow it to the declaration or where it is being used.
- Global Search – I use this all the time to find out where functions or object references are being used. Usually to make sure I am not breaking anything and to trace back the flow of execution. You can double click on a result and it takes you to it.
- Inspection – There are many plugins for this, I use the built-in one. This tells me all of the errors, warnings, etc… in the code. I use this as the first step to figuring out what negative impact my code changes may have had.
- Logging and Exceptions – Spend some time adding additional logging and exceptions, especially around new code that you write. Often times developers will leave out logging or debugging statements once they are comfortable with the code. Go ahead and add some back in, you can always adjust them later if you are concerned about performance. Python exception handling is really neat as well.
- Don’t Trust Logs or Comments – Logging statements and comments get stale very fast. So many times I’ve reviewed code, understood what it does, but the log entry or comment says it does something completely different. They cannot be trusted. Also, many developers write either no comments at all or crappy comments. Here’s a tip, if you are writing anything, write good descriptive comments. It will help you as the developer, and those that follow. For tips, read Code Complete, great book!
- Beware Of Spelling Mistakes – In the code I am working on, there are spelling mistakes. Lots of spelling mistakes. In comments. In code. Across multiple files. Your IDE likely has a spell checker, use it. Don’t leave any spelling mistakes in code! If you are making changes, be sure you are spelling it incorrectly or do a search and replace.
- Unit Testing – This helped me tremendously to clean-up a ton of code fast. Most languages have unit testing modules (e.g. Python unittest). This allows you to automatically test your code, and more importantly someone else’s.
Visit https://securityweekly.com/esw for all the latest episodes!
- Register for our upcoming webcasts with SaltStack, DomainTools, and LogRhythm by going to securityweekly.com/webcasts. If you have missed any of our previously recorded webcasts, you can find our on-demand library at securityweekly.com/ondemand