Case for variable names

  • Thread starter Thread starter Thomas Scheiderich
  • Start date Start date
T

Thomas Scheiderich

I thought I read that the case for the variable names is important.

For example

Dim Wheel As Integer

Wheel here is a different variable from WHEEL.

Is this correct?

It doesn't seem to be in my code. In my code, I am changing WHEEL (just
for testing)many times and displaying Wheel. Wheel is always correct.
I would have assumed that Wheel would have been 0, since I only changed
WHEEL - if case is important.

Also, if you define a variable, does it get initialized?

For example

"Dim Wheel As Integer" is initialized to 0 and "Dim firstName As String"
is initialized to "".

Thanks,

Tom
 
Thomas,
I thought I read that the case for the variable names is important.
VB.NET is case insensitive: Wheel, wheel and WHEEL within one routine are
all the same identifier.

C# is case sensitive: Wheel, wheel and WHEEL within one routine all unique
identifiers.
Dim Wheel As Integer
Wheel here is a different variable from WHEEL.
Is this correct? No.

Also, if you define a variable, does it get initialized?
Yes with the "default value" for that type.
"Dim Wheel As Integer" is initialized to 0
Correct the "default" value for Integer is a 0.
and "Dim firstName As String" is initialized to "".
Incorrect, String is a reference type, the default value for reference
types, including string, is Nothing. However VB.NET treats a string that is
Nothing the same as "" in most cases. However calling an actually method of
firstName when its Nothing will fail!

Dim firstName As String
Debug.WriteLine(firstName.Length())

Will cause a NullReferenceException, as firstName contains Nothing.

However, the following succeeds:

Dim firstName As String
Debug.WriteLine(firstName = "")


If I want or need string variables to contain "", I will explicitly
initialize them with "" or String.Empty.

Dim firstName As String = ""

Hope this helps
Jay
 
Hi Thomas,

I saw you are busy with webpages.
I thought I read that the case for the variable names is important.

Not with the language from VB (By instance for the ado.net variable names
between quotes it is)

The taste is different but for most people who uses VB that is an important
advantage from VB on other languages, VB find the propercase itself.

I hope this makes it clear?

Cor
 
Hi Tom,

In addition to Jay, because I saw you are busy with Webpages.

J++, Java, JavaScript, C++, C# and C are all case sensitive.
(It are all from C derived languages)

Cor
 
* Thomas Scheiderich said:
Dim Wheel As Integer

Wheel here is a different variable from WHEEL.

Is this correct?
No, Visual Basic isn't case sensitive, so the variable 'wheel' is the
same as 'Wheel' and 'WHEEL'.
Also, if you define a variable, does it get initialized?

Yes, it gets initialized with its default value, 'Nothing' for reference
types and the default value for value types (0 for numeric types, "" for
strings etc.).
 
Herfried,
types and the default value for value types (0 for numeric types, "" for
strings etc.).
Strings are initialized to Nothing, not "".

Jay
 
Cor said:
Hi Tom,

In addition to Jay, because I saw you are busy with Webpages.

J++, Java, JavaScript, C++, C# and C are all case sensitive.
(It are all from C derived languages)


So the only language not case sensitive is VB and VB.NET?

Thanks,

Tom.
 
Thomas,
So the only language not case sensitive is VB and VB.NET?

If you're counting language, RPG & COBOL are not case sensitive also.

And yes! there are RPG & COBOL compilers for .NET!

Hope this helps
Jay
 
Jay said:
Thomas,


If you're counting language, RPG & COBOL are not case sensitive also.

And yes! there are RPG & COBOL compilers for .NET!


Some languages just never die. :)

Tom.
 
Tom,
Yep. can't forget about good old Pascal...

Only reason I mentioned RPG & COBOL, is I have a gig on the side working
with RPG right now...

Jay
 
Hi Jay,

You forgot to mention that when those language started only uppercases where
used and that that is long been a habbit.

But in those languages where also not things like SqlClient.SqlCommand or
the most terrible of all in my eyes the Document Object Model, in which the
uppercases are for me unpredictable.

And therefore I hate case sensetive now.

:-)

Cor
 
Tom,

* "Tom Leylan said:
And Pascal isn't case sensitive and there is/are .net versions.

Delphi is case sensitive (AFAIR) and there is a .NET version.

;-)
 
Delphi is case-insensitive (AFAIR) ... my copy is anyway...

I know there is at least one .Net version of Pascal I believe there are a
few implementations.
 
Tom,

* "Tom Leylan said:
Delphi is case-insensitive (AFAIR) ... my copy is anyway...

Thank you. In the meantime, I had a look at the documentation and
Delphi is case insensitive too. It seems that I thought about Modula-2,
which was case sensitive (and very similar to Pascal).
 
Back
Top