473,396 Members | 1,987 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,396 software developers and data experts.

white space in expressions and argument lists

A minor concern, but I'm curious if there is any kind of best practice
for using whitespace within expressions and argument lists in the Python
world. For example:

1 + 2 or 1+2

func(1,2) or func(1, 2)

To me, the space makes it nicer and more readable, but I was surprised
to read in Guido's blog that he thinks 1+2 should be the normal way to
write it. What does everyone else think?
Mar 2 '06 #1
17 1360
John Salerno <jo******@NOSPAMgmail.com> writes:
1 + 2 or 1+2

func(1,2) or func(1, 2)


I prefer and use 1 + 2 and func(1, 2)
I don't do whitespaces only in argument defaults like

func(foo=baz)

--
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"
Mar 2 '06 #2
John Salerno wrote:
A minor concern, but I'm curious if there is any kind of best practice
for using whitespace within expressions and argument lists in the Python
world. For example:

1 + 2 or 1+2


IMO, good style calls for spaces. Most companies have style guides for
programmers to follow. Read this PEP:

http://www.python.org/peps/pep-0008.html
Mar 2 '06 #3
John Salerno enlightened us with:
To me, the space makes it nicer and more readable, but I was
surprised to read in Guido's blog that he thinks 1+2 should be the
normal way to write it. What does everyone else think?


I usually write 1 + 2 and func(a, b). Sometimes I even use more spaces
to align stuff:

foo = 'bar'
foobar = 42
azimov = 3

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Mar 2 '06 #4
Sybren Stuvel wrote:
John Salerno enlightened us with:
To me, the space makes it nicer and more readable, but I was
surprised to read in Guido's blog that he thinks 1+2 should be the
normal way to write it. What does everyone else think?


I usually write 1 + 2 and func(a, b). Sometimes I even use more spaces
to align stuff:

foo = 'bar'
foobar = 42
azimov = 3

Sybren


Guido listed a few rules that he'd like to see implemented in 2.5, and
one of them was no more than one consecutive white space. I don't know
how realistic some of those suggestions are, but they seem to be getting
a little to restrictive.
Mar 2 '06 #5
John Salerno wrote:
Guido listed a few rules that he'd like to see implemented in 2.5, and
one of them was no more than one consecutive white space. I don't know
how realistic some of those suggestions are, but they seem to be getting
a little to restrictive.


in his april 1st, 2005 paper ?

http://www.artima.com/weblogs/viewpo...?thread=101968

</F>

Mar 2 '06 #6
John Salerno enlightened us with:
Guido listed a few rules that he'd like to see implemented in 2.5,
and one of them was no more than one consecutive white space. I
don't know how realistic some of those suggestions are, but they
seem to be getting a little to restrictive.


I just read the PEP where my way of alignment is under a 'NO' header.
Too bad, since I think it can make things a lot clearer.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Mar 2 '06 #7
Fredrik Lundh wrote:
in his april 1st, 2005 paper ?

http://www.artima.com/weblogs/viewpo...?thread=101968


That was an April's Fools joke, right? I like it though :)
Maybe it'll happen!
Mar 2 '06 #8
Fredrik Lundh wrote:
John Salerno wrote:
Guido listed a few rules that he'd like to see implemented in 2.5, and
one of them was no more than one consecutive white space. I don't know
how realistic some of those suggestions are, but they seem to be getting
a little to restrictive.


in his april 1st, 2005 paper ?

http://www.artima.com/weblogs/viewpo...?thread=101968

</F>


Yes, that's the one.
Mar 2 '06 #9
rtilley wrote:
John Salerno wrote:
A minor concern, but I'm curious if there is any kind of best practice
for using whitespace within expressions and argument lists in the
Python world. For example:

1 + 2 or 1+2


IMO, good style calls for spaces. Most companies have style guides for
programmers to follow. Read this PEP:

http://www.python.org/peps/pep-0008.html


Thanks, this is great. Is it the most up-to-date?
Mar 2 '06 #10
rtilley wrote:
Fredrik Lundh wrote:
in his april 1st, 2005 paper ?

http://www.artima.com/weblogs/viewpo...?thread=101968


That was an April's Fools joke, right? I like it though :)
Maybe it'll happen!


All of it was a joke?
Mar 2 '06 #11
John Salerno wrote:
All of it was a joke?


You'd have to ask Guido that :)

I took it literally when I first read it b/c it made sense to me and I
did not notice the date. I don't think it will ever be _required_ of all
Python hackers, but I may be wrong.
Mar 2 '06 #12
Sybren Stuvel wrote:
I just read the PEP where my way of alignment is under a 'NO' header.
Too bad, since I think it can make things a lot clearer.


One reason is such code changes too much on code edits:
foo = 'bar'
foobar = 42
azimov = 3
to:
foo = 'bar'
something = 42
azimov = 3

which makes code differences hard to read.

--Scott David Daniels
sc***********@acm.org
Mar 2 '06 #13
rtilley enlightened us with:
I took it literally when I first read it b/c it made sense to me and
I did not notice the date. I don't think it will ever be _required_
of all Python hackers, but I may be wrong.


Well, part of it is a serious PEP. It being _required_ was the joke.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Mar 3 '06 #14
Scott David Daniels enlightened us with:
One reason is such code changes too much on code edits, which makes
code differences hard to read.


Good point. I'll keep it in mind :)

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Mar 3 '06 #15
Sybren Stuvel wrote:
Scott David Daniels enlightened us with:
One reason is such code changes too much on code edits, which makes
code differences hard to read.


Good point. I'll keep it in mind :)


Think particularly about using version management systems
and applying patches coming from different sources etc.

Touching more lines of code than you actually need will
both make it difficult for a reviewer to understand what
has changed (although good diff tools can be told to
ignore pure whitespace changes) and it will also increase
the risk of conflicts in the version management system if
several people are editing the same code.

Finally, if you end up with something like...

a = 1
b = 5
df = 7
ew = 5
qw = 7
a2 = 5
a4 = 7
d3 = 5
df = 7
this_is_a_very_long_variable_name_indeed = 42

....it's *not* easier to see what the value of
e.g. a4 is than if you had just used one space
between the variable name and the =.

As usual, Guido is right, even if it isn't
obvious at first unless you are Dutch. ;^)
Mar 3 '06 #16
Magnus Lycka wrote:
.... Touching more lines of code than you actually need will
both make it difficult for a reviewer to understand what
has changed (although good diff tools can be told to
ignore pure whitespace changes) ...

Such features have a nasty interaction with languages that use
significant whitespace; you might miss a re-blocking change while
suppressing the hassles from the extra "prettifying" spaces.

--Scott David Daniels
sc***********@acm.org
Mar 3 '06 #17
Magnus Lycka enlightened us with:
Think particularly about using version management systems and
applying patches coming from different sources etc.
I was :)
Finally, if you end up with something like...

a = 1
b = 5
df = 7
ew = 5
qw = 7
a2 = 5
a4 = 7
d3 = 5
df = 7
this_is_a_very_long_variable_name_indeed = 42
I won't. It was just an example. I write my code so it can easily be
read, not simply to blindly follow rules.
As usual, Guido is right, even if it isn't obvious at first unless
you are Dutch. ;^)


I'm Dutch.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Mar 4 '06 #18

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

Similar topics

12
by: lawrence | last post by:
I'm bad at regular expressions. Is this how I would look for any set of characters that go more than 60 characters without a white space? ..{60} Also, does this match a block of PHP in an...
72
by: Raymond Hettinger | last post by:
Peter Norvig's creative thinking triggered renewed interest in PEP 289. That led to a number of contributors helping to re-work the pep details into a form that has been well received on the...
24
by: Mahesh Padmanabhan | last post by:
Hi, When list comprehension was added to the language, I had a lot of trouble understanding it but now that I am familiar with it, I am not sure how I programmed in Python without it. Now I...
5
by: qwweeeit | last post by:
Hi all, I need to limit as much as possible the lenght of a source line, stripping white spaces (except indentation). For example: .. . max_move and AC_RowStack.acceptsCards ( self,...
1
by: MackS | last post by:
Dear all, I'm trying to use Python's readline module but I'm having some trouble. In particular, autocompletion seems to "get stuck" on white spaces. Please take a look at this code snippet: ...
38
by: Xah Lee | last post by:
sometimes i wish to add white space in <p> as to achived effects similar to tab. what should i do? using empty image seems the sure way but rather complicated. (and dosen't change size with...
3
by: Jordan S | last post by:
I have been using the old HTML unordered list in order to have bullet-point lists. But they don't look good because there is no white space between each list item. <UL> <LI>List Item Here...
12
by: JA | last post by:
Is there a way to remove all the white space in the fields? I have been using Find-and-replace - looking for 2 or 3 or 4 or 10 spaces and replacing them with none. I don't want to replace single...
12
by: snow | last post by:
Hi All, I noticed if file path has a white space, for example "C:\my document \test.txt", the function File.Exists(filePath) always return false in release mode. How could I make this function...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.