Re: [Python-ideas] parameter omit
On 5/11/07, Aaron Brady <castironpi@comcast.net> wrote:
-----Original Message----- From: Steven Bethard [mailto:steven.bethard@gmail.com] Sent: Friday, May 11, 2007 1:50 AM
On 5/11/07, Aaron Brady <castironpi@comcast.net> wrote:
Take a shot at this one.
class WebRetrieveElement: def netretrieveOld( self ): if hasattr( self,'hook' ) and self.filename: urlretrieve( self.url, self.filename, self.hook ) elif hashook: urlretrieve( self.url, reporthook= self.hook ) else: urlretrieve( self.url, self.filename )
def netretrieve(self): kwargs = {} if self.filename: kwargs['filename'] = self.filename if hasattr(self, 'hook'): kwargs['reporthook'] = self.hook urlretrieve(self.url, **kwargs)
Right. That's the alternative, -as- I keep bringing up.
Now let's compare, and judge if X is worth Y.
My solution, 3 lines. Yours, 6.
If you really care about lines and characters, you can write:: k = {} if self.filename: k['filename'] = self.filename if hasattr(self, 'hook'): k['reporthook'] = self.hook urlretrieve(self.url, **k) That's 4 lines, 132 characters, compared to your 3 lines, 133 characters. But the fact that you're drawing the "lets count lines of code" card suggests that there's no point discussing this any further. Good luck with your proposal. STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy
-----Original Message----- From: Steven Bethard [mailto:steven.bethard@gmail.com] Sent: Friday, May 11, 2007 2:11 AM
On 5/11/07, Aaron Brady <castironpi@comcast.net> wrote:
-----Original Message----- From: Steven Bethard [mailto:steven.bethard@gmail.com] Sent: Friday, May 11, 2007 1:50 AM
On 5/11/07, Aaron Brady <castironpi@comcast.net> wrote:
[snip]
def netretrieve(self): kwargs = {} if self.filename: kwargs['filename'] = self.filename if hasattr(self, 'hook'): kwargs['reporthook'] = self.hook urlretrieve(self.url, **kwargs)
Right. That's the alternative, -as- I keep bringing up.
Now let's compare, and judge if X is worth Y.
My solution, 3 lines. Yours, 6.
If you really care about lines and characters, you can write::
k = {} if self.filename: k['filename'] = self.filename if hasattr(self, 'hook'): k['reporthook'] = self.hook urlretrieve(self.url, **k)
That's 4 lines, 132 characters, compared to your 3 lines, 133 characters.
But the fact that you're drawing the "lets count lines of code" card suggests that there's no point discussing this any further.
Good luck with your proposal.
STeVe
Fine. No dice on lines of code alone. We talk readability. Tell me yours is easier to read, compressed or no.
participants (2)
-
Aaron Brady
-
Steven Bethard