C++ Potential

Pages: 12
closed account (S6k9GNh0)
So today, I had a discussion as to why C++ is losing momentum, not because of its syntax, but because of the nature of the language.

1. C++ holds compatibility with C. While this doesn't sound bad, most C++ programmers tell you not to use C techniques in C++ code. The backwards compatibility isn't neccessarily a good thing in this perspective. C is easy to interface with because of its basic symbol system (which is generally no mangling, i.e. function void test() will have a symble of "test"). ASM, C++, D, Java, all have some sort of ability to interface with C but not with C++ (D somewhat does, and technically, you can in ASM if you know the symbol mangling used but that's definitely not ideal). C++ mangling isn't "portable" in such a sense and makes C++ less viable for library programming. Linus Torvalds often complains of the mixture of C++ later in a C library which causes unfortunate problems such as minor incompatibilities, the want to change the entire codebase, and poor code in general. Although he's an asshole at saying what he does, I can currently see that point of view.

2. Compilation system. Plenty of people complain about the C preprocessor. Although I'm rather fond of it after so many years of use, I can begin to see its age. Java, Python, and D all have a compilation system that is not only convenient, they are compatible with systems programming languages (D being a systems programming language itself). D unfortunately has problems with this as the interface files (.di files) are rather poorly generated when the want to hide implementation arises. Although we hand create them _everyday_ here at C++.

3. And although this doesn't really concern me, the complicated syntax. Now, to me, C++ is rather simple to use. However, the D language and various Java and Python players bring up vital points on simplistic syntax grammars and you'll often find snippets commenting on the want to avoid any complex grammar related to C++.

EDIT: Oh, and I hate having to use C++'s half assed version of interfaces. D definitely kicks C++ ass at this one.

--------------------------------------------------------------------------------

I'm definitely not saying D, Java, Python, or any of these language surpass C++. As a matter of fact, nothing can rival C++ or C at this very moment in power and userbase. I'm still rather upset at the choice of Java for the Minecraft server software which, while not very optimized already, caused immediate problems such as 4gB+ RAM dedicated servers running out of memory.

But one cannot disagree with the idea that C++ quite obviously has some rough points that should and can be addressed, otherwise C++ will eventually fall out of the "the next big language" category.

The reason I posted this is for feedback. I'm currently using C for most of my applications and C++ for applications that aren't going to be reusable, and even a mixture of the two. I don't like that. I was thinking about how I'd rather use D than C++ with C and the only reason I don't is because I'm not sure if I could part with the Boost libraries (and D has community issues as in it has nowhere near the same library support C++ gets). I've yet to find something that surpasses C as a procedural language. Google GO is probably the next best thing and it's rather poor in quality at the moment, also getting rid of conventional things such as the while/do-while loop and forcing you into a garbage collector (once again, something I feel is truly not needed).

-------------------------------------------------------------------------------

On a side note, I'm currently taking a Programming course in college. I'm incredibly disappointed. I've finished _all_ of the assignments in the first two weeks outside of the tests which he hasn't posted up yet. The language used was, of course, C++. I cannot stand going out of my way to upload VC++ project files for this guy and I definitely can't stand uploading a screenshot of the resulting program and using Word Document formatted files to upload code. My heart aches for a class that teaches flexibility and something interesting.
Last edited on
Yeah, C++ is a silly language with loads of flaws; it's just because we love the concept that we continue with it.
ASM, C++, D, Java, all have some sort of ability to interface with C but not with C++


I read down to here and decided I'd better not read beyond it. The unmentioned "some sort of ability" to interface with C++ is suppressing the name mangling and exporting a C-compatible object file.

Basically, anytime you need something (component, library, module, function, etc.) to be compatible with other languages there is a boundary. These boundaries may (and often do) require conversions from higher-level constructs to simpler, more compatible ones. Take an error handling policy for example. In C++, we may find exceptions beneficial and all of the "internal" code should share the same policy. At a component boundary, however, exceptions must be converted to error equates to be exported into a C application. This is more of a pro for C++ than a con, IMO.

Thus, I would spend a little more time in C++ before joining one side or another...
What is a c++ interface? Is that the use of the virtual keyword?

When I first read about the virtual keyword, I had great difficulty grasping what was the point in using it.

Now, three years later, I still don't get it.

[Edit:] Just came up with a scenario where virtual could come in handy: if you would like to store a collection of heterogeneous objects in a vector. However, this scenario never happened to me: has it occurred to you? I find that whenever I need to treat a collection of objects, they are of the same type, or are completely unrelated (say, are members of the same class).
Last edited on
closed account (S6k9GNh0)
moorecm, SFML does this but I'm still not happy with it. Your actually wrapping C++ in C functions. Although, the point that you can make a C library using C++ syntax stands, that's not really a plus. Mostly any other systems programming language will probably be forced to do the same thing, D included. This helps with calls from assembly and adds obvious portability. That wasn't really the point anyways.

tition, C++ interfaces are somewhat poor as they aren't really supported very well. I'm not sure if they're even really considered "interfaces" although they can be used as such. If you look at D grammars, the support there is more robust (if not too robust). Not many know what "virtual" does. All it says is that the function declared virtual is put into the function table that the pointer associated with it (which is present any time a virtual function is (including in the parent) present if I'm not mistaken) points to. When a class implements a virtual class (or it's virtual functions), it can be downcasted into that virtual interface class and used as that virtual class while calling the implemented functions. For instance, If A is a pure virtual class and B inherits and implements A, B can be casted into A and be used as A while actually calling functions from B. The use of this is kinda abstract sometimes but it's used commonly in things that need to be switched out *at runtime*. If I'm not mistaken though, generic concepts (commonly used and maybe even coined in Boost) can be used as an alternative while avoiding the extra vpointer. Although, I don't remember the advantages and disadvantages, it's been awhile...

http://www.cplusplus.com/doc/tutorial/polymorphism/

So, I'm not sure if "pure virtual classes" which are simply poor conceptual interfaces should be a plus or a minus or neither. But when I work with interfaces, a clear syntax is a bit easier on the eyes.
Last edited on
Well, when I was writing myself a generic Matrix class some years ago, I considered using the virtual keyword. I even gave it a run, but it took me 30 minutes to give up. I don't think you can write a sane/useful Matrix (or Polynomial, etc.) class with the use of virtual.

Of course, polynomials/matrices are collections of homogenous objects, so the use of virtual naturally doesn't make sense.
Last edited on
My take on programming language not only C++ in general is the business or users indirecly 'drive' the language. Reason being why do we use some programming language to produce some programs? We do it so the final program can improve productivity and automate a lot of tasks for business and user correct?

If say a program takes 1 year to be delivered and one that takes half a year. As a business and user, which would you prefer? They won't be keen to know what programming language or algorithm is used underlying. What they want is a useful program that do the job for them fast and accurate and possibly in as shorter a time to delivery as possible.

So there lies the programming language evolution. It is getting more abstracted away from the OS and system level to the business level so programmers can focus on solving problems than worrying about those non-business stuff (which by the way is very important I know). It also make the final delivery much faster than usual.

This is a change that cannot be stopped and hence C++ is starting to show signs of age. Of cuz since most OS and systems stuff are built using low level language, there will still be a need for C++ for e.g But the question I am posing is if you are seeking for a job, how many vacancies are there for business programmers and how many are there for systems/infrastructure programmers?

I am in fact pretty much programming language neutral. I follow the programming language evolution. If say ABC is the next language in year 2020 onwards, you can bet I will dabble in it just like what I did with Android now. I like to ride along the wave rather than stuck in some far-away place reminiscing on past glory :P
@tition Consider a tile manager. You have an abstract base class of a tile:
1
2
3
4
5
6
class Tile {
// etc
public:
   virtual ~Tile() {}
   virtual void OnPlayerEnter(Player&) {}
};

with a derived tile, e.g.
1
2
3
4
5
class PoisonTile : public Tile {
// etc
public:
   void OnPlayerEnter(Player& p);
};

All the tiles are stored in a list:
std::vector<Tile*> tiles;
Then when a player stands on tile 67, one calls tiles[67]->OnPlayerEnter(&thePlayer) and the appropriate OnPlayerEnter(Player&) function is called even though the pointer is to the base class. This is an example of the use of virtual, unless I have misunderstood you.

I'm still rather upset at the choice of Java for the Minecraft server software which, while not very optimized already, caused immediate problems such as 4gB+ RAM dedicated servers running out of memory.


Knowing the size of Minecraft userbase, and the fact that the company has *no* experience in running such big projects, I wouldn't expect a different scenario, regardless of the language they chose. Probably if they used C++, except the problems they actually faced, they would have 10 more chances to get killed by other things.

Err, wait ... WTF have they used? 4 GB servers? Like a cheap laptop? Hello, my laptop has 6 GB. Running world-size MMO server by a company that has $30M per year or more in revenues on a commodity hardware? :D Good to hear, they aren't running it on a shared hosting... :D

I thought a "server" these days is something starting from 64 GB and 24 cores. And IBM calls it a cheap server.
Last edited on
Personally, I found the C compatibility very annoying, especially because many online C++ beginner guides use a mixture of both (e.g. using c-strings rather than c++ strings). They claim it's important to know and understand what happens "behind the scenes", which is true, but it also makes your first weeks/months/years very difficult. It's very frustrating to be taught a mixture of C and C++ in one guide, and then in another guide discover that using those C functions is bad practice. I guess it's due to the language's age that every experienced C/C++ programmer has his own style, but until you have your own, it's very difficult to get into.

Here at my University, they've given up on teaching C++ and skipped to C# for "actual programming courses" and Java for all the "okay it's not vital but it might be useful for them some day" directions.
closed account (S6k9GNh0)
rapidcoder, that's nice that your laptop has that but I'm not talking about your laptop. Go look on a price check on a quality server with *at least* 4GB. It's much more than it should be to run a simple Minecraft server. Or maybe you're rich and you don't give a damn. Unfortunately, not everyone is rich my friend.
Last edited on
Xander314, just to clear up the terminology, your example above demonstrates runtime polymorphism, which can be achieved using virtual methods. An interface describes the means to access and use a type. Some who have a, Java background, will call a class in C++ that is "purely" abstract (containing no concrete methods) an interface because it can be likened to the Java keyword. In C++ there are different interfaces, for example, the public interface comprises not only the class's public methods but also related methods in the same namespace that are available via Koenig lookup (stream insertion/extraction, for example). There is also a superset of that interface that can be provided for subclasses, etc..

The C++ In-Depth Series of books covers all of this and more. I highly recommend reading them.
computerquip wrote:
EDIT: Oh, and I hate having to use C++'s half assed version of interfaces. D definitely kicks C++ ass at this one.


I am curious. What does a D interface do that a C++ pure abstract class does not?
Last edited on

rapidcoder, that's nice that your laptop has that but I'm not talking about your laptop. Go look on a price check on a quality server with *at least* 4GB. It's much more than it should be to run a simple Minecraft server. Or maybe you're rich and you don't give a damn. Unfortunately, not everyone is rich my friend.


It's not that I'm rich or I'm not, but Minecraft company definitely is rich enough to afford a good server. They sold over 3M licenses. Do you really think spending $7000 is "expensive for them"? For $7000 you get a 24 GB quality IBM server with 4-cores with 12 MB cache.


It's much more than it should be to run a simple Minecraft server


You can't say until you know the workload. I worked for a company building MMOs with millions of registered users and it is not all that easy. You have to keep a huge database which benefits from caching, so actually the best thing is to have just enough RAM to hold all the data of the active users + all the data of the virtual world. It can be much more than 2GB - even the AAA desktop games (single player!) require often more than 2 GB to run fluently (yep, and they are in C++).
Last edited on
closed account (1vRz3TCk)
rapidcoder wrote:
It's not that I'm rich or I'm not, but Minecraft company definitely is rich enough to afford a good server.
I got the impression that computerquip was talking about His own server for Minecraft, I may be wrong.
Ah! Then ok. But then it just means they screwed something in the code like memory leak or something. It is much harder to make memory leaks in Java, but it is still possible.
@morecm My post was in answer to this:
tition wrote:

When I first read about the virtual keyword, I had great difficulty grasping what was the point in using it.

Now, three years later, I still don't get it.

[Edit:] Just came up with a scenario where virtual could come in handy: if you would like to store a collection of heterogeneous objects in a vector. However, this scenario never happened to me: has it occurred to you? I find that whenever I need to treat a collection of objects, they are of the same type, or are completely unrelated (say, are members of the same class).


I did realise the type of interface being discussed here - I don't know much about them in other languages, but I did come across them when I started learning C#, albeit a long, long time ago.

The C++ In-Depth Series of books covers all of this and more. I highly recommend reading them.

I'll look into them some time then :)
Last edited on
[Edit:] Just came up with a scenario where virtual could come in handy: if you would like to store a collection of heterogeneous objects in a vector. However, this scenario never happened to me: has it occurred to you? I find that whenever I need to treat a collection of objects, they are of the same type, or are completely unrelated (say, are members of the same class).
You have a collection of UI elements that need to be redrawn every once in a while. Of course, it's not the same to redraw a button than to redraw a progress bar, but the parent window needs to be able to redraw all of them. While you could in principle keep individual vectors for each type of object, it's much easier to make all of them derive from Drawable and implement the draw() function.

Another example is the interpreter pattern. This grammar:
1
2
3
expr: //...
    | expr '+' expr
    | expr '*' expr;
can be represented by this class hierarchy:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Expression{
    //...
    virtual int evaluate()=0;
    virtual int propagate_constants()=0;
    //...
};

class Addition:public Expression{
    Expression *lop,*rop;
    //...
};

class Subtraction:public Expression{
    Expression *lop,*rop;
    //...
};
closed account (S6k9GNh0)
Galik, it gives the keyword "interface" and clear syntax as to how to define an interface. It gives many other things but you can go look for yourself if you're curious.

rapidcoder, yes, I was talking about my own server (and majority of the minecraft community).
Also, I'm not sure if you're aware but there are Minecraft alternatives that do the job about 5 to 10 times better (unexaggerated). They, unfortunately, aren't as creative as Minecraft.
Last edited on
I'm definitely not saying D, Java, Python, or any of these language surpass C++. As a matter of fact, nothing can rival C++ or C at this very moment in power and userbase.


Wait is this one of that "I can feel the C++ programmer in me dying but I don't want to admit it" kind of thread?
May his torment end soon.
Pages: 12