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? 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"
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
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
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.
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>
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
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.
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?
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.
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
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
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
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. ;^)
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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,...
|
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:
...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |