readability - Tools and techniques to improve comprehension of unfamiliar code? -


i've realised greatest weakness programming student poor ability comprehend other people's code.

i have no trouble whatsoever 'textbook' code, or clearly-commented code, when given program of few hundred lines, containing dozen or different functions , no comments, find difficult begin.

i know type of code i'm more encounter in career, , think having poor code comprehension skills going great hindrance me, i'd focus on improving skills in area.

what tools/techniques have helped improve code comprehension in experience?

how tend tackle unfamiliar, uncommented code? why? technique find helpful?

thanks

familiarizing foreign code

if codebase small enough, can start reading straight away. @ point pieces start falling together.

in scenario, "small enough" varies, larger experience increases. start benefiting "cheating" here: can skip on pieces of code recognize experience "implementing pattern x".

you may find helpful make small detours while reading code, e.g. looking function see being called, spend a little time glancing on it. not stay on these detours until understand called function does; not point, , make feel jumping around , making no progress. goal when detouring understand new function in less half minute. if cannot, means function complicated. abort detour , accept fact have understand "current" function without help.

if codebase large, can't start reading it. in case, can start identifying logical components of program @ high level of abstraction. goal associate types (classes) in source code these components, , identify role each class plays in component. there classes used internally in component , classes used communicate other components or frameworks. divide , conquer here: first split classes related groups, focus on group , understand how pieces fit together.

to in task, can use source code's structure guide (not ultimate law; can misleading @ times due human error). can use tools such "find usages" of function or type see each 1 referenced. again, not try digest ide tells if can't reasonably quickly. when happens, means picked complicated piece of metal out of machine don't quite understand. put , try else until find can understand.

debugging foreign code

this matter entirely. cheat little saying that, until amass tons of experience, there no way debugging code long foreign you.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -