Question about indentation and bugs

Andrei Kulakov sill at optonline.net
Fri Aug 24 07:56:24 EDT 2001


On Thu, 23 Aug 2001 15:28:05 +0100, Dave Swegen <dswegen at allstor-sw.co.uk> wrote:
> First of all this is not intended as flame-baiting or trolling. I'm
> genuinly curious about this one weird feature.
> 
> I've recently started looking at python, as we are about to implement a
> whole new intranet, and it would seem that basically all web tools that
> are of interest (zope, mason etc) are either perl or python based. 
> 
> Now, I've done a bit of perl coding, and it does have some neat
> features. However, I feel that there are far too many cases where making
> hard-to-read code is too easy, or things feel tacked on (OOP, for
> instance). That is why I really like what I've seen of Python so far.
> 
> However, I (and others here at work) do have some real concerns about
> the indentation feature. Basically we are quite worried about subtle
> but nasty bugs creeping in. Take the following code for instance:
> 
> for i in [1234]:
> 	print i
> 	print "hello"
> 
> Perfectly fine, valid code. But one indentation step wrong, and you end
> up with perfectly fine, valid code that does something else, ie
> 
> for i in [1234]:
> 	print i
> print hello
> 
> I imagine that these sort of problems might not only appear due to
> incorrect coding, but also things such as broken mailers, applying
> patches from people using different indent levels etc
> 
> So my question (or rather questions) is this: In practice, how often do
> such problems crop up?  How does one go about avoiding such problems? Is
> there any way at all to make explicit where a block ends?
> 
> Any points of view much appreciated
> 
> Cheers
> 	Dave
> 

I had one such problem in about 2.5 years of coding, and I figured it out
in half an hour. I feel that the indentation feature does far more good
than harm for three reasons - 1. it's more readable 2. there's no bracing
style disagreements and 3. code executes the way it looks, so you can't
make an error like
while {
    expr
    expr
expr}
}

that conveys one thing through its indenting, but does another.

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



More information about the Python-list mailing list