views:

486

answers:

7

Is there an incarnation or fork of Python that formats blocks using punctuation instead of whitespace?

There seem to be quite a few branches of Python, such as JPython, IronPython, etc, so just wondered if optional whitespace indentation had been evolved into one of those variants.

I could potentially be interested in learning Python but the whitespace restrictions are an absolute no-go for me.

update: it appears people here are not reading the question! I'm fully aware most Python coders love Python's formatting rules more than any other feature of the language. However I was hoping there was more to the language than just layout. Unless there is a serious attempt to answer this question properly I'll have to assume Python is nothing but a formatting specification.

+5  A: 

Whython is what you want

Check out : http://bitbucket.org/gregglind/python-whython3k/src

and as this blog post example says :)

Ok

The Question is why python, you will find out when you use whython. 
pyfunc
Awesome! Thanks!
PP
@PP: Did you notice the date on the blog?
John Machin
........ aww :(
PP
+1  A: 

pybraces

dan04
A: 

It's not exactly "python without the significant whitespace", but Ruby comes pretty close to what you're asking for.

anon
I heard Python was cool. But it was, like, holding out a cross to a vampire, I just couldn't get close enough to experience the cool (and still want to).
PP
tell us more about the vampire.
flow
+14  A: 

Try this command:

from __future__ import braces
Mark Tolonen
+1  A: 

Use Python with a smart editor (like VIM). With a plug-in like this http://www.vim.org/scripts/script.php?script_id=974 or using VIM's internal syntax filetype plugin indent on indentation is automatically handled almost all the time.

Gökhan Sever
+1  A: 

The whitespace indenting is part of the Python Language Specification. All those things you mentioned are Python Implementations, so of course they all follow the specification.

gnibbler
A: 

i would like to second that i believe Python did something almost revolutionary by taking whitespace seriously and make it part of the syntax. i wish i had a way to write javascript with significant whitespace---those braces are a real nuisance. i always have to count them even in mildly nested code.

one of the big advantages of significant whitespace vs braces (or some kind of begin ... end syntax is the improved helpfulness of syntax errors: with braces, a missing brace will often lead to an error message that points to the end of the sourcefile---happy hunting for the one missing } hundreds of lines up. with significant whitespace, an indentation error most of the time gets you an error message that points almost precisely to the offending part (is this a fact of syntax or is it just due to some difference in parsing of python vs javascript, ruby? not quite sure at this moment).

that said, i'd really love it if it were possible to write python with even less, less parentheses that is. i know it is difficult since nested function calls can quickly turn ambiguous; i guess resolving this issue would be a matter of putting some clear rules of interpretation in to work. i find print repr int x so much clearer than print( repr( int( x ) ) ) (which is one reason i don't program in lisp).

that said, i otherwise find the question perfectly reasonable. i mean i don't like licorice, but some people love it. i frown a bit on the emotions such a question can provoke in python folks (tho i can relate to it).

i want to suggest that whitespace is just a presentational, not an inherent aspect of python, by which i mean python's big value (apart from the amount of working code that is available) is its usability, the speediness and correctness of its implementation, and the the amalgam of working, useful concepts (iterators, context managers, exceptions, early failure on bogus actions like indexing a string with a non-number) that other popular languages do not offer in this combination. whether you write out those concepts with braces or whitespace is as much a matter of presentation as much as whether you write them out primarily in english, dutch, or chinese is a matter of presentation. i imagine that you could separate the language 'itself' from the grammar of the language, and treat the presentation as a transformable piece of data. ideally, you could then just flick a switch on your IDE or issue a command on the command line and get your sources transformed from bracey to braceless, or from english to chinese. it should be possible to do that and remain consistent.

flow
i am trying to help by giving aspects you are free to use or ignore. you say python's "whitespace restrictions are an absolute no-go for me" and if you want to stay there, do so. others have already pointed out two projects that concretely address this question. i would like to see grammar more detached from the language-as-such. i feel it is valid to discuss this here even without this question being marked community wiki. then again, you constantly get told how to behave on stackoverflow. i guess it could raise the quality of the discussion if you gave any motivations for your adamant p.o.v.
flow
is there a way to give people points for rudeness? "Believes good developers have acquired humility." ???
flow
are you sure you are to the point? socialist propaganda?? regardless: "I was hoping there was more to the language than just layout." is exactly what i was saying. "I'll have to assume Python is nothing but a formatting specification"---it is *much* more, but sadly as it stands (as in all the other languages i know of) the layout is, sadly, somewhat deeply baked into the language. so i recommend using a preprocessor; maybe whython is your piece of cake. "could potentially be interested", "absolute no-go"—if you feel so strongly pls. explain. we only want to help you, dave.
flow