ESW #142

June 20, 2019

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:

  1. 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
    1. 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.
    2. 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.
    3. 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.
    4. 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.
  2. 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.
  3. 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!
  4. 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.
  5. 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.

Full Show Notes

Visit https://securityweekly.com/esw for all the latest episodes!

Hosts

Lee Neely

Lee Neely – Senior Cyber Analyst , Lawrence Livermore National Laboratory.

Paul Asadorian

Paul Asadorian – CTO, Security Weekly.

 

 

 

 

 

 

Announcements

  • 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

prestitial ad