[Pythonmac-SIG] NSTableView and NSOutlineView backgrounds

Bob Ippolito bob at redivi.com
Tue Oct 14 13:00:13 EDT 2003


On Tuesday, Oct 14, 2003, at 12:28 America/New_York, Drew McCormack 
wrote:

>>
>>   SOFT_BLUE = NSColor.colorWithCalibratedRed_green_blue_alpha_(
>>       0.92941, 0.95294, 0.99607, 1.0)
>>
>>   class MyOutlineView(NibClassBuilder.AutoBaseClass):
>>       def drawRow_clipRect_(self, row, rect):
>>           if row % 2 == 0 and not self.isRowSelected_(row):
>>               SOFT_BLUE.set()
>>               bounds = self.rectOfRow_(row)
>>               path = NSBezierPath.fillRect_(bounds)
>>           NSOutlineView.drawRow_clipRect_(self, row, rect)
>> <snip>
>> The inspiration for this came from Evan Jones' implementation in
>> Objective-C, which is, of course, several times larger than the
>> code above, especially since it involves more than only this one
>> method:
> As an fan of Obj-C, I can't really let this go unanswered. There seems 
> quite a bit of animosity toward Obj-C from python programmers, and I 
> don't really understand why.

--snip--

though to make your char-to-char comparison more fair you should to 
replace the Python "NSOutlineView(self, " with "self." .. I believe 
Dinu was using it for readability or something but it shouldn't be 
necessary, even for that, because he named it MyOutlineView.  Besides, 
your ObjC code won't even compile because the (seemingly useless, 
inherited from Dinu's Python) path variable isn't declared anywhere.

Also, don't the newer compilers complain when you declare variables in 
the middle of code?  Wouldn't you have to put a "NSRect bounds;" at the 
top of the block?  Obviously you could just do [NSBezierPath 
fillRect:[self rectOfRow: row]] .. which is probably how I'd have done 
it in the first place.

> This leads me to something that I think is better in Obj-C than 
> python: the smalltalk method naming. I like python a lot, and use it 
> when I can. It is a concise language, and there are countless modules 
> available which you can't find in Obj-C. But I find remembering method 
> signatures, particularly the number or order of arguments, much more 
> difficult in python than Obj-C. I have to continually go back to docs 
> to jolt my memory. You don't have that problem in Obj-C, because you 
> remember the method name, and it tells you what the arguments are. You 
> often also avoid in-code comments, because the method calls are self 
> documenting.

Yes, Python methods are typically a lot shorter than ObjC methods, but 
there's obviously nothing stopping you from naming them like 
drawRow_clipRect_ :)

> In my view, monolithic method naming is a hangup from C/C++ that 
> afflicts otherwise good languages like Java and python. It is the same 
> as the countless linux windows managers that were too short-sighted to 
> avoid using a 'Start' button. The dominant technology of the day 
> dictates the trends, whether for good or bad.
>
> Along these lines, has anyone ever 'hacked' the python interpreter to 
> do smalltalk like messaging, with segmented names? I've been tempted 
> to try it myself. You wouldn't think it would be that hard. Maybe just 
> an extra stage to convert segmented names to underscored ones, the 
> same way that PyObjC names methods. But I'm no python expert, so I 
> don't know what would be involved.

Along the same lines, ObjC doesn't have a short way to say anything (no 
operators).  Probably my favorite feature of Python are strings, lists 
and dicts, with all the great __setitem__/__getitem__ stuff to go with 
it.  In ObjC, a+b never means anything useful, unless a and b are 
primitive C types.. that's obnoxious, because you'd have to say 
a.add_(b) or something like that... Imagine writing an equation like 
that.  Sure, in ObjC you can use int, long, float, double.. but what 
about equivalents to Python's long or complex?  What about doing 
arrays/matrices (Numeric), etc.  You can't create a NSDictionary like 
{a:b}.  Operators and other syntax is extremely important, more so than 
a forced message passing syntax.  If you want message passing syntax 
just use keyword arguments all over the place:

def cryptic(method, with, arguments):
	pass
cryptic(method='foo', with='bar', arguments='baz')

If Python had any sort of "ordered dictionary" and the kwarg parsing 
could use it then you would basically have smalltalk style message 
passing syntax (if you wanted it).  If Python acted like this then I'm 
sure PyObjC probably would've ended up more like self(drawRow=row, 
clipRect=rect) then self.drawRow_clipRect_(row, rect).  I find myself 
wanting the "ordered dictionary" type for all sorts of things, for 
example in a class declaration, where it could be potentially useful to 
a metaclass to know the order.

In any case, yes, ObjC isn't that bad.  I like it more than most 
things, but I prefer Python, primarily for syntax reasons.

-bob




More information about the Pythonmac-SIG mailing list