473,395 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Python statements not forcing whitespace is messy?

Am I the only one that thinks that python statements should force
whitespace before and after them?

Right now this is not enforced and for an example these statements are
valid

print"hello"
"foo"if"bar"else"foobar"
for(x,y)in[(1,2),(3,4)]:print(x,y)
[(y)for(x,y)in[("foo",2),("bar",4)]if"foo"in(x)]

....and so on.

I know that writing code like this really shouldn't be done but
wouldn't it be a good idea to enforce the use of whitespace around
statements?

(I wrote a short blog post about this here http://blog.buffis.com/?p=55
but thought I would post here as well to see what other developers
think)
- Björn Kempén

Sep 15 '07 #1
10 1827
buffi wrote:
Am I the only one that thinks that python statements should force
whitespace before and after them?

Right now this is not enforced and for an example these statements are
valid

print"hello"
"foo"if"bar"else"foobar"
for(x,y)in[(1,2),(3,4)]:print(x,y)
[(y)for(x,y)in[("foo",2),("bar",4)]if"foo"in(x)]

...and so on.

I know that writing code like this really shouldn't be done but
wouldn't it be a good idea to enforce the use of whitespace around
statements?

(I wrote a short blog post about this here http://blog.buffis.com/?p=55
but thought I would post here as well to see what other developers
think)
- Björn Kempén
You may have a point--but on the other hand, this may be purposefully
allowed help to recruit perl programmers.

James
Sep 15 '07 #2
buffi wrote:
Am I the only one that thinks that python statements should force
whitespace before and after them?

Right now this is not enforced and for an example these statements are
valid

print"hello"
"foo"if"bar"else"foobar"
for(x,y)in[(1,2),(3,4)]:print(x,y)
[(y)for(x,y)in[("foo",2),("bar",4)]if"foo"in(x)]

...and so on.
On the other hand, this is just as bad:

[ ( y ) for ( x , y ) in [ ( "foo" , 2 ) , ( "bar" , 4 ) ] if "foo" in (
x ) ]
And I'd hate to have to remember all of the rules for what can go
together and what can't, especially when it comes time to debug. No.
I don't think it should be forced, but maybe put it in PEP8 or PEP3008.

Also, the only thing I find thoroughly disagreeable in all of that
mess, is the run-ins involving " characters. The rest are at least
clear at a glance what belongs where.

Also, would you require the following?

my_function (swallow='European')

Because that is just an awful use of whitespace.

Cheers,
Cliff

Sep 15 '07 #3
On 9/15/07, J. Cliff Dyer <jc*@sdf.lonestar.orgwrote:
And I'd hate to have to remember all of the rules for what can go
together and what can't, especially when it comes time to debug. No.
I don't think it should be forced, but maybe put it in PEP8 or PEP3008.
It is: see "Whitespace in Expressions and Statements" in PEP 8.
--
http://www.advogato.org/person/eopadoan/
Bookmarks: http://del.icio.us/edcrypt
Sep 15 '07 #4
On Sep 15, 10:11 pm, "J. Cliff Dyer" <j...@sdf.lonestar.orgwrote:
buffi wrote:
Am I the only one that thinks that python statements should force
whitespace before and after them?
Right now this is not enforced and for an example these statements are
valid
print"hello"
"foo"if"bar"else"foobar"
for(x,y)in[(1,2),(3,4)]:print(x,y)
[(y)for(x,y)in[("foo",2),("bar",4)]if"foo"in(x)]
...and so on.

On the other hand, this is just as bad:

[ ( y ) for ( x , y ) in [ ( "foo" , 2 ) , ( "bar" , 4 ) ] if "foo" in (
x ) ]

And I'd hate to have to remember all of the rules for what can go
together and what can't, especially when it comes time to debug. No.
I don't think it should be forced, but maybe put it in PEP8 or PEP3008.

Also, the only thing I find thoroughly disagreeable in all of that
mess, is the run-ins involving " characters. The rest are at least
clear at a glance what belongs where.

Also, would you require the following?

my_function (swallow='European')

Because that is just an awful use of whitespace.

Cheers,
Cliff
I believe that having whitespace around the builtin statements, and
having whitespace around everything is pretty different.

There would be no downside whatsoever to enforcing this, except for
backwards incompatibility (which is a rather huge downside but well...
py3k is gonna break everything anyways). There obviously shouldnt be
any limit to the maximum amount of whitespace used around statements
(due to formatting and so on), but allowing stuff like print"hello" is
just horrible.

- Björn Kempén

Sep 15 '07 #5
buffi wrote:
On Sep 15, 10:11 pm, "J. Cliff Dyer" <j...@sdf.lonestar.orgwrote:
>buffi wrote:
>>Am I the only one that thinks that python statements should force
whitespace before and after them?
Right now this is not enforced and for an example these statements are
valid
print"hello"
"foo"if"bar"else"foobar"
for(x,y)in[(1,2),(3,4)]:print(x,y)
[(y)for(x,y)in[("foo",2),("bar",4)]if"foo"in(x)]
...and so on.
On the other hand, this is just as bad:

[ ( y ) for ( x , y ) in [ ( "foo" , 2 ) , ( "bar" , 4 ) ] if "foo" in (
x ) ]

And I'd hate to have to remember all of the rules for what can go
together and what can't, especially when it comes time to debug. No.
I don't think it should be forced, but maybe put it in PEP8 or PEP3008.

Also, the only thing I find thoroughly disagreeable in all of that
mess, is the run-ins involving " characters. The rest are at least
clear at a glance what belongs where.

Also, would you require the following?

my_function (swallow='European')

Because that is just an awful use of whitespace.

Cheers,
Cliff

I believe that having whitespace around the builtin statements, and
having whitespace around everything is pretty different.

There would be no downside whatsoever to enforcing this, except for
backwards incompatibility (which is a rather huge downside but well...
py3k is gonna break everything anyways). There obviously shouldnt be
any limit to the maximum amount of whitespace used around statements
(due to formatting and so on), but allowing stuff like print"hello" is
just horrible.
If you don't like it then don't write it. I've been reading this group
on and off for about ten years and I believe your email is the first to
point out that this is possible. Clearly it isn't something that happens
a lot, and I don't know why you have a bug up your ass about it, as the
Americans say.

The Python philosophy is to be permissive, and to expect individual
users to write readable Python. Since they obviously do (one message in
ten years providing a counter-example) I think you are wasting your time
and energy on this.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

Sep 15 '07 #6
On Sep 15, 11:49 pm, Steve Holden <st...@holdenweb.comwrote:
buffi wrote:
On Sep 15, 10:11 pm, "J. Cliff Dyer" <j...@sdf.lonestar.orgwrote:
buffi wrote:
Am I the only one that thinks that python statements should force
whitespace before and after them?
Right now this is not enforced and for an example these statements are
valid
print"hello"
"foo"if"bar"else"foobar"
for(x,y)in[(1,2),(3,4)]:print(x,y)
[(y)for(x,y)in[("foo",2),("bar",4)]if"foo"in(x)]
...and so on.
On the other hand, this is just as bad:
[ ( y ) for ( x , y ) in [ ( "foo" , 2 ) , ( "bar" , 4 ) ] if "foo" in(
x ) ]
And I'd hate to have to remember all of the rules for what can go
together and what can't, especially when it comes time to debug. No.
I don't think it should be forced, but maybe put it in PEP8 or PEP3008.
Also, the only thing I find thoroughly disagreeable in all of that
mess, is the run-ins involving " characters. The rest are at least
clear at a glance what belongs where.
Also, would you require the following?
my_function (swallow='European')
Because that is just an awful use of whitespace.
Cheers,
Cliff
I believe that having whitespace around the builtin statements, and
having whitespace around everything is pretty different.
There would be no downside whatsoever to enforcing this, except for
backwards incompatibility (which is a rather huge downside but well...
py3k is gonna break everything anyways). There obviously shouldnt be
any limit to the maximum amount of whitespace used around statements
(due to formatting and so on), but allowing stuff like print"hello" is
just horrible.

If you don't like it then don't write it. I've been reading this group
on and off for about ten years and I believe your email is the first to
point out that this is possible. Clearly it isn't something that happens
a lot, and I don't know why you have a bug up your ass about it, as the
Americans say.

The Python philosophy is to be permissive, and to expect individual
users to write readable Python. Since they obviously do (one message in
ten years providing a counter-example) I think you are wasting your time
and energy on this.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline
I actually found out about this myself while grading student labs. I
myself didn't even know that you could write statements like this
until then, but since some students does it that means that there
should be other people out there as well that does it.

And I can't say that I agree about "The Python philosophy being
permissive, and to expect individual users to write readable Python".
Python enforces proper indentation which I think is a great idea since
I'm used to reading horribly indented code by others. I would love to
see this extended to enforce proper whitespacing for statements.

"There should be one-and preferably only one-obvious way to do it." is
a phrase that is usually considered pythonic, and I think that it
should also apply a bit when it comes to coding conventions.

- Björn Kempén

Sep 15 '07 #7
On 16/09/2007 8:11 AM, James Stroud wrote:
Steve Holden wrote:
>I don't know why you have a bug up your ass about it, as the
Americans say.

I think most Americans say "wild hare up your ass".
The essence of Steve's point appears to be that the OP has ridden into
town to preach a misguided crusade against the heretofore-unknown
non-spacing heretics. It also seems to be alleged that at some stage,
the OP's donkey has been severely molested by some malevolent fauna; I
am having difficulty understanding the connection between the two
themes, and which is cause and which is effect. Enlightenment, please.

Sep 15 '07 #8
John Machin wrote:
On 16/09/2007 8:11 AM, James Stroud wrote:
>Steve Holden wrote:
>>I don't know why you have a bug up your ass about it, as the
Americans say.
I think most Americans say "wild hare up your ass".

The essence of Steve's point appears to be that the OP has ridden into
town to preach a misguided crusade against the heretofore-unknown
non-spacing heretics. It also seems to be alleged that at some stage,
the OP's donkey has been severely molested by some malevolent fauna; I
am having difficulty understanding the connection between the two
themes, and which is cause and which is effect. Enlightenment, please.
I guess I got the metaphor wrong?

Eradicate the ten fetters of Buddhism and you will attain enlightenment.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

Sep 16 '07 #9
On 9/15/07, Steve Holden <st***@holdenweb.comwrote:
John Machin wrote:
On 16/09/2007 8:11 AM, James Stroud wrote:
Steve Holden wrote:
I don't know why you have a bug up your ass about it, as the
Americans say.
I think most Americans say "wild hare up your ass".
I guess I got the metaphor wrong?
Maybe it's a Southern US thing. I've always heard "bug" used; somehow
it doesn't seem that a wild hare would fit!

--

# p.d.
Sep 16 '07 #10
Peter Decker wrote:
On 9/15/07, Steve Holden <st***@holdenweb.comwrote:
>John Machin wrote:
>>On 16/09/2007 8:11 AM, James Stroud wrote:
Steve Holden wrote:
I don't know why you have a bug up your ass about it, as the
Americans say.
I think most Americans say "wild hare up your ass".
>I guess I got the metaphor wrong?

Maybe it's a Southern US thing. I've always heard "bug" used; somehow
it doesn't seem that a wild hare would fit!
We say "wild hare" down in Texas. I think I've heard "bug" before, but I
wanted an excuse to vent about the hair v. hare issue in some of these
American idioms. I guess I have a <insert idiom hereabout it.

James
Sep 17 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Michael Chermside | last post by:
richardc writes: > Im no expert but wouldnt you accept that Python has 'borrowed' FORTRAN's > fixed format syntax. I can only think of Python and FORTRAN off the top of > my head which use...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
37
by: michele.simionato | last post by:
Paul Rubin wrote: > How about macros? Some pretty horrible things have been done in C > programs with the C preprocessor. But there's a movememnt afloat to > add hygienic macros to Python. Got any...
68
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
2
by: jvvhie | last post by:
Hello, I am writing a pure-Python game engine that interprets the code of game objects within the same process with the exec statement. My main goal is to make as much power available as possible...
852
by: Mark Tarver | last post by:
How do you compare Python to Lisp? What specific advantages do you think that one has over the other? Note I'm not a Python person and I have no axes to grind here. This is just a question for...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
22
by: Kurien Mathew | last post by:
Hello, Any suggestions on a good python equivalent for the following C code: while (loopCondition) { if (condition1) goto next; if (condition2) goto next;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.