Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Neil Cerutti Newsgroups: comp.lang.python Subject: Re: The worth of comments Date: 31 May 2011 14:47:19 GMT Organization: Norwich University Lines: 33 Message-ID: <94kdbmFi80U2@mid.individual.net> References: <87sjs0apgh.fsf@benfinney.id.au> <4ddfd9bf$0$49183$e4fe514c@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: individual.net Pa4q0EC5Iaggrs52HZC5KAOGRVMsmxyR+n+/WCx6M3xQeZl5mN Cancel-Lock: sha1:3tDDSUFYrLt1j9mWEacH/h4sSxk= User-Agent: slrn/0.9.9p1/mm/ao (Win32) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6731 On 2011-05-28, Roy Smith wrote: > One reasonable definition of a bug is something the code > actually does which differs from the documented interface. > Unless you know what the code is supposed to do, how can you > possibly look at it and say whether it has a bug or not? For > example, take this function: > > def foo(): > l = [1, 2, 3] > return l[3] > > Is this code correct? I'll bet most people would look at this > and say, "I'm not sure what he had in mind, but whatever it > was, this has to be a bug because he's indexing past the end of > the list". Well, what if I showed you the interface contract: > > def foo(): > "Raise IndexError. This is useful as a testing fixture." > l = [1, 2, 3] > return l[3] > > Now it's obvious that the function does exactly what it's > supposed to do (even if it's not the best way to do it). That's an excellent illustration of bad code hid by a bad comment. Perhaps better: def foo(): raise IndexError() -- Neil Cerutti