Author Topic: Code organization and standards  (Read 3443 times)

Orcules

  • Guest
Code organization and standards
« on: 26 April 2008, 16:44:59 »
Hello all.  I have recently discovered the Glest project and think it has wonderful potential.  I downloaded the source, compiled it, and ran the game.  So far so good.  THEN I actually looked at the source code...

The code structure is a nightmare.  Many header files declare a dozen different classes, code is littered throughout the header files, and worst of all is the coupling.  An Ai has an AiInterface which in turn has a pointer to an Ai...  And the same spaghetti coupling exists for AiRule.  I haven't made it past the A's yet :O

Are there any attempts to enforce good coding practices in this project?  I am a professional programmer and this code makes my head spin.  Heaven help the newbies who are trying to learn C++ and want to contribute to this project as well.   Even a small thing such as running AStyle against all the code would be a good starting place.   And then for the sake of readability and navigation, enforce a rule that one header file may only contain one class declaration (excluding subclasses) , you may never define a method in the header file, and then refactor the old code to meet the new standards.

I have already started making these changes in my code set, but the coupling is a huge obstacle.  Are any of the main devs interested in the ideas I have mentioned or am I alone in my quest for readability and maintainability?
« Last Edit: 1 January 1970, 00:00:00 by Orcules »

Duke

  • Guest
(No subject)
« Reply #1 on: 26 April 2008, 21:26:24 »
Well the original main devs seem to be rather busy lately.

But you might want to contact daniel.santos.
He is currently overworking the code to add quite a list of new features.

I don't realy now if his stile is better, but it at least has more comments and docs. You might want to take a look at it.

The Project is called Glest Advanced and is stickied in the mods section.
« Last Edit: 1 January 1970, 00:00:00 by Duke »

martiño

  • Behemoth
  • *******
  • Posts: 1,095
    • View Profile
(No subject)
« Reply #2 on: 27 April 2008, 01:55:38 »
Please lets be a bit serious.

Code: [Select]
you may never define a method in the header file
This complete nonsense, compilers can not inline methods in header files. (well visual studio might be able to with some compiler options, but GCC can not).

Code: [Select]
An AI has an AiInterface which in turn has a pointer to an Ai

This is not exactly rocket science.

Glest code is extremely simple compared to any commercial game (I've seen a few), and this backed up by the fact that matze and daniel santos have been able to respectively port the game to linux and add an incredible amount of new features in not much time.

Regards.
« Last Edit: 1 January 1970, 00:00:00 by martiño »

hailstone

  • GAE Team
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
(No subject)
« Reply #3 on: 27 April 2008, 07:13:27 »
Quote from: "Martino"
compilers can not inline methods in header files
Didn't we have a discussion on inlining methods in header files?

I think the game is coded well but some sections could do with cleaning up and/or explained a bit with commenting. Maybe it's just my inexperience.

Quote from: "Orcules"
Are there any attempts to enforce good coding practices in this project?

Perhaps you could write some programming guidelines in a document to be included with GAE. I am always interested in ways to become better at programming.
« Last Edit: 1 January 1970, 00:00:00 by hailstone »
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/