ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

How to maintain a reusable updatable code

(1/5) > >>

justice:
This is a problem i've been struggling with for years now, and I wonder if any of you found a solution.

I'm trying to maintain a reusable and updatable function library of code. By reusable I mean that I want to use the same code in multiple projects in multiple locations (as any snippets library / function list / custom class?). This part is quite easy. At the moment we share a common onenote workbook that contains a page for each snippet / function / sub (we're talking web development). I'm considering setting up a seperate subversion repository for this so so that you can have it filebased, versionable and local at the same time.

However the way it's implemented is that code is copied into (usually the functions.asp include part of) the project. Then after one of us discovers an error or extends the function I have to update all the other projects with this code by a search and replace and I have no way to ensure that all instances have been updated. Someone might have made a small change in one of the functions for this specific project.

Hardly an ideal solution and I guess we're looking at some kind of extendable classes system but your thoughts would be appreciated.

mediaguycouk:
Wouldn't the answer be to have two seperate include files? Something like

index.asp
companyfunctions.asp
manualfunctions.asp

The company functions file(s) would contain all the code contained in your repository and you would be very very strict in ensuring that the code is read only

If you wanted to edit the code (even by one character) you would write the code into the manual function file for index.asp (in this example).

Once you edit code in the repository you would not need to do a find and replace, you could just replace the companyfunctions file as you can ensure that it will not delete any work (as it is 'read only' and you have only made the code better).

But obviously this is just an overview without really knowing much about your situation.

f0dder:
There are iirc snippet managers that try to maintain a database of "where is this snippet used?", which will then update all the use-sites when you update a snippet. But imho that's still as much a recipe for disaster, as general "snippe use" is by itself.

The only real acceptable thing to do is keeping a properly maintained function library, and keep it under source control. Period. Snippet usage way too easily leads to ill-designed functions, spaghetti code, and redundancy bloat. And, as you've discovered, is a maintenance nightmare.

Sure, it's so deceptively easy to just paste something from a snippet manager, instead of all the annoyance and bother of designing a proper function library, and the boooother of checking out from your source control system, etc. But it's the only sane thing to do.

justice:
Thanks both, I looked a bit more into the suggestion of a seperate
companyfunctions.asp
manualfunctions.asp

It look like this will work well, fortunately you can redefine functions in asp/vbscript quite happily and only the last function will be used, so that it will be compatible with functions inappropriately adapted for a specific project.

Now when I commit a new version of companyfunctions.asp then I want automatically that the other projects receive this update.Am currently thinking about setting up a client side post-commit script using tortoise svn to robocopy over the file into certain checkout folders.

mouser:
As has been suggested elsewhere, duplicating code snippets in different files should trigger a warning siren going off in your head.  Whenever that happens it means you have a function that belongs in a separate file that can be shared between projects in some form.

Navigation

[0] Message Index

[#] Next page

Go to full version