| 26 October 2001 |
The Flangy Guide to Hating VBScript. VBScript is probably the language I use most at work, no matter how many years go by I still can't get used to not having variables local only to functions. Global variables, scarey biscuits...
Update for anyone coming here from the Flangy link
To be explicit here's an example of the kind of thing that causes problems.
<%
Option Explicit
Dim i,j
i=5
response.write "Before Func i="&i&"<br>"
j=doFunc(i)
response.write "After Func i="&i&"<br>"
response.write "After Func j="&j&"<br>"
Function doFunc(i)
i=6
doFunc=i
End Function
%>
The output is:
Before Func i=5
After Func i=6
After Func j=6
i.e. the value of the global variable has been changed
There's nothing wrong with VBScript - it's just if you come to it from another strongly typed language you expect something in the parameter list to help you recognise that if you change the value of the function variable then it will affect the calling variable. It's more like a call by reference. If VBScript is your first language then you'll think nothing of it but I've seen this catch many folk from a C/Pascal background. Especially when it comes to coding functions that are called from a loop and e.g. do a replace on a string variable without having copied the values to a new variable. Then poor developer has to figure out why the same starting string value isn't being passed to further iterations. Even Visual Basic makes the status of the variable in the parameter lists clearer.
12:35:27 AM© Copyright 2002, Scottish Lass, www.scottishlass.co.uk, Contact: