I finally did it-- hungarian notation

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

    #1

    I finally did it-- hungarian notation

    So after three years of working in .NET and stubbornly holding on to my old
    hungarian notation practices--- I resolved to try to rid myself of the
    habit. Man, I gotta say that it is liberating!!! I love it.

    At first I struggled with how to name controls. I tried to keep some sort of
    notation with them... but I threw that away too!!! I now name them as if
    they were simply properties of the form (FirstNameLabel , etc.)... which they
    ARE!... and when I reference them I use the Me keyword (as all properties of
    a class should be referenced). Pure joy!

    Alas, I still use "m_" to indicate private class scoped variables. It helps
    to set them apart from properties and with avoiding collisions with property
    names... because, well, VB is not case sensitive like C#!!! This causes
    problems as in the following example:

    Private firstName As String
    Public Property FirstName() As String
    Get
    Return firstName
    End Get
    Set(ByVal value As String)
    firstName = value
    End Set
    End Property

    I recommend that any hold outs (you know you're out there!) give it a try.
    It's like a big weight is lifted from your shoulders.


  • Martin

    #2
    Re: I finally did it-- hungarian notation

    Never been to Hungary but I personally prefer to prefix all objects with a
    3-character code which signifies what kind of object it is. I started doing
    this in VB5 way back when but now in VB2005 it turns out to be even more
    useful since I can't ask the class name of an object anymore... When I loop
    through a form's control collection the first 3 characters tell me exactly
    what it is.

    Martin

    "CMM" <cmm@nospam.com > wrote in message
    news:%23EsQR8kJ GHA.3064@TK2MSF TNGP10.phx.gbl. ..[color=blue]
    > So after three years of working in .NET and stubbornly holding on to my
    > old hungarian notation practices--- I resolved to try to rid myself of the
    > habit. Man, I gotta say that it is liberating!!! I love it.
    >
    > At first I struggled with how to name controls. I tried to keep some sort
    > of notation with them... but I threw that away too!!! I now name them as
    > if they were simply properties of the form (FirstNameLabel , etc.)... which
    > they ARE!... and when I reference them I use the Me keyword (as all
    > properties of a class should be referenced). Pure joy!
    >
    > Alas, I still use "m_" to indicate private class scoped variables. It
    > helps to set them apart from properties and with avoiding collisions with
    > property names... because, well, VB is not case sensitive like C#!!! This
    > causes problems as in the following example:
    >
    > Private firstName As String
    > Public Property FirstName() As String
    > Get
    > Return firstName
    > End Get
    > Set(ByVal value As String)
    > firstName = value
    > End Set
    > End Property
    >
    > I recommend that any hold outs (you know you're out there!) give it a try.
    > It's like a big weight is lifted from your shoulders.
    >[/color]


    Comment

    • Phill  W.

      #3
      Re: I finally did it-- hungarian notation

      "Martin" <x@y.com> wrote in message
      news:Oj9kjglJGH A.3352@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Never been to Hungary but I personally prefer to prefix all objects with a
      > 3-character code which signifies what kind of object it is.[/color]

      That's no problem - three letters gives 17,000-odd possibilities, and
      there's
      only 4,000-odd classes in the Framework... ;-)
      [color=blue]
      > I started doing this in VB5 way back when but now in VB2005 it turns out
      > to be even more useful since I can't ask the class name of an object
      > anymore...[/color]

      What makes you think that?
      [color=blue]
      > When I loop through a form's control collection the first 3 characters
      > tell me exactly what it is.[/color]

      And what's wrong with

      For Each ctl As Control in Me.Controls

      If TypeOf ctl Is TextBox Then
      . . .
      ElseIf TypeOf ctl Is ListBox Then
      . . .
      End If

      Next

      ??

      Regards,
      Phill W.


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: I finally did it-- hungarian notation

        "CMM" <cmm@nospam.com > schrieb:[color=blue]
        > So after three years of working in .NET and stubbornly holding on to my
        > old hungarian notation practices--- I resolved to try to rid myself of the
        > habit. Man, I gotta say that it is liberating!!! I love it.[/color]

        Well, I do not use type prefixes ("Systems Hungarian") because I use 'Option
        Strict On' most of the time. However, I use type prefixes when dealing with
        late binding (variables typed as 'Object'). Additionally I use the 'm_'
        prefix to mark private fields, and I tend to use Apps Hungarian because it
        still makes sense in strictly-typed languages.

        On a side note: I still refuse to use camel case for the reasons listed in
        <URL:http://dotnet.mvps.org/dotnet/articles/camelcase/> (German article!).

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: I finally did it-- hungarian notation

          Herfried,

          I have forever hated the use of the underscore in any dataname.

          Why not just mMyPrivate instead of m_MyPrivate?

          Cor


          Comment

          • _AnonCoward

            #6
            Re: I finally did it-- hungarian notation


            "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> wrote in message
            news:%23RIVW6mJ GHA.524@TK2MSFT NGP09.phx.gbl.. .
            :
            : Herfried,
            :
            : I have forever hated the use of the underscore in any dataname.
            :
            : Why not just mMyPrivate instead of m_MyPrivate?
            :
            : Cor


            I've been back and forth on that one myself. I've finally settled on
            mMemberVar because it requires one less character to type.


            In addition, I typically prefix private shared variables with 'g' versus 'm'
            (indicating that its global rather than a member of an instance)


            Ralf
            --
            --
            ----------------------------------------------------------
            * ^~^ ^~^ *
            * _ {~ ~} {~ ~} _ *
            * /_``>*< >*<''_\ *
            * (\--_)++) (++(_--/) *
            ----------------------------------------------------------
            There are no advanced students in Aikido - there are only
            competent beginners. There are no advanced techniques -
            only the correct application of basic principles.


            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: I finally did it-- hungarian notation

              Cor,

              "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> schrieb:[color=blue]
              > I have forever hated the use of the underscore in any dataname.
              >
              > Why not just mMyPrivate instead of m_MyPrivate?[/color]

              My eyes need a visual separator. I do not claim that "_" is ideal for this
              purpose, but it's doing its job pretty well...

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://classicvb.org/petition/>

              Comment

              • _AnonCoward

                #8
                Re: I finally did it-- hungarian notation


                "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                news:uwk1C0mJGH A.648@TK2MSFTNG P14.phx.gbl...
                :
                : "CMM" <cmm@nospam.com > schrieb:
                : >
                : > So after three years of working in .NET and stubbornly holding on to my
                : > old hungarian notation practices--- I resolved to try to rid myself of
                : > the habit. Man, I gotta say that it is liberating!!! I love it.
                :
                : Well, I do not use type prefixes ("Systems Hungarian") because I use
                : 'Option Strict On' most of the time. However, I use type prefixes when
                : dealing with late binding (variables typed as 'Object'). Additionally
                : I use the 'm_' prefix to mark private fields, and I tend to use Apps
                : Hungarian because it still makes sense in strictly-typed languages.
                :
                : On a side note: I still refuse to use camel case for the reasons listed
                : in <URL:http://dotnet.mvps.org/dotnet/articles/camelcase/> (German
                : article!).


                Could you summarize the points being raised in this article for those of us
                who don't read German? Thanx,


                Ralf
                --
                --
                ----------------------------------------------------------
                * ^~^ ^~^ *
                * _ {~ ~} {~ ~} _ *
                * /_``>*< >*<''_\ *
                * (\--_)++) (++(_--/) *
                ----------------------------------------------------------
                There are no advanced students in Aikido - there are only
                competent beginners. There are no advanced techniques -
                only the correct application of basic principles.


                Comment

                • Herfried K. Wagner [MVP]

                  #9
                  Re: I finally did it-- hungarian notation

                  "_AnonCowar d" <abcdef@uvwxyz. com> schrieb:[color=blue]
                  > : > So after three years of working in .NET and stubbornly holding on to
                  > my
                  > : > old hungarian notation practices--- I resolved to try to rid myself of
                  > : > the habit. Man, I gotta say that it is liberating!!! I love it.
                  > :
                  > : Well, I do not use type prefixes ("Systems Hungarian") because I use
                  > : 'Option Strict On' most of the time. However, I use type prefixes when
                  > : dealing with late binding (variables typed as 'Object'). Additionally
                  > : I use the 'm_' prefix to mark private fields, and I tend to use Apps
                  > : Hungarian because it still makes sense in strictly-typed languages.
                  > :
                  > : On a side note: I still refuse to use camel case for the reasons listed
                  > : in <URL:http://dotnet.mvps.org/dotnet/articles/camelcase/> (German
                  > : article!).
                  >
                  > Could you summarize the points being raised in this article for those of
                  > us
                  > who don't read German? Thanx,[/color]

                  The points made in the article are:

                  * Distinction of two identifiers (property, backing field) by case only
                  can
                  lead to bugs in the implementation which cannot be easily detected.

                  * By naming the property using pascal case and the backing field using
                  camel case it's harder to visually detect that both belong to each
                  other.
                  This argument is based on a human visual character recognition model.

                  * The naming rules described in the .NET Framework Design Guidelines
                  and the internal Guidelines published by Brad Abrams [MSFT] cannot be
                  applied to VB.NET because VB.NET is not case-sensitive.

                  * The first character of a word/sentence serves an important role for
                  word recognition. In classic typography the first letter has often been
                  written in upper-case and sometimes ornamented to underline its
                  importance. By starting identifiers' names with a lower-case letter
                  while using upper-case letters inside the identifier this long tradition
                  in typography is obeyed.

                  * Most naming guidelines are made by developers only instead of
                  consulting developers, psychologists, linguists, etc. who have the
                  scientific background to optimize naming guidelines.

                  --
                  M S Herfried K. Wagner
                  M V P <URL:http://dotnet.mvps.org/>
                  V B <URL:http://classicvb.org/petition/>

                  Comment

                  • Cor Ligthert [MVP]

                    #10
                    Re: I finally did it-- hungarian notation

                    Herfried,

                    I did not read your complete article.
                    [color=blue]
                    >
                    > * The first character of a word/sentence serves an important role for
                    > word recognition. In classic typography the first letter has often
                    > been
                    > written in upper-case and sometimes ornamented to underline its
                    > importance. By starting identifiers' names with a lower-case letter
                    > while using upper-case letters inside the identifier this long
                    > tradition
                    > in typography is obeyed.
                    >[/color]
                    However this is real something special German speaking people would see. But
                    it is true. We by instance make in our language from more words one word by
                    concatenating them (you will often see me that wrong in English doing as
                    well). I wished that even in our language this notation we are now talking
                    about was used. Although now is again that we use more and more hyphens.
                    However who knows where.

                    Dutch is probably the language with the most imbecile rules and in that ten
                    deep sub-rules, which are changed almost every 10 years to make it more
                    crazy.

                    Cor


                    Comment

                    • Herfried K. Wagner [MVP]

                      #11
                      Re: I finally did it-- hungarian notation

                      "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> schrieb:[color=blue][color=green]
                      >> * The first character of a word/sentence serves an important role for
                      >> word recognition. In classic typography the first letter has often
                      >> been
                      >> written in upper-case and sometimes ornamented to underline its
                      >> importance. By starting identifiers' names with a lower-case letter
                      >> while using upper-case letters inside the identifier this long
                      >> tradition
                      >> in typography is obeyed.
                      >>[/color]
                      > However this is real something special German speaking people would see.[/color]

                      Not really. Capitalization of initials is common in German, English, and
                      IIRC French, and likely other languages too.
                      [color=blue]
                      > true. We by instance make in our language from more words one word by
                      > concatenating them (you will often see me that wrong in English doing as
                      > well).[/color]

                      Well, that's common in German too.

                      --
                      M S Herfried K. Wagner
                      M V P <URL:http://dotnet.mvps.org/>
                      V B <URL:http://classicvb.org/petition/>

                      Comment

                      • Armin Zingler

                        #12
                        Re: I finally did it-- hungarian notation

                        "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> schrieb[color=blue]
                        > Herfried,
                        >
                        > I have forever hated the use of the underscore in any dataname.
                        >
                        > Why not just mMyPrivate instead of m_MyPrivate?[/color]


                        private mMember as integer
                        private mEmber as integer 'oops, is property, too.

                        public property Ember
                        '...
                        end property

                        public property Member
                        '...
                        end property

                        Doesn't work. ;-) Well, rare case but possible. Avoidable with "_" (if "_"
                        is not used with property names). I use the underscore for visual clarity
                        and for better intellisense, but I also see the drawback of "hidden"
                        underscores for the last declaration if the "procedure separator line" is
                        active in the editor - but that's only one declaration and not that
                        important.

                        I use the prefix "f_". f = Field. Only for those that also have a property.
                        For other fields I don't use a prefix, just like I do not use "fun_" for
                        functions or "prop_" for properties. Fields and other members are on the
                        same level, thus I don't distinguish in the usage of a prefix. But I also
                        make exceptions, like "txt" for textboxes (or others for controls) which
                        are also fields.

                        My 2 Eurocents.


                        Armin

                        Comment

                        • Cor Ligthert [MVP]

                          #13
                          Re: I finally did it-- hungarian notation

                          Herfried,
                          [color=blue][color=green][color=darkred]
                          >>>[/color]
                          >> However this is real something special German speaking people would see.[/color]
                          >
                          > Not really. Capitalization of initials is common in German, English, and
                          > IIRC French, and likely other languages too.
                          >[/color]
                          But not the use of capitals. Just pasted from Bild without any extra meaning
                          for the text..

                          Öffentliches Interesse erregt der Patent-Motorwagen mit der
                          100-Kilometer-Reise von Benz’ Ehefrau Bertha, die 1888 mit dem Wagen von
                          Mannheim nach Pforzheim fährt. Eine „Promotion-Tour“, die Benz eine Reihe
                          neuer Kunden verschafft. Eine Erfolgsgeschich te beginnt. Nicht nur für Karl
                          Benz.

                          Cor


                          Comment

                          • _AnonCoward

                            #14
                            Re: I finally did it-- hungarian notation

                            Thanx. I appreciate the effort.

                            Ralf


                            "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                            news:uHVR$QnJGH A.648@TK2MSFTNG P14.phx.gbl...
                            : "_AnonCowar d" <abcdef@uvwxyz. com> schrieb:
                            : > : > So after three years of working in .NET and stubbornly holding on to
                            : > my
                            : > : > old hungarian notation practices--- I resolved to try to rid myself
                            of
                            : > : > the habit. Man, I gotta say that it is liberating!!! I love it.
                            : > :
                            : > : Well, I do not use type prefixes ("Systems Hungarian") because I use
                            : > : 'Option Strict On' most of the time. However, I use type prefixes
                            when
                            : > : dealing with late binding (variables typed as 'Object'). Additionally
                            : > : I use the 'm_' prefix to mark private fields, and I tend to use Apps
                            : > : Hungarian because it still makes sense in strictly-typed languages.
                            : > :
                            : > : On a side note: I still refuse to use camel case for the reasons
                            listed
                            : > : in <URL:http://dotnet.mvps.org/dotnet/articles/camelcase/> (German
                            : > : article!).
                            : >
                            : > Could you summarize the points being raised in this article for those of
                            : > us
                            : > who don't read German? Thanx,
                            :
                            : The points made in the article are:
                            :
                            : * Distinction of two identifiers (property, backing field) by case only
                            : can
                            : lead to bugs in the implementation which cannot be easily detected.
                            :
                            : * By naming the property using pascal case and the backing field using
                            : camel case it's harder to visually detect that both belong to each
                            : other.
                            : This argument is based on a human visual character recognition model.
                            :
                            : * The naming rules described in the .NET Framework Design Guidelines
                            : and the internal Guidelines published by Brad Abrams [MSFT] cannot be
                            : applied to VB.NET because VB.NET is not case-sensitive.
                            :
                            : * The first character of a word/sentence serves an important role for
                            : word recognition. In classic typography the first letter has often
                            been
                            : written in upper-case and sometimes ornamented to underline its
                            : importance. By starting identifiers' names with a lower-case letter
                            : while using upper-case letters inside the identifier this long
                            tradition
                            : in typography is obeyed.
                            :
                            : * Most naming guidelines are made by developers only instead of
                            : consulting developers, psychologists, linguists, etc. who have the
                            : scientific background to optimize naming guidelines.
                            :
                            : --
                            : M S Herfried K. Wagner
                            : M V P <URL:http://dotnet.mvps.org/>
                            : V B <URL:http://classicvb.org/petition/>
                            :


                            Comment

                            • Cor Ligthert [MVP]

                              #15
                              Re: I finally did it-- hungarian notation

                              Armin,

                              Where is that underscore situated on your keyboard. I type with ten fingers,
                              that underscore is so far on my keyboard, maybe is it that why I don't like
                              it. However it is for me probably the most that I don't like it because, as
                              something is underlined than it becomes not visible.

                              Although don't misunderstand me, your explanation makes sense. Probably I
                              just take another word in those cases.

                              :-)

                              Cor

                              "Armin Zingler" <az.nospam@free net.de> schreef in bericht
                              news:uX9mAunJGH A.2900@TK2MSFTN GP14.phx.gbl...[color=blue]
                              > "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> schrieb[color=green]
                              >> Herfried,
                              >>
                              >> I have forever hated the use of the underscore in any dataname.
                              >>
                              >> Why not just mMyPrivate instead of m_MyPrivate?[/color]
                              >
                              >
                              > private mMember as integer
                              > private mEmber as integer 'oops, is property, too.
                              >
                              > public property Ember
                              > '...
                              > end property
                              >
                              > public property Member
                              > '...
                              > end property
                              >
                              > Doesn't work. ;-) Well, rare case but possible. Avoidable with "_" (if "_"
                              > is not used with property names). I use the underscore for visual clarity
                              > and for better intellisense, but I also see the drawback of "hidden"
                              > underscores for the last declaration if the "procedure separator line" is
                              > active in the editor - but that's only one declaration and not that
                              > important.
                              >
                              > I use the prefix "f_". f = Field. Only for those that also have a
                              > property.
                              > For other fields I don't use a prefix, just like I do not use "fun_" for
                              > functions or "prop_" for properties. Fields and other members are on the
                              > same level, thus I don't distinguish in the usage of a prefix. But I also
                              > make exceptions, like "txt" for textboxes (or others for controls) which
                              > are also fields.
                              >
                              > My 2 Eurocents.
                              >
                              >
                              > Armin
                              >[/color]


                              Comment

                              Working...