Jump to content

Recommended Posts

Posted (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 by Lee Mac
  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • be_bo

    7

  • Lee Mac

    5

  • pBe

    5

  • irneb

    4

Top Posters In This Topic

Posted

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."

Posted
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 :o, but for 3 recursions it shouldn't matter (may even be slightly better than setting a state variable as in mine).

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...