Good read: What's wrong with VBA (1 Viewer)

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:10
Joined
Feb 28, 2001
Messages
27,183
AB: Regarding the coffee - I'm joining you in spirit despite the distance. Cheers!
 

AccessBlaster

Registered User.
Local time
Today, 13:10
Joined
May 22, 2010
Messages
5,951
Doc: Most of the topics in this forum are outside of my wheel house. I can however appreciate the time an effort required to comment on them with your level of expertise.
Cheers!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:10
Joined
Feb 19, 2002
Messages
43,274
Some languages can do everything and others can to very little. The capabilities of a language don't have any bearing on whether it is good or bad. A language that works efficiently to solve problems it was designed to solve is "good", no matter what it is capable of. Some years ago before the inmates started running the asylum, we actually chose the language we used based on the needs of the application. If we needed to twiddle bits, we wrote in BAL if we need to do a lot of math, we used FORTRAN, if we wanted to create a report we used a report writer (whose name escapes me at the moment). For general purpose computing, we used COBOL and called subroutines written in other languages as necessary. That gave us high level, readable (assuming the programmer was competent) code that could be modified by someone who didn't write it. It was a very efficient way of developing business applications. COBOL was never something anyone would choose as the base language for controlling a rocket ship or an assembly line or drawing graphics for games. Somehow the logic of being able to choose the tool best suited to the job got perverted into using whatever language was "best". "Best" always varied with whatever was new and shiny. I had one programmer working for me who refused to do "batch". In his mind, the ONLY environment was CICS which was referred to at the time as "on line". Of course, he was still writing in COBOL but he was interacting with a screen rather than mundanely acting on some sequential input file.

I have only once ever called a "sub" written in another language from VBA. I think we've forgotten how to integrate and use what is best about each language. Dot Net became all the rage more than 20 years ago. I'm not sure if it has been supplanted or if we just see variations of shells that make the .net languages workable for the ordinary programmer. No one actually wants to write business logic in the lowest level of C. So shells get built to make C more like COBOL so we don't have to twiddle bits unless we really need to.

An old friend of mine, Gerald Weinburg, wrote a great book called the "Psychology of Computer Programming". It was all about how programmers thought and worked and got into what made a language "good" or "bad". By Gerry's definition, VBA would be a "bad" language, not because of its limitations but because of its flexibility!! The fact that VBA supports multiple ways to do certain things makes it bad rather than good. It causes confusion and makes people have to think about things that they should not have to worry about. As an example, in VBA, the & is the concatenation operator. Therefore 1 & 1 should = 11. However, VBA also allows the + to do concatenation as long as one of the operands is a string so 1 + A = 1A BUT 1+1 = 2. So as a programmer reading code, you have to think about some code that is:
varX = varA + varB
Is the code adding the two operators or is it concatenating them? You should NEVER have to think about this when reading someone else's code.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:10
Joined
Feb 28, 2001
Messages
27,183
VBA would be a "bad" language, not because of its limitations but because of its flexibility!!

It is precisely because the original C language was so loose about data typing that I refused to learn it. C in the early days was the only language I knew that needed some type of pre-compiler to warn you of data type abominations. I know that more modern variants of C do better about that, or at least they CAN do better - but I found the loose structure of early C abhorrent. To me, C was a TERRIBLY bad language when it first came out. Though I'm glad we didn't get saddled with B.

Some of you might think I'm kidding, but the predecessor to C was called B, and C was an improvement over it. But then again, I knew how C had originated. That was another reason I didn't like it. It was actually a bunch of really complex assembly language macros written in the PDP-11 assembler. Want to guess where C got the "(X)+" and "-(Y)" syntax? Pure PDP-11 assembler.

The way I saw it, I was already so fluent in PDP-11 MAC that I didn't need C anyway. Still don't, since I'm no longer an active product programmer.
 
Last edited:

vba_php

Forum Troll
Local time
Today, 15:10
Joined
Oct 6, 2019
Messages
2,880
The fact that VBA supports multiple ways to do certain things makes it bad rather than good. It causes confusion and makes people have to think about things that they should not have to worry about.
OK you guys, this is HUGE problem in almost any platform that has been released. Doesn't matter what it is. I suspect that this is done on purpose by the creators as an attempt to give programmers multiple ways to do the same thing in the event that if one way fails or is incomprehendable, then another is available. that makes perfect sense.
As an example, in VBA, the & is the concatenation operator. Therefore 1 & 1 should = 11.
are you sure that wouldn't result is a bitwise calculation? I've never tried it. Or would you have to use 'AND'?
So as a programmer reading code, you have to think about some code that is:
varX = varA + varB
javascript uses '+', so does many other languages. in PHP, it's '.'. In Oracle it's '||'. I recently did an interview and took an SQL test and the WILDCARD symbol was "%". :rolleyes: Since I've done a lot with PHP, I'll say that the language is annoying as hell with all this:

|| = OR
. = AND (for strings/strings, strings/nums, nums/nums)
! = FALSE (applies to everything)
&& = TRUE (applies to everything)
.= = CONCAT (preceeding value + trailing value)
== = COMPARE (both values are equal, but not necessarily the same type)
=== = COMPARE (both values are equal and same type)
++ = INCREMENT
-- = DECREMENT

and let us not forget the notorious dollar ($) sign, which if it did not exist, neither would PHP.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:10
Joined
Feb 28, 2001
Messages
27,183
Could be worse: You might run across APL, a Ken Iverson special for mathematical programming, in which the basic data type is a multidimensional array. If you guessed that it was oriented towards matrix operations, you wouldn't be wrong, but it does more than just that. It has some derivative languages that are insanely complex.

I would have to start dinking with a special character set (not completely ASCII based) to show the syntax, but since it is a language I have only read about, I wouldn't know what I was telling you if I reproduced it. Wikipedia will tell you more than you ever wanted to know about it.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:10
Joined
Jan 20, 2009
Messages
12,852
The horrors from VBA stemmed from its accessibility, which allowed a lot of terrible code to propagate. The reputation of Access also suffered for the same reason.

Eventually the dislike became cultural. Those who wanted to be considered "proper" programmers bagged VBA because that is what they saw those they perceived as proper programmers do. A bit like proper musicians or music fans hate certain kinds of music.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:10
Joined
Feb 28, 2001
Messages
27,183
G., I don't know about "proper" but I have to admit there are three types of music I don't allow in the house.

1. "Howlin' dawg" country laments - where if the moon isn't full, it should be, because all the dogs will be howling anyway.

2. Extreme super-heavy-metal acid rock - which might include but surely is not limited to "music" from GWAR. I like my music to be of the type that (a) I can understand and (b) I can hear it and (c) after the event, I can hear normal conversations because my ears haven't been burned out.

3. Angry ghetto / gangsta rap - where they talk of popping caps (and aren't talking about bottled beer), and they talk about hoes (and aren't referring to long-handled garden implements.)

Any other music is fair game.
 

vba_php

Forum Troll
Local time
Today, 15:10
Joined
Oct 6, 2019
Messages
2,880
3. Angry ghetto / gangsta rap - where they talk of popping caps (and aren't talking about bottled beer), and they talk about hoes (and aren't referring to long-handled garden implements.)
I love this type of music someimes. All those uncensored cuss words. Songs that I have that fall into this category:

Rolllout - Ludicris
Hot in Herre - Nelly
In Da Club - 50 Cent
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:10
Joined
Sep 12, 2006
Messages
15,656
I think I would find a real "normal" pointer useful - one that can easily reference and dereference a user defined structure, and enable you to build your own doubly linked list, or tree. You know, instead of a pretty useless "collection". Posters claim you can build your own pointers, but it's not that easy, I don't think.

A nice "in" operator in VBA would be good.

Finally, in my opinion, arguments should be byval, not byref. The programmer should need to explicitly declare byref.

[edit - and make explicit variable declaration mandatory, ffs]
 
Last edited:

vba_php

Forum Troll
Local time
Today, 15:10
Joined
Oct 6, 2019
Messages
2,880
Finally, in my opinion, arguments should be byval, not byref. The programmer should need to explicitly declare byref.
I've seen many examples over my short career of developers using one of these in favor of the other, and the one that is not used *should* be the one to use. Is there any ambiguity still present in the minds of developers regarding the purposes of these 2 declarations specs? I have a suspicion that a lot of developers don't even know the difference between the 2. Is that the case? And are there "function call" situations where it really doesn't even matter which one is used? I ran into this many many times working in aerospace.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:10
Joined
Sep 12, 2006
Messages
15,656
"pearls before swine" and similar adages - often remind me of "the mote in one's eye", or maybe "in god's eye", as Niven/Pournelle would have it.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:10
Joined
Sep 12, 2006
Messages
15,656
I've seen many examples over my short career of developers using one of these in favor of the other, and the one that is not used *should* be the one to use. Is there any ambiguity still present in the minds of developers regarding the purposes of these 2 declarations specs? I have a suspicion that a lot of developers don't even know the difference between the 2. Is that the case? And are there "function call" situations where it really doesn't even matter which one is used? I ran into this many many times working in aerospace.

it probably goes back to Pascal and Wirth. A byref argument can introduce unexpected side effects. So if you make everything byval as standard, and make the programmer explicitly declare byref if that's what he wants, it makes it safer.
 

vba_php

Forum Troll
Local time
Today, 15:10
Joined
Oct 6, 2019
Messages
2,880
So if you make everything byval as standard, and make the programmer explicitly declare byref if that's what he wants, it makes it safer.
I have rarely seen byRef used. it's usually byVal, and if it's not byVal it's nothing at all.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:10
Joined
Jul 9, 2003
Messages
16,282
I have rarely seen byRef used. it's usually byVal, and if it's not byVal it's nothing at all.
You don't see byRef, explicitly stated in VBA arguments because it is the default.

Sent from Newbury UK
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:10
Joined
May 21, 2018
Messages
8,527
I have a suspicion that a lot of developers don't even know the difference between the 2. Is that the case? And are there "function call" situations where it really doesn't even matter which one is used? I ran into this many many times working in aerospace.
First of all I completely doubt there are any real "Developers" who do not know the difference. Next you will tell me you know serious developers who cannot declare variables and do not know how to build a class module.

I say 99% of the time (depending on how you write code), it does not matter. Normally what you pass in as an argument gets used but not acted on. In that one percent of the time you better know the difference.

Example:



Code:
'Matters should be byval
Public Function Add2(Val as Long) as long
  val = val + 2 ' acted on parameter
  add2 = val
end function

'does not matter
Public Function Add2_New(Val as Long) as long
  add2_New = val + 2
end function

Code:
Public Sub Test
 Dim x as long
 Dim y as long
 x = 2
 Y = add2_New(x)
 debug.print x & " " & Y
 y = Add2(x)
 debug.print x & " " & Y
end sub
if it's not byVal it's nothing at all
No! If it is not explicitly ByVal it is ByRef. But yes more updated languages tend to default byval. VB.NET is byval as default.
 

vba_php

Forum Troll
Local time
Today, 15:10
Joined
Oct 6, 2019
Messages
2,880
Next you will tell me you know serious developers who cannot declare variables and do not know how to build a class module.
smarta$$. :p I'm sorry, I should have said: "the people I work with", not "developers".
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 16:10
Joined
Apr 27, 2015
Messages
6,341
MajP,

Excellent example. I have asked this question before and I have had it explained to me and I didn't want to admit to Doc and Galaxiom that although they did their best to dumb it down for me, I still did not get it. So I said thank you and went on my way.

Even with your explanation, I still had to load up your code and step through the process to get it through my thick skull - but it DID get in and the light bulb was bright indeed!

Really appreciate the example.

John
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:10
Joined
Jan 20, 2009
Messages
12,852
I have asked this question before and I have had it explained to me and I didn't want to admit to Doc and Galaxiom that although they did their best to dumb it down for me, I still did not get it.

You were probably looking for something more complicated than it was.
 

Users who are viewing this thread

Top Bottom