First read C++ annotations. It's free and online.
Honestly I don't think you're best off starting with TDD. TDD is really cool once you realize its true value. And to do that, I believe you've got to have your share of agonizing debugging.
So first you might want to just implement some random programs in C++. Just make-up games and such, or find some people who want things done (and maybe get some money out of it). Take your implementation seriously.
Then, once you think you're really good at programming (at this point, programming for you will probably stand for "making super complex things ultimately - and magically - work), read some books about Testing. Watch some GoogleTechTalks about testing.
Good authors you should remember: Robert C. Martin, Michael Feathers, Martin Fowler, Kent Beck.
Then search for some videos about clean, testable code by Misko Hevery from Google.
Almost every word you might think of adding as a keyword to a language has almost certainly been used as a variable name or some other part of working code. This code would be broken if you made that word a keyword.
The incredibly lucky thing about auto
is that it already was a keyword, so people didn't have variables with that name, but nobody used it, because it was the default. Why type:
auto int i=0;
when
int i=0;
meant exactly the same thing?
I suppose somewhere on the planet there was some small amount of code that used 'auto' the old way. But it could be fixed by removing the 'auto' and it would be working again. So it was a pretty obvious choice to repurpose the keyword.
I also happen to think it's a clearer meaning. If you've worked with variants and such, when you see var
you may think that the declaration is somehow less strongly typed than if you pressed all the keys yourself on the keyboard to specify the type of the variable. To me, auto
makes it clearer that you're asking the compiler to automatically deduce the type, which is just as strong as if you had specified it yourself. So it really was a very lucky break that made a good name available to the committee.
To clarify the (small) breaking:
If you had
auto int i=0;
and tried to compile with a C++ 11 compiler, you will now get an error such as
error C3530: 'auto' cannot be combined with any other type-specifier
This is trivial, you just remove either the auto or the int and recompile.
There is a bigger problem though. If you had
auto i = 4.3;
C and the really old C++ would make i
an int
(as it would if you left off auto
- default declaration was int
). If you have gone a really long time without compiling this code, or have been using old compilers, you could have some of this code, at least in theory. C++ 11 would make it a double
since that's what 4.3 is. (Or maybe a float
, I'm still in Boxing Day mode, but the point is, not an int
.) This might introduce subtle bugs throughout your app. And without any warnings or errors from the compiler. People in this boat should search globablly for auto
to make sure they weren't using it the old way before they move to a C++ 11 compiler. Luckily, such code is extremely rare.
Best Answer
The motivations in C++ are more extreme, as types can become vastly more convoluted and complex than C# types due to metaprogramming and other things.
auto
is faster to write and read and more flexible/maintainable than an explicit type. I mean, do you want to start typingThat's not even the full type. I missed off a couple template arguments.