Women in Technology

Hear us Roar

  VBScript or Perl?
Subject:   More considerations
Date:   2003-11-24 14:30:54
From:   brianiac
VBScript Strengths
[Formatting Functions]
FormatCurrency(), FormatDateTime(), FormatNumber(), and FormatPercent() not only make short work of tedious formatting tasks, but also use locale-specific formatting rules.
[Data Conversion]
CBool(), CByte(), CCur(), CDate(), CDbl(), CInt(), CLng(), CSng(), CStr(), CBool() all tend to overreact to unconvertable data, but are nicely complemented by VarType(), IsDate(), IsEmpty(), IsNull(), IsNumeric(), and IsObject(). Hex() and Oct() allow converting numbers to non-decimal strings. DateValue() and TimeValue() allow returning just the parsed date or time values, respectively.
[Date/Time Support]
Along with the usual functions for individual date fields, Day(), Hour(), Minute(), Month(), MonthName(), Second(), Timer(), Weekday(), WeekdayName(), Year(), and the more generic DatePart(), there are some more granular functions for current info: Now(), Date(), Time(). The DateSerial() and TimeSerial() functions allow for complex date arithmetic, as do DateAdd(), DateDiff(). Date literals are supported, using # as the delimiter: #datestring#.

VBScript Weaknesses
[Unforgivably Bad Array Support]
While standard functions like Filter(), Join(), and Split() are supplied; no sort, slice, splice, or concatenation functions exist. The stack and queue functions: push, pop, shift, and unshift are also missing.
[Clumsy Exception Handling]
Automatic exception handling has two modes: on (all errors and warnings are fatal), and off.
[Unreasonably Strong Typing]
Objects are not first-class objects; assignment, for example, is handled completely differently from built-in datatypes. This precludes, among other things, programs from passing functions as arguments. Adding to this difficulty, naught is expressed in many distinct (and confusing) terms: Nothing is an invalid object variable, Null adds the database-style complexity of three-valued logic (not true, not false), and Empty is the value in an uninitialized variable. Numeric values can be interpreted as booleans, as can some string values (but only if they are numeric or boolean strings).

JScript Strengths
[Strong Array Support]
A reasonable complement of expected array functions is supported: sort(), split(), join(), slice(), splice(), concat(), push(), pop(), shift(), unshift(), and reverse(). No grep/filter, search, or membership-test function exist.
[Native Associative Arrays (hashes)]
Actually, all JScript arrays are hashes: an array with numeric keys can have string keys added, and all keys can be iterated via the for...in loop. As Perl programmers already know, native hash support allows arbitrarily complex data structures to be built quite easily.
[Structured Exception Handling]
Using try...catch, errors can be handled much more readably, maintainably, and conveniently.

JScript Weaknesses
[NO Formatting Abilities]
All languages should have some kind of formatting ability: C's (and Perl's) printf, C++'s iomanip.h library, Python's % operator, etc. JScript does not. Doing something as simple as including exactly two digits after the decimal when converting a number to a string, or commafiying a number, is incredibly tedious.
[Limited Data Conversion Support]
Dates and non-decimal numbers are not always converted easily. No native currency type is supported.
[Date/Time Support]
No functions exist specifically for date/time arithmetic, and there is an inadequate granularity for parsing control. No date literal is supported.

Full Threads Oldest First

Showing messages 1 through 4 of 4.

  • Function Pointers
    2004-05-11 20:14:46  tby@yehl.us [View]

    It is possible to get a "function pointer" in VBS: GetRef.
  • More considerations
    2003-12-31 02:08:28  anonymous2 [View]

    "all JScript arrays are hashes: an array with numeric keys can have string keys added, and all keys can be iterated via the for...in loop. As Perl programmers already know, native hash support allows arbitrarily complex data structures to be built quite easily."

    Actually, JScript (ECMAScript) support of associative arrays is not very useful. You cannot get as the keys (indices) and let's say sort them, as you can in Perl. This prevents popular data-structures, such as frequency hashes.

    For example this functionality of Perl would be quite impossible under Perl.

    foreach $key (sort {$a <=> $b} keys %hash) {
    printf "%s %s", $hash{$key} $key

    However, this could be emulated in JScript (or any other language) using array of an array.

    Another nice thing about Perl, not found in other languages is list/array slicing, such as this:

    foreach $line (<FILE>) {
    my ($empno, $name, $salary) = (split /,/)[0,2,4];

    The above slices out the 1st, 3rd, and 5th elements of a CSV file and stores them into local variables called empno, name, and salary. In JScript, this gets a little ugly, and in other languages it gets uglier.

    - Joaquin Menchaca
    • More considerations
      2004-01-06 08:14:11  brianiac [View]

      Extracting keys from a JScript array is ugly, but not impossible:
      var hash= { 'one': 'first', ... }, keys= {};
      for(key in hash) keys.push();
      keys= keys.sort();

      Slicing is also supported, though only for contiguous regions:
      var slice234= arr.slice(2,4);
  • More considerations
    2003-11-30 12:03:53  anonymous2 [View]

    1) I definitely would not take the formating functions of VBScript as a strong point. They are almost useless. Using the system locale specific rules is quite often a bad idea. Especialy for web based projects and for log files. I would really love to get logfiles with differently formated dates from different computers.
    But you are right, it's a surprise there is at least this.

    2) Data conversion in VB is also horrible. Especialy thanks to the complete evaluation of conditions. The fact that I can't write
    IF IsNumeric(foo) AND CInt(foo) > 0 Then
    is driving me crazy every time I have to use VB(Script).