Google Groups Home
Help | Sign in
Method signatures in example code
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Lloyd Kvam  
View profile
 More options Jan 31 2006, 2:58 pm
From: Lloyd Kvam <goo...@venix.com>
Date: Tue, 31 Jan 2006 14:58:59 -0500
Local: Tues, Jan 31 2006 2:58 pm
Subject: Method signatures in example code
Perhaps it is just me, but I hate the way the example code fails to
reflect the way CherryPy actually calls methods.

def index(self, **responseMap):

is the "normal" index signature.  If there are no parameters, then
responsemap will be an empty dict.  I think it is a mistake to present
code that is brittle and will fail when the actual request differs from
the expected request.

Similarly the default signature is really

def default(self, *urlpath, **responseMap):

I realize the current examples may look less threatening by only
presenting the expected arguments, but I think it does a disservice to
gloss over issues that should not be ignored.

I am willing to work through the documentation and make corrections so
that the examples are more robust, but do not want to waste my time if
that is not wanted.

This is example #7 from my 2.0 installation.

    def default(self, user):
        # Here we react depending on the virtualPath -- the part of the
        # path that could not be mapped to an object method. In a real
        # application, we would probably do some database lookups here
        # instead of the silly if/elif/else construct.
        if user == 'remi':
            out = "Remi Delon, CherryPy lead developer"
        elif user == 'hendrik':
            out = "Hendrik Mans, CherryPy co-developer & crazy German"
        <snipped>

I'd rather see:

    def default(self, user, *discard, **ignore):

and explain why discard and ignore should be included.  It might even be
worth pointing out that no default value is needed for user because if
there were no path value for user, the index method will be called
rather than default.

Is the example code really the preferred way to write a CherryPy
application?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Brewer  
View profile
 More options Feb 8 2006, 3:30 am
From: "Robert Brewer" <fuman...@amor.org>
Date: Wed, 8 Feb 2006 00:30:49 -0800
Local: Wed, Feb 8 2006 3:30 am
Subject: RE: [cherrypy-docs] Method signatures in example code

Lloyd Kvam wrote:
>     def index(self, **responseMap):
> is the "normal" index signature.  If there are no
> parameters, then responsemap will be an empty dict.
> I think it is a mistake to present code that is
> brittle and will fail when the actual request
> differs from the expected request.

IMO that is exactly what you want to have happen--failure. Errors should not pass silently.

> Similarly the default signature is really
>     def default(self, *urlpath, **responseMap):

> Is the example code really the preferred way to write
> a CherryPy application?

IMO, yes. In almost all of the cases where I've experienced errors due to extraneous arguments, it's been during my own development and testing. I can honestly say that I haven't had a single occurrence of extraneous-arg errors in production unless it pointed out a bug that needed fixing in my own app code. YMMV--maybe you're writing mashup apps that demand fuzzier interfaces.

Any other anecdotal opinions out there?

Robert Brewer
System Architect
Amor Ministries
fuman...@amor.org

  winmail.dat
4K Download

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google