Re: Class definitions
dn via Tutor <[email protected]> Tue, 2 Jan 2024 14:08:38 +1300
| Newsgroups | gmane.comp.python.tutor |
|---|---|
| Organization | DWM |
| Message-ID | <[email protected]> |
On 2/01/24 12:53, Alan Gauld via Tutor wrote: > 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? When helping folk start-out, the preference is to go with the one and only one way to do things. Code Review is about (organisational) convention. >> 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. A useful concept to understand - but often rather too theoretical for first-timers. Which has been true only since 'new style types' were brought-in (somewhere back in the mists of Python 2.n history). Thus, one of several changes to the way we define custom-classes. > 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. That's what I was wondering. Is there some authoritative statement for this? OTOH it seems a little odd, that some classes are defined with parentheses and others not. Hence the 'full' parentheses indicate a sub-class, whereas the 'empty' ones indicate a super-class or something that stands-alone and outside of any hierarchy. Consulting PEP-008 (latest update, last month) there is considerable discussion about "Designing for Inheritance" (much of which curls the hair of SOLID OOP-ers) but no mention of parentheses (that I noticed). Although, the one code-example does feature the ubiquitous Cartesian Co-ordinate as "class Point:"!? -- Regards, =dn _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor