Python scoping

Steve Horne sh at ttsoftware.co.uk
Thu Oct 26 11:30:12 EDT 2000


On 24 Oct 2000 03:42:39 GMT, suppamanx at collector.org (SuppamanX)
wrote:

>   I have been using Python off and on for 6 months now and have grown to 
>love it from the beginning. However, there is a facett of Python that 
>annoys me somewhat. It is the 'scoping by indentation'. Coming from a 
>background of 'formal' languages (e.g. Pascal, C, Java,...), I am 
>accustomed to explicitly start and end my scopes with a braces. From a 
>readability standpoint, it gets quite problematic for especially for some 
>of the example code that I am trying to learn from.
>
>Can someone clarify why there is no explicit end for scopes?
>(i.e. IFs, FORs, WHILEs, METHODs, etc...)
>
>Thanx

I've been using Python for about 4 years, and one of the major reasons
for changing was that Python uses indentation for block structure.

I still use C++ regularly, and never get confused.

Good coding style requires sensible indentation. Once you have
sensible indentation, the begins, ends, braces and whatever are just
noise - obstructing your view of the actual code.

Furthermore, using indentation this way forces people to indent their
programs properly - making the code much more readable than, for
example, C++ which has been edited a few times, got some new blocks
added and some old ones taken out, but where noone bothered to fix the
indenting.

Sorry - I'm just a fan of languages that enforce good coding style. If
only I could find a language that enforces a sensible name convention.

-- 
Steve Horne
sh at ttsoftware.co.uk



More information about the Python-list mailing list