4 ms·
I recently started working my way through the C++ Primer after years of avoiding C++ and its reputation for complexity. My first impression is that it has actu
by AndrewBissell 13y ago
I recently started working my way through the C++ Primer after years of avoiding C++ and its reputation for complexity. My first impression is that it has actually matured into quite a nice language which strikes a balance between simplicity and programmer power which just isn't all that bad, especially given its genesis.
There are some annoyances for sure -- lots of mentions of "subtle" differences in how certain concepts work are already cropping up in introductory chapters. I'm sure there's some reason that "auto" discards top-level qualifiers while "decltype" does not, but trying to ingrain so many of those distinctions is a pain.
I'm also glad to have learned both Java and C before trying C++. The former so that I know some OO mistakes to avoid (I would not want to discover the pain of over-enthusiastic use of generics while knee deep in compiler template errors), and the latter because learning manual memory management and the stack/heap distinction is enough of a cognitive load without layering all of C++'s extra features on top. It's also good to have a bit deeper understanding of what's really going on with the memory and pointers under the hood, before handing over control to automatic resource management and smart pointers and such.
- jpgvm 13y agoI too have started learning C++11 recently after having never really had success picking up the language in the past. Coming from C I found C++ to be really difficult when I tried to pick it up a few years ago. I have since learnt Python,Ruby and C# and now I am having alot more success. So I really do second your opinion that learning something like Java (in my case C#) really helps a ton. I also highly recommend checking out the books recommended here: http://isocpp.org/get-started http://isocpp.org/get-started I am currently reading C++ Primer. :)
- userbinator 13y agoC++ is mostly an extension of C (there are some subtle differences like changes in the type system), so I also recommend C before C++; understanding how classes and methods are implemented (which would be the natural way to do it in C anyway) gives you better knowledge of practical, pragmatic use of OOP. As you mention, the layering of C++ is another thing that can guide the approach to learning the language: begin with the simple concepts that C++ added, like classes with methods, and then move on to inheritance, virtual methods, overloading/overriding, operator overloading, exceptions, and then templates, making sure you understand the previous ones before proceeding to the next extension. It's a big language, with many features, not all of which you'll need to use for any one application.
- pjmlp 13y ago> C++ is mostly an extension of C (there are some subtle differences like changes in the type system), so I also recommend C before C++ Never ever do this in 2014. It is the path of writing unsecure code. Modern C++ has better, more secure, approaches how to write code. Leave C like coding to legacy code.
- userbinator 13y ago> It is the path of writing unsecure code. Why? If anything you will learn more about the types of bugs that lead to security issues, and thus gain a better understanding of how to avoid them. I feel like "security" is the new "think of the children" phrase these days.
- pjmlp 13y ago- Prefer STL data types (vector, string...) over the native ones - Use references for modifiable parameters. No need to check for null - Templates, enum classes, const/constexpr, inline calls instead of preprocessor macros - Use of RAII and smart pointers over manual memory management > I feel like "security" is the new "think of the children" phrase these days. It was nothing new. It was present since the early days in the form of languages like Mesa(1970), Modula-2 (1978), among others. Just that developers got to forget about them when UNIX got out of the universities into the enterprise. Nowadays we pay for it as we discover how important it is to have secure software. edit: typo (import => important )
- userbinator 13y ago> Nowadays we pay for it as we discover how important it is to have secure software. I'm going to give a very controversial perspective here: Things like jailbreaks and homebrew on consoles are possible because of certain "security flaws" that are more common in languages like C and C++. If everyone used "safer" languages, wouldn't these become much rarer? If it weren't for this "insecurity", would our computing devices and software be even more locked-down and restricted against us and more control be put in the hands of large corporate entities or governments? Making software more secure against malicious attackers also makes it more secure against those fighting for freedom and control. The world is not quite so black-and-white...
- saurik 13y agoGenerally, the goal of auto is to create a variable whose purpose is to store a value of the type you have: you called a function, got a constant reference, but to store that you need a concrete value. Generally, the goal of decltype is to compute a type based on other code whose type you don't already know: a simple canonical example is to make a function that does something and transparently returns the result "as if" it were the original code. These are two drastically different use cases and, given the semantics of the various qualifiers, it makes sense to strip them for one and not for the other, lending to two different syntaxes. If you find yourself needing to transparently store the result of an expression, in C++14 you can use "decltype(auto) ;P".