BASIC or Python?

Rainy sill at optonline.net
Tue Jul 10 00:06:39 EDT 2001


On Tue, 10 Jul 2001 02:17:31 GMT, Gerry Quinn <gerryq at indigo.ie> wrote:
> In article <slrn9kkgfp.dj6.kamikaze at kuoi.asui.uidaho.edu>, kamikaze at kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) wrote:
>>[ Followups set where they belong. ]
>>
>>Sun, 08 Jul 2001 14:52:13 GMT in <0t_17.14670$Fk7.131382 at news.indigo.ie>,
>>Gerry Quinn <gerryq at indigo.ie> spake:
>>> In article <slrn9kcfuq.2b7g.kamikaze at kuoi.asui.uidaho.edu>,
>> kamikaze at kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) wrote:
>>>>  Likewise, Python's string handling is IMO just brilliant; slicing is
>>[...]
>>>>string"""`.  What's not to love?
>>> 
>>> Remember that the meaning of a line depends on its indentation.  Plenty 
>>> not to love, IMO.
>>
>>  That has nothing to do with strings, though.
>>
>>  However, do you not indent your code in C?
>>if(foo)
>>bar();
>>  in a longer example would be unreadable and unmaintainable.  Python
>>just eliminates the curly braces, and assumes you wrote exactly what you
>>meant.  It also eliminates those idiotic religious arguments over
>>indentation style, because there's only one correct indentation style.
>>
>>  It's a very old, very bogus argument, dragged out every time by the
>>people who haven't used Python; once you program in Python, it becomes a
>>non-issue.
>>
> 
> In case anyone is fooled, here's an example from the tutorial at 
> www.python.org, which also has a FAQ on what Python is for:
> 
>>>> for n in range(2, 10):
> ..     for x in range(2, n):
> ..         if n % x == 0:
> ..            print n, 'equals', x, '*', n/x
> ..            break
> ..     else:
> ..          print n, 'is a prime number'
> .. 
> 
> Now some people may very well find that lovable, but I certainly don't.  
> Note how the clever language design means that the 'else' must be 
> level-indented with the 'for'.   No doubt longer programs are even more 
> fun.  The FAQ on increasing speed helpfully notes that function calls 
> are expensive...
> 
> The second print statement is one character offset from the 'if' - I 
> don't know whether that is necessary or not.  It is unlikely that I will 
> ever wish to know.
> 
> - Gerry Quinn

Isn't this an example of how python's indentation is a *good* thing?

In python, above code causes an error, a programmer goes and corrects it.
No harm done.

In indentation-unaware language, it may work but it will look like there is
no else to that if. That can be really confusing. Also, if there's a block like
this:

if:
    ...
    if:
        ...
else:

in python it looks like else is for outer if, and that's how it'll work. In
other languages, it may in fact work with inner if, while it will *look* like
it works with outer, leading to even worse confusion than in the first example.

IOW, if there's something wrong with indentation, it's best to find out as
soon as possible, not half a year later after 3 hours of trying to figure out
why else block doesn't work. Am I missing something here?

> 
> 
> 
> 
> 
> 


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



More information about the Python-list mailing list