Removal of defs.h

Removal of defs.h

Postby Roots » 09 Nov 2012, 18:06

I'd like to ask why defs.h was removed from the source code. Here is a link to the file as is found in the Allacrost repository:

http://allacrost.svn.sourceforge.net/vi ... iew=markup

As you can see, the only thing this file did was to declare the name of classes in their appropriate namespaces, along with a few function names used by defs.cpp. Defs.h was not dependent (did not include) any other file. At all. The reason why defs.h was so great was that in all the other code, you didn't have to manually declare each class that was used (eg. class AudioEngine; class VideoEngine; etc). All you had to include was defs.h, and all the declarations you could possibly need are in place. The disadvantage to this approach was that you couldn't look at the top of the file and see all of the classes that is actually used through the declarations list, although you could still guess what they were likely to use by seeing which namespaces were being used. But this list often became misleading or outdated, especially in code that is under extensive development, as sometimes classes are used initially, only to be unused at a later date and the programmer forgot to remove the class declaration 100% of the time. I heard that there was concern about defs.h increasing the compile time. The only time it would increase compile time is if you are modifying defs.h, because then nearly the entire game would have to recompile. But the only time you need to modify defs.h is when you are adding or removing classes. This is not a frequent occurence, especially with how mature the code base is, so I don't really see it as a problem.


I'd really like to see defs.h return to use, but I'm open for listening to reasons why it should be done away with. Here's a list of the advantages and disadvantages of having this file, as I understand it:

Using defs.h:
+ No need to declare classes in other headers and source files
+ Easy to read list of nearly every shared class in the game
- Adding/removing classes or otherwise modifying defs.h requires nearly the entire game to re-compile
- Have to always remember to update defs.h when creating/removing classes anywhere in the source code
- Can't see which external classes a file explicitly uses

Not using defs.h:
+ Can see every external class declaration that a file uses
+ Don't have to continually update defs.h with new classes
- Have to declare external classes for every single source and header file
- Class declaration lists can become outdated as the code changes
Image
Roots
 
Posts: 96
Joined: 04 Mar 2010, 21:54

Re: Removal of defs.h

Postby Roots » 09 Nov 2012, 18:12

A possible compromise, by the way, is to separate defs.h into multiple files. So for example, defs_engine.h could include all engine class declarations, defs_modes.h includes all game mode declarations, etc. That way if you change def_modes.h, you don't have to recompile the engine since no engine code would rely on game mode code (on the other hand, changing the engine defs would still require recompiling the entire game, as almost everything else depends on the engine). This would mitigate the recompile time issue when adding a new class at the cost of having class declarations split across multiple definition files and having to include more than one defs header file in code. I think I actually prefer this solution to just keeping a single defs.h. So my preferences right now stand at:

#1: Create mutiple defs headers based on some logical breakdown of the code (engine, editor, etc)
#2: Use a single defs.h file that includes all class definitions
#3: Abandon using class declaration headers and manually declare classes in each source file
Image
Roots
 
Posts: 96
Joined: 04 Mar 2010, 21:54

Re: Removal of defs.h

Postby Bertram » 09 Nov 2012, 18:46

Hi Roots,

I'm quite surprised you put this point first in the discussion list but why not. :)

I'd like to ask why defs.h was removed from the source code.

Err, src/defs.h wasn't removed from VT. It is still there. I'm just leaning forward its deletion little by little.

Not using defs.h:
+ Can see every external class declaration that a file uses
+ Don't have to continually update defs.h with new classes
I'll add this:
+ The entire project doesn't recompile when you touch certain common files, including this one.

- Have to declare external classes for every single source and header file
-> You already have to do inclusion anyway, I can't get why this is a problem.

- Class declaration lists can become outdated as the code changes
-> It is a drawback whatever solution you choose, not only this one.

Using defs.h:
+ No need to declare classes in other headers and source files
-> Same here: We already have to maintain inclusion. It's just a matter of doing it at the same time.
I can't get why this is a problem.

+ Easy to read list of nearly every shared class in the game
-> Err, actually, I never had in my life the need to read all the shared class of an app. Just looking for one already doing what I'm looking for.
Plus most IDE do it for you. I can't get the point here.

- Adding/removing classes or otherwise modifying defs.h requires nearly the entire game to re-compile
-> Well, that point is the one annoying me the most, and the base of my will to remove that file.

- Have to always remember to update defs.h when creating/removing classes anywhere in the source code
-> You have to update stuff whatever solution you choose anyway. That can't be considered.
- Can't see which external classes a file explicitly uses.
-> Thanks for doing sophism here. ;)

As a conclusion,
- The file defs.h is still in the code atm, and won't move until it is sufficiently reduced, changes after changes. I see no rush in doing this, don't worry.
- The compile time per object is actually too big, even for a project of this type. As for me, I do not like to lose time waiting for everything to recompile
when I'm trying something new.
- Again, the removal can happen little by little, it's just a matter to have the discipline to at least not add more to it at first.
- Let's discuss of more urgent things, shall we? ;)

Best regards,

Yohann
User avatar
Bertram
VT Moderator
 
Posts: 1652
Joined: 09 Nov 2012, 12:26

Re: Removal of defs.h

Postby Bertram » 25 Mar 2013, 11:03

Hi again,

The defs.h file has been removed a few days ago.

As for me, the whole project compile time decreased by 40 seconds, which is not insignificant.
Plus, it has reduced the binary size somewhat, even if this wasn't the main goal, anyway.

If someone has interesting results concerning this point, feel free to share :)
User avatar
Bertram
VT Moderator
 
Posts: 1652
Joined: 09 Nov 2012, 12:26

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron