The Artima Developer Community
Sponsored Link

Weblogs Forum
Python 3000 - Adaptation or Generic Functions?

23 replies on 2 pages. Most recent reply: Aug 4, 2006 4:19 PM by Prateek Sureka

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 23 replies on 2 pages [ « | 1 2 ]
Laurence Rowe

Posts: 1
Nickname: elro
Registered: Apr, 2006

Re: Python 3000 - Adaptation or Generic Functions? Posted: Apr 7, 2006 11:48 AM
Reply to this message Reply
Advertisement
Having just started using Zope 3 -- and therefore adapters -- in the last month or so, I think the real justification for them is to simplify inheritance hierarchies and more easily encapsulate the different 'aspects' of your objects. Anyway coming from Zope 2 will feel the importance of that!

I also like the way it enables a sort of functional programming with objects. You get to easily break down the functionality of your program into smaller bite sized chunks.

Guido van van Rossum

Posts: 359
Nickname: guido
Registered: Apr, 2003

Re: Python 3000 - Adaptation or Generic Functions? Posted: Apr 7, 2006 12:44 PM
Reply to this message Reply
> Actually, yes, there's still some of us who use Dylan out
> there, and after the Open Source release of the
> ex-Harlequin Dylan compiler, there's even something like a
> future for Dylan.

I won't be part of it.

> Nice to see that Python is getting support for Generic
> Functions. Now if you add macros for support of
> metasyntactic abstractions, get rid of fundamental
> ("non-object") types for orthogonality, add type
> annotations and optimistic type inferencing for
> performance, you'll end up with a language that pretty
> much looks like Dylan, but with a bigger user base.

Tong firmly in cheek I hope?

> Which isn't a big surprise, given that both Python and
> Dylan are based on Scheme, just with a different syntax.

I consider that an insult.

Dick Ford

Posts: 149
Nickname: roybatty
Registered: Sep, 2003

Re: Python 3000 - Adaptation or Generic Functions? Posted: Apr 7, 2006 5:46 PM
Reply to this message Reply
.... Lisp or Dylan users (are there any left? :-)

Are there any Python users left? I thought the last one moved on to Ruby a few months ago. :-)

Andreas Bogk

Posts: 2
Nickname: abogk
Registered: Apr, 2006

Re: Python 3000 - Adaptation or Generic Functions? Posted: Apr 7, 2006 5:47 PM
Reply to this message Reply
> > there's even something like a
> > future for Dylan.
> I won't be part of it.

I'd be surprised if you were. You have a successful, living language, after all.

> > Nice to see that Python is getting support for Generic
> > Functions. Now if you add macros for support of
> > metasyntactic abstractions, get rid of fundamental
> > ("non-object") types for orthogonality, add type
> > annotations and optimistic type inferencing for
> > performance, you'll end up with a language that pretty
> > much looks like Dylan, but with a bigger user base.
> Tong firmly in cheek I hope?

Well, I'm dead serious about being glad that the Python community considers generic functions. They are a powerful concept after all, and I think a much more natural way to approach object-oriented design. It should be already obvious by looking at a trivial example like a + b. Talking about + being a function of the type of a, like you would in the single dispatch model, just isn't as natural as thinking about the generic function +, which has a method for adding a specific combination of the types of both a and b. Additionally, to get the kind of decoupling you need for extensibility you need to implement the Visitor pattern, which is just additional work.

So since Python is among the languages I do use, and consider one of the saner languages out there, and since I do like generic functions, I'd be happy to see them in.

The comment about Python becoming like Dylan is entirely tongue-in-cheek, of course. But sometimes I wish Python had more of the powerful features I've become accustomed to, or Dylan had the user base to come up with such well-polished implementations and wide range of maintained libraries.

With PyPy, Python has become a serious language to keep on the radar. I'm curious to see whether it will be possible to close the performance gap.

Oh, by the way, I missed separation of non-local exits, stack unwind protect mechanisms and exception handlers in my wishlist of features above. It's so much nicer to be able to handle conditions before the stack is unwound, because it allows recovery.

> > Which isn't a big surprise, given that both Python and
> > Dylan are based on Scheme, just with a different
> syntax.
> I consider that an insult.

Oh, it wasn't meant to be, and if that insulted you, I apologize. I meant to say that the semantic distance between those languages is small, compared to, say, ML, C++ or Prolog. There are more good ideas to steal from that camp than just generic functions.

seth falcon

Posts: 1
Nickname: sethf
Registered: Apr, 2006

Re: Python 3000 - Adaptation or Generic Functions? Posted: Apr 9, 2006 12:26 AM
Reply to this message Reply
> I'm actually thinking of calling this feature (if/when it
> gets added to Python) "overloading" -- what do you think
> of that?

I think adding a generic function feature would be a wonderful addition. When I'm not writing Python, I'm most often coding in R which has a generic function based object system. I've come to appreciate the flexibility that generic functions provide in terms of multiple dispatch and adding behaviors without touching class definitions.

I hope that you will call them "generic functions" and not "overloading". It is only a name and I would be happy enough to have the feature, but to my mind there is enough confusion between what multimethods can provide as opposed to method overloading (compile-time).

Matthias Benkard

Posts: 4
Nickname: kompottkin
Registered: Mar, 2006

Re: Python 3000 - Adaptation or Generic Functions? Posted: Apr 9, 2006 6:51 AM
Reply to this message Reply
I'm not sure I like the idea of having both single and multiple dispatch in the same language. It seems to me to be a case of There's More Than One Way To Do It. In my opinion, traditional singly dispatched methods should either be thrown out completely (which would be a very big change) or kept the only kind of method.

Of course, there's nothing keeping you from defining »a.foo(b)« as the syntax for »call multimethod foo on arguments a and b«.

Then again, my experience regarding multimethods is rather limited. I'm sure Guido is going to make the right decision, as always :)

Aaron Bingham

Posts: 1
Nickname: bingham
Registered: Apr, 2006

Re: Python 3000 - Adaptation or Generic Functions? Posted: Apr 11, 2006 3:50 AM
Reply to this message Reply
I'm curious how adaptation and generic functions might differ in their interaction with design by contract.

It seems you could associate a contract with a protocol and thus ensure that any adapted objects conform to the protocol's contract. Since a protocol presumably corresponds to an abstract data type this looks like only a slight variation on traditional DBC.

I've not used generic functions before, so I'm not sure how they would be used in practice, though I can imagine some applications. Could you associate a contract with the generic function itself which would then be checked against all specializations? How would that pan out in practice?

-- Aaron

Sam Deane

Posts: 1
Nickname: samdeane
Registered: Apr, 2006

Re: Python 3000 - Adaptation or Generic Functions? Posted: Apr 15, 2006 7:20 AM
Reply to this message Reply
As another Dylan fan, who's also a Python fan, I have to agree with Andreas. Generic functions in Python would be a great development.

Prateek Sureka

Posts: 1
Nickname: psureka
Registered: Aug, 2006

Re: Python 3000 - Adaptation or Generic Functions? Posted: Aug 4, 2006 4:19 PM
Reply to this message Reply
Hello Guido,
I just saw your talk on Python 3000 on Google Video and was came here to talk about specifically this issue.


I think the idea and motivation behind adaptation is good. However, I don't think generic functions are the answer. Although the overloading feature in Java is very useful, it doesn't appy to Python because of something that Python has which Java doesn't - keyword arguments. Since they don't have to be in order, I don't see how the G(X1, X2) when type(X1)==T1 and type(X2)==T2 concept will apply. Also, what about keyword arguments which are used inside switch statements inside the function call to change the implementation? Use case:

def foo(x, output='xml'):
if (output == 'xml'):
# return xml data
elif (output == 'json'):
# return json data
else:
# return html data


Suppose this function took multiple types of x or even multiple optional variables - a case for using generic functions, you'd be left with pretty unmaintainable code where the number of implementations are hard to track. Also, if you count the fact that each branch inside the if block is a separate 'implementation', it worsens the problem.

My 2 cent solution:
You want adaptors? Great idea - implement them as an __adapt__(self, classobject) method of the source object... i.e. Calling adapt(source_instance, destination_instance.__class__) will return an instance of destination_instance.__class__ . This also eliminates the need for a global registry. Also, since you can easily modify class instances, to define a new adaptor is simple (just create a function and attach it as the special named method to the instance (or class) you wish to adapt)

Flat View: This topic has 23 replies on 2 pages [ « | 1  2 ]
Topic: Python 3000 - Adaptation or Generic Functions? Previous Topic   Next Topic Topic: Cat Programming Language Presentation


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us