Trailing comma

Peter Hansen peter at engcorp.com
Wed Oct 22 16:38:30 EDT 2003


Michael Geary wrote:
> 
> > > Timo Virkkala wrote:
> > > Maybe I should get into the habit of always including the
> > > trailing comma and see where I get. Before this I didn't
> > > even know that it was allowed.
> 
> > 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.

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!




More information about the Python-list mailing list