Ian said:
Right, but it's not something a Java (or VB) programmer would have
thought about. So for you it's no problem, but the OP asked the question
from the point of view of someone learning the language.
I'd argue that this isn't true if he has been writing good Java.
Garbage collection no, you do have to think about lifetime of object
issues at the design level, as part of the design.
In Java, most of the time, your work stops there. A quick evaluation,
just to be sure that garbage collection IS adequate, and no real code to
write, except in the exceptional cases (somewhere between 5% and 10%)
where it for one reason or another, you do need determinist disposal.
In C++, when you've handled the design aspects, your work has just
started. BUT... if you get the design aspects right (which you should
be doing in Java as well), most, if not all of the extra work is just
grunt work -- it doesn't require much thought, and while it often
requires more code than one would like, C++ does have several
techniques, such as destructors, which make it actually superior to Java
when you need determinstic disposal.
No so much difficult as unforgiving.
If you mean that a small mistake can do a lot of damage...
But that's the design philosophy of C and C++, isn't it? That
programmers never make an error, so if they in fact do...
IIRC, the containers use pointer arithmetic for iterators.
It depends. Some of the containers have iterators which allow
arithmetic which behaves somewhat like pointer arithmetic. All of those
containers also support indexation, however, so once again, you're not
obliged to do stupid things if you don't want to.
When it comes down to it, of course, neither C++ nor Java can be taken
as models with regards to their collections and iterators. C++ uses
really stupid names, like ++ and *, rather than a simple, understandable
next() and element() (or something along those lines), but that's just a
naming convention. Java combines access and incrementation, which is
very constraining, and not at all nice. But C++ takes the cake by
requiring two iterators -- try using one function to determine the range
that you want to pass to another function, and you'll pull your hair
out.
What I really don't understand in all this, of course, is that most
pre-Java and pre-STL libraries used pretty good, straightforeward
iterators -- like those described in the GoF Design Patterns book, for
example, or those in the OSE C++ library. Given that we knew well how
to do it before the STL or Java, it's hard to understand the design
decisions in these libraries. (The Java Collections, in fact, implement
the iterators in the USL C++ library almost exactly. Something that C++
users knew was a mistake as early as 1990.)
Still, if you are going to learn C++, you probably have to count on
investing a bit of time learning the STL. And THAT isn't easy. There
are alternatives, like the OSE library, but they aren't widely used, and
as a beginning C++ programmer, you probably won't be able to impose them
on your employer. (I have yet to succeed in imposing them, and I'm far
from a beginner when it comes to C++.)
As you don't offer up your alternative, I'll just take that as a
personal slur.
Sorry. Today, of course, std::string is pretty much standard. I don't
know of a compiler which doesn't support it, and I don't know of any new
code which doesn't use it.
Before around 2000, of course, this wasn't so true. But I've still
never seen a C++ application which didn't use some sort of String class.
Historically, it was the first class you wrote; even today, a simple
String class is a good exercise for a value oriented class.
Think of it from a Java point of view. If the language didn't provide
java.lang.String, would you really use Char[] with a '\0' terminator?
Or would you write your own String class?
The OP mentioned jobs that ask for C++ experience. Often that means that
they have an existing code base, and often the programmer who proceeded
you used STL.
That depends. Real support for STL has only appeared in the last few
years, so if the code base goes back some, they more likely have some
third party library, or their own. And if they have their own, you'll
find real resistance to the STL, even if their own is worse (and believe
me, I've seen lots worse that the STL).
On the other hand, one of the major motivations today for taking on new
C++ programmers is to acquire knowledge of these new techniques.
Personally, at the application level, I"ve yet to find the slightest use
for template meta-programming (although it's fun -- very intellectually
challanging), and I find the STL a disaster. But... good knowledge of
the two will almost certainly land you a job.
I like the associative containers for parsing lvalue,rvalue pairs into.
Agreed. Although as usual, the interface is a bit twisted. This is one
point where Java is definitly better, although when I did Java daily, I
missed the lack of type safety.
Yep, second the Meyer's book.
It's the Meyers' books. "Effective C++" and "More Effective C++" for the
language, and "Effective STL" for the library.