rejeep / f.el

Modern API for working with files and directories in Emacs
GNU General Public License v3.0
680 stars 68 forks source link

(f-directory? nil) results in an error #44

Closed tmalsburg closed 9 years ago

tmalsburg commented 9 years ago

Wouldn't it be more convenient it if would just return nil?

phst commented 9 years ago

I disagree, specifying a wrong type is a programming bug and should always result in an error. Cf. built-in functions such as zerop.

tmalsburg commented 9 years ago

Serious question: why is nil the "wrong" type? Nil is often used to indicate the absence of a value of any type.

phst commented 9 years ago

Yes, but it's not a string ((stringp nil) is nil). Currently the contract for f-directory? is simple and strict, the argument must be a string. Adding nil as allowed argument would weaken the contract, require additional special-casing, and introduce unnecessary ambiguity (what is the meaning of the absence of a path name?). nil is otherwise known as Hoare's "billion-dollar mistake" (http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare). If we can avoid weakening the contract for existing functions, we should.

rejeep commented 9 years ago

To decide these things I usually look at other languages, for example Ruby:

$ File.exists?(nil)
TypeError: no implicit conversion of nil into String
tmalsburg commented 9 years ago

Ok, convinced.