=- and -= snag

Thomas Passin list1 at tompassin.net
Mon Mar 13 22:23:38 EDT 2023


On 3/13/2023 9:47 PM, Chris Angelico wrote:
> On Tue, 14 Mar 2023 at 12:38, Thomas Passin <list1 at tompassin.net> wrote:
>>
>> On 3/13/2023 9:07 PM, Chris Angelico wrote:
>>> Of course, all this is predicated on you actually putting whitespace
>>> around your equals signs. If you write it all crunched together as
>>> "x=-5", there's no extra clues to work with.
>>>
>>> Linters and code reviewers can make use of all the available
>>> information, including whitespace, to determine programmer intent.
>>
>> This is the kind of thing that unit tests can catch.
>>
> 
> Maybe, but that's quite orthogonal. The linter would highlight the
> exact line of code with the odd whitespace; a unit test would merely
> point out that the overall behaviour is incorrect, which would have
> been no further information beyond what the OP already knew (the
> numbers weren't adding up).
> 
> ChrisA

*This* time the OP happened to know.  People in the thread have been 
discussing how to pick this kind of mistake with linters or what have 
you.  Even with a linter, whether or not this would have been picked up 
depends on how it has been configured.

Really, the only defense against these kind of potential mistakes or 
typos is not to use constructions that may be more likely to get wrong 
(or be typoed).  In this particular case, that would probably be too 
great a limitation for most of us.  But the general principle is a good 
one.  Douglas Crockford wrote a book on using just the better parts of 
Javascript (JavaScript: The Good Parts - rather dated by now but still 
worth the reading).

Of course, anyone can have a brain blip on any given day!



More information about the Python-list mailing list