| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
There is no such var of which I am aware. Too bad, too, it'd be a neat feature. Irregardless, I wouldn't want to use it in this manner; the overhead of sending the isKind/MemberOfClass messages would negate the use.Fair enough. Although I must say your path towards optimized ObjC is a well travelled road, without a happy ending.. :/
I'm in fact the only coder for the project I have in mind, but I prefer that the compiler enforce some things, because as a human I'm as prone to mistakes as all the rest.Fair enough, I suppose. But, where do you draw the line.. :)
That's two messages just to retrieve a variable reference that would require two pointer deferences given compiler support (i.e. ((TheClass *)self->isa)->sharedVar). You tell me which is faster :).Would it be possible, as a workaround, for you to maintain a pointer in each instance which refers to the global variable? At least then you'd only have to do the two message calls when you initialize each instance. If your variable will be a pointer of some kind anyway, there shouldn't be any overhead with dereferencing and what have you.
2) promote thread-unsafe coding (globals require locks to be thread-safe unless they are guaranteed to be accessed from only a single thread)You'd have to lock the shared variable somewhere, anyway, whether it be in your setter function or wherever else.
3) promote non-reentrant coding (a global can be read fine from a reentrant method, but if that method writes to the global, you're in trouble)My memory's a bit faded on this... could you elaborate a bit, if it's still on topic? While style is a subjective thing, crashes and data corruption is something I'd like to know about. :)
4) violate OO principles, specifically enscapulation (globals can not belong to any unit of code smaller than a single object file (compiled source code file), while member variables belong only to their owning class).It may only be me, but I find when writing in C++ I have to violate a lot of OO principles, simply because the language makes it too difficult to do some things - particularly the sort of dynamism I'm used to in ObjC. Sure, there's RTTI and virtuals and so forth, but it's never quite enough, it seems..
Perhaps we're doomed always to have imperfect OO languages, because sooner or later practicality - whether ease of coding, performance, or otherwise - steps in. I guess it's a matter of picking which imperfections you prefer. :)
-- Sed quis custodiet ipsos custodes?
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.