Some advice I can offer, be very very careful of the quality of resources you use to learn C and C++. In particular look at the year the book/tutorial/etc. was written and try to get stuff that was written or updated recently. Both languages have been around for many years and evolved quite a bit. Advice about how to use C++ in 1990 is vastly different than how to use it in 2014 with modern C++ versions. Also read so…
Ask HN: How do I learn C and C++ when I love high-level languages?
41–50 of 62 posts
Re: Ask HN: How do I learn C and C++ when I love high-level languages?
#42Earlier quoted context omitted.
"All general-purpose programming languages can solve the same problem." That's not really true, in general. They can all compute the same things. Some problems have constraints beyond "what is computed".
I don't get it. What do you mean?
Re: Ask HN: How do I learn C and C++ when I love high-level languages?
#43It's an excellent book (see the ratings on Amazon) and also fun to read through.
C should be much easier to learn than C++. The language is much more basic feature-wise and the standard C library is very small indeed.
[0]: http://www.amazon.com/Programming-Modern-Approach-2nd-Editio...
Re: Ask HN: How do I learn C and C++ when I love high-level languages?
#44Re: Ask HN: How do I learn C and C++ when I love high-level languages?
#45I can't think of anything that I will like to make in C/C++ Let me address the motivation issue. C/C++ strength is speed. Write a simple piece of computation in your favorite language (Ruby for instance). Write the same in C and measure the time it takes. Once you see how slow Ruby is, you may get excited by C enough to continue exploring it.
C/C++ can also produce data structures that are more compact than any managed language could allow. For example, one of the oldest tricks in raytracing is to stuff a few bits of information into the lower bits of a float, so that you don't have to waste a whole byte encoding the metadata for a kd-tree node. But even this is ultimately related to speed. It allows the programmer to squeeze a whole lot into a cache line…
Re: Ask HN: How do I learn C and C++ when I love high-level languages?
#46Re: Ask HN: How do I learn C and C++ when I love high-level languages?
#47http://msdn.microsoft.com/en-us/library/hh279654.aspx
If you primarily use value and reference semantics, RAII, smart pointers, STL containers and algorithms, etc, C++ looks a lot like a really powerful high-level language, because that's what it is. Things only start to get ugly and/or low-level when you are trying to heavily optimize things.
Stroustrop (mentioned in other comments) is a great way to get started, and Effective C++ (http://www.amazon.com/Effective-Specific-Improve-Programs-De...) and its cousins will help you not shoot yourself in the foot.
C is a whole different beast. If you've coded in Java, you have a basic idea of how to do encapsulation in C++. Encapsulation in C is nearly impossible to guarantee. Really, a lot of C programming relies heavily on negotiated conventions and design by contract. Learning the C language is pretty easy (read K&R some weekend), but learning to program well in C is a completely different thing.
Re: Ask HN: How do I learn C and C++ when I love high-level languages?
#48Re: Ask HN: How do I learn C and C++ when I love high-level languages?
#49Fundamentally, though, they're a value just like any other, just a number that's an index into the giant array called memory. The language provides convenient syntactic sugar to 'dereference' them, which just means evaluate the address and index to it.
Basically:
*blah
is equivalent to: all_of_memory[blah]
which, incidentally, is equivalent to: 0[blah]
and back around again: blah[0]Re: Ask HN: How do I learn C and C++ when I love high-level languages?
#50http://www.amazon.com/Memory-Programming-Concept-Frantisek-F...
A rather expensive book but stellar reviews. I borrowed it from the library. It's very concise too.
For C++ a lot of people still recommend "Accelerated C++":
http://www.amazon.com/Accelerated-C-Practical-Programming-Ex...
because it teaches you "canonical" C++ instead teaching you "C with classes," which seems to be a common complaint among veteran C++ programmers. It's very readable too.
I'm going to pick up "Writing Great Code":
http://www.amazon.com/Write-Great-Code-Understanding-Machine...
because it explains computer architecture. Once you start programming in C/C++ you are much closer to the metal and having an understanding of the architecture will lead to better choices.