[Tutor] Class definitions

Alan Gauld alan.gauld at yahoo.co.uk
Mon Jan 1 18:53:16 EST 2024


On 01/01/2024 22:05, dn via Tutor wrote:
> Are you training folk, or requiring in Code Reviews, the use of 
> parentheses in stand-alone class definitions (or not)?
> 

I'm not quite sure who you are addressing here?

> Accordingly, wondered if you feel there is virtue in writing class-names 
> without parentheses, and only moving to such syntax upon reaching more 
> advanced levels involving inheritance (and multiple-inheritance)?

My personal take is that it would have been consistent with
Python's "explicit is better" approach if class definitions
always required the parens with object where appropriate

class MyClass(object):

Even though it meant more typing.

But Guido obviously thought different and we are stuck with
the definition structures. Since the idiomatic way of writing
it is to omit the parens that's what I do and encourage others
to do too. Idioms are powerful tools.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos





More information about the Tutor mailing list