views:

1268

answers:

8

I've got to do some significant development in a large, old, spaghetti-ridden ASP system. I've been away from ASP for a long time, focusing my energies on Rails development.

One basic step I've taken is to refactor pages into subs and functions with meaningful names, so that at least it's easy to understand @ the top of the file what's generally going on.

Is there a worthwhile MVC framework for ASP? Or a best practice at how to at least get business logic out of the views? (I remember doing a lot of includes back in the day -- is that still the way to do it?)

I'd love to get some unit testing going for business logic too, but maybe I'm asking too much?

+1  A: 

Is there any chance you could move from ASP to ASP.Net? Or are you looking at keeping it in classic ASP, but just cleaning it up. If at all possible, I would recommend moving as much as possible moving to .Net. It looks like you may be rewriting/reorganizing a lot of code anyway, so moving to .Net may not be a lot of extra effort.

Kibbee
A: 

There are over 200 ASP scripts in the project, some thousands of lines long ;) UGH!

We may opt for the "big rewrite" but until then, when I'm in changing a page, I want to spend a little extra time cleaning up the spaghetti.

ryw
+3  A: 

Since a complete rewrite of a working system can be very dangerous i can only give you a small tip: Set up exuberant tags, ctags, on your project. This way you can jump to the definition of a function and sub easy, which i think helps a lot.

On separating logic from "views". VBScript supports som kind of OO with classes. I tend to write classes which do the logic which I include on the asp-page which acts as a "view". Then i hook together the view with the class like Username: <%= MyAccount.UserName %>. The MyAccount class can also have methods like: MyAccount.Login() and so on.

Kind of primitive, but at least you can capsulate some code and hide it from the HTML.

jamting
+1  A: 

Presumably someone else wrote most or all of the system that you're now maintaining. Look for the usual bad habits (repeated code, variables that are too widely scoped, nested if statements, etc.), and refactor as you would any other language. Keep an eye out for recurring things in the same file or different files and abstract them into functions.

If the code was written/maintained by various people, there might be some issues with inconsistent coding style. I find that bringing the code back into line makes it easier to see things that can be refactored.

"Thousands of lines long" makes me suspicious that there may also be situations where loosely-related things are being displayed on the same page. There again, you want to abstract them into separate subroutines.

Eventually you want to be writing objects to help encapsulate stuff like database connectivity, but it will be a while before you get there.

Scott
+5  A: 

Assumptions

The documentation for the Classic ASP system is rather light.

Management is not looking for a rewrite.

Since you have been doing ruby on rails, your (VB/C#) ASP.NET is passable at best.

My experience

I too inherited a classic ASP system that was slapped together willy-nilly by ex excel-vba types. There was a lot of this stuff <font size=3>crap</font> (and sometimes missing closing tags; Argggh!). Over the course of 2.5 years I added a security system, a common library, CSS+XHTML and was able to coerce the thing to validate xhtml1.1 (sans proper mime type, unfortunately) and built a fairly robust and ajaxy reporting system that's being used daily by 80 users.

I used jEdit, with cTags (as mentioned by jamting above), and a bunch of other plugins.

My Advice Try to create a master include file from which to import all the stuff that's commonly used. Stuff like login/logout, database access, web services, javascript libs, etc.

Do use classes. They are ultra-primitive (no inheritance) but as jamting said, they can be convenient.

Indent the scripts properly.

Comment

Write an external architecture document. I personally use LyX, because it's brain-dead to produce a nicely formatted pdf, but you can use whatever you like. If you use a wiki, get the graphviz add-in installed and use it. It's super easy to make quick diagrams that can be easily modified.

Since I have no idea how substantial the enhancements need to be, I suggest having a good high-level to mid-level architecture document will be quite useful in planning the enhancements.

On the business logic unit tests, the only thing I found that works is setting up an xml-rpc listener in asp that imports the main library and exposes the functions (not subroutines though) in any of the main library's sub-includes, and then build, separately, a unit test system in a language with better support for the stuff that calls the ASP functions through xml-rpc. I use python, but I think Ruby should do the trick. (Does that make sense?). The cool thing is that the person writing the unit-test part of the software does not need to even look at the ASP code, as long as they have decent descriptions of the functions to call, so they can be someone beside you.

There is a project called aspunit at sourceforge but the last release was in 2004 and it's marked as inactive. Never used it but it's pure vbscript. A cursory look at the code tells me it looks like the authors knew what they were doing.

Finally, if you need help, I have some availability to do contract telecommuting work (maybe 8 hours/week max). Follow the link trail for contact info.

Good luck! HTH.

Christopher Mahan
+2  A: 

My advice would be to carry on refactoring, classic ASP supports classes, so you should be able to move all everything but the display code into included ASP files which just contain classes. See this article of details of moving from old fashioned asp towards ASP.NET

Refactoring ASP

Regarding a future direction, I wouldn't aim for ASP.NET web forms, instead I'd go for Microsoft's new MVC framework an add-on to of ASP.NET) It will be much simpler migrating to this from classic ASP.

or since you are familiar with RoR, then you should look into Castle Monorail as an alternative to Microsoft ASP.NET MVC. They are both quite mature now, but Monorail was there first, and it integrates nicely with the Castle ActiveRecord implementation, so it might be easier to pick up and the Microsoft MVC stack.
nocache
The author of this answer should disclose that he is the author of the pay-to-view article he links to here. For $8, it doesn't cover much of anything you won't find in Fowler's book, or Feather's.
Tristan Havelick
+2  A: 

I use ASPUnit for unit testing some of our classic ASP and find it to be helpful. It may be old, but so is ASP. It's simple, but it does work and you can customize or extend it if necessary.

I've also found Working Effectively with Legacy Code by Michael Feathers to be a helpful guide for finding ways to get some of that old code under test.

Include files can help as long as you keep it simple. At one point I tried creating an include for each class and that didn't work out too well. I like having a couple main includes with common business logic, and for complicated pages sometimes an include with logic for each of those pages. I suppose you could do MVC with a similar setup.

Mike Henry
A: 

This is very old, but couldn't resist adding my two cents. If you must rewrite, and must continue to use classic ASP:

  • use JScript! much more powerful, you get inheritance, and there some good side benefits like using the same methods for server-side validation as you use for client-side
  • you can absolutely do MVC - I wrote an MVC framework, and it was not that many lines of code
  • you can also generate your model classes automatically with a bit of work. I have some code for this that worked quite well
  • make sure you are doing parameterized queries, and always returning disconnected recordsets
RedFilter