I recently came across this text describing said possibility. It looks pretty interesting, in fact I may try coding my next project in that style.
Does anyone have an opinion or thoughts on this?
Java style classes in C++
I'd say use a proper IDE instead. I am just as annoyed with header/source separation but it is not too bad really.
The most obvious problem I see here is, that if you change anything in your code, everything is recompiled. You can't use precompiled headers (other than for headers outside of your project) or benefit in any other way from separation of compilation units.
Programming a huge project this way means, that the tiniest change requires the whole project to recompile. Nuts.
Whatever time you plan to save this way is eaten up by the compiler for sure.
The most obvious problem I see here is, that if you change anything in your code, everything is recompiled. You can't use precompiled headers (other than for headers outside of your project) or benefit in any other way from separation of compilation units.
Programming a huge project this way means, that the tiniest change requires the whole project to recompile. Nuts.
Whatever time you plan to save this way is eaten up by the compiler for sure.
I don't have time to read all of that as i'm at work but is he seriously suggesting putting all class information into a header file so that the .cpp isn't required?
That's just mental... when you #include a header it copies the file into that location... if your header includes every bit of code of the class, such as possibly even 1000s of lines of function code then you're going to seriously bloat out the application and compilation would be nightmarish, surely!
When i switched from java to C++ the .cpp/.h idea was a bit strange to me but it's like that for a reason and it works... i've never had any problems with it at all!
That's just mental... when you #include a header it copies the file into that location... if your header includes every bit of code of the class, such as possibly even 1000s of lines of function code then you're going to seriously bloat out the application and compilation would be nightmarish, surely!
When i switched from java to C++ the .cpp/.h idea was a bit strange to me but it's like that for a reason and it works... i've never had any problems with it at all!
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Hmm. While I agree in principle, I was ready to dismiss it on practical grounds. However, he does make some interesting points. Yes, every compilation will be a "rebuild all", but compilation of a single compile unit will indeed be somewhat offset by quicker linking. And from testing various build systems, calculating dependencies is a surprisingly significant part of the time involved in building a complex project, which this would also help with.
You'd really have to try it on your own build system and project to see.
He gets props for just assuming that the reader will know that a struct is a class. That's always nice to see.
This though... this is either madness or genius:
I'm tending towards genius, although again, you'd have to try it with a real project to see if it's actually practical.
It's a very interesting read. Thanks for sharing it.
You'd really have to try it on your own build system and project to see.
He gets props for just assuming that the reader will know that a struct is a class. That's always nice to see.
This though... this is either madness or genius:
Code: Select all
inside a class, declare before use doesn't hold (!). [...] So we can effectively solve [the mutual dependency] problems by wrapping the entire program (all our classes/headers) in a single "dummy" class It's a very interesting read. Thanks for sharing it.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Well, it works as advertised, and it does indeed take care of mutual dependencies if you wrap all your classes inside a master class.
The minor downside is that you have to define and initialise all static members outside of the master class, but that's fairly inconsequential.
The build (i.e. rebuild all) time with a small project (17 files, 4125 lines of code) is too short to measure. I'm not sure yet how much it would scale with larger projects, but I find the argument about compile versus link time credible. Incidentally, if you're consistent in following the suggested include architecture, then you neither need nor want include guards in your "header" files, as they should only be included once anyway, and the #ifdefs will just give the preprocessor more work to do.
I'm actually really liking this. I think I'll keep tinkering with it.
The minor downside is that you have to define and initialise all static members outside of the master class, but that's fairly inconsequential.
The build (i.e. rebuild all) time with a small project (17 files, 4125 lines of code) is too short to measure. I'm not sure yet how much it would scale with larger projects, but I find the argument about compile versus link time credible. Incidentally, if you're consistent in following the suggested include architecture, then you neither need nor want include guards in your "header" files, as they should only be included once anyway, and the #ifdefs will just give the preprocessor more work to do.
I'm actually really liking this. I think I'll keep tinkering with it.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Hmm, I personally don't like this. Putting code in with the header files is simply madness. I mean just look at some of the stuff in Irrlicht, like the drivers, or the extension handler.
I have never been partial to change on the structure of code when it comes to stuff like this. If other people like it though that's cool.
I have never been partial to change on the structure of code when it comes to stuff like this. If other people like it though that's cool.
TheQuestion = 2B || !2B
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
"header files" are a holdover from C though. Java and C# do away with the concept and get by just fine; everything is just a "source" file, and all methods are defined in the class declaration.
If it helps conceptually, there's no reason at all why "header" files need to be called "foo.h". You can include "foo.cpp" just as easily.
If it helps conceptually, there's no reason at all why "header" files need to be called "foo.h". You can include "foo.cpp" just as easily.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
[quote="rogerborg"]"header files" are a holdover from C though. Java and C# do away with the concept and get by just fine; everything is just a "source" file, and all methods are defined in the class declaration.[quote]
Yes, they do get along with other people. But that way of defining classes is what has always driven me away from them. I don't know why, but I just don't like that style. Personally though I have always been a fan of data design over code design though.
Yes, they do get along with other people. But that way of defining classes is what has always driven me away from them. I don't know why, but I just don't like that style. Personally though I have always been a fan of data design over code design though.
TheQuestion = 2B || !2B
