Over a million developers have joined DZone.
Silver Partner

Reading Code: Assume it doesn’t work

· Performance Zone

The Performance Zone is brought to you in partnership with Smartbear. Learn more about how the performance of your API's, web, and mobile applications have a direct impact on your bottom line with the Guide to Synthetic Monitoring.

Jae and I have spent a reasonable chunk of the past few weeks pairing on code that neither of us are familiar with and at times we’ve found it quite difficult to work out exactly what it’s supposed to be doing.

My default stance in this situation is to assume that the code is probably correct and then try and work out how that’s the case.

After I’d vocalised this a few times, Jae pointed out that we couldn’t be sure that the code worked and it didn’t make sense to start with that as an assumption.

He pointed out that we were often going down paths of the code that were executed infrequently and since there were no tests around the code we couldn’t be sure what it did.

A more useful approach was to assume that it doesn’t work and then reason about it from scratch to determine whether or not that assumption is correct.

I quite like making this assumption because it makes you concentrate much more closely when you’re reading the code rather than skimming over it and assuming that it does what it’s supposed to do.

Reading the code has become a mini debugging session where we try to discover how some unfamiliar code actually works.

We’ve found a couple of bits of code that weren’t actually working by following this mindset but it is mentally quite tiring and obviously slower than other styles of reading code!



The Performance Zone is brought to you in partnership with Smartbear. Discover how important it is to recognize the inherent power of APIs and bulding the appropriate safeguards to protect it with the Essential Guide to API Monitoring.

Topics:

Published at DZone with permission of Mark Needham , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}