From: Dr Balwinder S Dheeman Date: 2005-05-10T01:14:37+09:00 Subject: Re: No Thing Here vs Uninitialized and RCR 303 On 05/09/2005 04:21 AM, Bill Atkins wrote: > This isn't about changing programming habits. Having nil return nil > for missing methods can have serious consequences. > > Consider: > > file = create_new_log_file > file.log "here's a bit of information" > > You're expecting this code to log something to a file every time it > gets called. But suppose create_new_log_file returns nil, due to some > mistake you've made while coding it. No exception is raised, so when > you run your program, it performs its job appropriately. You move on. > > Two months later, you urgently need to get information from those > logs. But uh-oh - the log files are empty. Now you're screwed. irb(main):001:0> file.log 'here is a bit of infromation' NameError: undefined local variable or method `file' for main:Object from (irb):1 irb(main):002:0> file = nil => nil irb(main):003:0> file.log 'here is a bit of infromation' NoMethodError: undefined method `log' for nil:NilClass from (irb):3 irb(main):004:0> -- Dr Balwinder Singh Dheeman Registered Linux User: #229709 CLLO (Chief Linux Learning Officer) Machines: #168573, 170593, 259192 Anu's Linux@HOME Distros: Ubuntu, Fedora, Knoppix More: http://anu.homelinux.net/~bsd/ Visit: http://counter.li.org/