Python with braces?

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

Magitek
Posts: 28
Joined: Fri Aug 24, 2007 5:54 am UTC

Python with braces?

Postby Magitek » Tue May 20, 2008 11:53 pm UTC

I have very little experience with python, but have coded in many other languages before. I would love to use python, but I really miss those braces, the thought of whitespace with semantic value horrifies me (after a brief stint with the esoteric language of Whitespace). Is there a way to code in python with braces?

++$_
Mo' Money
Posts: 2370
Joined: Thu Nov 01, 2007 4:06 am UTC

Re: Python with braces?

Postby ++$_ » Tue May 20, 2008 11:59 pm UTC

No. Well, you could try this.

Seriously, whitespace is not significant in Python except at the beginning of a line. I have never once encountered a whitespace-related problem with Python. Never. Actually, I have fewer problems, because in C you can forget a closing brace and spend a few seconds trying to figure out where it's supposed to be. In Python, you never have that problem.

User avatar
Jach
Posts: 167
Joined: Sat May 05, 2007 8:38 pm UTC
Contact:

Re: Python with braces?

Postby Jach » Wed May 21, 2008 12:42 am UTC

In time you will come to love Python's indentation. =P If that somehow doesn't happen though, you could check out Ruby which is real similar to Python but sticks an end after everything.

My philosophy is that you're supposed to be indenting properly anyway, so it might as well mean something to the computer as well.
I love reading quotes.

User avatar
r1chard
Posts: 281
Joined: Thu Dec 06, 2007 2:17 am UTC
Location: Melbourne, AU
Contact:

Re: Python with braces?

Postby r1chard » Wed May 21, 2008 1:17 am UTC

I have had a single instance of whitespace-related buggery (er ... buggery in the sense of ... fun-related-to-a-bug :)

It was due to line that had crept into the code that was indented with a tab, in code that was otherwise indented with spaces. It took me a while to figure out too.

That's once in over 10 years of Python programming.

Now I have vim highlighting in red all tabs that appear in source files:

Code: Select all

highlight BadWhitespace ctermbg=red guibg=red
au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/
match BadWhitespace /\s\+$/


(it also highlights unnecessary trailing whitespace in all opened files)



I should also point out that Python 3.0 (and 2.6? or perhaps it will only generate warnings) will automatically generate syntax errors if a source file has mixed tabs-n-spaces. You can get the same effect right now with the -tt command-line switch.

Fat Tony
Posts: 1501
Joined: Wed Jan 16, 2008 9:12 pm UTC

Re: Python with braces?

Postby Fat Tony » Wed May 21, 2008 1:27 am UTC

...Am I the only one who, upon reading this thread's title, began to picture a large snake with corrective dental equipment?
Wanna hear the truth? Life is downright ok.

User avatar
Dropzone
Posts: 405
Joined: Sun Dec 30, 2007 10:12 pm UTC
Location: North Lincs., UK

Re: Python with braces?

Postby Dropzone » Wed May 21, 2008 2:17 am UTC

On a related note: try adding from __future__ import braces as the first line of a source file (or typing it in an interactive session), and watch the interpreter's response...

User avatar
biolution
Ken
Posts: 560
Joined: Wed Sep 05, 2007 10:05 pm UTC
Location: San Francisco, Ca
Contact:

Re: Python with braces?

Postby biolution » Wed May 21, 2008 3:30 am UTC

++$_ wrote:No. Well, you could try this.

Seriously, whitespace is not significant in Python except at the beginning of a line. I have never once encountered a whitespace-related problem with Python. Never. Actually, I have fewer problems, because in C you can forget a closing brace and spend a few seconds trying to figure out where it's supposed to be. In Python, you never have that problem.


It also has significance if you use "\" for line continuation and have a trailing space after it. Another case is when you need to line break but are in the middle of a string (common if you have a line length limit in your style guide); the implicit string concatenation doesn't work across lines unless you use \ or enclose it in parentheses. "\" is rarely used, and () isn't a big deal, though.

The OP smells like a troll, though.

Magitek
Posts: 28
Joined: Fri Aug 24, 2007 5:54 am UTC

Re: Python with braces?

Postby Magitek » Wed May 21, 2008 4:17 am UTC

biolution wrote:The OP smells like a troll, though.


Not trying to troll, I really want to use python, but the few times I tried it out I was too weirded out by it. I guess I'll give it another shot.

And the interpreter thing about future import was checked into the python svn by somebody under the guise to “Improve SyntaxErrors for bad future statements”

http://scott.yang.id.au/2006/09/python-and-braces/


P.S. I'm amazed at how fast google's crawler works. I posted this topic earlier this afternoon and it's already showing up under a google search of "python with braces"

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Python with braces?

Postby EvanED » Wed May 21, 2008 9:41 pm UTC

Okay, this thread is over. Original question is pretty much answered. I pretty crudely split & merged the second half of the thread into here. The split posts are near the bottom.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 4 guests