As a Java programmer, I'm looking to learn either C or C++ by writing a database manager. Obviously, Java shares many idioms with C and C++, but yet both bring vastly different program design challenges. I'm looking to for a way to make this exercise as educational as possible. What aspects of taking on this project in C or C++ can help me make a decision about which approach will teach me the most, as a Java programmer?

One particular target of this exercise would be at least a subset of the spatial extensions in PostgreSQL.

Obvious issues to consider would be goodness of fit of C vs. C++ for:

  • modeling concepts of databases in general.
  • modeling spatial modeling in particular

Another major point would be the degree of expected difference from Java. Would a good, idiomatic design in C++ be enough different from a design in Java to teach new, different concepts, or would it mostly be the same concepts with slightly different syntax? Would a good design in C contain more concepts that were new or different than one in C++?


2 Answers 2


First, don't take C and C++ as the same beast, they are different too.

Second, from Java, you could go to one or the other. C is simpler to understand, it's almost only functions.

C++ on the other side, is widely alien if you've worked only with Java or .Net. But it might be the most interesting for you.

I recommand to get familiar with what we call the RAII (badly named) idiom as it is central to the way you manage object lifetime in C++. It's about destructors and their benefic impact on resource management. There are a lot more to learn but that might be the most interesting part.

In fact, If I was you, for any new language I want to learn, I would just assume I'm a total newbie and go for basic tutorials. Never assume you know "a lot" of C++ in the first weeks. You'll be (badly) surprised later otherwise. Try reading Accelerated C++ or/and Thinking C++ (that is meant to explain C++ from the point of view of C or Java programmer) then pass to Effective C++ books and Effective STL books.

  • 2
    +1 for "assume I'm a total newbie". enter humbly... or prepare to be humbled!
    – Javier
    May 16, 2011 at 21:38
  • thank you very much. Do you think I will have no trouble doing a dbms with C++ (I don't know for some reason many dbmss have been done in C). Do let me know if my question is foolish.
    – picmate
    May 17, 2011 at 14:23
  • 1
    @picmate> There are other such library in C++ so you might want to check how they do it. Google "c++ database library"
    – Klaim
    May 17, 2011 at 14:38

This is a pretty tough question. In the end, I think the language depends primarily on which language you want to know. That, in turn, depends primarily on the targets you find interesting.

If your interest in a database server is primarily to write something minimalist, such as for a "mobile platform" (e.g., smart phone) then the more minimalist language (C) probably fits your needs better. It lends itself better to situations where (for one obvious example) executable size matters more than flexibility or a rich feature set.

If you're thinking of a database server more along the lines of something that handles huge amounts of data, and is likely to run on relatively high-end hardware (that may well be dedicated almost exclusively to running that software) then C++ is likely to be a much better fit. C++ does have some cost (larger executables) for small programs, and many of the features it adds to C are intended primarily for keeping code organized in larger programs.

I would urge caution on one point: whichever way you go, be prepared for the fact that any language change tends to be at least a little painful for a while. Especially during the first few weeks, you'll inevitably find yourself thinking some variation of: "but why couldn't they just let me do X, like I'm used to?"

If you keep having those thoughts for a long time, it may simply be that Java is a better fit for your way of thinking and programming, and you'll be better off sticking with Java. I'd caution, however, against concluding that too soon -- like I said, especially for the first couple of weeks, and to a lesser extent for a few months, they're almost inevitable, even if you'd find C or C++ preferable given enough chance.

In fairness, I should add that even though I don't want to go back to them, there are a few features of languages I used to use that I still miss. I haven't written any Pascal in years now, but I still miss its built-in support for sets, and being able to do things like if X in 1..20. Even Fortran had a few features I still miss. I certainly don't miss those pieces enough to give any serious thought (any more) to going back to using Fortran at anything short of dire need, but ~30 years ago when I was first learning Pascal, I certainly did.

In fact, at one point I did actually try to go back to using Pascal after using C for a few years. Moving from Fortran to Pascal was almost euphoric. Moving from Pascal to C never felt nearly as positive, so after a few years of using C, I decided to go back to Pascal. That was, in a word, horrible. Despite some good points that were easy to remember, Pascal had far too many horrible shortcomings that I'd managed to forget (and hadn't originally noticed how huge of an improvement C really provided). Fortunately, it wasn't all wasted effort though: it got me out of the C rut enough that I never returned to it either, and moved on to C++ instead (though, unfortunately, I haven't found anything sufficiently attractive to get me out of that rut since, despite having really tried a few times).

Not the answer you're looking for? Browse other questions tagged or ask your own question.