What If..... Strong Types

Don Garrett garrett at bgb.cc
Wed Jun 19 14:48:42 EDT 2002


brueckd at tbye.com wrote:

> One approach is to not even define a weight member variable until I've
> weighed the package, and I can test to see if I've weighed it already by
> checking for the presence of that variable. The alternative is to define a
> weight variable up front and then initialize it to some dummy value, e.g.
> -1. I believe that when I do this, though, it is more because of my
> "upbringing" in other languages rather than it being a good idea. Does the
> package really weigh -1? No.  Worse, to make it be "good code" I'll
> probably define -1 to be NOT_WEIGHED or something, and check against it so
> I'm not using magic numbers. 

   I might suggest the use of None over -1, since it has a real meaning of 
'not really there'. But not defining the member would have the same meaning as 
well. I do get your point here.

> It's sometimes hard for me to model my objects this way because of having
> had to always do it the other (completely statically defined) way, but
> when this approach works the solutions are often quite elegant and
> straightforward (btw - I believe that a good portion of bugs and program
> cruftiness is related to forcing the programmer to clearly define, up
> front, what the complete type of the object is. In many cases this forces
> the programmer to make decisions without enough information, in others it
> is too constricting, and in others it's just too tedious to make the
> programmer worry about all those details, and in all cases general
> hackiness ensues).
> 
> -Dave

   The point about programmers having to make decisions about the data before 
they are ready is a very good one. I've certainly run into that myself, but 
I've never heard it phrased that way, so it never clicked the way it just did.

   Don't you find that you miss the advantages of a clear definition of what a 
class is and/or does? That's more important with group development, but even 
when it's just me.... I need memory aids.

   Regardless, thanks for the reply. I'm learning, and I like that!

-- 
Don Garrett                             http://www.bgb.cc/garrett/
BGB Consulting                                      garrett at bgb.cc




More information about the Python-list mailing list