strong/weak typing and pointers

Steven Bethard steven.bethard at gmail.com
Thu Nov 4 13:55:53 EST 2004


Diez B. Roggisch <deetsNOSPAM <at> web.de> writes:
> 
> > Does this make my concern any clearer?  What I'm asking for is an example
> > like yours above that not only shows that you can treat, say, the bits of
> > a float as an integer, but also shows why this would be useful.
> 
> The question is  not so much if there is an actual usecase, but more that if
> things _can_ be done, they inevitably _will_ be done.

No, the (my) question really was for an actual usecase. ;)  People do a lot of
things in programming languages, not all of them particularly good or
appropriate.  The recent example of intrinsics.replace to change the behavior of
Python's str class strikes me as one such example. =)  I would be much more
convinced that weak-typing is useful if someone could actually use it for me. ;)

> I can remeber abusing 32bit pointers in 68k processors by
> altering the most-significant byte. It took advantage of the fact that the
> old 68k had only 24 address registers, thus ignoring the msbyte. That
> allowed to pass 2 parameters in one pointer. And was for a short period of
> time considered a clever trick....

I'm not sure I see how this is taking advantage of weak-typing, unless I
misunderstand what you were doing here.  Did you ever interpret your
two-parameter structure as anything other than either a set of bits or the two
parameters?  You didn't ever treat the set of bits as a float, for example,
right?  You *could* have, of course, but I'm guessing your interpretation of the
bits was consistent...

My point here is that I think in most code, even when people do a bunch of
bit-twiddling, they have a single underlying structure in mind, and therefore
you see them treat the bits as one of two things: (1) The sequence of bits, i.e.
the untyped memory block, or (2) the intended structure.  IMHO, an example of
taking advantage of weak-typing would be a case where you treat the bits as
three different things: the sequence of bits, and two (mutually exclusive)
intended structures.

I guess I'm drawing a thin line here, but I see a difference between using the
untyped (bit-based) representation of a structure and actually converting a
structure between two different types.

Steve




More information about the Python-list mailing list