apardon at forel.vub.ac.be
Wed Jan 11 02:51:05 EST 2006
Op 2006-01-10, Terry Hancock schreef <hancock at anansispaceworks.com>:
> On 9 Jan 2006 11:21:10 GMT
> Antoon Pardon <apardon at forel.vub.ac.be> wrote:
>> Op 2006-01-06, Terry Hancock schreef
>> <hancock at anansispaceworks.com>:
>> > On 6 Jan 2006 07:30:41 -0800
>> > "KraftDiner" <bobrien18 at yahoo.com> 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". ;-)
Who says someLongName is a method?
> 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.
But that is not an accepted idea here in c.p.l. I also find
it strange that redundancy via type declarations is so hard
resisted here and is then defended with the argument it
isn't needed is you test sufficiently (with unit tests)
which is also a kind of redundancy.
> 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.
But you don't type attribute names twice in unit tests,
because attributes are in general implementation details
that are of no concern to the tester. So unit tests can
not introduce the redundancy to find out a missed spelled
attribute in some methods.
> 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).
Yes and you also tend to read over your own spelling errors.
More information about the Python-list