Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Best practices question - how do you name your variables?

Best practices question - how do you name your variables?

Scheduled Pinned Locked Moved The Lounge
questioncomdata-structureslearning
21 Posts 12 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Vikram A Punathambekar

    This is partly with regard to a Lounge thread the other day. FxCop will catch you if you use variables with incorrect spelling. Do you always name variables using standard* English** words? I found that I use only one variable name regularly that is not a standard word, conn for connection. 1. Do you make it a point to name variables correctly, like transactionDate instead of trDate, or, God forbid, trDt? 2. Where do you make exceptions to the above rule? * Of course, obscure technical terms may, and even should be used in certain cases, but I'm not talking about that here. ** Or any other human language, as appropriate. Cheers, Vikram.


    "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #6

    Hmm, looks at code... PNET_BUFFER_LIST pEthernetBufferList; PNET_BUFFER pEthernetBuffer; PMDL pEthernetBufferMdl; NDIS_WORK_ITEM SendNetBufferFromListWorkItem; PNDIS_OID_REQUEST pOidRequest; PDEVICE_OBJECT pMiniportPDO; PCM_RESOURCE_LIST pResources; LIST_ENTRY SendListHead; KSPIN_LOCK SensListLock; KDPC DoAnAsyncOpenCloseDPC; NDIS_SPIN_LOCK DoAnAsyncOpenCloseDPCSpinLock; PIRP pOpenCloseIRP; BOOLEAN OpenCloseIrpGone; KEVENT OpenCloseFinished; PNDIS_PACKET pCurrTxPacket; IO_STATUS_BLOCK WriteStatusBlock; NDIS_MINIPORT_TIMER ReTxBufferNamedAdapterBufferTimer; PUCHAR ReTxBuffer; SIZE_T ReTxBufferLen; So, p for Pointers, the usual abbreviations, Len for length, Tx for transmit, Curr for current, then acronyms, DPC, MDl. Apart form that always full descriptive names. Although longer to type, using full names makes detailed comments redundant, it is only necesary to comment a block of code describibg its intended aims. Nunc est bibendum

    R 1 Reply Last reply
    0
    • L Lost User

      Hmm, looks at code... PNET_BUFFER_LIST pEthernetBufferList; PNET_BUFFER pEthernetBuffer; PMDL pEthernetBufferMdl; NDIS_WORK_ITEM SendNetBufferFromListWorkItem; PNDIS_OID_REQUEST pOidRequest; PDEVICE_OBJECT pMiniportPDO; PCM_RESOURCE_LIST pResources; LIST_ENTRY SendListHead; KSPIN_LOCK SensListLock; KDPC DoAnAsyncOpenCloseDPC; NDIS_SPIN_LOCK DoAnAsyncOpenCloseDPCSpinLock; PIRP pOpenCloseIRP; BOOLEAN OpenCloseIrpGone; KEVENT OpenCloseFinished; PNDIS_PACKET pCurrTxPacket; IO_STATUS_BLOCK WriteStatusBlock; NDIS_MINIPORT_TIMER ReTxBufferNamedAdapterBufferTimer; PUCHAR ReTxBuffer; SIZE_T ReTxBufferLen; So, p for Pointers, the usual abbreviations, Len for length, Tx for transmit, Curr for current, then acronyms, DPC, MDl. Apart form that always full descriptive names. Although longer to type, using full names makes detailed comments redundant, it is only necesary to comment a block of code describibg its intended aims. Nunc est bibendum

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #7

      Ouaouh ! Your type definitions are shouting ... ~RaGE();

      L 1 Reply Last reply
      0
      • V Vikram A Punathambekar

        This is partly with regard to a Lounge thread the other day. FxCop will catch you if you use variables with incorrect spelling. Do you always name variables using standard* English** words? I found that I use only one variable name regularly that is not a standard word, conn for connection. 1. Do you make it a point to name variables correctly, like transactionDate instead of trDate, or, God forbid, trDt? 2. Where do you make exceptions to the above rule? * Of course, obscure technical terms may, and even should be used in certain cases, but I'm not talking about that here. ** Or any other human language, as appropriate. Cheers, Vikram.


        "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

        V Offline
        V Offline
        Vasudevan Deepak Kumar
        wrote on last edited by
        #8

        Vikram, Check out http://www.macadamian.com/ There is a code review article too. :) Hmm. I forgot the article URL but that should be searchable from the website though. :( Vasudevan Deepak Kumar Personal Web: http://www.lavanyadeepak.tk/ I Blog At: http://deepak.blogdrive.com/

        1 Reply Last reply
        0
        • R Rage

          Ouaouh ! Your type definitions are shouting ... ~RaGE();

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #9

          aint mine, they come from the windows kernel. Nunc est bibendum

          1 Reply Last reply
          0
          • V Vikram A Punathambekar

            This is partly with regard to a Lounge thread the other day. FxCop will catch you if you use variables with incorrect spelling. Do you always name variables using standard* English** words? I found that I use only one variable name regularly that is not a standard word, conn for connection. 1. Do you make it a point to name variables correctly, like transactionDate instead of trDate, or, God forbid, trDt? 2. Where do you make exceptions to the above rule? * Of course, obscure technical terms may, and even should be used in certain cases, but I'm not talking about that here. ** Or any other human language, as appropriate. Cheers, Vikram.


            "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #10

            I use polish notation to a point. pXxxx for pointers nXxxx for ints and doubles sXxxx for strings aXxxx for arrays bXxxx for booleans tpaXxxx for CTypedPtrArray tplXxxx for CTypedPtrList mXxxx for maps ctrlXxxx for dialog controls I prefix member variables with m_, and global variables with g_, but for local variables in a function, there is no prefix. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            1 Reply Last reply
            0
            • V Vikram A Punathambekar

              ThatsAlok wrote:

              Hai you name changes

              Long story, but a troll made some outrageous remarks, so I'm getting my revenge tongue in cheek. I'll revert to my real name in a few days. :-D Cheers, Vikram.


              "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #11

              Vikram Shannon wrote:

              Long story, but a troll made some outrageous remarks, so I'm getting my revenge tongue in cheek.

              Can I get three guesses as to who it was? :laugh: ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

              V 1 Reply Last reply
              0
              • V Vikram A Punathambekar

                This is partly with regard to a Lounge thread the other day. FxCop will catch you if you use variables with incorrect spelling. Do you always name variables using standard* English** words? I found that I use only one variable name regularly that is not a standard word, conn for connection. 1. Do you make it a point to name variables correctly, like transactionDate instead of trDate, or, God forbid, trDt? 2. Where do you make exceptions to the above rule? * Of course, obscure technical terms may, and even should be used in certain cases, but I'm not talking about that here. ** Or any other human language, as appropriate. Cheers, Vikram.


                "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

                J Offline
                J Offline
                Jain Mohit
                wrote on last edited by
                #12

                m_strThisIsHowIDeclareMyStringMemberVariable :cool:

                1 Reply Last reply
                0
                • V Vikram A Punathambekar

                  Marc Clifton wrote:

                  I don't use FxCop

                  But still, how do you name your variables? Cheers, Vikram.


                  "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

                  M Offline
                  M Offline
                  Marc Clifton
                  wrote on last edited by
                  #13

                  Vikram Shannon wrote:

                  But still, how do you name your variables?

                  Properties and fields I usually don't abbreviate, unless they're ridiculously long. Local variables, I'm fine with short names, even acronyms. So, I might have something like this (this is an example only, and not intended to be an example of any kind of code I'm using!):

                  public class Foo
                  {
                  protected SchemaDomain schemaDomain;

                  public SchemaDomain SchemaDomain
                  {
                  get; set;
                  }

                  public SchemaDomain Clone(SchemaDomain schemaDomainToClone)
                  {
                  SchemaDomain sd=schemaDomainToClone.Clone(); // EXAMPLE ONLY!
                  return sd;
                  }
                  }

                  The point being that I try to use informative names for visible aspects of the class, and names for parameters that relate to what is expected, but internally, if we're talking simple functionality, I'll use abbreviations. If the method is more than a few lines (say, 10 or 20) I seem to subconsciously revert back to more descriptive local variable names to keep things a bit clearer. Marc Pensieve -- modified at 8:10 Thursday 19th January, 2006

                  1 Reply Last reply
                  0
                  • V Vikram A Punathambekar

                    This is partly with regard to a Lounge thread the other day. FxCop will catch you if you use variables with incorrect spelling. Do you always name variables using standard* English** words? I found that I use only one variable name regularly that is not a standard word, conn for connection. 1. Do you make it a point to name variables correctly, like transactionDate instead of trDate, or, God forbid, trDt? 2. Where do you make exceptions to the above rule? * Of course, obscure technical terms may, and even should be used in certain cases, but I'm not talking about that here. ** Or any other human language, as appropriate. Cheers, Vikram.


                    "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

                    C Offline
                    C Offline
                    Curtis Schlak
                    wrote on last edited by
                    #14

                    FxCop supports a custom dictionary. (I don't know if it supports Unicode.) From FxCop FAQ[^]:

                    Create a file named CustomDictionary.xml. Add the following XML structure, with the new words (case insensitive) under the <Recognized> node.

                    <Dictionary>    <Words>
                            <Recognized>
                                   <Word>aNewWord</Word>               <Word>AnotherNewWord</Word>        </Recognized>
                        </Words>
                    </Dictionary>

                    To use the dictionary with all projects, place the file in the FxCop install directory (usually C:\Program Files\Microsoft FxCop). For project-specific dictionaries, place the file in a separate directory along with the project file. For the words to be recognized, you must close and restart FxCop after creating or modifying the custom dictionary.

                    "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                    V 1 Reply Last reply
                    0
                    • C Colin Angus Mackay

                      Vikram Shannon wrote:

                      Long story, but a troll made some outrageous remarks, so I'm getting my revenge tongue in cheek.

                      Can I get three guesses as to who it was? :laugh: ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

                      V Offline
                      V Offline
                      Vikram A Punathambekar
                      wrote on last edited by
                      #15

                      I'll give you one. Go ahead, guess. :-D He's a major PITA. :sigh: Cheers, Vikram.


                      "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

                      1 Reply Last reply
                      0
                      • V Vikram A Punathambekar

                        This is partly with regard to a Lounge thread the other day. FxCop will catch you if you use variables with incorrect spelling. Do you always name variables using standard* English** words? I found that I use only one variable name regularly that is not a standard word, conn for connection. 1. Do you make it a point to name variables correctly, like transactionDate instead of trDate, or, God forbid, trDt? 2. Where do you make exceptions to the above rule? * Of course, obscure technical terms may, and even should be used in certain cases, but I'm not talking about that here. ** Or any other human language, as appropriate. Cheers, Vikram.


                        "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #16

                        Why do people use for example, strMyName as a variable? Isnt it obvious it is a string? Or how about intCount! Holy cow, its a number of some sort. p for pointers, g for globals everything else just as it is, ie, a full descriptive variable name. Nunc est bibendum

                        R 1 Reply Last reply
                        0
                        • L Lost User

                          Why do people use for example, strMyName as a variable? Isnt it obvious it is a string? Or how about intCount! Holy cow, its a number of some sort. p for pointers, g for globals everything else just as it is, ie, a full descriptive variable name. Nunc est bibendum

                          R Offline
                          R Offline
                          Rage
                          wrote on last edited by
                          #17

                          fat_boy wrote:

                          Why do people use for example, strMyName as a variable? Isnt it obvious it is a string?

                          Because strInteger is a string, and iString a number of strings. What is best:

                          SetWindowText(Integer); // Integer is text ?? :confused:
                          Display(Strings[String]); // String as an array index ??? :confused:

                          or

                          SetWindowText(strInteger);
                          Display(straStrings[iString]);

                          ~RaGE();

                          L 1 Reply Last reply
                          0
                          • R Rage

                            fat_boy wrote:

                            Why do people use for example, strMyName as a variable? Isnt it obvious it is a string?

                            Because strInteger is a string, and iString a number of strings. What is best:

                            SetWindowText(Integer); // Integer is text ?? :confused:
                            Display(Strings[String]); // String as an array index ??? :confused:

                            or

                            SetWindowText(strInteger);
                            Display(straStrings[iString]);

                            ~RaGE();

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #18

                            them use IntegerAsString and NumberOfStrings as variable names. Nunc est bibendum

                            1 Reply Last reply
                            0
                            • V Vikram A Punathambekar

                              This is partly with regard to a Lounge thread the other day. FxCop will catch you if you use variables with incorrect spelling. Do you always name variables using standard* English** words? I found that I use only one variable name regularly that is not a standard word, conn for connection. 1. Do you make it a point to name variables correctly, like transactionDate instead of trDate, or, God forbid, trDt? 2. Where do you make exceptions to the above rule? * Of course, obscure technical terms may, and even should be used in certain cases, but I'm not talking about that here. ** Or any other human language, as appropriate. Cheers, Vikram.


                              "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

                              D Offline
                              D Offline
                              David Crow
                              wrote on last edited by
                              #19

                              Vikram Shannon wrote:

                              1. Do you make it a point to name variables correctly, like transactionDate instead of trDate, or, God forbid, trDt?

                              Yes, I'm pretty anal about that.


                              "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

                              1 Reply Last reply
                              0
                              • V Vikram A Punathambekar

                                This is partly with regard to a Lounge thread the other day. FxCop will catch you if you use variables with incorrect spelling. Do you always name variables using standard* English** words? I found that I use only one variable name regularly that is not a standard word, conn for connection. 1. Do you make it a point to name variables correctly, like transactionDate instead of trDate, or, God forbid, trDt? 2. Where do you make exceptions to the above rule? * Of course, obscure technical terms may, and even should be used in certain cases, but I'm not talking about that here. ** Or any other human language, as appropriate. Cheers, Vikram.


                                "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

                                T Offline
                                T Offline
                                toxcct
                                wrote on last edited by
                                #20

                                http://www.codeproject.com/script/survey/detail.asp?survey=438[^]


                                TOXCCT >>> GEII power
                                [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]

                                1 Reply Last reply
                                0
                                • C Curtis Schlak

                                  FxCop supports a custom dictionary. (I don't know if it supports Unicode.) From FxCop FAQ[^]:

                                  Create a file named CustomDictionary.xml. Add the following XML structure, with the new words (case insensitive) under the <Recognized> node.

                                  <Dictionary>    <Words>
                                          <Recognized>
                                                 <Word>aNewWord</Word>               <Word>AnotherNewWord</Word>        </Recognized>
                                      </Words>
                                  </Dictionary>

                                  To use the dictionary with all projects, place the file in the FxCop install directory (usually C:\Program Files\Microsoft FxCop). For project-specific dictionaries, place the file in a separate directory along with the project file. For the words to be recognized, you must close and restart FxCop after creating or modifying the custom dictionary.

                                  "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                                  V Offline
                                  V Offline
                                  Vikram A Punathambekar
                                  wrote on last edited by
                                  #21

                                  Yup, I use that. Although, the only 'non-standard' name is conn, which I've added. :-O Cheers, Vikram.


                                  "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups