Jump to content

  • Log In with Google      Sign In   
  • Create Account


Variables... uppercase... merrrrrr


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 way2lazy2care   Members   -  Reputation: 782

Like
1Likes
Like

Posted 09 September 2011 - 07:46 AM

So I was just running through an XNA tutorial quickly just to get caught up with it again. I don't think I've messed with it since 2.x and it's currently at 4.0, so I just wanted to catch up quickly and refresh my C# jazz.

ANYWAY, I was reading through one of the tutorials and this was one of the code snippets:

[source lang="csharp"]// Animation representing the playerpublic Texture2D PlayerTexture;// Position of the Player relative to the upper left side of the screenpublic Vector2 Position;// State of the playerpublic bool Active;// Amount of hit points that player haspublic int Health;[/source]

and this:

[source lang="csharp"]public void Initialize(Texture2D texture, Vector2 position){PlayerTexture = texture; // Set the starting position of the player around the middle of the screen and to the backPosition = position;// Set the player to be active<br class="cdc2"> Active = true;// Set the player healthHealth = 100;} [/source]

Does anybody get super bugged by seeing member variables capitalized? D: It feels dirty and wrong. Most of the time all my variables lowercase start camalcase after, and methods are all uppercase start camalcase after. It feels really weird looking at this code for that reason.

/totally pointless mini-rant

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9550

Like
1Likes
Like

Posted 09 September 2011 - 08:03 AM

That's actually part of the .NET naming guidelines. You get used to it after a while.

#3 way2lazy2care   Members   -  Reputation: 782

Like
0Likes
Like

Posted 09 September 2011 - 08:05 AM

That's actually part of the .NET naming guidelines. You get used to it after a while.


D:

edit: clearly I had no idea there was a word for pascal case... I learned 2 new things from your linking :D

#4 Wan   Members   -  Reputation: 1366

Like
0Likes
Like

Posted 09 September 2011 - 08:10 AM

I'm more upset about the utter uselessness of the comments. /* comment about the comments */

#5 kunos   Crossbones+   -  Reputation: 2205

Like
1Likes
Like

Posted 09 September 2011 - 08:13 AM

true.. I still have an hard time adopting it.. I developed my liking in naming conventions through Java even if I mostly work with C++... I think MS had had capital letters in public methods forever so I thought it was just that heritage.

But then I started to dig deeper andit really make sense in C# because you have properties...it is much nicer imo to have a property named "Whatever" wrapping a protected member "whatever"... Java forces you to have the "getWhatever / setWhatever" thing which isn't nice either.. in C++ you would maybe do "whatever / whatever(value) ) which is better.. but you'll have to have a protected member "m_whatever" "whatever_" which again.. isn't nice.. so afterall, I think .NET guidelines are keepers.
Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#6 alnite   Crossbones+   -  Reputation: 2068

Like
2Likes
Like

Posted 09 September 2011 - 10:21 AM

It's best to follow the convention of the language you are coding in, no matter how horrid it is. The worst thing you couldve ever done is to use one convention in a language that has completely different convention (such as m_strVar in Java)

#7 ApochPiQ   Moderators   -  Reputation: 15037

Like
2Likes
Like

Posted 09 September 2011 - 12:46 PM

This is part of working with other people's code.


I prefer the Correct Bracing Style in curly-braces-oriented languages:

if(foo)
{
	bar();
	baz();
}


However, it is also popular to use the Incorrect Bracing Style:

if (foo) {
	bar();
	baz();
}

Indeed, I've now worked for several companies whose internal conventions mandate using the Incorrect style. This is just the price you pay for interacting with other programmers. It's worth getting over it sooner rather than later, because you will never work with anyone else who formats code exactly the way you like it.

It's somewhat like food. You can cook your own meals, and get them precisely as you want them; but if you want to eat at a restaurant, or at someone else's home, you'd better be willing to tolerate variety.

#8 Telgin   Members   -  Reputation: 200

Like
1Likes
Like

Posted 09 September 2011 - 02:44 PM

This is part of working with other people's code.
...


I can't agree with this enough.

Although it isn't the precise point of the thread, I can't stress enough that no matter how the code is formatted, if you're maintaining or adding to existing code, just do whatever the previous programmer did.

I learned this the hard way with my first real programming job. There was only one other developer, who was my manager. He had a lot of code already written to do various things, and his coding format was, for lack of knowledge of a proper term, old C style. That is, in particular using underscores to separate words in variables and using inline braces (or The One True Brace Style, if I'm remember correctly).

I'd learned to use camel case and braces on their own lines, which had suited me just fine for personal projects and programming assignments for school where it didn't matter.

Whenever I had to modify his code, I blindly used my own style instead of his, and it made the code horrid to look at and confusing at times. I'd have to stop and think, was that variable called object_timer or objectTimer? It was a waste of time. I was once even boneheaded enough to write code to translate between the two styles (this is in PHP, where you can use reflection to do this sort of thing) instead of just adopting his style.

He never called me out on it, which surprises me to this day, but within a few weeks I learned to use his style and things fell into place much better. I'm working on a project right now that I started over 2 years ago (because the client can't figure out what the heck they really want it to do), and I have to continuously fight with the fact that the code has mixed styles in it. And I can't fix the variable names in one place, else I have to fix them in five.

Of course, that's indicative of just me being a stupid programmer more than anything, so I've amended my ways.


On topic though, I agree that style is a bit... unusual to me. I haven't done any .NET development, and understand that they have style guidelines, but even using member names like MemberFunction instead of memberFunction bugs me. Not sure why really. I've also never really been a big fan of using different name conventions for member variables versus other variables either. I've seen recommendations to use underscore separation for stack variables and camel case for member variables for instance, and while I can see some marginal benefits, it would bug me actually writing code like that.
Success requires no explanation. Failure allows none.

#9 D.Chhetri   Members   -  Reputation: 181

Like
0Likes
Like

Posted 09 September 2011 - 08:11 PM

This is part of working with other people's code.


I prefer the Correct Bracing Style in curly-braces-oriented languages:

if(foo)
{
	bar();
	baz();
}


However, it is also popular to use the Incorrect Bracing Style:

if (foo) {
	bar();
	baz();
}

Indeed, I've now worked for several companies whose internal conventions mandate using the Incorrect style. This is just the price you pay for interacting with other programmers. It's worth getting over it sooner rather than later, because you will never work with anyone else who formats code exactly the way you like it.

It's somewhat like food. You can cook your own meals, and get them precisely as you want them; but if you want to eat at a restaurant, or at someone else's home, you'd better be willing to tolerate variety.


Can you explain why option 1 is the "correct bracing style" ? I use something like:
if( condition){
  statement
}

Edge cases will show your design flaws in your code!
Visit my site
Visit my FaceBook
Visit my github

#10 Nanoha   Members   -  Reputation: 296

Like
0Likes
Like

Posted 09 September 2011 - 08:24 PM

Can you explain why option 1 is the "correct bracing style" ? I use something like:

if( condition){
  statement
}


It's not "incorrect". There is no correct or incorrect. Personally I prefer:
if()
{
}

Just because its what I'm used to and I like how the brackets line up (rather than if/while/for/whatever lining up to a }. I'd imagine people just stick to whatever they started with (once settled).

#11 jbadams   Senior Staff   -  Reputation: 17941

Like
1Likes
Like

Posted 09 September 2011 - 08:53 PM


This is part of working with other people's code.

I prefer the Correct Bracing Style in curly-braces-oriented languages:
[...]
However, it is also popular to use the Incorrect Bracing Style:
[...]

Can you explain why option 1 is the "correct bracing style" ?

He was being facetious -- neither is "correct" or "incorrect", but programmers will often claim that whichever method they personally prefer is "correct", and may even have a string of reasons they believe this to be true -- you can see a similar reference in Telgin's reply, where he refers to "The One True Brace Style".

As has already been noted the important thing is to choose a style and to apply it consistently, or if you're working in a professional environment to consistently and correctly follow any guidelines provided by your organisation. Even if there aren't guidelines provided, if you're working with an existing body of code it's usually easier to stick with the conventions already in use.

Your bracing style is fine for your own projects or where it matches the style already in use -- the only approach that is really Wrong™ is to mix different styles rather than being consistent -- and then we only say it's Wrong™ because it's likely to make your code harder to read and maintain; it won't cause compile errors or anything, and if you really want to you can be as inconsistent as you like in your personal projects, it's just likely to end up biting you in the ass down the road, and no good programmer would recommend it.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS