• 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: + initialize docs conflict?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: + initialize docs conflict?


  • Subject: Re: + initialize docs conflict?
  • From: j o a r <email@hidden>
  • Date: Wed, 2 Feb 2005 09:39:03 +0100


On 2005-02-02, at 02.17, Simon Robins wrote:

A static flag means storage, and in addition, to be totally safe, that
implies a lock to synchronize access. So a little more overhead
overall.
You've convinced me. Thanks.
On the other hand the static flag is thread safe in 10.2+, and is the singleton pattern which may be more easily recognised by those who come after you.

I don't think that it's very useful to mix thread safety concerns into this discussion that at least up until now was at a more general level. I would assume that most classes that you write will not benefit from having a thread safe +initialize (*), and the ones that do will require a very special and super careful design in any case.


*) The absolute majority of classes should of course (IMO) not have an +initialize at all, as it's so easy to make incorrect assumptions about when it's going to be called and what you can do when it's called.

On 2005-02-02, at 02.25, John Stiles wrote:

On the other hand the static flag is thread safe in 10.2+, and is the singleton pattern which may be more easily recognised by those who come after you.
Catering to the weaknesses of other programmers doesn't seem like it promotes best practices to me. I'd rather write the best possible code, and if they don't understand it, they'd learn something new and valuable.

Writing code that is easier for your colleagues (and yourself!) to understand is a big win in my book. You have to strike a balance, but personally I strongly favour maintainability.
I don't think that promoting easily understandable code has anything to do with an ambition to "cater to the weaknesses of other programmers", and I don't think that Simon wanted to imply that "those cho come after you" needs to be "weaker" programmers. In fact, I don't like the tone of that statement at all - but perhaps I'm not reading it correctly, or perhaps I'm just not the programmer you are John. ;-)


A good thing about using a static BOOL is that you can move the method over to a new class without having to remember to review anything but the "core" of the method (ie. not including the if-statement). I try to avoid using references to the explicit class name if possible (ie. use [self class] rather than MyClass where applicable), as it makes it easier to re-factor / re-use the code.

That said, I've enjoyed this thread - I'll review how I guard calls to +initialize.

j o a r

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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: + initialize docs conflict?
      • From: Will Mason <email@hidden>
References: 
 >Re: + initialize docs conflict? (From: Bill Cheeseman <email@hidden>)
 >Re: + initialize docs conflict? (From: Simon Robins <email@hidden>)
 >Re: + initialize docs conflict? (From: John Stiles <email@hidden>)

  • Prev by Date: Re: Drag from iTunes
  • Next by Date: Re: + initialize docs conflict?
  • Previous by thread: Re: + initialize docs conflict?
  • Next by thread: Re: + initialize docs conflict?
  • Index(es):
    • Date
    • Thread