What does DIM stand for in Visual Basic and BASIC?
Dim
have had different meanings attributed to it.
I've found references about Dim
meaning "Declare In Memory", the more relevant reference is a document on Dim Statement published Oracle as part of the Siebel VB Language Reference. Of course, you may argue that if you do not declare the variables in memory where do you do it? Maybe "Declare in Module" is a good alternative considering how Dim
is used.
In my opinion, "Declare In Memory" is actually a mnemonic, created to make easier to learn how to use Dim
. I see "Declare in Memory" as a better meaning as it describes what it does in current versions of the language, but it is not the proper meaning.
In fact, at the origins of Basic Dim
was only used to declare arrays. For regular variables no keyword was used, instead their type was inferred from their name. For instance, if the name of the variable ends with $
then it is a string (this is something that you could see even in method names up to VB6, for example Mid$
). And so, you used Dim
only to give dimension to the arrays (notice that ReDim
resizes arrays).
Really, Does It Matter? I mean, it is a keyword it has its meaning inside an artificial language. It doesn't have to be a word in English or any other natural language. So it could just mean whatever you want, all that matters is that it works.
Anyhow, that is not completely true. As BASIC is part of our culture, and understanding why it came to be as it is - I hope - will help improve our vision of the world.
I sit in from of my computer with a desire to help preserve this little piece of our culture that seems lost, replaced by our guessing of what it was. And so, I have dug MSDN both current and the old CDs from the 1998 version. I have also searched the documention for the old QBasic [Had to use DOSBox] and managed to get some Darthmouth manual, all to find how they talk about Dim
. For my disappointment, they don't say what does Dim
stand for, and only say how it is used.
But before my hope was dim, I managed to find this BBC Microcomputer System Used Guide (that claims to be from 1984, and I don't want to doubt it). The BBC Microcomputer used a variant of BASIC called BBC BASIC and it is described in the document. Even though, it doesn't say what does Dim
stand for, it says (on page 104):
... you can dimension N$ to have as many entries as you want. For example, DIM N$(1000) would create a string array with space for 1000 different names.
As I said, it doesn't say that Dim
stands for dimension, but serves as proof to show that associating Dim
with Dimension
was a common thing at the time of writing that document.
Now, I got a rewarding surprise later on (at page 208), the title for the section that describes the DIM keyword (note: that is not listed in the contents) says:
DIM dimension of an array
So, I didn't get the quote "Dim stands for..." but I guess it is clear that any decent human being that is able to read those document will consider that Dim
means dimension.
With renewed hope, I decided to search about how Dim
was chosen. Again, I didn't find an account on the subject, still I was able to find a definitive quote:
Before you can use an array, you must define it in a DIM (dimension) statement.
You can find this as part of the True BASIC Online User's Guides at the web page of True BASIC inc, a company founded by Thomas Eugene Kurtz, co-author of BASIC.
So, In reallity, Dim
is a shorthand for DIMENSION
, and yes. That existed in FORTRAN before, so it is likely that it was picked by influence of FORTRAN as Patrick McDonald said in his answer.
Dim sum as string = "this is not a chinese meal" REM example usage in VB.NET ;)
Dim originally (in BASIC) stood for Dimension, as it was used to define the dimensions of an array.
(The original implementation of BASIC was Dartmouth BASIC, which descended from FORTRAN, where DIMENSION is spelled out.)
Nowadays, Dim is used to define any variable, not just arrays, so its meaning is not intuitive anymore.
Dimension a variable, basically you are telling the compiler that you are going to need a variable of this type at some point.
It's short for Dimension, as it was originally used in BASIC to specify the size of arrays.
DIM — (short for dimension) define the size of arrays
Ref: http://en.wikipedia.org/wiki/Dartmouth_BASIC
A part of the original BASIC compiler source code, where it would jump when finding a DIM
command, in which you can clearly see the original intention for the keyword:
DIM LDA XR01 BACK OFF OBJECT POINTER
SUB N3
STA RX01
LDA L 2 GET VARIABLE TO BE DIMENSIONED
STA 3
LDA S 3
CAB N36 CHECK FOR $ ARRAY
BRU *+7 NOT $
...
Ref: http://dtss.dartmouth.edu/scans/BASIC/BASIC%20Compiler.pdf
Later on it came to be used to declare all kinds of variables, when the possibility to specify the type for variables was added in more recent implementations.