r wrote:
On Jan 1, 4:40 pm, Robert Kern <robert.k...@gmail.com> wrote:
Hamish McKenzie wrote:
sometimes I want to be able to initialize an instance with a variety of 
different data types.
as an obvious example I might want to initialize a 4x4 matrix with either 16 
floats, a list/tuple or 16 floats, another matrix or a quaternion.
is there any other way to do it other than putting case statements in the 
__init__ method of the class, or having a Matrix.FromQuaternion( quat )?
I recommend keeping the __init__() as dumb as possible. Ideally, it should just
assign to attributes. I would add a from<foo>() classmethod for each <foo> that
I wanted to support. If I really wanted an all-singing, all-dancing
initialization method, I would add another classmethod that would just dispatch
to the appropriate type-specific classmethod. I prefer classmethods to plain
functions because I can subclass.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

Why are you busting into this thread?

Are you talking to me, or Hamish, who (presumably unintentionally) responded to a message instead of making a new thread?

If you want to suggest that one should have more care about starting new threads, that's fine, but please do not jump to the conclusion that there is malintent. And don't chastise people for not being as rude as you.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to