Leaving the implementation in the header file

Jan 5, 2011 at 3:05am
closed account (3pj6b7Xj)
I know this is a bad thing to do but for years, this was my practice. I always created a class and coded the implementation for it inside its header and left it all in there. Like if I had a class called Bananas, I would store it in Banana.h and put the implementation inside with it, did not split it like you are supposed to and put the implementation in a Banana.cpp well recently, I abandoned the practice due to Windows programming and now I have a Banana.h & Banana.cpp. My coding style is also beginning to change after browsing this board, my coding was simple and basic, now I find i'm making use of templates, operator overloading were needed & function pointers...stuff that I never liked messsing around with because I didn't like the level of detail and coplexity it involved. It is weird, I can't explain it, I feel like I am asceding to a new level and have begun to experience a new level of confidence in C++ programming, perhaps it was the windows programming shift I did 3 months ago, moving from console programming with DJGPP which I did for the last 2 years and making the move to Windows and learning the api, maybe thats what did this too me but I have abandoned a lot of BAD practices and I mean A LOT. I've been at it with C++ for the last 2 years, making all sorts of games and programs using these bad practices, the funny thing is, they worked but probably only from my point of view.

Here "WERE" some of my bad practices...

1. using global variables.
2. leaving implementation inside the header file, didn't make sense to me to put it in a foo.h and foo.cpp
3. using #define to convert is to == and avoid the stupid if (a=b) ... #define is == so for some time my coding looked like if (a is b) what ever.
4. never-ending loops: for(;;) and while (true) now I just initialize a bool bQuit = false; and set to true to kill loop.

I can't remember any more but i'm sure there are, in DJGPP I twisted the C++ language so much with #define that my code did not look at all like C++, as a matter of fact, you would open one of my console programs and you would say, "what programming language is this!?"

Lol, it was bad thats why I my source never met the public, I was afraid of the criticism I would received. I will try to find my text editor class I created in DJGPP and post it here, you guys will have a good laugh at the retarded C++ syntax.
Last edited on Jan 5, 2011 at 3:15am
Jan 5, 2011 at 5:23am
Ha, I did some of that. I think if you put the implementation in there you should name it .cpp, but still #include it.
#include "Bananas.cpp"
I used a lot of macros, not so much any more, though.
I still use one of the cool macros I made:
#define let(x,y) typeof(y) x=y
This helps with the long type names that are rife in c++.
Jan 5, 2011 at 9:17am

1. using global variables.

You could have make it worse by naming them a, b, c, d, e, f, like some of my students do.



leaving implementation inside the header file, didn't make sense to me to put it in a foo.h and foo.cpp


Ha, the guys from Boost or STL do it all the time. This is not your fault. If you write templated code there is no possibility to put it in the cpp files (ok, there is, but it requires to include the cpp file somewhere and instantiate all the templates used by the program - which is probably worse than having code in the headers). Also, when doing OOP, the OOP kind of interface/implementation is not the same as the header-file-kind of interface/implementation - there is a large "impedance mismatch" here.

Last edited on Jan 5, 2011 at 9:19am
Topic archived. No new replies allowed.