[MERGE] Nested trees: CompositeTree

John Arbash Meinel john at arbash-meinel.com
Thu Apr 16 14:56:52 BST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


...


> Compare:
> 
>    def func(p1, p2)
>        pass
>    
>    func('a', 'b')
> 
> then
> 
>    def func(p1, p2, opt=None):
>        pass
> 
> (1)   func('a', 'b', opt='c')
> (2)   func('a', 'b', 'c')
> 

I'll just point out that I will often use named parameters whenever the
option I'm passing doesn't have enough context for it to be
understandable. Especially for stuff like "True".
For example:
 foo(True)
vs
 foo(enable_frob=True)

They both would be valid, but in the later case, I didn't need to go
look up foo and count the number of parameters to figure out what that
True implied.

In this particular case, we have an easy clarification on a "None"
parameter:
   def get_file_sha1(self, file_id, path=None, stat_value=None):
       """See Tree.get_file_sha1."""
       return self._nested_trees.get_tree(file_id).get_file_sha1(
          file_id, None, stat_value)

   def get_file_mtime(self, file_id, path=None):
       """See Tree.get_file_mtime."""
       return self._nested_trees.get_tree(file_id).get_file_mtime(
            file_id, None)

^- It is obvious what "file_id" is, but not what we are setting to None.
Naming the parameter here makes it a lot clearer, IMO.

Now, as these are just redirecting a function, you can pretty well guess
that the parameter list is identical to the current function.

It is a bit unfortunate that in the former case you would have to pass
both "path=None" and "stat_value=stat_value", since the later is already
named...

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknnOSQACgkQJdeBCYSNAAPzxQCgh76+gu1iyA8QKlDTyTmvL82E
ZmUAoK6N1pVZhllPe/P1FTymBNlr36vs
=1rTV
-----END PGP SIGNATURE-----



More information about the bazaar mailing list