Ted Leung on the air
Ted Leung on the air: Open Source, Java, Python, and ...
Wed, 21 Jul 2004
Categories, aspects, posing, and pyprotocols
After last night's SeaJUG, I had a discussion with my friend Bob Coombs, who is a long time NeXTStep programmer. He was explaining some features of Objective-C to me. In particular, categories, which allow you to group up methods (which sound a lot like aspects in some ways), and posing, a way for one object to pose as another. The posing functionality sounds a lot like features that Bob Ippolito and Donovan Preston described as part of pyprotocols. As usual the world is small, especially the world of ideas.

Aside from issues of licensing and market share, Cocoa/NeXTStep is probably the most advanced commercially available system for building desktop applications, so I've been getting more interested in learning how things work. It's kind of like the scene in The Matrix when they are about to extract Neo from the Matrix. Neo touches a mirror, his finger goes silvery, and all of a sudden the silver is crawling up his arm. Next thing he knows, it's taking over his head. Yep, it's kind of ... exactly ... like that.

[22:59] | [computers/operating_systems/macosx] | # | TB | F | G | 1 Comments | Other blogs commenting on this post
I think categories in ObjC can be used somewhat like aspects (though I'm sketchy on AOP). But there were two features to categories that I really liked.

First, you could subdivide your class over several files. This was primarily useful with classes that acted as points of interface: interact with the model by looking up a manager object and calling a method on it. These classes tended to get hairy with methods pretty quickly, and consequently difficult to comprehend at a glance. By breaking it into multiple files that were thematically coherent, it was much easier to understand each file (though not necessarily easier to find....)

In Python, you can assign attributes to a foreign object, so you can simulate this by importing the class and assigning methods to attributes on the class. It's brutal and ugly and not as easy to comprehend. I generally prefer to write several other classes, and have my manager object delegate operations to the children. It's not quite as efficient, but it has the advantage of making the manager class an "index" to all the subsidiary functionality.

Second was really the clincher though. A category could be declared on any object in the system. This was especially tasty when working with a full framework, like the EOF or WebObjects or Cocoa. If you wanted all Objects to be able to handle the message "frobozz", you could write a category on Object that defined that behavior in the generic, and then all Objects would in fact frobozz. Contrast this with the inheritance way of doing things, where you need to write a mixin and declare a subclass for every object you're using that explicitly includes the mixin. In complicated models, where a facade class selects the appropriate specific class for a given context, this gets even worse, because you need to reimplement the facade class to know about your mixed-in subclasses. It's very messy, and really reduces the value of a framework.

That's where I miss categories the most -- and to my knowledge, AOP doesn't really provide a remedy for this problem so much as a possible pathway to remedy, assuming the framework designer does the right thing.

I've read interviews that say Java took much of its heritage from ObjC, and this feature was one that got passed over because it needs to be "safe" to execute arbitrary content from the tainted world at large. I think it's sad; between categories and the curiously baroque syntax, I think Objective C is one of the languages I love most.
Posted by
Geoff Gerrietts at Fri Jul 23 13:28:43 2004

You can subscribe to an RSS feed of the comments for this blog: RSS Feed for comments

Add a comment here:

You can use some HTML tags in the comment text:
To insert a URI, just type it -- no need to write an anchor tag.
Allowable html tags are: <a href>, <em>, <i>, <b>, <blockquote>, <br/>, <p>, <code>, <pre>, <cite>, <sub> and <sup>.

You can also use some Wiki style:
URI => [uri title]
<em> => _emphasized text_
<b> => *bold text*
Ordered list => consecutive lines starting spaces and an asterisk

Name:


E-mail:


URL:


Comment:


Remember my info?


twl JPG

About

Ted Leung FOAF Explorer

I work at the Open Source Applications Foundation (OSAF).
The opinions expressed here are entirely my own, not those of my employer.

Creative Commons License
This work is licensed under a Creative Commons License.

Now available!
Professional XML Development with Apache Tools : Xerces, Xalan, FOP, Cocoon, Axis, Xindice
Technorati Profile
PGP Key Fingerprint
My del.icio.us Bookmarks
My Flickr Photos


Syndicate
RSS 2.0 xml GIF
Comments (RSS 2.0) xml GIF
Atom 0.3 feed
Feedburner'ed RSS feed

< July 2004 >
SuMoTuWeThFrSa
     1 2 3
4 5 6 7 8 910
11121314151617
18192021222324
25262728293031

Archives
2006
2005
2004
2003

Articles
Macintosh Tips and Tricks

Search
Lucene
Blogs nearby
geourl PNG

Categories
/ (1567)
  books/ (33)
  computers/ (62)
    hardware/ (15)
    internet/ (58)
      mail/ (11)
      microcontent/ (58)
      weblogs/ (174)
        pyblosxom/ (36)
      www/ (25)
    open_source/ (145)
      asf/ (53)
      osaf/ (32)
        chandler/ (35)
        cosmo/ (1)
    operating_systems/ (16)
      linux/ (9)
        debian/ (15)
        ubuntu/ (2)
      macosx/ (101)
        tips/ (25)
      windows_xp/ (4)
    programming/ (156)
      clr/ (1)
      dotnet/ (13)
      java/ (71)
        eclipse/ (22)
      lisp/ (34)
      python/ (86)
      smalltalk/ (4)
      xml/ (18)
    research/ (1)
    security/ (4)
    wireless/ (1)
  culture/ (10)
    film/ (8)
    music/ (6)
  education/ (13)
  family/ (17)
  gadgets/ (24)
  misc/ (47)
  people/ (18)
  photography/ (25)
    pictures/ (12)
  places/ (3)
    us/ (0)
      wa/ (2)
        bainbridge_island/ (17)
        seattle/ (13)
  skating/ (6)
  society/ (20)



[Valid RSS]

del.icio.us linkblog

www.flickr.com

Blogroll

java.blogs
Listed on BlogShares

Locations of visitors to this page
Where are visitors to this page?


pyblosxom GIF