Lost in the lands of C++?

Posted by Astryl on May 17, 2012, 10:46 a.m.

I recently found this image floating around on GamaSutra:

Click to see full sized 18.5MB image

I declare 64Digits to be that bit near the North-Eastern corner.

Now discuss the C++0x/11 standard. I'll update my blog a bit later.

The rest of the blog, as promised

Well, I promised an extension on my blog, and boy do I need it. Two short blogs within the week? Am I ill?

Anyway, besides the fact that I nearly used a Lorem Ipsum generator to fill these blank spaces, I did remarkably little on my game in the last two days.

Besides drawing a goblin. I'll upload it tomorrow maybe.

Today I did spend some time extracting the framework code from my game's code, leaving me with a nice template to experiment with new ideas in. Also, it's a great way to create an OpenGL window with all the correct parameters set up (Besides the correct projection, but if you can't do that, you're hopeless).

To the hopeless:

// The quick and easy way to set up an OpenGL perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewPort(0,0,640,480);
gluPerspective(60.0F, 1.33F, 0.01F, 500.0F); // 1.33 can be substituded for 1.337 if you're feeling particularly idiotic :3
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Render as normal

Anyway, tomorrow I hope to animate my goblin (Three required: Standstill, Walk and Attack. Oh, and 'Hit' so that's four), and add him to the game.

I've discovered an interesting and ironic thing while working on this game: The programming of the game is the easy part. It's the art that takes time, patience and every four-letter word you can conjure up.

On the new C++ standard

You know, normally I ignore the C++ standard 'updates', because honestly, when in the last decade did they try and change anything?

Well, now they did. And started to give C++ some handy new features.

Of course, there are already a lot of myths floating around the net about C++11. Such as it's 'slowness'. The only slowness I've encountered with regards to the new standard is the speed at which both Microsoft and the maintainers of GCC are implementing them. Both compilers only support a fraction of the new features.

Anyway, here's an interesting piece of legal C++ code:

#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

vector<string> vec = {"This","is","one","of","many","new","features"};

class TClass
{
    public:
        TClass():number(0),data("Nothing"){}
        TClass(int n, string d):number(n), data(d){}
        ~TClass(){}

        string getdata(){return data;}
    private:
        int number;
        string data;
};

// This is previously unheard of:
TClass g_tclass[] = {{0,"Pretty"},{1,"Darned"},{5,"Useful"}};

// How about this?

class CClass
{
    public:
        CClass(int x):x(x){}
        CClass()
	{
	    CClass(5); // Delegation
	}
        ~CClass();
    private:
        int x;
}

// Here, have some more:

int main(int argc, char** argv)
{
    auto var1 = "Auto types";
    // Almost weak-typing, but not really, because 
    // adding in var1 = 4.55F; would be illegal right now.
    // There is also declspec(), but it works differently.
    // Both are determined at compile-time, meaning no speed impact.
    
    // Lets print the data I defined earlier, the new way:
    for(auto i : g_tclass)
	  cout << i.getname << endl;

    // And the vector:
    for(string i : vec)
    	  cout << i << endl;
    
    // Old method would be one of these two:
    for(int i = 0; i < vec.size(); i++)
	  cout << vec[ i] << endl; // That was messing up my [ i] tags...
    for(vector<string>::iterator i = vec.begin(); i != vec.end(); i++)
	  cout << (*i) << endl;
}

Other benefits include Lambda functions (Anonymous functions), base-constructor inclusion, elimination of several 'copy' problems with temporaries, an override keyword, a final keyword (nor really keywords actually, kinda language constructs, but does the same as you'd expect them to do), new smart pointers, and the ability to nuke sites from orbit at the press of a button. [Citation needed]

Anyway, discuss. Point out the supposed issues with the new standard, at which point I will happily condemn you to a C++-less environment, where you can spend your time coding in FORTRAN, COBOL, or FORTH.

I actually have a reason to discard all the 'speed' claims. C++ still does what it does best: Generate efficient machine code, then assemble and link that into executable object code. And so far, looking at the output of gcc -S, it seems pretty darned efficient

Comments

Juju 12 years, 4 months ago

Hmn, the thumbnail tag seems to be a little slow on big images.

Astryl 12 years, 4 months ago

Yes, it does. Can't think of a way to fix it, unless it was server-side (Create a thumbnail cache).

Juju 12 years, 4 months ago

Resize the image manually and upload to the file manager then use an image/url tag combo.

ludamad 12 years, 4 months ago

C++0x/11:

Great… but C++'s getting too complex. Scratch that. C++ is horribly complex, but I'm really use to it as it is, and find the idea of more complexity frightening. But it gets my +1 for having threads, hash maps, shared pointers. As much as the whole concept of 'Concepts' Makes Sense, I'm glad I don't have to worry about them, and I'm glad their not in the standard.

Astryl 12 years, 4 months ago

There. Fixed it.

@ludamad: TBH, if you're going to even try use C++, you must be prepared for complexity. Just as an interesting potential scenario from life: You nab a job at some company or other, and a few weeks in you have to rewrite the firmware for an elevator control device. Then you're going to be using a struct ROM-compatible subset of the language, with complex inlines (Assembly, not inline methods).

And C++ has been complex ever since they added in the concept of Multiple Inheritance. No, scratch that, ever since the language was born. But that's besides the point: Programming is complex.

Taizen Chisou 12 years, 4 months ago

my god that is like the best thing

ludamad 12 years, 4 months ago

Mega: Oh believe me. I understand that C++ is complex. And that programming is complex. But that doesn't mean it should be arbitrarily complex, just because it already has X amount of complexity.

Also, 'auto' is nothing like weak typing. It's rudimentary type inference : ). boost::any on the other hand …

There is a far bigger concern though I have with C++ than its complexity, believe me, I'm C++'s biggest advocate. It's the damn compile time. ConceptGCC, the preliminary implementation of Concepts, is known to be impossibly slow. (Of course, it would have got a lot better with time if Concepts were in the standard, but the point stands).

The compile time isn't necessarily due to any specific feature, but due to the interaction of features such as conditional compilation, templates interacting with many other features and existing only in headers, etc, that cause much duplication of effort for the compiler. I would love a language that captures the beauty of C++ and richness of features in a much cleaner language. (In fact, I'm designing one, albeit much less focused on efficiency.)

Also efficiency isn't everything. A language must first prove itself in usability, efficiency should always be an afterthought, once proven necessary.

Anywho. I will continue to use C++ for years to come. And I will happily embrace the new standard. It is truly a unique language that you have to use for quite a while to appreciate.

Astryl 12 years, 4 months ago

It boils down, as usual, to something I have to force myself to remember: Use the right tool for the job. I'd definitely not want to even think of any language but C++/C for creating a kernel, (Of course with some C++), but I'd rather use Python for anything involving creating a parser, Java for threading, either for networking, etc.

As for compilation time, it's often a moot point (With the exception of ConceptsGCC). You have to use design patterns to reduce dependencies, thus reducing compile time (Unless you rebuild your project).

ludamad 12 years, 4 months ago

While -carefully- designed C++ can drastically reduce compile time, any rich use of C++ features such as highly nested templates etc will cause much overhead in terms of compile time. But yes it is an important tool as a C++ programmer. In my game I have one module that links to the main game that uses Boost out of necessity (for threading + networking), and the rest is blissfully unaware of any Boost headers.

Astryl 12 years, 4 months ago

And we mustn't forget the ability to copy+paste the definitions we need from header files if we're not using too many of them. I sometimes do that with the GLU library.