Case for variable names

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Scheiderich

    Case for variable names

    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

  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: Case for variable names

    Thomas,[color=blue]
    > I thought I read that the case for the variable names is important.[/color]
    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.
    [color=blue]
    > Dim Wheel As Integer
    > Wheel here is a different variable from WHEEL.
    > Is this correct?[/color]
    No.
    [color=blue]
    > Also, if you define a variable, does it get initialized?[/color]
    Yes with the "default value" for that type.
    [color=blue]
    > "Dim Wheel As Integer" is initialized to 0[/color]
    Correct the "default" value for Integer is a 0.
    [color=blue]
    > and "Dim firstName As String" is initialized to "".[/color]
    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.Leng th())

    Will cause a NullReferenceEx ception, 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

    "Thomas Scheiderich" <tfs@deltanet.c om> wrote in message
    news:4030FD40.4 070005@deltanet .com...[color=blue]
    > 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
    >[/color]


    Comment

    • Cor

      #3
      Re: Case for variable names

      Hi Thomas,

      I saw you are busy with webpages.
      [color=blue]
      > I thought I read that the case for the variable names is important.[/color]

      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



      Comment

      • Cor

        #4
        Re: Case for variable names

        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


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Case for variable names

          * Thomas Scheiderich <tfs@deltanet.c om> scripsit:[color=blue]
          > Dim Wheel As Integer
          >
          > Wheel here is a different variable from WHEEL.
          >
          > Is this correct?[/color]
          No, Visual Basic isn't case sensitive, so the variable 'wheel' is the
          same as 'Wheel' and 'WHEEL'.
          [color=blue]
          > Also, if you define a variable, does it get initialized?[/color]

          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 K. Wagner [MVP]
          <http://www.mvps.org/dotnet>

          Comment

          • Jay B. Harlow [MVP - Outlook]

            #6
            Re: Case for variable names

            Herfried,[color=blue]
            > types and the default value for value types (0 for numeric types, "" for
            > strings etc.).[/color]
            Strings are initialized to Nothing, not "".

            Jay

            "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
            news:c0qvt8$1ab hbp$2@ID-208219.news.uni-berlin.de...[color=blue]
            > * Thomas Scheiderich <tfs@deltanet.c om> scripsit:[color=green]
            > > Dim Wheel As Integer
            > >
            > > Wheel here is a different variable from WHEEL.
            > >
            > > Is this correct?[/color]
            > No, Visual Basic isn't case sensitive, so the variable 'wheel' is the
            > same as 'Wheel' and 'WHEEL'.
            >[color=green]
            > > Also, if you define a variable, does it get initialized?[/color]
            >
            > 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 K. Wagner [MVP]
            > <http://www.mvps.org/dotnet>[/color]


            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: Case for variable names

              * "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> scripsit:[color=blue]
              > Strings are initialized to Nothing, not "".[/color]

              Ooops. You are right!

              --
              Herfried K. Wagner [MVP]
              <http://www.mvps.org/dotnet>

              Comment

              • Thomas Scheiderich

                #8
                Re: Case for variable names

                Cor wrote:
                [color=blue]
                > 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)
                >[/color]


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

                Thanks,

                Tom.

                [color=blue]
                > Cor
                >
                >
                >[/color]

                Comment

                • Jay B. Harlow [MVP - Outlook]

                  #9
                  Re: Case for variable names

                  Thomas,[color=blue]
                  > So the only language not case sensitive is VB and VB.NET?[/color]

                  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

                  "Thomas Scheiderich" <tfs@deltanet.c om> wrote in message
                  news:4031227B.1 070303@deltanet .com...[color=blue]
                  > Cor wrote:
                  >[color=green]
                  > > 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)
                  > >[/color]
                  >
                  >
                  > So the only language not case sensitive is VB and VB.NET?
                  >
                  > Thanks,
                  >
                  > Tom.
                  >
                  >[color=green]
                  > > Cor
                  > >
                  > >
                  > >[/color]
                  >[/color]


                  Comment

                  • Tom Leylan

                    #10
                    Re: Case for variable names

                    And Pascal isn't case sensitive and there is/are .net versions.

                    Tom

                    "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
                    news:uztiH4M9DH A.2604@TK2MSFTN GP10.phx.gbl...[color=blue]
                    > Thomas,[color=green]
                    > > So the only language not case sensitive is VB and VB.NET?[/color]
                    >
                    > 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
                    >
                    > "Thomas Scheiderich" <tfs@deltanet.c om> wrote in message
                    > news:4031227B.1 070303@deltanet .com...[color=green]
                    > > Cor wrote:
                    > >[color=darkred]
                    > > > 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)
                    > > >[/color]
                    > >
                    > >
                    > > So the only language not case sensitive is VB and VB.NET?
                    > >
                    > > Thanks,
                    > >
                    > > Tom.
                    > >
                    > >[color=darkred]
                    > > > Cor
                    > > >
                    > > >
                    > > >[/color]
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • Thomas Scheiderich

                      #11
                      Re: Case for variable names

                      Jay B. Harlow [MVP - Outlook] wrote:
                      [color=blue]
                      > Thomas,
                      >[color=green]
                      >>So the only language not case sensitive is VB and VB.NET?
                      >>[/color]
                      >
                      > If you're counting language, RPG & COBOL are not case sensitive also.
                      >
                      > And yes! there are RPG & COBOL compilers for .NET!
                      >[/color]


                      Some languages just never die. :)

                      Tom.

                      [color=blue]
                      > Hope this helps
                      > Jay
                      >
                      > "Thomas Scheiderich" <tfs@deltanet.c om> wrote in message
                      > news:4031227B.1 070303@deltanet .com...
                      >[color=green]
                      >>Cor wrote:
                      >>
                      >>[color=darkred]
                      >>>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)
                      >>>
                      >>>[/color]
                      >>
                      >>So the only language not case sensitive is VB and VB.NET?
                      >>
                      >>Thanks,
                      >>
                      >>Tom.
                      >>
                      >>
                      >>[color=darkred]
                      >>>Cor
                      >>>
                      >>>
                      >>>
                      >>>[/color][/color]
                      >
                      >[/color]

                      Comment

                      • Jay B. Harlow [MVP - Outlook]

                        #12
                        Re: Case for variable names

                        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

                        "Tom Leylan" <gee@iamtiredof spam.com> wrote in message
                        news:uvD4%23CN9 DHA.1592@TK2MSF TNGP10.phx.gbl. ..[color=blue]
                        > And Pascal isn't case sensitive and there is/are .net versions.
                        >
                        > Tom
                        >
                        > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
                        > news:uztiH4M9DH A.2604@TK2MSFTN GP10.phx.gbl...[color=green]
                        > > Thomas,[color=darkred]
                        > > > So the only language not case sensitive is VB and VB.NET?[/color]
                        > >
                        > > 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
                        > >
                        > > "Thomas Scheiderich" <tfs@deltanet.c om> wrote in message
                        > > news:4031227B.1 070303@deltanet .com...[color=darkred]
                        > > > Cor wrote:
                        > > >
                        > > > > 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.
                        > > >
                        > > >
                        > > > > Cor
                        > > > >
                        > > > >
                        > > > >
                        > > >[/color]
                        > >
                        > >[/color]
                        >
                        >[/color]


                        Comment

                        • Cor

                          #13
                          Re: Case for variable names

                          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.SqlCo mmand 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





                          Comment

                          • Herfried K. Wagner [MVP]

                            #14
                            Re: Case for variable names

                            Tom,

                            * "Tom Leylan" <gee@iamtiredof spam.com> scripsit:[color=blue]
                            > And Pascal isn't case sensitive and there is/are .net versions.[/color]

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

                            ;-)

                            --
                            Herfried K. Wagner [MVP]
                            <http://www.mvps.org/dotnet>

                            Comment

                            • Tom Leylan

                              #15
                              Re: Case for variable names

                              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 .

                              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                              news:c0re7g$1b4 l7p$1@ID-208219.news.uni-berlin.de...[color=blue]
                              > Tom,
                              >
                              > * "Tom Leylan" <gee@iamtiredof spam.com> scripsit:[color=green]
                              > > And Pascal isn't case sensitive and there is/are .net versions.[/color]
                              >
                              > Delphi is case sensitive (AFAIR) and there is a .NET version.
                              >
                              > ;-)
                              >
                              > --
                              > Herfried K. Wagner [MVP]
                              > <http://www.mvps.org/dotnet>[/color]


                              Comment

                              Working...