[Edu-sig] Properties use case
delza at livingcode.org
Sat Mar 18 00:08:35 CET 2006
> > Are you a CS type? If so, speak directly.
I'm a CS type (BS in CS, MS in CSEE). Kirby's right, it's generally
considered "better" to return a new primitive type rather than mutate
it in place. Many programming languages impose "striction
functionality" which means you have no (or nearly no) mutable state at
all, just returning new values. This can avoid many, many types of
problems in programming, but isn't as friendly in some cases.
For "better" in the first sentence above you can insert any of:
faster, more stable, less error-prone, and frequently more readable.
> > If not, why do you feel compelled to speak on their behalf.
> I'm volunteering this information.
And therein I think we have the nub of the frequent Arthur/Kirby
semi-argument. My impression is that Kirby often offers suggestions
and information, and Arthur interprets this as telling him what to do
and pushes back. No idea what to do about this, just pointing it out.
> > My complex number is an old fashioned object. For my purposes - destroying it and
> > recreating another every time a value changes is wasteful, (and cruel ;))
Wasteful how? By implementing your own complex type and ignoring the
built-in one you are wasting memory, speed, and (arguably) your time.
The bytes that are thrown away when an existing complex object is
reclaimed are treated humanely and given a decent recycling to emerge
as new objects. Where is the waste?
> how primitive numbers behave too. -2 .__invert__() returns 3, doesn't
> alter -2 in any way.
I hadn't noticed the __invert__ method before so I tested this:
-2.__invert__() gave a SyntaxError
(-2).__invert__() gave 1
(2).__invert__() gave -3
Just to be pedantic about it. %-)
> It all depends on your goals. If your goal is a working PyGeo with
> code your well understand, then the mutable complex number may be no
> hindrance at all. If your goal is to get your source code studied in
> CS departments, as exemplary of how to go about coding such a VPython
> app, that'd be a different challenge.
That about sums it up. You can make up you're own types to your
hearts content: mutable ints and floats if you want. It can be a good
learning experience, as long as you're not trying to to pass it off as
a best practice.
More information about the Edu-sig