Re: python styles: why Use spaces around arithmetic operators?

2010-07-30 Thread Cousin Stanley

> Parentheses are punctuation. Why not leave spaces around the commas as well, 
> to be consistent?
>
> myTuple = ( 1 , 2 , 3 , 4 , 5 )

  Personally, I do use this particular style with commas
  as I find it more readable to my old and tired eyes 

  Mandate  m o r e  whitespace  :-)


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-30 Thread Lawrence D'Oliveiro
In message , J.B. Brown 
wrote:

> I personally prefer to be slightly excessive in the amount of spacing
> I used, especially when parentheses are involved.
> 
> myTuple = ( 1, 2, 3, 4, 5 )

Parentheses are punctuation. Why not leave spaces around the commas as well, 
to be consistent?

myTuple = ( 1 , 2 , 3 , 4 , 5 )

T,FTFY.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-28 Thread J.B. Brown
I personally prefer to be slightly excessive in the amount of spacing
I used, especially when parentheses are involved.

In no way do I assert that my code style is right for all situations,
but here are a few examples of my personal style.
---
myTuple = ( 1, 2, 3, 4, 5 )# Comment about what this tuple will
conceptually represent or store.

myTuple2 = ( 1, 2, 3*myFunc(4), 4*myFunc2( "text arg" ), )   # Yes, I
leave the tailing comma for spacing and to remind myself it is a
tuple/list.

textFieldWidth = 80 / numFields # Balance width of fields

fileObject.write( "My text goes here.  Value of some function = " +
str( someFunc( argList ) ) )  # Write out results.
---
Combining my code style with the parenthesis/brace/bracket
highlighting feature of Vi/Vim makes it easy for me to figure out if I
have closed all braces, and additionally what is the context in which
I am nesting functions or arguments.

Again, this is just my preference, but it emerged over time after many
hours of development and debugging on remote machines where only a
terminal environment and a text-based editor are available.

Even in my comments, in which I _strongly_ believe in a minimum of 1
comment line per 3 code lines (1:3) though I often code 1:2 or 1:1, I
use the parenthesis style above.
Example:
# The true positive rate of an experiment is calculated as: TPR = [ TP
/ ( TP + FN ) ]  .

Just food for thought.

J.B. Brown
Kyoto University
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-27 Thread Roy Smith
In article ,
 Stephen Hansen  wrote:

> PEP8 is a style guide. Parts of style guides are rational judgements and
> decisions based on experience and can certainly be "explained" or
> justified, but parts are just... personal taste. Style is part rational
> thought and part intuition, and in the latter -- people will disagree
> quite a bit. There's no right or wrong there. There isn't always a
> rationale.

I strongly suggest that ALL Python projects adopt PEP-8.  Here's why.

Style, at one level, doesn't really matter.  Yet, it's something people 
get worked up over.  If you add up all the time people have wasted 
arguing about stupid shit like indenting and where the braces go (in 
languages that have them) and how to spell variable names, we could have 
sent a man to Mars and had time left over to solve P = NP.

I don't agree with PEP-8 100%, but it's perfectly reasonable.  Avoiding 
all that time wasting arguing about trivia like variableName vs 
VariableName vs variable_name more than pays me back for any minor 
arguments I might have with the style.

If everybody in the entire world uses the same style, then as people and 
code move around from project to project, everybody benefits by fitting 
in better.

As the old-time press pythonistas would say, "PEP-8 and be there".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-26 Thread Stephen Hansen
On 7/26/10 3:20 PM, Peng Yu wrote:
> This webpage http://www.python.org/dev/peps/pep-0008/ recommends the
> following. It looks to me that both styles are fine. Could anybody let
> me know what the rationale is behind this recommendation?

PEP8 is a style guide. Parts of style guides are rational judgements and
decisions based on experience and can certainly be "explained" or
justified, but parts are just... personal taste. Style is part rational
thought and part intuition, and in the latter -- people will disagree
quite a bit. There's no right or wrong there. There isn't always a
rationale.

Guido finds "x=a+1" less readable then "x = a + 1". Originally he wrote
this down with other anecdotal little tidbits up into an eassy and
posted it on the python.org website. Eventually, others decided that his
intuitive sense of style actually tended to be rather spot on for them
too (why wouldn't it, since that same sense of style brought Python into
existence and most of us quite like it), and so that guide and some
others were codified into PEP8, and tweaked from time to time.

PEP8 is only a "rule" for the stdlib, and only for new code in the
stdlib at that -- and its only really a rule to encourage consistency
and maintainability, not because its objectively The Right Way To Code.

Personally, while I agree with much of it, I disagree in several points
and ignore PEP8 whenever it suits me (most notably on line length rules,
and for a long time on methodNamingSchemes, but lately I've found I'm
coming_around).

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-26 Thread geremy condra
On Mon, Jul 26, 2010 at 4:31 PM, Steven D'Aprano
 wrote:
> On Mon, 26 Jul 2010 17:20:09 -0500, Peng Yu wrote:
>
>> This webpage http://www.python.org/dev/peps/pep-0008/ recommends the
>> following. It looks to me that both styles are fine. Could anybody let
>> me know what the rationale is behind this recommendation?
>>
>>     - Use spaces around arithmetic operators:
>
> Because it looks better and is easier to read. Operators are small
> (single characters) and sometimes need space around them to stand out.
>
>>           i=i+1
>
> See? It's hideously ugly and cramped. It's much worse if you use larger
> names:
>
> sensiblynamedvariable=sensiblynamedvariable+1
>
> But use your common sense. I usually group powers, multiplications and
> divisions, and separate additions and subtractions:
>
> y = 2*x + 1 - (3*x - 4/(2 + x**2))**-2
>
> And unary + and - operators should always be grouped with their operand:
>
> y = -2  # not "- 2"

This is the rule that I use, with the exception that I will generally
explicitly parenthesize the numerator in a division, since my eyes
frequently gloss over the / symbol for some reason.

Geremy Condra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-26 Thread Steven D'Aprano
On Mon, 26 Jul 2010 17:20:09 -0500, Peng Yu wrote:

> This webpage http://www.python.org/dev/peps/pep-0008/ recommends the
> following. It looks to me that both styles are fine. Could anybody let
> me know what the rationale is behind this recommendation?
> 
> - Use spaces around arithmetic operators:

Because it looks better and is easier to read. Operators are small 
(single characters) and sometimes need space around them to stand out.

>   i=i+1

See? It's hideously ugly and cramped. It's much worse if you use larger 
names:

sensiblynamedvariable=sensiblynamedvariable+1

But use your common sense. I usually group powers, multiplications and 
divisions, and separate additions and subtractions:

y = 2*x + 1 - (3*x - 4/(2 + x**2))**-2

And unary + and - operators should always be grouped with their operand:

y = -2  # not "- 2"



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-26 Thread rantingrick
> Martin wrote:
>
> Wat is er mis met klompen?

Well specifically their made from wood and wood is a very hard
substance. Also i did not go into detail but he makes sure to pick
shoes that are three sizes too small. You know a good podiatrist can
be tough to come by in these times. It's a pretty severe punishment if
you ask me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-26 Thread Martin P. Hellwig

On 07/27/10 00:06, rantingrick wrote:

On Jul 26, 5:20 pm, Peng Yu  wrote:

This webpagehttp://www.python.org/dev/peps/pep-0008/recommends the
following. It looks to me that both styles are fine. Could anybody let
me know what the rationale is behind this recommendation?


The rational is simple. Guido is God and if you don't follow his words
then you will be tortured. His favorite means is by forcing you to
wear Dutch wooden shoes every day whist programming Ruby! ;-)


Wat is er mis met klompen?

--
mph

--
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-26 Thread rantingrick
On Jul 26, 5:20 pm, Peng Yu  wrote:
> This webpagehttp://www.python.org/dev/peps/pep-0008/recommends the
> following. It looks to me that both styles are fine. Could anybody let
> me know what the rationale is behind this recommendation?

The rational is simple. Guido is God and if you don't follow his words
then you will be tortured. His favorite means is by forcing you to
wear Dutch wooden shoes every day whist programming Ruby! ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-26 Thread Thomas Jollans
On 07/27/2010 12:20 AM, Peng Yu wrote:
> This webpage http://www.python.org/dev/peps/pep-0008/ recommends the
> following. It looks to me that both styles are fine. Could anybody let
> me know what the rationale is behind this recommendation?

Beauty is in the eye of the beholder, even when we call it "coding style".

There is no rationale, except if you accept "easier to read", "looks
better", or "that's what Guido has been doing for years".

> 
> - Use spaces around arithmetic operators:
> 
>   Yes:
> 
>   i = i + 1
>   submitted += 1
>   x = x * 2 - 1
>   hypot2 = x * x + y * y
>   c = (a + b) * (a - b)
> 
>   No:
> 
>   i=i+1
>   submitted +=1
>   x = x*2 - 1
>   hypot2 = x*x + y*y
>   c = (a+b) * (a-b)
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


python styles: why Use spaces around arithmetic operators?

2010-07-26 Thread Peng Yu
This webpage http://www.python.org/dev/peps/pep-0008/ recommends the
following. It looks to me that both styles are fine. Could anybody let
me know what the rationale is behind this recommendation?

- Use spaces around arithmetic operators:

  Yes:

  i = i + 1
  submitted += 1
  x = x * 2 - 1
  hypot2 = x * x + y * y
  c = (a + b) * (a - b)

  No:

  i=i+1
  submitted +=1
  x = x*2 - 1
  hypot2 = x*x + y*y
  c = (a+b) * (a-b)

-- 
Regards,
Peng
-- 
http://mail.python.org/mailman/listinfo/python-list