• 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: Is Apple's singleton sample code correct?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is Apple's singleton sample code correct?


  • Subject: Re: Is Apple's singleton sample code correct?
  • From: mmalcolm crawford <email@hidden>
  • Date: Thu, 1 Dec 2005 20:25:32 -0800


On Dec 1, 2005, at 8:06 PM, Jeff Laing wrote:

What I read was "one more person complaining about what appeared to be
poorly-explained complexity in Apple sample code".

It is certainly the case the the example etc. could be better explained, but I didn't get the impression that that was the issue (to be frank, I couldn't keep track of what the issue was...).

The fact that the "I've been doing this for ten years" crowd howled him down
did not undercut the complaint, in my opinion. Who cares that experienced
programmers have never had a problem with it? What about the rest of us?

"I've been doing this for a decade" doesn't excuse poor documentation. It does, however, suggest that the various claims that the pattern suggested is not fraught with the dangers claimed.



why on earth would it be "good form" to allow the caller to even think he
can *copy* a singleton? Or does the contract for -copy say "might not give
you a copy"? Lets check the documentation:
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ ObjC_cla
ssic/Protocols/NSCopying.html#//apple_ref/occ/intfm/NSCopying/ copyWithZone:
"Returns a new instance that's a copy of the receiver."

In general agreed -- and the documentation has been updated to remove the -copy method. Attempting to copy a singleton should really result in an error. Again, though, it might be reasonable to leave that in to guard against copy-style accessor methods...

[Taken out of order]
David asserts that the hackery is not *mandatory* - no-one else has
contradicted him authoratively, and they can't unless they expose
information about the internal voodoo, and if they know that stuff, then
***it should be explained in the sample***
[...]
Now, I agree that when David said:
To make it clear that Apple's singleton sample code is broken, that
there is no trade-off that justifies a singleton to be written that
way.

that he was expressing a fairly extreme opinion - "broken" is not the word
I'd use, unless you consider it from the perspective of "providing
educational value, explaining what you MUST do to write a singleton" rather
than "functioning correctly(?) even if you mistreat it".
The trade off that justifies that approach is, sadly, that Apple have a
finite number of hours to develop documentation and must spend their
resources where they get the most bang for buck. Pretty much everyone on
this thread understands the topic enough such that there's no point, from
our personal perspectives, on improving that specific sample. Its only a
question of how much you care about the novices who follow ....

Agreed and disagreed.
If the point was simply that the example needs to be better explained, then that's a fair comment and it would be appropriate to file a bug report about it (again, I haven't seen one...). And from my perspective, I do care about how novices who follow, so have taken it upon myself to try to get it improved. There will be a first pass revision shortly, and I would welcome suggestions for how it might be made better with more time in the future...

mmalc

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Is Apple's singleton sample code correct?
      • From: Dietmar Planitzer <email@hidden>
    • Re: Is Apple's singleton sample code correct?
      • From: Ondra Cada <email@hidden>
References: 
 >RE: Is Apple's singleton sample code correct? (From: Jeff Laing <email@hidden>)

  • Prev by Date: Implementing image pre-caching in a multi-threaded app.
  • Next by Date: What is the best way to use NSOutlineView without NSTreeController?
  • Previous by thread: Re: Is Apple's singleton sample code correct?
  • Next by thread: Re: Is Apple's singleton sample code correct?
  • Index(es):
    • Date
    • Thread