Brian Ray's Blog : Python/whitespace.htmlPainting is just another way of keeping a diary. --Picasso
Tue, 13 Dec 2005Python's Whitespace"There should be one-- and preferably only one --obvious way to do it." -- Tim Peters Most people who know me know I am fond of Python. The biggest gripe I hear from programmers about Python is it feels restrictive, at first. Although, what I say in return is to think about with other languages how much time is waisted trying to adhere to all the best practices, DRY and Agile and so on, and work with a flimsy language. Some choices should be trivial and treated this way. Also, if your making something for someone else to use, the "how to" should be as self explanatory as possible. Take whitespace in Python. One good thing about ChiPy is that I get to hear a lot of programmers talk about programming Python. Once a presenter said when he was first placing is Python code under version control he had done some thing really stupid, he said. He said that instead of converting his tabs to space, he checked them into source control as tabs. Now is this so bad? What is wrong with tabs under source control. For one thing, the tab size, three spaces or four... needs not specified. I still think back to Guido van Rossum's April's fool joke in his blog. But seriously, why are people afraid of white space? And what is the proper way to handle it? Also, why does it seem some editors are so unfit for managing white space? Why are some programmers afraid to work off a restrictive foundation? It seems to me, I am better off with Python being restrictive much the same way a carpenter feels comfortable with a rigid piece of wood. Through carefully tooling, the wood can be made pliable into whatever you want and without ever hindering productivity or creativity. Although, if you start with a flimsy piece of wood you can not do as much: not as quickly and not as concisely.
Posted by Stephen Thorne at Tue Dec 13 23:56:33 2005
Use one, or the other. Know what you use. Never mix them. There is nothing worse than tabs and spaces in a single file.
Posted by Matt at Thu Dec 15 01:03:38 2005
The whitespace thing does rear its head occasionally when I do a hurried cut-and-paste of code from a web page or SourceForge; for some reason every 100th line or so just indents funny and I have to spend a few minutes hunting down the extra spaces.
Posted by sudhir at Mon Jan 23 12:05:05 2006
"What is wrong with tabs under source control. For one thing, the tab size, three spaces or four... needs not specified." IMO, that is the advantage of tabs. I can set the width of tabs according to what I want. I agree with Stephen Thorne, that there is nothing worse than mixing tabs and spaces. I always indent with tabs, never ever with spaces, and found this to be a lot better than indenting with spaces only. Tabs cut down number of key strokes, auto indent works great with vi, I can set the tab width according to the real estate available to me ...
Posted by K Lars Lohn at Mon Jan 23 20:10:48 2006
I am continually astounded at the hostility that I encounter when talking about Python's syntactically significant whitespace. I blogged about my experience at OSCON 2005 http://staff.osuosl.org/~lohnk/?p=7 I've actually gotten hate mail about it. While I like the whitespace rules, I do wish there were more support in editors. Highlighting blocks when "out-denting" would be helpful. Perhaps some light vertical lines from the top of the screen to the bottom at each indention level would make it easier to match the indents. Did you ever see Stroustrup's April Fool paper on overloading whitespace in C++? http://public.research.att.com/~bs/whitespace98.pdf It's brilliant and completely took me for a fool...
Posted by K Lars Lohn at Tue Jan 24 11:31:05 2006
I am continually astounded at the hostility that I encounter when talking about Python's syntactically significant whitespace. I blogged about my experience at OSCON 2005 http://staff.osuosl.org/~lohnk/?p=7 I've actually gotten hate mail about it. While I like the whitespace rules, I do wish there were more support in editors. Highlighting blocks when "out-denting" would be helpful. Perhaps some light vertical lines from the top of the screen to the bottom at each indention level would make it easier to match the indents. Did you ever see Stroustrup's April Fool paper on overloading whitespace in C++? http://public.research.att.com/~bs/whitespace98.pdf It's brilliant and completely took me for a fool...
Posted by K Lars Lohn at Tue Jan 24 12:00:45 2006
I am continually astounded at the hostility that I encounter when talking about Python's syntactically significant whitespace. I blogged about my experience at OSCON 2005 http://staff.osuosl.org/~lohnk/?p=7 I've actually gotten hate mail about it. While I like the whitespace rules, I do wish there were more support in editors. Highlighting blocks when "out-denting" would be helpful. Perhaps some light vertical lines from the top of the screen to the bottom at each indention level would make it easier to match the indents. Did you ever see Stroustrup's April Fool paper on overloading whitespace in C++? http://public.research.att.com/~bs/whitespace98.pdf It's brilliant and completely took me for a fool...
Posted by Chris Arndt at Wed Jan 25 06:58:31 2006
> While I like the whitespace rules, I do wish there were more support in editors. Highlighting blocks when "out-denting" would be helpful. Perhaps some light vertical lines from the top of the screen to the bottom at each indention level would make it easier to match the indents. All Scintilla base editors are capable of doing that. check out SciTE for example.
Posted by Jacob Hallén at Wed Jan 25 13:41:26 2006
The whitespace problem is easily solved. 1. You decide to never use tabs. 2. You use 4 space indents, except in interactive mode, where you can be lazy and do just 1 space indents. 3. You use an editor that handles this without problems. There are several that nicely handle block indentations and stuff. 4. You use a translation program on all source code you need to touch that contains tab characters. I did this 5 years ago and have had no problems since. When I first came to Python, the significant whitespace was bothersome for all of 4 hours, because I was unused to how the code was to be read. Now, that I am used to both visible and invisible block limiters, I find the unvisible ones to reduce clutter (chart junk in the terminology of EdwardTufte), thereby improving readability.
|
Categories Calendar
Hosted by Google Ad
|
|||||||||||||||||||||||||||||||||||||||||||||||||