Re: Stylistic question about inheritance

2005-04-01 Thread Guy Bolton King
Andrew Koenig [EMAIL PROTECTED] writes: Lonnie Princehouse [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] If you try this sort of inheritance, I'd recommend writing down the formal grammar before you start writing classes. Don't try to define the grammar through the

Stylistic question about inheritance

2005-03-31 Thread Andrew Koenig
Suppose I want to define a class hierarchy that represents expressions, for use in a compiler or something similar. We might imagine various kinds of expressions, classified by their top-level operator (if any). So, an expression might be a primary (which, in turn, might be a variable or a

Re: Stylistic question about inheritance

2005-03-31 Thread Carl Banks
Andrew Koenig wrote: [snip] Of course, there are reasons to have a base class anyway. For example, I might want it so that type queries such as isinstance(foo, Expr) work. My question is: Are there other reasons to create a base class when I don't really need it right now? Well, Python

Re: Stylistic question about inheritance

2005-03-31 Thread Martin v. Löwis
Andrew Koenig wrote: Of course, there are reasons to have a base class anyway. For example, I might want it so that type queries such as isinstance(foo, Expr) work. My question is: Are there other reasons to create a base class when I don't really need it right now? You would normally try to

Re: Stylistic question about inheritance

2005-03-31 Thread Lonnie Princehouse
If you try this sort of inheritance, I'd recommend writing down the formal grammar before you start writing classes. Don't try to define the grammar through the inheritance hierarchy; it's too easy to accidentally build a hierarchy that can't be translated into a single-pass-parsable grammar...

Re: Stylistic question about inheritance

2005-03-31 Thread Andrew Koenig
Carl Banks [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Well, Python seems to get along fine without the ability to do isinstance(foo,file_like_object); probably better off in the end for it. So I'd say you should generally not do it. Inheritence is for when different classes

Re: Stylistic question about inheritance

2005-03-31 Thread Andrew Koenig
Martin v. Löwis [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] You would normally try to avoid type queries, and rely on virtual methods instead, if possible. Of course. It seems likely for the application that code can be shared across different subclasses, for example, you

Re: Stylistic question about inheritance

2005-03-31 Thread Andrew Koenig
Lonnie Princehouse [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] If you try this sort of inheritance, I'd recommend writing down the formal grammar before you start writing classes. Don't try to define the grammar through the inheritance hierarchy; it's too easy to accidentally

Re: Stylistic question about inheritance

2005-03-31 Thread Irmen de Jong
Andrew Koenig wrote: Lonnie Princehouse [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] If you try this sort of inheritance, I'd recommend writing down the formal grammar before you start writing classes. Don't try to define the grammar through the inheritance hierarchy; it's too

Re: Stylistic question about inheritance

2005-03-31 Thread Donn Cave
In article [EMAIL PROTECTED], Andrew Koenig [EMAIL PROTECTED] wrote: Carl Banks [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Well, Python seems to get along fine without the ability to do isinstance(foo,file_like_object); probably better off in the end for it. So I'd

Re: Stylistic question about inheritance

2005-03-31 Thread Stefan Seefeld
Andrew Koenig wrote: Of course, there are reasons to have a base class anyway. For example, I might want it so that type queries such as isinstance(foo, Expr) work. My question is: Are there other reasons to create a base class when I don't really need it right now? Coming from C++ myself, I

Re: Stylistic question about inheritance

2005-03-31 Thread Martin v. Löwis
Andrew Koenig wrote: So, for example, you don't think it's worth including the base class as a way of indicating future intent? No. In this respect, I believe in XP: refactor when the need comes up, but not before. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Stylistic question about inheritance

2005-03-31 Thread Bengt Richter
On Thu, 31 Mar 2005 20:24:08 GMT, Andrew Koenig [EMAIL PROTECTED] wrote: Martin v. Löwis [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] You would normally try to avoid type queries, and rely on virtual methods instead, if possible. Of course. It seems likely for the application

Re: Stylistic question about inheritance

2005-03-31 Thread Lonnie Princehouse
Well, that's true, but I meant to convey that no grammatical entity is the base class of another entity, so it's a flat inheritance tree in that respect. ASTNode would not be something that the parser would know anything about. I guess that's sort of moot if your expression trees are just a

Re: Stylistic question about inheritance

2005-03-31 Thread Michele Simionato
Koenig: want to know about the Python community's stylistic preferences for defing such hierarchies that don't absolutely need a root. I don't know if there is an official style guide or a Guido's prononcement on the issue. Personally I found such hierarchies attractive in the past, but

Re: Stylistic question about inheritance

2005-03-31 Thread Ivan Van Laningham
Hi All-- Michele Simionato wrote: recently I realized that they look better on the paper than in practice. A non-needed class just adds cognitive burden to the maintainer. Agreed. Too many classes make me think I'm back trying to figure out what the )([EMAIL PROTECTED] those guys were

Re: Stylistic question about inheritance

2005-03-31 Thread Steve Holden
Andrew Koenig wrote: Martin v. Löwis [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] You would normally try to avoid type queries, and rely on virtual methods instead, if possible. Of course. It seems likely for the application that code can be shared across different subclasses,