Antoon Pardon wrote: > Op 2005-12-13, Chris Mellon schreef <[EMAIL PROTECTED]>: [...] >>If you have a consistent API and you're checking for error values from >>your GTK functions, then you already have a lot more code than using 2 >>varaibles will cost you. 10 lines, maybe. >> >>The fact that you think setting two variables is "too hard" but you're >>perfectly happy with checking for boolean types instead just testing >>truth values I think is a real problem. > > > These aren't just truth values. If I would have to go split in > meaningfull truth values I would need at least three variables. > > >>You aren't saving yourself any >>performance. You're barely even saving yourself any typing, and you're >>making your code (intentionally, it seems) that much more compllicated >>and hard to understand. > > > There is nothing complicated or hard to understand. > Nope, just a messy, hard to maintain misuse of a single variable for multiple purposes. Perfectly simple, perfectly easy to understand and rather more bug-prone that a straightforward separation of state and other data.
> I find it odd that each time declaration are mentioned people here > react very rejecting and say that one of the features they love > about python is the freedom that a name is not limited to a variable > of one type, while when someone makes use of that freedom labeling > such code as code smell. > There's a difference between using a single name to refer to values of polymorphic types (which can therefore all be handled by the same code) and using the same name to reference state information in one case (this item has no connected callback) and other data (the callback is to such-and-such an object). > But lets make an effort to make the code more readable. What > about the following suggestion. I use a kind of EnumType with > two values: NotRegistered and Registerd. And the name of the > type is NotConnected. So I can then write > > if type(self.callback) is NotConnected. > > Would that be selfdocumenting enough for you? > It would be somewhat more self-documenting, but why not just use one name to indicate the state and another, only meaningful in certain states, to indicate the callback? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list