• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mutability
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mutability


  • Subject: Re: Mutability
  • From: "Josh Braun" <email@hidden>
  • Date: Wed, 21 Nov 2001 09:27:23 -0800

If I may add to Julien's point, it has been my experience that excessive programmatic tests and case statements are often a sign of a lack of polymorphism. Ondra proposed the following formulation:

"... give any id to me; I'll ask it what kind it is, and I'll behave accordingly."

Perhaps a handier formulation is as follows:

"... give me a instance that conforms to the interface of type X (so that I know the contract between X and its clients); I'll ask it to do something for me, and then its behavior can vary according to what it actually is "

That's not to say that one ought never to use messages like 'isKindOf' to test for certain types of objects -- but, to borrow a term from Kent Beck and Martin Fowler, excessive conditionality in code tends to "smell bad", no matter whether your language is strongly typed or loosely typed.


On Wednesday, November 21, 2001, at 07:37 AM, Julien Dufour wrote:

On Wednesday, November 21, 2001, at 02:57 PM, Ondra Cada wrote:

So far as I understand OOP, the proper OO point of view is "give _any_
object to me; I'll determine what kind it is, and I'll behave accordingly".

That's not OOP, that untyped langage programming.

[Delete]

DMC> Really, using things like "isKindOfClass" is often a symptom of bad
DMC> design.

Is it?!? I'd say it is a symptom of _THE PROPER_, ie. run-time design, as
compared with the bad, C++-like compile-time one!

No it's really not. You are recommending untyped langage instead of typed ones. Typechecking is compilation stage where the compiler tells you if you are doing something wrong. Stronger typesystems lead to robuster programs. With the ""give _any_ object to me; I'll determine what kind it is, and I'll behave accordingly" philosophy (untyped philosophy), anything can happend at runtime. You then have to produce much more complex code to check what happend and to handle invalid cases... etc. You do compiler's work here (aren't computer there to work instead of us).

This work SHOULD be done by the compiler. It won't commit mistake (but you will), it is automatic, you save time and work, and you procuce more safe code, you have less to debug! Moreover, your code will be much faster as lot of tests are not needed anymore, and many optimisations are made possible.

The dictinction between mutable objects and not mutable ones, even if the same objects are used behind (I think it is the case, but we do not have to know, that's implementation, not interface!), is a really good thing. It uses as much as possible the poor capabilities of ObjectiveC/Java type systems.
--
Julien Dufour
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


  • Follow-Ups:
    • Re: Mutability
      • From: "John C. Randolph" <email@hidden>
References: 
 >Re: Mutability (From: Julien Dufour <email@hidden>)

  • Prev by Date: Re: Mutability
  • Next by Date: Re: Problem with method in NSBezierPath?
  • Previous by thread: Re: Mutability
  • Next by thread: Re: Mutability
  • Index(es):
    • Date
    • Thread