[Pythonmac-SIG] Categories for class methods

Dethe Elza delza at livingcode.org
Fri Jan 28 01:19:15 CET 2005


That's a good tip, I haven't gotten the hang of Cocoa's verbosity yet.  
The choice of read: was to balance write:.  The whole thing started 
because I found it odd that writing an image to a file was such a 
convoluted process.  In a lot of ways, Cocoa makes things really easy, 
but when it isn't easy, sometimes it becomes really, really hard (at 
least hard to figure out, if not to implement).

Some of that is just getting to know the libraries, of course, and a 
lack of howtos for the things I'm trying to do.

--Dethe

On 27-Jan-05, at 12:57 PM, Bob Ippolito wrote:

>
> On Jan 27, 2005, at 15:24, Dethe Elza wrote:
>
>> FYI, once I updated PyObjC from svn, my example code worked, thanks 
>> again Ronald.
> ...
>> class NSImage(Category(NSImage)):
>>
>>     def rect(self):
>>         return (0,0),self.size()
>>
>>     @classmethod # for Python2.3 replace with read_ = 
>> classmethod(read_)
>>     def read_(cls, filepath):
>>         return NSImage.alloc().initWithContentsOfFile_(filepath)
>
> Just a nit here, you should probably call this imageWithFilePath_ to 
> follow convention.  "read:" is a really confusing name for an 
> initializer.
>
> -bob
>
>

"...coding isn't the poor handmaiden of design or analysis. Coding is
where your fuzzy, comfortable ideas awaken in the harsh dawn of reality.
It is where you learn what your computer can do. If you stop coding,
you stop learning."     Kent Beck, Smalltalk Best Practice Patterns

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2488 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20050127/6d7b76d5/smime.bin


More information about the Pythonmac-SIG mailing list