From: Sam Smoot Date: 2008-06-20T01:13:41+09:00 Subject: Re: Rather validate values or use exceptions? On Jun 19, 12:14 am, "ara.t.howard" wrote: > On Jun 18, 2008, at 7:23 PM, Sam Smoot wrote: > > > Exceptions are _orders of magnitude slower_ than normal flow-control > > structures. > > only when they occur - having a rescue block defined cost next to   > nothing on most cases.  the best approach is often to *try* to use   > conditional structures but to still use the rescue block - but that   > ends up being very verbose and i'm personally no fan of the common   > rails pattern of using AR in such a fashion that the 'db ought to   > maintain integrity'. > > so while i totally agree with you i also see *way* too much ruby code   > written as > > unless File.exists?( pidfile ) >    # race condition >    create_pidfile pidfile > > which races on a normal fs and races *badly* on standard production   > shared filesystems like NFS.  so, although exceptions might be slow,   > i'll take them over code that works 'most of the time' any day -   > although, if code is going to blow up i do like it to do so order of   > magnitude more quickly ;-) > > just my two cents on the issue - not responding to your post   > directly.  i guess i would summarize by saying that i totally agree,   > but that there are *far* more exceptional behaviours in the real world   > that much code seems to be acknowledge. > > cheers. > > a @http://codeforpeople.com/ > -- > we can deny everything, except that we have the possibility of being   > better. simply reflect on that. > h.h. the 14th dalai lama No, you're right, agree 100%. I'm more thinking of seeing people raise/catch exceptions for validation. Or a locked record in the database. Basically using them like a GOTO. And they're really functionally identical to throw/catch in those situations, because you don't _really_ care about the stack- trace that produced a validation error. It's a case you can handle. On the other hand, ArgumentError is my favorite thing since sliced bread. ;-) No, I can't pass a Symbol, String, Integer, Array or Hash. Pick one. Even if I have to type a couple more characters. At least I won't forget the method signature. :-) /off topic