Theocacao
Leopard
Design Element
Comment on "Class Variables and Categories"
by David Young — Nov 29
Dave:

I got the idea that you were trying to use categories to override methods from this sentence:

The problem with +initialize is that it is virtually useless for categories, in that if I override a class's initialize method in my category, I can't call the original initialize. Also, if I have two categories on a class, and both have initialize methods, it is unclear which one will be called.

I apologize for the misunderstanding. But the paragraph as written suggests that you can't write two categories on the same class containing +initialize methods, which is correct, but for the wrong reason.

It does seem like thread safety is backing you guys into implementation corners. I wouldn't want to be dependent upon __attribute__ ((constructor)) as I agree with someone else here that it seems like the kind of thing that might break in future gcc releases.

Have you considered maybe moving your "class variables" into a class of their own? Perhaps the code you want to put in category methods might be better moved into its own class, which you can initialize early (e.g., ahead of the time at which threads are spawned) and thus avoid taking locks later on?
Back to "Class Variables and Categories"
Design Element

Copyright © Scott Stevenson 2004-2015