[OPINION] - does language really matter if they all dothe samething?

Brian Quinlan brian at sweetapp.com
Sat Jan 24 03:31:11 EST 2004


> I agree that functions are objects in Python.  However, not everything
> in Python is an object.  For example, names are not objects.  In the
> above example, "foo.bar()", neither "foo" nor "bar" are objects, but
> they are references to objects.  In some languages, such as C and Lisp,
> references to objects can be directly manipulated (Lisp has symbols, C
> has pointers).

I'm having problems figuring out your follow-up. Your original point was:

 "It's [Python] build from a procedural standpoint, in an environment where
  most things are objects and some are functions."

I disagreed with the contrast between functions and objects. Now you seem to
be making the totally different point that names are not objects in Python.
Following along:

1. I can't see how your mention of C pointers is relevant at all
2. I don't see what is so special about Lisp symbols versus Python names
   i.e. what functionality are you missing?

[snipped]
> If you think this example is contrived, maybe you haven't worked with
> the paradigms used in Objective-C very much.  The example above was
> used dozens of times in a class that I wrote in Objective-C which draws
> a grid to the screen, for example, when it asks itself or its delegate
> what color the grid should be, or the maximum scale allowed.  The
> practice is also used heavily by Apple's Cocoa libraries, which are my
> favorite UI libraries of all time to program with.

The cost in writing a function to check for the availability of a method on
your target object is a one-time thing (which you just did), so it doesn't
seem like a big deal to me.

- (void)resetToDefaultSettings
{
   if ([delegate respondsToSelector:@selector(defaultSettingsFor:)])
     [self setSettings:[delegate defaultSettingsFor:self]];
   else
     [self setSettings:someFallbackValue];
}

In Python you'd write it as:

def resetToDefaultSettings():
   if self.delegate().respondsToSelector_('defaultSettingsFor:'):
       self.setSettings(delegate().defaultSettingsFor_(self))
   else:
       self.setSettings(someFallbackValue)

I don't really like the syntax that much but I guess the guys writing the
Python Objective-C bindings thought it was ok.

Cheers,
Brian





More information about the Python-list mailing list