- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Many veteran software engineers have to always keep their eyes peeled for bad code lurking in our software.
Admin
Of all the bizarre naming choices out there,
dim
for a variable declaration has got to be pretty high up there. (I know what it means, but it's still bizarre.)Admin
I thought the answer was "it contains nan"
Admin
How silly! Everybody knows that the correct way to do that is:
Dim params : params = Split(String(7,”,”), ",")
Admin
That's the revolutionary new zero based array size number system! You're a genius.
Admin
It was a pretty Dim-witted naming choice!
Admin
{facepalm} After 40 years, I thought I had seen every type of "bad code that actually works". But this one truly left my jaw hanging open and me thinking WTF . . .
Admin
VBScript was more JavaScript with VB synatx and had actually little to do with VB6 otherwise. It was completely redundant because JS was supported by every browser, VBScript basically only by Internet Explorer. There was one benefit to VBScript, it made handling ActiveX objects way easier - again, that was something very Windows specific, but I encountered a few of those in my career.
Admin
It's been quite a while, 20+ years, but, IIRC, there's a useful difference between
Dim params(8) and Dim params : params = Split(",,,,,,,", ",")
The first gives you an uninitialised array (null variants, Nothing in VB land, and you can look up variants - horrid things - for yourselves) the second gives you an array of 8 empty strings. By doing the latter subsequent code doesn't have to check for Nothing (null) before every operation on an array element. It would have been better if the array type had been specified as string because as it stands it's still (again IIRC) an array of variants, but the code really isn't as stupid as it looks at first glance.
Admin
So, I will say regarding that- I opted to crunch this down into a Representative Line, but the submitter supplied more context- the next lines were a loop which initialized each element in the array. Good thought, though.
Admin
Centuries ago, Mozart wrote his "Musical Joke" that showcases all the mistakes beginning and/or incompetent composers write. I've been tempted to accumulate all the screwy things I've encountered over the years and put them into one "working" program. Sadly, I don't think I and deal with so much stupid in one place.
Admin
Well, as everybody surely knows, split("", ",") is the only[1] way to get an array with zero elements, so it totally makes sense to initialize all[2] other arrays the same way.
there are some functions in some COM dll, which should be able to set an array to zero size, but they fuck up some internal state, and you get weird errors later
so what about arrays with 1 element? Yeah, well, this is VB we're talking about, so why do you expect this to make any sense?
(this dev has not touched VB for almost a year, and does not miss it at all)
Admin
The history is pretty straightforward and mostly innocent. Back in the dark ages, VB had no variable declaration, variable typing was done by suffix. Before variable declaration was introduced, arrays were. So, enter the Dim statement to describe the dimensions of the array.
When variable declaration was added, it was chosen to not create a new keyword, but reused the keyword that was already used to declare arrays.
Admin
VBScript was designed to be familiar to VB programmers, but the type system is/was completely different
Admin
not really - VBScript was used extensively in Windows outside the Browser - most notably for Active Server pages but also for general scripting
Admin
DIM
as the general variable declaration statement in modern BASICs reminds me of all the various meanings ofstatic
in C. Another case of coopting an existing keyword rather than creating a new one.Admin
I think you are mixing up VBA and VBScript when talking about "outside of the browser". And classic ASP was dead around 2001 because it got replace by ASP.net ... and before that it played a very underwhelming role.
Admin
As far as I remember you could use two different languages with classic ASP: VBscript (VB) and Jscript (Javascript).
Admin
VBScript arrays by default were (are?) zero based DIm params(8) gives a 9 element array.
Admin
No, not really.
Group Policy for instance could run both VBScript and batch files.
Windows still actually comes with 2 executables that can run .vbs (VBScript) files, wscript.exe for a graphical version, and cscript.exe for a command line version.
Prior to powershell, one useful purpose for vbscript for instance was retrieving the OU that a computer is in on the domain controller, or getting the current computer name, etc...
Admin
"Why don't you make like program and beat it?" — Biff Tannen
Admin
Weeeeeeeell, this one has an obvious-ish way forward to default values, doesn't it, so… 3.6 röntgen, not great, not terrible?
Admin
Also in C: Borland C (for DOS) had the "auto" keyword, meaning something different than it does today (see: auto / static / register).
Admin
That's nice to know considering I am working on a Classic ASP project right this minute.
Actually, what I am working on is even more of a WTF since it started life as Microsoft Front Page which then had carefully created ASP scripts inserted
Admin
Oh boy, I'm sorry about that. Obviously with JSP arriving at the end of the millennium and Java pushing itself into colleges, ASP was already declared dead before MS brought out ASP.net in 2001 - must be hard working on an old relic like that.
Microsoft Front Page giggle - that's a product I haven't heard about for at least two decades. I actually had no client that had it in use. I tried it out when I was in school, but preferred to actually write my HTML by hand. Ah, that was the good old times where MS pushed web functionality into everything. Obviously it had little chance against the competition like Dreamweaver, but because it pretty much came along for free, some of my co-students use it to prototype their private webpages.
Admin
Oh yes, you are correct. There was the niche use by admins and ops while there was this limbo period, but I luckily never had to work in an environment like that. WSH was notorious instable and prone for security issues, so in most companies I worked at with a proper software dev department, shell scripting before PS was pretty much not allowed beyond simple batch files. But I guess I worked mostly in companies with a proper software department present, I guess for smaller companies with more relaxed security standards there could have been broader adoption.
Admin
Once again, not a WTF. CPU wasteful, but code efficient. It's been a long time but I don't see any other way to fill the array with empty strings with one statement.
Admin
Re "it would have been better to specify the element type", you can't do that in VBScript. Everything's a Variant. (This is the most significant different from non-"script" VB.)
Admin
Nah, it is automatically bad.