Lee Mac Posted October 27, 2010 Posted October 27, 2010 (edited) I'd advise an iterative version over recursion in nearly all cases. While recursion could make for short-n-sweet coding, it's not the most efficient if not done exactly correct. I'd be inclined to disagree in this case - I know how recursion dumps activation records onto the stack, but, as you can see, my function will only ever go three levels deep (and perhaps less in some cases for which an extension or directory is not provided). So in this case, I would think there wouldn't be much of a performance difference between the two. Edited October 27, 2010 by Lee Mac Quote
be_bo Posted October 28, 2010 Author Posted October 28, 2010 I didn't mean to discourage you with my comment, pBe. When asked about the secret of his excellence in sword fighting, the famous samurai explained: "I learned it through experience in many battles, - mostly lost." Quote
irneb Posted October 28, 2010 Posted October 28, 2010 I'd be inclined to disagree in this case - I know how recursion dumps activation records onto the stack, but, as you can see, my function will only ever go three levels deep (and perhaps less in some cases for which an extension or directory is not provided). So in this case, I would think there wouldn't be much of a performance difference between the two.True! Didn't consider this - it would've been an issue if you called the recursion for each character in the path , but for 3 recursions it shouldn't matter (may even be slightly better than setting a state variable as in mine). Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.