C plus plus version

From WikiManual
Revision as of 17:17, 7 January 2006 by Sprotiel (talk | contribs) (Coding style: adding Numsgil's signature)
Jump to: navigation, search

Original document (and comments) by Taldor in black, comments by Numsgil in Red and comments by Griz in green.

We discuss the C++ design and coding standards in here. A wiki is much handier then a forum or PM's for this.

Language switch

You wonder why we're switching? Because VB is for simple, gui based programs. Darwinbots is nor a simple program, nor gui based. In contrary C++ is a powerfull language, but it has a higher development cost.

Visual Basic controvercy

C++ design

General concepts

  • Class based approach. In some cases, procedural in others. It's a value decision I'll make as I port the code.
  • Portable code. Where possible. Preferably in house or free library wrappers for non portable functions, such as multithreading and OS timers.

Structure

See the present VB code

The VB stucture is not a good C++ structure. VB and C++ are totally diffrent languages.
Only in the microscopic sense.
Could you please explain? To me they seem totally diffrent.
When you view the way in which the VB modules interact, that's exactly the same way the C++ modules will interact. Wether you paint in black and white or in color, shapes are going to be the same.
Shapes and colors have very little to do with the structure of a program.
That was a metaphor ... Nums is trying to say, if i may interpret here ... that both VB and C++ utilize 'moduals' in much the same way. The code within a modual may be quite different ... but the 'structure' of how moduals and routines are called up ... is similar. So i take him as saying the 'infrastructure', the outline, the 'overview' ... is already there.
but then ... perhaps i haven't a clue. ;) that's always a possibility as well. Griztalk 19:10, 1 Nov 2005 (MST)
That's exactly what I meant. ;)
You could make the Darwin engine (the part of the engine that takes care of the robots, vegs, senses, etc.) the same as it was in VB. There are a lot of things that I would change (like not using friend classes), but it's acceptable for C++. The other part of the program (the GUI and the graphics) is totally diffrent in VB and in C++.
Yep, but GUI and graphics aren't ranking very high on my list of concerns. I mean, look at the program we have as it stands right now. It's always been somewhat of an afterthought. Now if you'd like to change that and add some killer graphics...  ;)
I didn't mean the implementation, but the structure of that part of the program. (read: the design)


  • User Interface (Fox Toolkit)
    • Simulation sub window (3D - OpenGL)
    • Darwin (the simulation engine)
      • Tie
        • Robot
          • Sense
        • Veg

To be used everywhere:

  • Vector_4 (using uBLAS) Present vector class is from this gamedev.net article. I'll use whichever is fastest, feel free to perfrom benchamrks
  • Matrix_4 (also using uBLAS) See above
  • Random (using 'srand()' and 'rand()') See the chapter on random numbers
  • Object (the base class) Depends on the class

Ahem! This doesn't seem very conclusive nor very detailed. I suggest we discuss this on another page. Sprotiel 11:45, 6 Jan 2006 (MST)

C++ coding standards

  1. C++ C++ libraries where such libraries do what I want them to do, C libraries otherwise. Another value decision. All C librairies are included in C++. Mixing C and C++ isn't the easiest task, however OO C++ and procedural C++ can be mixed easily. I agree, but I've been having some trouble with various C++ libraries that immediatly goes away when I switch to the C versions. Might just be my compiler MSVC++ 6.0 Prolly, it's crap. :-P Try the MinGW version of the gcc compiler.
  2. Four spaced tabs - Aye.
  3. External librairies when possible (ie. Boost) Internal libraries where possible, to decrease the number of code dependancies, except where external libraries perform the job faster/more comoprehensively than internal libraries can.
  4. Use the 80 character line If you insist... Yup, I do. ;-)
  5. Fox Toolkit
  6. OpenGL

Coding style

This is how I code:

void function(parameter 1, parameter 2)
{
    for(some; things; inside)
    {
        blah;
    }
}

Notice the 4 space indentation.

I don't care how you write code, so long as I can read it and understand it. When we edit each other's code, we should endeavor to maintain the same style as the rest of the function we're editing. That is, don't mix styles in the same function.

If you don't like the idea of mixing styles at all in the whole project, feel free to adopt my style. ;)

If you're adding a line that isn't very reader friendly, please comment in thoroughly. Write the code as if a bunch of non-savvy beginning programers are going to read and edit it. No fancy programming tricks please. Do in 8 lines what you can cram into 2 if 8 lines makes it more readable. Use lots of white space. This code needs to be maintainable by anyone and everyone.

My compiler is MSVC++ 6.0, and so that's the official compiler of the rest of the project. If you use a different compiler, I will endeavor to let it compile for you. But the privelege of compiling to the nice sight of 0 errors, 0 warnings is reserved for me and others using MSVC++ 6.0. I can supply versions of MSVC++ 6.0 to some who'd like it. Numsgil

Quotes

  1. "There must be something terribly wrong with your code. Please fix it." -- Dev-C++

See also

  1. RoundTable
  2. C/C++ Reference
  3. C++ FAQ Lite

Paul is still alive , he will be back to see the c++ virsion bau2005