Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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.


Comment on Re: Is readdir ever deterministic?
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://112875]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2014-08-23 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls