|
|
|
|
|
by azeirah
3808 days ago
|
|
Something I found to be really useful is to remove all statements inside the code, so you'll be left with large skeleton structures. Look at it from a distance, (small font), see some patterns. Can you split it up? getting a feel for the structure of the function helps me understand it. Ex: function someFunction () { if () {
for () {
if () {
} else {
}
}
if () {
for () {
}
}
}
}
|
|
Ferinstance:
It's easy to spot that there are really two paths through the method (depending on what thingy1? returns) in this simplified form, but rewriting it will make it clearer even in a 2k line function: This is also useful even when the 'if' clauses aren't identical - even then, there are frequently implied relationships (for instance, if one checks if something is positive and the other checks for zero) that can simplify things.