More Joys of Vendorscript

Someone recently suggested to me that the selection of VBScript for an automation language is because it’s easier for testers. This is slightly rant-y, but I promise there are a few helpful tips in here just to make up for a mild dose of language-warring.

Exhibit A.

I can understand that there’s a chance that a tester (if they came from a business role) might have some familiarity with VBScript as a result of writing office macros, but really…

Which would you rather write (and read)?


Dim newList
newListNextItem = 0

For i=1 to ubound(list)
Redim newList(newListNextItem)
newList(newListSize) = list(i).getROProperty(“text”)
newListNextItem = newListNextItem+1
Next i

OR


list.each do | item |
newList.push item.text
end

Of course, you can (and probably should) implement your own class to do something like the above. Below is how things might look if do.


Set newList = new dynamicList
while list.hasNextItem do
newList.add(list.nextItem)
end while

You will, however, quickly encounter the issue detailed in exhibit C.

Exhibit B.

Is it easier to have to change the way that you assign a variable based upon the type of the thing being assigned?


a="Fred"
Set b=New Fred
c=a
Set c=b

OR


a="Fred"
b=Fred.new
c=a
c=b

The net effect of this is to have functions which need to be aware of exactly what kind of thing they are returning, then have them do this:


If isObject(a) then
Set functionReturnValue = a
Else
FunctionReturnValue = a
End if

Exhibit C.

We include a reference to file B from file A

File A contains:


Set a = New a

File B contains:


Class A
End Class

For some reason this doesn’t work, so just to check, we try a different method to include our Class definition. Now we are told that the class already exists.

But wait, if you somehow thought to create a special factory function to give you an instance of the class, it all works.

So now we change File B to:


Function newA
Set newA = New A
End Function

Class A
End Class

Now why didn’t I think of that?

Rant off. I’ll be working with different languages and tools for a while now…But do we really have to suffer this as testers? I’ve never spent so much time in a debugger, ever. Productivity tool? I leave that to you to decide.

And in case you didn’t read this the first time around, discover the joys of Visual Basic over here:

http://adamv.com/dev/articles/hatevbs/vbscript
Terry Horwath has also done some further investigation of the namespace issue (Exhibit C) over at SQA Forums.

Leave a Reply

Your email address will not be published. Required fields are marked *