Thursday, October 23, 2014

Recursion, really! Because it doesn't have to be complicated.

I ran across something recently that went like this: some method (a[], b[]) = { do c with a and b; x[] = getTheArray(); bool MOE = false; while(MOE) { do c with a and x; MOE = does x meet condition of egress? } } of course c was some repeated code, not it's own method. But it didn't have to be either. I ended up refactoring the "some method" body to look something like the following: { if(a && b meet some condition) { do c with a and b; x[] = getTheArray(); call this recursively with a and x; } }

No comments:

Post a Comment