Variables... uppercase... merrrrrr
#1 Members - Reputation: 632
Posted 09 September 2011 - 07:46 AM
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
#2 Moderators - Reputation: 6663
Posted 09 September 2011 - 08:03 AM
#3 Members - Reputation: 632
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
#5 Members - Reputation: 1309
Posted 09 September 2011 - 08:13 AM
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.
#6 Members - Reputation: 1453
Posted 09 September 2011 - 10:21 AM
#7 Moderators - Reputation: 7768
Posted 09 September 2011 - 12:46 PM
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.
[Work - ArenaNet] [Epoch Language] [Scribblings] [Journal - peek into my shattered mind]
#8 Members - Reputation: 198
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.
#9 Members - Reputation: 174
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
}
#10 Members - Reputation: 296
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 Staff - Reputation: 8926
Posted 09 September 2011 - 08:53 PM
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".Can you explain why option 1 is the "correct bracing style" ?
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:
[...]
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.
- Jason Astle-Adams.
From my blog: 20 ways to advertise your game | What next? Intermediate to advanced C++
How to make games WITHOUT programming | 4 reasons you aren't a successful indie developer






