Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Is readdir ever deterministic?

by VSarkiss (Monsignor)
on Sep 17, 2001 at 19:14 UTC ( #112875=note: print w/replies, xml ) Need Help??

in reply to Is readdir ever deterministic?

As a further point on defensive programming, consider that while some platform may guarantee to return . and .. as the first two entries, they may not guarantee that in the future. If you can make your code more robust in the face of potential future changes at no additional cost, why not do so?

To me, the real point is this: your code should say what you mean. If you intend to exclude . and .., then write that, as shown in your example code. Even if every platform in existence guaranteed the contents of the first two directory entries, IMHO it'd be better to code it as in your example than to eliminate the first two elements and have to explain in a comment what the code is intended to achieve.

Replies are listed 'Best First'.
Re: Re: Is readdir ever deterministic?
by evlg (Novice) on Sep 17, 2001 at 20:28 UTC
    I concur, especially since testing for . and .. is not especially expensive. Sure, there are 2 extra checks per directory entry, but unless a profiler tells you that is a specific performance problem for your program, IMO it's not worth the potential maintenance problems to "optimize" it. Later programmers might not immediately understand why the code did that, and it could the time of those assigned to maintain that code.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://112875]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2018-07-20 03:28 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (423 votes). Check out past polls.