Jump to content
  • Advertisement
Sign in to follow this  
deus.ex.nova

Unity How do you organize your classes and their respective implementation files?

This topic is 2587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey Everyone,

Anyways, I am constantly debating with myself about how I should organize and write my code (e.g. where I should put whitespaces, etc.), and once again I am at another dilemma. I want to make my classes look more professionally organized, but because I am mostly a self-taught programmer, I don't get a lot of insight on good ways of organizing my code. So I am asking the GameDev community: How do you guys organize your classes and class implementations? For example, do you structure members first by private and public members, or by declarations and functions? Do you organize your source files in order of where members appear in the header, or by some other method (i.e. alphabetical order)? I was originally going to make this into a poll, but I found my choices were getting way too complicated.

Thanks in advance for all of your feedback. biggrin.gif Please feel free to mention other ways in which you organize your classes!

Share this post


Link to post
Share on other sites
Advertisement
I feel your pain. Suggest finding a style that you like and then stick to it. Some style guides (I use bitsquid in my personal projects and a style that shall remain unmentioned - for your own safety - at work):
http://google-styleg...nk/cppguide.xml
http://bitsquid.blog...ding-style.html

And some awesome tools that you can set up to automatically reformat your code:
http://uncrustify.sourceforge.net/
http://universalinde...ourceforge.net/


Writing with a consistent style is great and IMO helps readability. So make sure that when you are editing other peoples' code that you use their conventions!

Share this post


Link to post
Share on other sites
"Suggest finding a style that you like and then stick to it."

I would argue against the 'stick to it' bit, obviously it is wise to use a consistant style throughout any project but you should allways be aware that their probably a better style out there.

Share this post


Link to post
Share on other sites

I feel your pain. Suggest finding a style that you like and then stick to it. Some style guides (I use bitsquid in my personal projects and a style that shall remain unmentioned - for your own safety - at work):
http://google-styleg...nk/cppguide.xml
http://bitsquid.blog...ding-style.html

And some awesome tools that you can set up to automatically reformat your code:
http://uncrustify.sourceforge.net/
http://universalinde...ourceforge.net/


Writing with a consistent style is great and IMO helps readability. So make sure that when you are editing other peoples' code that you use their conventions!



Thanks for the links! smile.gif I understand that it is good to keep a consistent style at least across a project, but related to what Jim1664 said, I created this topic post in order to gather different styles from the GameDev community and pick elements from each that I like. So to add onto what I originally posted:

Share a particular styling rule that you think is great in making code better organized and/or easier to read. This can include many things such as white spaces, number of spaces before starting a new line, etc. If you can, provide reason(s) as to why you think it works well. Let's get a discussion happening!

It is difficult to say what is the best style, but I would love to hear things that coders have discovered really work for them.

Share this post


Link to post
Share on other sites
This is always going to be a subjective conversation. There is no objectivity to be had.

Some people like spaces. I like tabs. Some people like K&R bracing. I like the bracing style that isn't fuck-ugly.

We can argue back and forth about this all month, and neither side will ever really be convinced.


Pick something that looks nice to you, and stick with it within a given codebase. If you decide later that something else looks nicer, feel free to switch. It's 2011, we should all be using pretty-printers on our code anyways, so it should never actually matter.

Share this post


Link to post
Share on other sites

This is always going to be a subjective conversation. There is no objectivity to be had.

Some people like spaces. I like tabs. Some people like K&R bracing. I like the bracing style that isn't fuck-ugly.

We can argue back and forth about this all month, and neither side will ever really be convinced.


Pick something that looks nice to you, and stick with it within a given codebase. If you decide later that something else looks nicer, feel free to switch. It's 2011, we should all be using pretty-printers on our code anyways, so it should never actually matter.


Well I know this kind of stuff is mostly subjective, I just wanted to see what styles other programmers use in case I never thought of a good method or a good reason for that method. There would be no need for people to point fingers and tell the other person that their style seems absurd. That's not what I want at all, so I guess it was wrong of me to try to promote a "discussion". Rather, this is more of "show-and-tell".

By the way, what do you mean by K&R bracing?

Share this post


Link to post
Share on other sites
[font="Consolas"]"By the way, what do you mean by K&R bracing?[/font]"

Its the style used in the 'C Programming Language', by Kernighan and (someone else whos name begins with an R)

Which is;


void function( ... )
{
doSumfink();
for( int a = 10; --a; ) {
doSummitElse();
}
}



By comparison, I use.


void Function( ... ) {
DoSumfink();
for( int a = 10; --a; ) {
DoSummitElse();
}
}


Edit: That guys name is Ritchie, not knowing annoyed me so I had to google it, or bing actualy but 'bing it' isn't quite the same.

Share this post


Link to post
Share on other sites

Well I know this kind of stuff is mostly subjective, I just wanted to see what styles other programmers use in case I never thought of a good method or a good reason for that method. There would be no need for people to point fingers and tell the other person that their style seems absurd. That's not want I want at all, so I guess it was wrong of me to try to promote a "discussion". Rather, this is more of "show-and-tell".


Fair enough smile.gif

You can see examples of my formatting style at http://epoch-language.googlecode.com/ and http://scribblings-by-apoch.googlecode.com/

Share this post


Link to post
Share on other sites

[font="Consolas"]"By the way, what do you mean by K&R bracing?[/font]"

Its the style used in the 'C Programming Language', by Kernighan and (someone else whos name begins with an R)

Which is;


void function( ... )
{
doSumfink();
for( int a = 10; --a; ) {
doSummitElse();
}
}



By comparison, I use.


void Function( ... ) {
DoSumfink();
for( int a = 10; --a; ) {
DoSummitElse();
}
}


Edit: That guys name is Ritchie, not knowing annoyed me so I had to google it, or bing actualy but 'bing it' isn't quite the same.


I see. So from what I can tell, K&R bracing is where they leave the first brace on the same line as the function call? I much rather have my braces have their own line. I feel like I can lose track of where I am enclosing the scope of a particular chunk of code. I too like capitalizing functions names so that I can tell them apart from my variables - it's just something I found appealing when I was learning C#.


[quote name='Robot Ninja' timestamp='1316341910' post='4863002']
Well I know this kind of stuff is mostly subjective, I just wanted to see what styles other programmers use in case I never thought of a good method or a good reason for that method. There would be no need for people to point fingers and tell the other person that their style seems absurd. That's not want I want at all, so I guess it was wrong of me to try to promote a "discussion". Rather, this is more of "show-and-tell".


Fair enough smile.gif

You can see examples of my formatting style at http://epoch-language.googlecode.com/ and http://scribblings-b...googlecode.com/
[/quote]

Very cool. I clearly have a lot to learn in C++, because a lot of the source code is still out of the scope of my understanding. laugh.gif

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!