Best way to modify code without breaking stuff.

J

Jesse Aldridge

I've got a module that I use regularly. I want to make some extensive
changes to this module but I want all of the programs that depend on
the module to keep working while I'm making my changes. What's the
best way to accomplish this?
 
I

Ivan Illarionov

I've got a module that I use regularly. I want to make some extensive
changes to this module but I want all of the programs that depend on the
module to keep working while I'm making my changes. What's the best way
to accomplish this?

Version control system.

http://en.wikipedia.org/wiki/List_of_revision_control_software

Make your module a versioned repository.
Make your changes in different place, then commit them.

I use SVN and mercurial.

Ivan
 
U

Ulrich Eckhardt

Jesse said:
I've got a module that I use regularly. I want to make some extensive
changes to this module but I want all of the programs that depend on
the module to keep working while I'm making my changes. What's the
best way to accomplish this?

You simply run the module's unit tests that tell you if the new module's
behaviour differs from the expectations. If you don't have unit tests, I'd
say it's about time writing them.

Uli
 
A

André Malo

Jesse said:
I've got a module that I use regularly. I want to make some extensive
changes to this module but I want all of the programs that depend on
the module to keep working while I'm making my changes. What's the
best way to accomplish this?

Don't ;-)

If the changes are that extensive it might be considerable to write a new
module and switch the depending code to use that new module when you're
done and they're ready.

As mentioned in another posting revision control is a good thing as well.
Not just for that task.

nd
 
U

Ulrich Eckhardt

André Malo said:
As mentioned in another posting revision control is a good thing as well.
Not just for that task.

From my point of view revision control is not a question but a fact.
Seriously, if you are not using any RCS already, it is about time you start
doing so. I even use it for my private toy projects.

Uli
 
C

Carl Banks

I've got a module that I use regularly. I want to make some extensive
changes to this module but I want all of the programs that depend on
the module to keep working while I'm making my changes. What's the
best way to accomplish this?

If I'm understanding you correctly: you want to load the old module
when running code normally, but want to use a new module when
developing, but is has to have the same name?

Here's what you could do:

1. Rename "whatever.py" to "oldwhatever.py".

2. Copy "oldwhatever.py" to "newwhatever.py", and make your extensive
changes there.

3. Create a new "whatever.py" with code that imports all the symbols
from the old or new module depending on which module you want to use.
For instance, you could use an environment variable to choose which
one:

if os.environ.get("USENEWMODULE") == "yes":
from newwhatever import *
else:
from oldwhatever import *

Or, you could set a flag in some sort of configuration module and
check that:

import config
if config.use_new_module:
from newwhatever import *
else
from oldwhatever import *


Carl Banks
 
C

Carl Banks

Version control system.

http://en.wikipedia.org/wiki/List_of_revision_control_software

Make your module a versioned repository.
Make your changes in different place, then commit them.

That doesn't seem like a good solution for the OP's particular
problem. To do it in a "different place", as you say, he'd have to
check out a new working copy, which might be a bit of overkill
depending on the size of the project. It could also be problematic to
have separate working copies; there could be programs outside the
project that are configured to use a certain location, for instance.

One thing you could do with some version control systems is to switch
the particular version for the module in question between different
branches depending on whether you're using the tools or changing the
model. (Subversion can do this, but I'm not sure if it's for
individual files or only directories.)


Carl Banks
 
P

Paul Rubin

Jesse Aldridge said:
I've got a module that I use regularly. I want to make some extensive
changes to this module but I want all of the programs that depend on
the module to keep working while I'm making my changes. What's the
best way to accomplish this?

Do you mean you want to hot-patch a running program? The short answer
is: don't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top