CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 22

Threaded View

  1. #14
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Why start variable names with _?

    Quote Originally Posted by TheGreatCthulhu View Post
    I personally tend to use m_ out of habit, and also because variables starting with _ just "pokes" my eyes.
    I definitely do share this feeling.

    And just to contribute my own $.02...

    However, those arguing against this practice say that (1), most IDE's today will provide ways for you to distinguish member variables from other types of variables, for example, just by hovering your mouse over [...]
    IDEs may do, online platforms where code is published, like CG, for instance, AFAICT usually don't. Neither do books, at least as long as they're made out of ordinary paper.

    [...] (2) there are comparatively few cases where you need, due to name collisions, to type in the extra "this.", as opposed to typing "m_" or "_" every single time.
    Though distinguishing between locals (and parameters) and members of the same name perhaps IMO is the only legitimate reason to explicitly dereference this, I still simply don't like it. Simply looks too javaish to me and also seems to be somewhat common in C#. Personal taste, admittedly.

    Personally, I use m_ for class members and s_ for statics, together with hungarian notation. I experimented with decorating parameters but dropped that since I found it too cluttering together with hungarian notation. For locals and parameters I use hungarian notation without any further decoration except when they're static. (And except for some really obvious things like for loop variables which often simply are named i or something. Some sort of "hungarian only" notation.)

    And for completeness, I use Pascal case for methods (and .NET properties, at least most of the time).
    Last edited by Eri523; May 3rd, 2012 at 10:53 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured