[PATCH] Factor out duplicate code
Andrew Bennetts
andrew at canonical.com
Wed Oct 12 05:33:47 BST 2005
On Tue, Oct 11, 2005 at 10:13:23PM -0500, John A Meinel wrote:
> Andrew Bennetts wrote:
> >On Tue, Oct 11, 2005 at 06:45:06PM -0700, Dan Loda wrote:
>
> ...
>
> >A simpler and less fancy approach would be to add the 'create' method as
> >you
> >suggest, but just leave the if statement hard-coded in there, rather than
> >mucking about with the versionable_kinds dictionary -- or do you have a
> >use-case for a plugin or something that needs this sort of extensibility?
>
> I do think that using a dictionary is the preferred method for factory,
> even if at present there aren't any ideas about how it will be extended.
> It is just much easier to add a new entry to dictionary, rather than
> tracking down another if statement.
It feels to me like it may be a premature generalisation, so my inclination is
to suspect it's a YAGNI (You Aren't Gonna Need It), until I see evidence
otherwise ;)
Hmm, I guess reducing the duplication between the ifs and the
versionable_kind staticmethod is something I overlooked the first time
round, that's another argument for the dictionary.
> Plus, I believe in python the dictionary lookup is faster than the if/then.
In this case I think you're probably right, but I also think it's probably
not a measurable difference compared to the rest of bzr. So I'm calling
that a premature optimisation, until I see evidence otherwise ;)
It's not a big difference either way, I just thought that reducing the
indirection would be slightly more readable.
-Andrew.
More information about the bazaar
mailing list