structure in Python

C

Cousin Stanley

Peter ....

Thanks for the reply ....

I usually format long lists as one item per line as well ....

I only stuck Alex' example on a single line
since it was short and I was using the interpreter ....

The style that looks the most natural and seems the easiest
to extend and edit to me is ....

x = [ 'fe' ,
'fi' ,
'fo' ,
'fum' ]
 
C

Cousin Stanley

| Depending on the style guide the teacher is using,
| even "Uncle Scrooge took Huey, Duey, and Louie to the park"
| .... "Uncle Scrooge took Huey, Duey and Louie to the park"
| ....

Dennis ....

Thanks for the reply ....

This style difference also occurred to me
after I posted the example ....

I think I remember it being taught
that it is a grammatical option
and correct in either case ....

I always include the _final_ comma in these cases myself,
as it usually seems harder to read and potentially confusing
without it ....
 
M

Michael Geary

Georgy Pruss wrote:
Another "solution" is just to look at the previous line and
check if it has the comma or not. You'd better get a habit to
THINK and not do things mechanically, as others suggest.

It is better to think and not do things mechanically, and that's exactly why
people add the trailing comma.

If you do things mechanically, you may leave out the trailing comma, because
it certainly isn't necessary.

If you think about making your code maintainable, you will look for ways to
prevent mistakes when people edit your code later. The trailing comma helps
prevent mistakes, so you'll use it.

-Mike
 
P

Peter Hansen

Michael said:
It is better to think and not do things mechanically, and that's exactly why
people add the trailing comma.

If you do things mechanically, you may leave out the trailing comma, because
it certainly isn't necessary.

While I agree with your point, which is that putting *in* the trailing
comma is the result of a great deal of thought in advance (such as we're
doing right now), I have to disagree with your explanation for what
"mechanical" would imply.

Mechanical would be more appropriately used when you do the same thing
over and over, completely without having to think. The mere fact that
you say "because it isn't necessary" shows that thought had to be involved
(to evaluate the need for the comma) and therefore it's not mechanical.
If you think about making your code maintainable, you will look for ways to
prevent mistakes when people edit your code later. The trailing comma helps
prevent mistakes, so you'll use it.

Quite true!
 
P

Patrick Maupin

Cousin said:
The style that looks the most natural and seems the easiest
to extend and edit to me is ....

x = [ 'fe' ,
'fi' ,
'fo' ,
'fum' ]

Other people have raised some good points as to why using
trailing commas can be better, but for my money the best
reason to consistently use trailing commas is how a CVS
(or other) diff will look later. You can either see
one deleted line plus two added lines, or a single added
line, your choice.

Pat
 
G

Georgy Pruss

Patrick Maupin said:
Cousin said:
The style that looks the most natural and seems the easiest
to extend and edit to me is ....

x = [ 'fe' ,
'fi' ,
'fo' ,
'fum' ]

Other people have raised some good points as to why using
trailing commas can be better, but for my money the best
reason to consistently use trailing commas is how a CVS
(or other) diff will look later. You can either see
one deleted line plus two added lines, or a single added
line, your choice.

Pat

You can always find a better diff which will show you an added
comma and an additional line. Again, it's a tool problem.

Georgy
 
P

Patrick Maupin

Georgy said:
You can always find a better diff which will show you an added
comma and an additional line. Again, it's a tool problem.

Do not presume, simply because I choose to arrange my affairs
such that I can usually use a BB gun more effectively than many
can use a howitzer, that I have a "tool problem."

Pat
 
C

Cousin Stanley

| ...
| the best reason to consistently use trailing commas
| is how a CVS (or other) diff will look later.
| You can either see one deleted line plus two added lines,
| or a single added line, your choice.

Patrick ....

Thanks for the info ....

I'm not currently using versioning tools
as I'm only a single developer and most
of my code at this point is very simple
and a backup copy or two usally work OK for me ....

However, I will keep this in mind for the future ....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,918
Members
47,458
Latest member
Chris#

Latest Threads

Top