Knowing where to put the mug. (functions and such)

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Knowing where to put the mug. (functions and such)

Post by JS Lemming »

I think one of the biggest problems I have in programming is organization. First off, I don't know when your supposed to break things into thier own seperate cpp file. I just don't.

Secondly... when you are programming and you frequenlty make new functions, where do you physicaly put the new functions? Right below the one you just made? Or is there some professional way to determine its location in the file... and which file!?!?

Let me see what organization you prefer.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

Sorry about the late reply, I've been so emo lately. The plague of homework + busy work is really getting to me. I remember just last year when the end of the year came around nothing could stop my cheeriness, but it looks like this year is almost the exact opposite. I can't not be emo-core while I'm at school. (there now, heh)

Okay, first off, always use prototypes. Keep your prototypes and class definitions in .h files. So if you're program is called Oogama.cpp, you'd also have an Oogama.h which could look something like this:

Code: Select all

//Oogama.h

class VideoGame {
private:
    char type[30];
    int release_date;
    char title[50];
public:
    //Constuctor and all that crap
};

void Function1(int arg);
void Function2(int arg, char blarg);
Then, in your .cpp file you have the definitions. Just remember: .h is for declarations and .cpp/.c is for definitions.

As for breaking it up into seperate files, I do that so religiously it isn't even funny. There isn't a rule, I just separate things into files that make sense to me. Something like a draw.cpp, main.cpp, input.cpp, particle.cpp layout is what I used on DCParticlez. Then every one of the .cpp's have their own corresponding .h to declare all the crap used by the functions and whatnot.

As far as actually including goes, I once thought it was okay to do just a #include "whatever.cpp"

As I've talked to people, that apparently is a very bad habbit. Not only that, but the only time I've ever gotten that to work is when I was building using the Pern project with VC++ for Dreamcast. All my SDL crap refuses to compile like that.

I need to go and look at the C++ book to see the "real" way to include other files. I doubt I'll get around to it before this summer though. Everything is one emo episode after another. All that I want to do nowadays is go home and either 1) kiss the ground and thank god I'm done with school for the day 2) Play video games.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Its not that I don't know how to do all that including stuff... its just I have problems when it comes to actually deciding when to break something into its own file. Oh well.

WOOT ONE MORE DAY OF SCCCCHOOLLOL!!!!!
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Post Reply