Over a million developers have joined DZone.

Reading Code: Assume it doesn’t work

· Performance Zone

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

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!



Learn tips and best practices for optimizing your capacity management strategy with the Market Guide for Capacity Management, brought to you in partnership with BMC.

Topics:

Published at DZone with permission of Mark Needham, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}