From: David Vallner Date: 2006-02-09T05:46:03+09:00 Subject: Re: boolean annoyance Dňa Streda 08 Február 2006 16:25 Claudio Jeker napísal: > > will execute in any case. Perhaps I'm biased because I'm a crazy C hacker > but I can not believe that others do not fall into this trap. I realy like > the clearness of the ruby syntax but this "everything but nil and false is > true" logic is totaly non obvious and annoying. > This is in my opinion a matter of convention. The predominant C convention is to return logical values in predicates, and then either return a NULL on failure, and a valid result on success; or return 0 on success, a nonzero error code on failure, and pass a valid result via an output parameter. Frankly, I find remembering which function uses which slightly annoying. The predominant Ruby convention is to return true / false in predicates; and in other functions return the result of computation on success, nil on "mild" failure, and throw an exception on severe failure. Because of exceptions, using error codes is unnecessary. This means that: if (foo = some_method) puts "#some_method succeeded" end is -always- a valid idiom if this convention is followed, and a return of value 0 always indicates success, as opposed C, where it can mean either depending on the call. David Vallner