On 9 Jan 2006 11:21:10 GMT Antoon Pardon <[EMAIL PROTECTED]> wrote: > Op 2006-01-06, Terry Hancock schreef > <[EMAIL PROTECTED]>: > > On 6 Jan 2006 07:30:41 -0800 > > "KraftDiner" <[EMAIL PROTECTED]> wrote: > >> in an init method I declare a variable > >self.someLongName > > >> later in a different method of the class I use > >> self.sumLongName > >> Now I really meant self.someLongName. > >> In fact I don't want a variable called sumLongName. > >> Frankly how are you ever to know if this type of error > >is > occuring? > > > > Both "unit tests" and "interfaces" are useful for > > catching simple errors like this one. There is a > > 'unittest' module in the Python standard library, and > > 'interface' modules are available from the Zope 3 > > project and PyProtocols, both are good. > > I don't think unit tests are that helpfull in this case. > Unit tests help you in finding out there is a bug, they > don't help that much in tracking down a bug. > > I for some reason a person is reading over the difference > between sumLongName and someLongName and doesn't notice > the different spelling in his source a unit test won't > be of much help.
Well, if you are doing fairly frequent unit tests, then you will have written a unit test to test the "someLongName" method, and if you manage to type "sumLongName" in BOTH the code and the unit test, then there must be some Freudian reason you really did want to use "sumLongName". ;-) It's a bit like the standard practice of making you type a password twice. In fact, most of the common "bug avoidance" methods in programming all come down to this -- you have to type the same thing twice in two different places to get the result. C and C++ make you do declarations -- so you have to mention the name before you can use it. You have to type the variable names twice. Interfaces define the "publically viewable" parts of a class, then you have to actually create them in a separate class definition. You have to type the methods twice. In unit testing, you write the code, then write code to test the code, which must correctly identify the methods in the code. So you have to type 'everything' twice. And so on. The ideal of "don't repeat yourself" seems to get nudged out by "repeat yourself exactly once" when it's really important to get it right. ;-) It's really just a fancy way to force you to proof-read your own work carefully enough (which is tricky because you tend to ignore stuff that's too repetitious). Cheers, Terry -- Terry Hancock ([EMAIL PROTECTED]) Anansi Spaceworks http://www.AnansiSpaceworks.com -- http://mail.python.org/mailman/listinfo/python-list