If your language supports private member variables

And it's not part of the language style guide


Shit is ugly as fuck.

  • 5
  • 4
    The problem with C# in particular is historical. Those of us who remember the earliest days remember the internal coding style from MS which had lowerCamelCase for private members. Unfortunately, that had been scrubbed from memory/the internet, so most places adopt the most highly visible style guide, which is from google.

  • 7
    In C++ leading underscores are reserved for standard libraries. Which means for most people don't use them.
  • 3
    dart is great with this. if a variable starts with _ it's private. no private keyword, it's style and functionality.
  • 6
    @calmyourtities I find it retarded...
  • 1
  • 2
    @calmyourtities Name-based semantics are a plague to language design. It makes refactoring a nightmare. We learned this with Go I believe it was.
  • 1
    On that note, why is it so common to name member variables in C++ with a leading ‘m’

    That's ugly as hell
  • 1
    I prepend them all with my_private_variable_

  • 0
    Thank god there's someone that thinks like me!
  • 2
    @LotsOfCaffeine It's leftover from the ollldd days. Usually when you see such code, it's either written by someone who's been writing C/C++ for ages, or someone brand new who is parroting someone who's been writing C/C++ for ages.
  • 0
    @junon I'm pretty sure it's part of the current Google C++ style guide....
    And at my work place it's also common practice
  • 0
    @LotsOfCaffeine That doesn't surprise me. However most open source C/C++ from independent developers that I've personally come across avoids the m_ prefix. It just means "member" and I suppose it helps readability if you're not using `this->` everywhere, but even then, I've never personally used it.
  • 0
    @LotsOfCaffeine at some point in time there were no smart and powerful IDEs which could help you with types and other stuff so you've had to insert metadata in the names.
  • 1
    @iiii Don't think it has much to do with IDEs as most C/C++ developers I know still use "dumb" editors. It's just more about being able to read the code without having to check multiple places.

    Now that globals/statics are discouraged, it's safe to assume more or less that a symbol not declared in the current method's scope is a property.
  • 0
    @LotsOfCaffeine I see this a lot in Qt code bases. probably influenced by that.
  • 1
    In Objective-C, a leading underscore also means "Internal. Don't touch this!"

    Hungarian notation has been purged from modern language style for good reasons.

    Like OP said, don't use prefixes just for "style" if there is language support to express what you want to show with the prefix.
Add Comment