• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
way2lazy2care

Variables... uppercase... merrrrrr

10 posts in this topic

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 player
public Texture2D PlayerTexture;

// Position of the Player relative to the upper left side of the screen
public Vector2 Position;

// State of the player
public bool Active;

// Amount of hit points that player has
public 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 back
Position = position;

// Set the player to be active<br class="cdc2"> Active = true;

// Set the player health
Health = 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
1

Share this post


Link to post
Share on other sites
That's actually part of the [url=http://msdn.microsoft.com/en-us/library/x2dbyw72(v=vs.71).aspx].NET naming guidelines[/url]. You get used to it after a while.
1

Share this post


Link to post
Share on other sites
[quote name='SiCrane' timestamp='1315577016' post='4859501']
That's actually part of the [url="http://msdn.microsoft.com/en-us/library/x2dbyw72%28v=vs.71%29.aspx"].NET naming guidelines[/url]. You get used to it after a while.
[/quote]

D:

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

Share this post


Link to post
Share on other sites
I'm more upset about the utter uselessness of the comments. [color=#008800]/* comment about the comments */[/color]
0

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
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)
2

Share this post


Link to post
Share on other sites
This is part of working with other people's code.


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

[code]if(foo)
{
bar();
baz();
}[/code]


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

[code]if (foo) {
bar();
baz();
}[/code]

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 [i]exactly[/i] 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.
2

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1315593962' post='4859691']
This is part of working with other people's code.
...
[/quote]

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.
1

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1315593962' post='4859691']
This is part of working with other people's code.


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

[code]if(foo)
{
bar();
baz();
}[/code]


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

[code]if (foo) {
bar();
baz();
}[/code]

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 [i]exactly[/i] 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.
[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='D.Chhetri' timestamp='1315620719' post='4859856']
Can you explain why option 1 is the "correct bracing style" ? I use something like:
[code]
if( condition){
statement
}
[/code]
[/quote]

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).
0

Share this post


Link to post
Share on other sites
[quote name='D.Chhetri' timestamp='1315620719' post='4859856']
[quote name='ApochPiQ' timestamp='1315593962' post='4859691']
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:
[...]
[/quote]
Can you explain why option 1 is the "correct bracing style" ?
[/quote]
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 [i]mix different styles[/i] 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.
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0