Monday, May 29, 2006
Let's make this clear: the notion of programming language has acquired a very new meaning in the last 10-15 years and now means much more than merely a language (which is more or less set of rules how to formally lay down the algorithm, like a human language is a way to semi-formally express one's thoughts). Rather, programming language must also have certain standard libraries, or standard bindings for number of important things such that:
- Regular expressions;
Moreover, a language is to include some minimal native datatypes, such that arrays, lists, associative lists, etc.
In this sense, neither plain C or C++ are languages till we attach to them required libraries; one such library is GNU libc, which includes most, if not all, of items listed above.
Still, C+GNU libc is not a language since it does not possess all required datatypes which are either native or standard. That means that virtually any not-completely-trivial programming job in C must begin with writing some "utility" functions (such as expandable arrays) or at least adopting some 3rd-party external library. Good explanation of this problem with C (suggesting C++ as a better choice) could be seen here.
In this respect, C++ does possess a uniques feature that C does not: STL. (C++)+GNU libc+STL can be qualified as full-featured language and as such compared with Python, OCaml, Java, .NET, Haskell and other popular systems.
One immediate trouble that must be mentioned is the lack of central Internet resource documenting this (complete) language. Here is a list of most important resources available:
- C++ language structure: The C++ resources network; good explanation of basic language constructs with source code examples. Look, for instance, at their page explaining templates;
- GNU libc has official documentation .While it isn't bad, it's not perfect either. Many pieces of GNU libc can be better documented somewhere else; see for example very detailed UNIX sockets in C FAQ; there is also a good UNIX reference here.
- STL is the most difficult thing to find a good documentation for. C/C++ Reference is good but very very brief; there is also somewhat outdated but still very much useful SGI STL documentation; See also A Tour of the Standard Library from Bjarne Stroustrup.
- There is also GNU libstd++ documentation which is not really a documentation but a collection of pretty much random remarks that deal with some specifics of GNU implementation of ISO C++ standard as well as with other issues of interest;
- The official C++ page of the language creator and standardizer Bjarne Stroustrup must be mentioned here;
- Very classical C++ FAQ is very much up-to-date and has a bit of everything.
Well, I am not impressed.
Very brief list of main problems I see is:
- There is no simple and safe way to call C functions. Most libraries that C++ programmer is using are C libraries, and while calling C functions isn't difficult it often presents challenges copying between std::string and char* "strings", dealing with const, etc.;
- Code tends to be tedious and hard to read. Things like that: std::vector<std::string>::iterator ii=my_arr.begin() do not cause me any pleasure to read or to write;
- Lack of Java-style interfaces is killing me. Hasn't polymorphism always been considered part of OO programming paradigm?
- At least with GNU g++ error messages are often meaningless and extremely long with plenty of reference to internal include files that I have no interest in;
- In principle, wring in C++ you might not worry about memory allocations (unless you are explicitly calling new, which is rarely needed in small programs, why would you call delete?) but this might create a false sense of security; unlike all other relatively high-level language, you are writing programs without a protection of a garbage collector, and I am reasonably sure many programs are in fact leaking memory;
- STL is often a poor replacement of complex data types from other languages. E.g., functors do in principle exist but are rarely usable; number of functions is very limited. Try, for example, to print a map sorted by value (trivial in Perl or Python) and see how much code you'll have to write to execute this quite trivial and not at all uncommon task. Or, how do you like testing whether map a has key key with this code: a.find(key)==a.end() ?
- I may be stupid, but I fail to see how iostream-style formatted output is better that printf. How is this std::cout << std::hex << std::setw(8) << std::setfill('0') << ii << std::endl; easier than this: printf ( "%08X\n", ii ); (Well, actually C++ FAQ mentioned above has a direct response to that)
UPD. Found more C++ documentation, including the ISO standard as 776-page PDF file, here.