tungwaiyip.info

home

about me

links

Blog

< June 2012 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930

past articles »

Click for San Francisco, California Forecast

San Francisco, USA

 

Python Whitespace Misconception

Whitespace is significant in Python. This uncommon syntax rule is one of the refrain of many non-Python programmers about Python. Given most computer languages since Fortran has adopted free layout syntax, this feel like an objectionable design.

Now that I think of it, I find this mostly a problem of wrong framing. The term "whitespace" has already embedded the meaning of unimportant filler. In this sense "significant whitespace" sounds like a problem. Actually the right way to describe it is that Python uses indentation to determine the block structure. Rather than feeling wrong, this is lot more likely to evoke an "aha" reaction from non-Python programmers. Of course it makes a lot sense for the indentation to follow the block structure. I can hardly find any legitimate case for those two to differ.

Austere programmers may notice that there are two way to indicate block structure in main stream languages, by using language construct like "begin" and "end" and by laying out the code using indentation. Whenever there are two ways to do express one thing there will be problem of inconsistency. This extra degree of freedom can get you into trouble sometimes. One of the most nasty class of programming bug is dangling else. It is the case in free layout language when the apparent block structure is different from the actual block structure. Dangling else is not possible in Python. It is because the block structure is determined by the indentation.

2012.06.08 [] - comments

 

 

blog comments powered by Disqus

past articles »

 

BBC News

 

Trump impeachment inquiry: New claims amid public hearing (13 Nov 2019)

 

Venice floods: Climate change behind highest tide in 50 years, says mayor (13 Nov 2019)

 

Hong Kong protests: Students fight police with petrol bombs, bows and arrows (13 Nov 2019)

 

General election 2019: Don't give up on stopping Brexit - Tusk (13 Nov 2019)

 

Secrets of the largest ape that ever lived (13 Nov 2019)

 

Ebola vaccine approved as second jab trialled (13 Nov 2019)

 

Israel-Gaza fighting continues for second day after militant's death (13 Nov 2019)

 

Greta Thunberg to sail to Spain climate summit with YouTubers (13 Nov 2019)

 

'Berlin rocks,' says Elon Musk as he chooses European factory (13 Nov 2019)

 

Libya: Migrant mother's dying wish to get children to Europe (13 Nov 2019)

more »

 

SF Gate

 

Ship traffic, November 14 (13 Nov 2019)

 

Is some of Calif.'s .3 billion in unclaimed assets yours? Here's how to find out (13 Nov 2019)

 

Ship traffic, November 13 (12 Nov 2019)

 

Disney’s ambitious streaming service is here. And cable feels the force (11 Nov 2019)

 

Stocks slip as uncertainty reigns in US-China trade talks (11 Nov 2019)

 

Apple co-founder says Goldman’s Apple Card algorithm discriminates (11 Nov 2019)

more »


Site feed Updated: 2019-Nov-13 15:00