views:

43

answers:

3

I've made this a community wiki...

Okay, I was looking through someone's code one day and I was annoyed how they declared all their functions first and then later called them below. I guess I'm use to Visual Studio's automatically generated functions, that are made after you call them- and I was wondering, which way do you prefer? Or is there a standard on these kind of things?

+1  A: 

Whatever Visual Studio do automatically can be considered a Microsoft standard. Not always the best standard, but a standard anyway =)

Samuel Carrijo
Sometimes I wish you could hover over the function name and see the entire function or something.
DMan
@DMan: Uhm...that could be a very big tooltip. And that's what the intelli-sense descriptions are for (why do you need to see the code?). Ctrl+click works in a bunch of IDEs...
Mark
@Mark- Sometimes I don't use Visual Studio or in VC++'s case, a not very good one.
DMan
+4  A: 

I'm not sure what you mean by this. In C and C++, a function must be declared before it is called, otherwise the compiler won't know how to verify your arguments and return values.

lacqui
Oh, maybe *that's* why. I actually noticed this after transferring from C# to C++. Maybe this should have been a question after all! Thanks!
DMan
Also note that there is difference between "declared" and "defined". In C++ they must be "declared" first, but you can do that with a 1-line function prototype and then put the body of the function below if you'd like. Even in dynamic languages, the function must be defined before it's called (in runtime). Like in Python, you can put the function above or below, but if it's below, and the function is called *immediately* (before the parser gets to to the definition) then you'll get a run-time error.
Mark
+2  A: 

I don't think it matters as the functions are all loaded into memory before execution begins. It's mostly a matter of style.

Personally I put miscellaneous functions that aren't part of a class definitions at the bottom of my code so it's easier to read.

That's just my $0.02 though.

primehunter326