I have to dive into a big chunk of legacy ASP code. What ressources would you recommend reading in order to grasp the best practices of this platform (object orientation, configuration for i18n, ..)
I frequently referred to the Wrox publication of VBScript: A Programmer's Reference. Essentially, your ASP pages are just VBScript anyway.
If your pages are heavy on the COM+ code, god help you. Stack Overflow wasn't invented then, but I'd suggest you spend a fair bit of time here.
Well classic asp a lil bit outage thats true but still many big website running with it and success with it, and i still using it for some particular projects.
below are some resources which you interested with:
- MSDN Library docs
- W3Schools
- Webdevbros
- CHM Format Language Documentation
- Advanced topics at zend.lojcomm.com.br
- Ajaxed Library, ASP3 + Prototype + Scriptaculous Wrapper
I also still playihg with it a li'l bit at asp.web.id, hope that will help
First, understand that "classic ASP" can actually refer to a whole combination of technologies:
- The ASP runtime and intrinsic HTTP objects (Request, Response, Server, Session, Application)
- a scripting engine (usually VBScript, but some sites use JScript or Perlscript instead)
- a COM host that lets you work with COM objects
Most classic ASP sites will use VBScript as their scripting language, and ADO (Connections, Commands and Recordsets) for database access. You may also come across various COM objects used for sending mail, processing XML, and so on - there may even be some bespoke/custom COM objects (probably written in VB6 or C++) in your legacy codebase.
Scott Mitchell's Designing Active Server Pages is probably the best overall reference on "best practice" on the classic ASP platform. There's also a wealth of useful material on 4guysfromrolla.com
You'll then want to make sure you've got the latest documentation for each element of the environment you're using:
- VBScript/JScript documentation (CHM format)
- ADO documentation is included in the MDAC 2.8 SDK
- The W3Schools reference on ASP is also highly recommended.
If you're in this for the long haul, you'll also want to consider ways you can improve/clean up the code over time. Porting individual pages from .asp to .NET can be an effective strategy in this regard; if you isolate your authentication and security into cookies rather than using the built-in Session object, you'll be able to use Request.Cookies from both classic ASP and ASP.NET, and then begin moving bits of business logic out of the pages themselves and into a set of core modules or even something like a domain model.
And don't freak out. Classic ASP is not that bad. I'd use it over ASP.NET WebForms any day. :)
Your first resource should be a bottle of vodka (I feel sorry for you - I had the experience developing ASP around ten years ago). If you don't drink, don't worry - you will.
As far as I remember, object orientation is extremely rudimentary in ASP (objects in ASP are COM objects so you can encapsulate them but not inherit) and all you can do is group code in functions and modules (that is, separate files).
Standard code cleanliness rules apply (consistent naming convention, if you write the same code twice put it into a function, etc); other than that ... good luck.
I'd be the first to admit that VBScript/ASP is far from an ideal platform, but it's nowhere near as bad as some of the comments imply. It's not the most modern language in the world, and it has its share of warts, but it's perfectly possible to write good, solid code in VBScript. And it doesn't have to be an ordeal; although the platform lacks many of the tools that make programming in other languages easy (lists, inheritance, importing, reasonable assignment syntax, proper constructors), most of them can be replaced, simulated, or worked around. And VBScript gives you a fair bit to work with:
- Dynamicism
- Default properties
with
blocks- Predictable garbage collection
- Efficient response buffer
I often hear many of VBScript's features (particularly default properties) disparaged as confusing, but if you're familiar with the language, they can be powerful assets. Think of the built-in functions and features as a base to build on. With these tools, you can patch over most of the warts. For example:
Problem: the friggin' mandatory set syntax. Example:
if isObject(foo) then
set bar = foo
else
bar = foo
end if
Pain in the rear, huh?
Solution: VBScript supports pass-by-reference!
function assign (byref var, val)
if isObject(val) then
set var = val
else
var = val
end if
end function
Example:
assign bar, foo
Obviously, a technique to use with discipline, but perfectly clear when well-used.
More examples of what you can do in VBScript if you're willing to make it work:
myList.map getRef(lcase)
set myDict = DB.get_record "select * from Foo where id=?", Array(42)
import "MyLib"
printf "%s, %!s" Array("Hello", "<World>")
' => Hello, <World>'
with Form.define("User")
with .field("name")
.validate_nonempty
.validate getRef("userNameNotTaken"), "That user name is taken"
end with
with .field("email")
.validate_format emailRegex
end with
with .field("password")
.validate_length 6, null
.validate getRef("passwordIsComplex"), "Your password must contain…"
end with
end with
There's an old saying that you can write COBOL in any language. It means, more or less, that the features of a language are less important than the programmer in producing good code. Now, you can't quite write ruby or python in VBScript, but you can come a lot closer than you might think.
EDIT: Almost forgot. Eric Lippert was one of VBScript's designers, and his blog is an invaluable resource for some of the trickier parts of the language.