“ASP” Does Not Equal “VBScript”

By Deane Barker on July 12, 2005

Note: This entry changed quite a bit in the 24 hours after it was published. I discovered a lot of stuff I’m ashamed to say I didn’t know, I posted several updates to the end of the post, and I eventually changed the title.


Quick survey: if you are a “traditional” ASP programmer (non .Net, so ASP 3.0 or below), what language do you program in: VBScript or JScript?

I’m guessing VBScript will win by a huge margin. I always programmed in VBScript back when I was working with ASP — it’s considered the default langauge for ASP.

For those not familiar, “Active Server Pages” is often considered a language, but it really refers to a method of integrating scripting code with the IIS Web server. You can actually write that code in two languages: VBScript — a subset of Visual Basic — or JScript, which is Microsoft’s implementation of the ECMA standard — JavaScript, essentially.

Back then, I was only vaguely aware that there was even another option, and I certainly didn’t want to soil myself with those silly brackets and semicolons — those were for the goofy Linux crowd (of which I am now proudly a member).

When I made the move to PHP, I felt liberated by the language — the best example being array handling. You see, VBScript’s array support is utterly laughable. You have to declare the number of elements beforehand, then redeclare if you need to add to them (and make sure to use the “preserve” keyword, or else you’ll lose all the data…). Worse yet, to get a hash or associative array, you have to use a Dictonary object. It’s ridiculous.

In PHP, arrays are gorgeous, fluid creatures that let you do anything and everything. They’re one of the most powerful features of the language. They give you simple ways around complex problems, and I don’t think I’ve ever written a decent-sized PHP app that didn’t use them extensively. I use the array functions in PHP more than any other library.

Based on arrays alone, I can’t believe I wasn’t programming ASP in JScript instead of VBScript. ECMA Script has good array support — not as good as PHP’s, but you can do associative arrays easily, there’s a “push” method for tacking things on the end of an array, they can hold anything, etc.

(And I won’t even get into the fact that ECMA has “try – catch – finally” blocks. “On Error Resume Next” is just absurd by comparison.)

There are so many problems that I could have avoided by abandoning VBScript. Why didn’t I do it? I asked Joe — who programmed ASP with me for a long time — and he didn’t know why we didn’t switch either.

(It’s not an infrastructure issue, since making page execute in JScript rather than VBScript is just a matter of doing this at the top:

<%@ language="javascript"%>

You could do this and not tell anyone. For that matter, you can make one page of an app execute in JScript and all the others in VBScript, if you want. No one would know the difference.)

If you’re a ASP / VBScript programmer, why don’t you switch? That’s not rhetorical — please tell me: what is stopping you from programming in JScript? Are there deficiencies in JScript I’m not considering?

Update: I found this page which lists the strengths and weaknesses of both languages when programming ASP.

It’s interesting to look at the weaknesses. The first one for VBScript is — not surprisingly — “Unforgivably Bad Array Support.” But JScript has it’s problems too: “Stunningly Inadequate Formatting Facilities” and “Lousy Date/Time Support” are both very true.

Another Update: I’m learning a lot. It turns out you can even install other languages into IIS and use them under ASP. You can do this with both Perl and Python.

Look at this page (a Microsoft page, even) to see examples of using Python with ASP. In this case, “ASP” merely becomes (1) the framework to execute the pages within IIS, and (2) the five intrinsic objects that get handed to the page (Request, Response, Session, Application, and Server) before execution.

Yet Another Update: I’ve changed the title of this entry to “ASP Doesn’t Equal VBScript” because that’s really what I’ve distilled this to after all these updates. A final example: ActivePHP. Yes, you could use PHP as a language for ASP. Seriously. I found a thread over at Zend where some guy says you could do this with ActivePHP:

<%@lanugage=ActivePHP%>
<%
$Response->Write("hello");
%>

The time for “traditional” ASP has obviously passed with the advent of .Net, but I’m frustrated that I never truly understood the separation between framework and language with that platform. I could have been a much more effective developer.

Gadgetopia
What Links Here

Comments

  1. How hard is it to connect to a database and retrieving data in JScript? VBscript is so easy and straightforward, I bet that’s why most people still use it, besides the syntax.

  2. How hard is it to connect to a database and retrieving data in JScript?

    JScript uses COM as well. COM is a separate thing from VBScript, JScript, and even ASP and works roughly the same regardless of how it’s invoked. The JScript would look something like this:

    var db = Server.CreateObject("ADODB.Connection")
    db.open([DSN goes here])
    var results = db.Execute("SELECT * FROM table")
    

    Etc.

  3. I found a good page that summarizes the differences between the languages. I’ve updated the entry with a link. Scroll back up…

  4. Legacy code.

    If you’ve got hundreds and hundreds of functions already defined in VBScript changing is a bigdeal_.

  5. You learned a lot, your posters have a lot to learn.

    To the poster with the investment in vbscript functions. I had no problem writing a program that took my vbscripts and converted them to javascripts, a process that was admittedly eaiser because i was consistant in my vbs programming style. The effort was well worth it.

    I don’t use ASP (or IIS), but I do use WSH and I believe that the script engines are similar. In WSH, js can call vbs functions and vbs can call js functions. Variables and objects of all types can be freely defined under one language and referenced under the other. There is one exception and that is the VBS array of variants. js can not process it natively, so an object/method combination is provided to copy the contents of a vbs array to a js array where they can be referenced. It is a one way operations, changes made in the js array are not reflected in the original vbs array. Point being that an existing library of VBS functions should not hold any knowledgeable programmer back from doing the right thing.

  6. You can also have multiple scripting languages on the same page, and they can talk to each other as well. I often use this to create functions for use in vbscript that jscript does a better job at. Simple example:


    < %
    dim a
    a = “The quick brown fox jumps over the lazy dog”
    response.write a&”

    a = regexReplace(a, “quick”, “slow”) ‘simple replace
    response.write a&”

    a = regexReplace(a, “DOG”, “fox”) ‘will do nothing
    response.write a&”

    a = regexReplace(a, “DOG”, “fox”, true) ‘make it case insensitve
    response.write a&”

    a = regexReplace(a, “the”, “a”, true) ‘will only replace first one
    response.write a&”

    a = regexReplace(a, “\b[^\s]{4}\b”, “EXPLETIVE-DELETED”, false, true) ‘will be global
    response.write a&”

    %>

  7. Nice thread.

    Here’s my thoughts on why VBScript is more prominent for ASP:

    1. Because there are more example code in VBScript. It’s hard to find code samples for the same thing in JScript, PerlScript, etc. Luckily, MS kind of changed that with .NET and their MSDN docs.

    2. ASP developers more likely came from MS environment and would likely be more accustomed to VB, hence VBScript.

    3. VBScript is the default for ASP. It’s not widely documented (like on the front page of the help info) that you can use JScript for ASP, etc.

    And by the way, interoperability with VBScript and JScript in ASP and WSH is great but there are still some problems like passing null objects, true/false values, etc. Numbers, strings, and COM objects are more ok though. Not sure about arrays.

    One last thing, JScript provides better error handling of COM objects using try/catch block. You can’t do that with Error object in VBScript (only works for native VBScript oriented objects like ADO and FSO, etc., not necessarily for custom or third party COM objects).

Comments are closed. If you have something you really want to say, email editors@gadgetopia.com and we‘ll get it added for you.