topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday April 19, 2024, 1:51 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Coding Standards  (Read 5081 times)

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Coding Standards
« on: April 03, 2011, 08:59 AM »
So... we've been given new coding standards where I work.  I'm ok with that.  But one of the conventions is driving me CRAZY!

Normally, I'd write something like...

Code: C# [Select]
  1. private string _propertyX = string.Empty;
  2. public string PropertyX
  3. {
  4.   get { return this._propertyX; }
  5.   set { this._propertyX = value; }
  6. }

(Yes, I know about auto-implemented properties; this is just an example. ;))

But under the new coding standards, it would look like this.
Code: C# [Select]
  1. private string propertyX = string.Empty;
  2. public string PropertyX
  3. {
  4.   get { return this.propertyX; }
  5.   set { this.propertyX = value; }
  6. }

I have spent *so* much time debugging typing errors now... the _ clearly separated my property store from my property name.  But this... AIEEEEEE!

I just had to vent...  :-[

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Coding Standards
« Reply #1 on: April 03, 2011, 09:04 AM »
i also cant stand the practice of using _ prefix for internal properties.  i think it's asinine and ugly.

oops -- i see you were the one using _ hahahaahaha :) :) :)

i can't say i love the coding standard you have to use either -- too hard to distinguish.

i've always liked the idea of using lowercase for internal variables, mixed case for exposed stuff.
« Last Edit: April 03, 2011, 09:06 AM by mouser »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Coding Standards
« Reply #2 on: April 03, 2011, 09:11 AM »
i can't say i love the coding standard you have to use either -- too hard to distinguish.

i've always liked the idea of using lowercase for internal variables, mixed case for exposed stuff.

Even in that case, don't you have a hard time distinguishing?  And not using any caps in the internal stuff would *really* screw me up... I use CodeRush, and it allows you to navigate the camel caps- saves a lot of time!

And I like the (_) :P :) :)  a lot better than m_, etc at least...  ;D

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Coding Standards
« Reply #3 on: April 03, 2011, 09:35 AM »
i just cant wrap my mind around a leading _ it always feels to me like something got truncated.

i'm a fan of long variable names, so i'd even prefer using some prefix like i_

alivingspirit

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 167
    • View Profile
    • Donate to Member
Re: Coding Standards
« Reply #4 on: April 03, 2011, 11:10 AM »
Wow that is annoying. >:( That is the kind of coding standard that makes me want to scream "Why?!". Usually coding standards are supposed to make code easier to read. This just makes you second guess every variable. Is it a property or no? Do we want to set it using the property store?
I strongly am of the opinion the property stores should only be accessed directly under the most dire of circumstances because of how unclear and unstable it makes the code look. They should therefore be unmistakably different from the rest of the code. I hope they change the standards back to the "_" way. Sounds like your work place is a tough bureaucracy. Good luck getting it back the way it was.

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,288
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Coding Standards
« Reply #5 on: April 03, 2011, 11:21 AM »
At the risk of sounding like a heretic, Hungarian has some merit.

I'll stop there before I get lynched. :)
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Coding Standards
« Reply #6 on: April 03, 2011, 11:24 AM »
wraith: Be a rebel - APPEND the underscore!

Renegade: if used properly, yes - most people tend to think hungarian means prefixing the data type ("i" for integer, "s" for string etc, "p" for a pointer etc), which is pretty pointless. If used for the purpose of the variable, the logical data type, it holds some merit... like "cb" for "count (in bytes)".
- carpe noctem

worstje

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 588
  • The Gent with the White Hat
    • View Profile
    • Donate to Member
Re: Coding Standards
« Reply #7 on: April 03, 2011, 11:26 AM »
I prefer the _ prefix myself as well. While a lowercase first letter might work for private variables, it is just too easy to write or read the wrong thing. I've had it happen more than once that autocomplete (or maybe my temperamental shift key - I am not sure yet) caused the wrong one to be put in. It's caused a few nice stack overflows because the property accessor kept looping into itself, which is really bloody annoying.

Hungarian notation is nice, but it needs to be sensible hungarian, not the overly verbose whats-the-point hungarian that adds no extra information. For more information, see Joel On Software: Making Wrong Code Look Wrong.

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,288
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Coding Standards
« Reply #8 on: April 03, 2011, 11:39 AM »
Ok, I'll come out of the closet then...

Private variables?

Type _variableName;


Public members?

Done as properties like:

VariableName
get { return _variableName; )
set { _variableName = value; }


Methods? Pascal case:

private void SomeMethod()


Local variables? camelCase:

Type someVariable;


Interface components? Pure Hungarian. e.g. Check boxes are:

chkSomeBoxPurpose

A list?

lstSomething

A text box?

txtWhatIsit

Similar for other components.


I like Hungarian. It's easy to work with and is clear. I really don't care about the anti-Hungarian hype/crap. I'm all for stuff that works and is simple and understandable. :)

EDIT: Fixed a drunken error. :)
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker
« Last Edit: April 03, 2011, 11:01 PM by Renegade »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Coding Standards
« Reply #9 on: April 03, 2011, 02:37 PM »
^ You've got my preference almost *exactly* written there.  And interfaces, I append I to it, i.e. IMyInterface.  Generic types, I use T.

And worstje hit the nail on the head with why I've been having *so* many problems.  I just can't figure out how intellisense alphabetizes, but it seems that no matter what order I declare them in, I get the problem of it autocompleting with the wrong case.  AIEEEE!

And up until now, it wasn't really that bureaucratic before the beginning of the year.  We have a product side (that deals with client facing apps) and a content side (that deals with internal apps used to create content).  They decided to merge all of the developers into one happy group (yay...?) so this is an attempt to help with that.  As such, I can see the need for a unified standard.  It's just that the upper and lower case is *really* slowing me down, just as I've started to try to minimize the use of the mouse.

Something else I've noticed- the change in your personal coding standards as you go through career development.  My personal code is a mixture of things, purely because of my history as a contractor, and going from place to place, having to adapt.  I looked at a bit of code that I posted in the SQL injection thread, and gagged because I had all of the variables defined in pseudo hungarian, i.e. strThisString, etc.  I was so put off from it, that I actually had to change it, but missed an instance of a variable.  And that's not the first time I've had that issue.

Just an observation...