<p>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.</p>
<p>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.</p>
<p>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?)</p>
<p>I'd love to get some unit testing going for business logic too, but maybe I'm asking too much?</p>
<h3>Update:</h3>
<p>There are over 200 ASP scripts in the project, some thousands of lines long ;) UGH!</p>
<p>We may opt for the &quot;big rewrite&quot; but until then, when I'm in changing a page, I want to spend a little extra time cleaning up the spaghetti.</p>

[{'answer_id': 24431, 'author': 'Kibbee', 'author_id': 1862, 'author_profile': 'https://Stackoverflow.com/users/1862', 'pm_score': 1, 'selected': False, 'text': '<p>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.</p>\n'}, {'answer_id': 24663, 'author': 'jamting', 'author_id': 2639, 'author_profile': 'https://Stackoverflow.com/users/2639', 'pm_score': 2, 'selected': False, 'text': '<p>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.</p>\n\n<p>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: &lt;%= MyAccount.UserName %>. The MyAccount class can also have methods like: MyAccount.Login() and so on.</p>\n\n<p>Kind of primitive, but at least you can capsulate some code and hide it from the HTML.</p>\n'}, {'answer_id': 60337, 'author': 'Scott', 'author_id': 6126, 'author_profile': 'https://Stackoverflow.com/users/6126', 'pm_score': 1, 'selected': False, 'text': "<p>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.</p>\n\n<p>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.</p>\n\n<p>&quot;Thousands of lines long&quot; 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.</p>\n\n<p>Eventually you want to be writing objects to help encapsulate stuff like database connectivity, but it will be a while before you get there.</p>\n"}, {'answer_id': 60404, 'author': 'Christopher Mahan', 'author_id': 479, 'author_profile': 'https://Stackoverflow.com/users/479', 'pm_score': 5, 'selected': True, 'text': '<p><strong>Assumptions</strong></p>\n\n<p>The documentation for the Classic ASP system is rather light.</p>\n\n<p>Management is not looking for a rewrite.</p>\n\n<p>Since you have been doing ruby on rails, your (VB/C#) ASP.NET is passable at best.</p>\n\n<p><strong>My experience</strong></p>\n\n<p>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 <code>&lt;font size=3&gt;crap&lt;/font&gt;</code> (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. </p>\n\n<p>I used jEdit, with cTags (as mentioned by <a href="https://stackoverflow.com/users/2639/jamting">jamting</a> above), and a bunch of other plugins.</p>\n\n<p><strong>My Advice</strong>\nTry 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.</p>\n\n<p>Do use classes. They are ultra-primitive (no inheritance) but as jamting said, they can be convenient.</p>\n\n<p>Indent the scripts properly.</p>\n\n<p>Comment</p>\n\n<p>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.</p>\n\n<p>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.</p>\n\n<p>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. </p>\n\n<p>There is a project called <a href="http://aspunit.sourceforge.net/" rel="nofollow noreferrer">aspunit</a> 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.</p>\n\n<p>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.</p>\n\n<p>Good luck! HTH.</p>\n'}, {'answer_id': 264966, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>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.\nSee this article of details of moving from old fashioned asp towards ASP.NET</p>\n\n<p><a href="http://microsoft.apress.com/asptodayarchive/73655/refactoring-and-asp" rel="nofollow noreferrer">Refactoring ASP</a></p>\n\n<p>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.</p>\n'}, {'answer_id': 293072, 'author': 'Mike Henry', 'author_id': 14934, 'author_profile': 'https://Stackoverflow.com/users/14934', 'pm_score': 2, 'selected': False, 'text': '<p>I use <a href="http://aspunit.sourceforge.net/" rel="nofollow noreferrer">ASPUnit</a> 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.</p>\n\n<p>I\'ve also found <a href="https://rads.stackoverflow.com/amzn/click/com/0131177052" rel="nofollow noreferrer" rel="nofollow noreferrer">Working Effectively with Legacy Code</a> by Michael Feathers to be a helpful guide for finding ways to get some of that old code under test.</p>\n\n<p>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.</p>\n'}, {'answer_id': 2686744, 'author': "D'Arcy Rittich", 'author_id': 39430, 'author_profile': 'https://Stackoverflow.com/users/39430', 'pm_score': 0, 'selected': False, 'text': "<p>This is very old, but couldn't resist adding my two cents. If you must rewrite, and must continue to use classic ASP:</p>\n\n<ul>\n<li>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</li>\n<li>you can absolutely do MVC - I wrote an MVC framework, and it was not that many lines of code</li>\n<li>you can also generate your model classes automatically with a bit of work. I have some code for this that worked quite well</li>\n<li>make sure you are doing parameterized queries, and always returning disconnected recordsets</li>\n</ul>\n"}, {'answer_id': 31032637, 'author': 'Hikari', 'author_id': 1956207, 'author_profile': 'https://Stackoverflow.com/users/1956207', 'pm_score': 0, 'selected': False, 'text': "<p>Software Development Project Management practices indicates that softwares like this are requiring to retire.</p>\n\n<p>I know how hard it is to do the right thing, even more when the responsible manager knows sht and is scared of everything other than the wost way possible.</p>\n\n<p>But still. It's necessary to start working on the development of a new software. It's simply impossible to maintain this one forever, and the loger they wait for retiring it the worse.</p>\n\n<p>If you don't have proper specification/requirements documentation (I think no asp software in the world does, given the noobatry hability of those coders), you'll need both a group of users that know the software features and a manager to be responsible for validating the requirements. You'll need to review every feature and document its requirements.</p>\n\n<p>During that process you'll go learning more about the software and its business. Once you have enough info, you can start developing a new one.</p>\n"}]
['https://Stackoverflow.com/questions/23899', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2477/']