Re: [Pyobjc-dev] problem saving as rtfd
Brought to you by:
ronaldoussoren
From: Marcel W. <ma...@me...> - 2003-05-12 21:21:20
|
On Monday, May 12, 2003, at 07:51 Uhr, Ronald Oussoren wrote: > > On Monday, May 12, 2003, at 08:43 Europe/Amsterdam, Marcel Weiher > wrote: > >> >>> plaintext = "" >>> cyphertext = NSData.alloc() >> >> Minor nit: you shouldn't really have a partly initialized instance >> flying around. > > This is *not* a minor issue. Some Cocoa classes will cause crashes if > you do anything with them before calling init, and that includes > releasing them. PyObjC tries to protect you from this, but this is > still bad form. Yes, actually doing anything with the object other than sending some sort of init message *would* be bad. However, the original poster didn't do that, and for the object in question, it actually makes no difference whatsoever, since only the sequencing matters (unless the code is seriously messed up). It cannot tell what if anything happened between the alloc and the init. It can be the very next thing, it can be a million years later. id object = [[NSObject alloc] init]; and id obj = [NSObject alloc]; sleep( 365 * 24 * 3600 ); obj=[obj init]; are completely equivalent as far as the object is concerned. Of course, the latter is definitely odd looking, and there is no good reason for not initializing it immediately, whereas there are very good reasons *for* doing the initialization immediately, which is why I did bring it up. Of course, with a bridge involved, you may have to be more careful because the bridge might have reasons for touching the object that aren't obvious from the code. Marcel -- Marcel Weiher Metaobject Software Technologies ma...@me... www.metaobject.com Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc. |