#ifdef like question.

Kragen Sitaker kragen at pobox.com
Fri May 17 03:39:06 EDT 2002


Jeff Shannon <jeff at ccvcorp.com> writes:
> No, I don't think there's a need for a nicer way to write two 
> sets of code with identical functionality.  Once you've written 
> the old, backwards-compatible code, then (as Dave Brueck has 
> already pointed out) where's the benefit in also writing the 
> using-new-features code?

Well, mostly I agree with you, but there are a couple of exceptions in
my experience.
1. where using the new feature means you can offer something extra: better
   performance, access to more file formats, etc.
2. where the new feature is only useful with the new version of Python.  For
   example, MetaPy.Sequence defines a += operator in a backwards-compatible
   way, but the test suite for MetaPy.Sequence only tests it if += doesn't 
   raise a SyntaxError.

But usually I agree that it's better to go with only one version, even
if it's slower or clumsier.  It goes without saying that if you *do*
decide to duplicate code, you should go to great lengths to duplicate
as little as possible.




More information about the Python-list mailing list