allowing braces around suites
Roel Schroeven
rschroev_nospam_ml at fastmail.fm
Sat Aug 28 09:00:59 EDT 2004
Kjetil Torgrim Homme wrote:
> [Roel Schroeven]:
>
>> Kjetil Torgrim Homme wrote:
>> > how long do you have to stare before spotting the bug?
>>
>> Just the time needed to read the code.
>>
>> > db.update_name(person)
>> > if is_student(person):
>> > db.update_courses(person)
>> > db.commit()
>> > only students have their names updated. I wonder why.
>>
>> No offense, but I wonder why you have a problem with this
>> code. IMO the indentation makes perfectly clear what's happening.
>
>
> I don't think it is appropriate that I dump thousands of lines of code
> here to illustrate the problem :-)
>
> when I provide four lines of code and tell you there's a bug, of
> course you can spot it immediately.
I immediately saw what the code does; at first I didn't know it was the
bug you were referring to since I don't know what the code is supposed
to do. Then I read 'only students have their data updated' as
description of the bug, and only then I knew that the commit was
incorrectly indented.
> when it's part of a large system,
> it's a bit harder. also consider that the db.commit() originally was
> correctly placed by the programmer, and the wrong indentation was
> introduced later by an editing glitch.
In that case, I agree it can be harder. But IMO it gets harder with
increasing code complexity, whether braces are used or not. I haven't
yet seen very complex python programs, but I have seen C and C++ code
with multiple nesting levels, and let me assure that it can sometimes be
very difficult to spot errors.
--
"Codito ergo sum"
Roel Schroeven
More information about the Python-list
mailing list