Choosing a scripting language for ASP
by Manohar Kamath
Oct 10, 1999
Active Server Pages introduced a whole new concept to web
development - scripting language of your choice. Before ASP came around, the web
development tools such as ColdFusion by Allaire required that you know a proprietary
scripting language (in the case of ColdFusion it is CFML). On the other hand there was
(still is) Perl, which with packages provides access to databases and other functionality
that you have come to expect from a web development environment.
ASP provides a better way of doing things - it modularizes the
web development effort. It gives you the option of choosing your scripting language,
something most other web development tools do not offer. While there are many scripting
languages around, the two most prominent are - VBScript and JavaScript. I would also like
to mention PerlScript, an ActiveX scripting engine available from ActiveState Tool Corp., that you
can use for scripting your ASP pages. A very good PerlScript resource can be found at .
Let's get back to VBScript and JavaScript. A common question that
has been asked in newsgroups is "What is better scripting language, VBScript or
JavaScript?" In my opinion, there is no "better" scripting language. It all
depends on what context you ask the question. This is the question many technical leads
face, especially when working with team members with different programming backgrounds.
Also, a tinge of bias seeps into this argument - many people tend to think JavaScript is
the same as Java, a programming language from the "enemy camp."
All these can possibly affect what scripting language you will
use in your ASP pages. Here are some of the factors you may want to consider before
settling on one.
a. Ease of Use
People will tell you VBScript is easier than JavaScript, simply
because it looks like Visual Basic language. While this is true, a programmer with Java
experience may think otherwise. People with no programming background may find VBScript
easier to use because
It is easier to understand owing to its English-like syntax.
E.g. If you want to get first 2 letters in a word, do Left(someWord, 2) in VBScript,
whereas in JavaScript you do someWord.substr(0,2)
There is more ASP reference material with VBScript than there
is with JavaScript.
JavaScript is case-sensitive and VBScript isn't. While this
argument is valid, I personally feel case-sensitivity helps people understand the syntax
better (conditioning, anyone?)
b. Features
Both scripting languages are powerful in their own right.
JavaScript offers a rich set of object-oriented framework to work with - you could create
classes. But with its version 5, this functionality extends to VBScript as well.
Again, sometimes people confuse power with lines of code. Just
because something can be done in VBScript with one line of code when it takes three lines
in JavaScript does not mean JavaScript is any less powerful.
However, JavaScript and VBScript differ in some features
Error handling:
At the time of this writing, there was no error handling mechanism in JavaScript (in
version 1.2, they are talking about it in 1.3). VBScript on the other hand provides a
small but sufficient set of error handling capabilities.
Arrays:
Handling multi-dimensional arrays is easier in VBScript than in JavaScript. VBScript
arrays can easily be dimensioned and re-dimensioned. JavaScript on the other hand provides
a great feature - associate arrays, something that can easily replace dictionary objects.
Collection objects:
With VBScript, one can enumerate items in a collection using the For Each.. Next loop.
This way, you avoid using an index to get the value of any item within the collection.
Note: JScript version 3 supports an Enumerator object which lets you loop
through the collection without using any index.
c. Client-side Scripting
"Why?" you may wonder. Although client-side scripting
has nothing to do even remotely with the server-side, you may find yourself considering
this in some situations
This factor becomes important when you have to work on a team
and the team members are new to scripting. Instead of climbing two learning curves, settle
on one language for both client-side and server-side scripting. JavaScript can be a good
candidate in these situations, as runs on most browsers. VBScript, on the other hand, does
not run on Netscape browsers which at this time constitute about half the browser market.
If you are working in an Intranet environment where the
standard browser is Internet Explorer, you can choose either VBScript or JavaScript.
How about both?
ASP not only supports multiple scripting languages, but it lets
you mix languages within a single page. For instance, you can have both JavaScript and
VBScript routines on the same page. This ability, while it offers flexibility, is not all
that efficient when you have a large number of pages. consider this only if necessary,
when one language does not give you what you want.
Conclusion
This article was written to help you in deciding choose a
scripting language to write ASP pages, especially when you are new to ASP. The language
should not become a holy grail, but instead I suggest that you give both VBScript and
JavaScript a try before you decide what's best for you. If you have something to add to
this article, please email us at feedback@kamath.com.
Related links 
Microsoft Scripting Site: Download the latest scripting engines
VBScript Reference & VBScript Tutorial
JScript Reference & JScript Tutorial
ActiveState
Tool Corp.: Perl related products, including PerlScript, an ActiveX scripting engine.
|