Live data from Hacker News

Ask HN: How do I learn C and C++ when I love high-level languages?

news.ycombinator.com

41–50 of 62 posts

Re: Ask HN: How do I learn C and C++ when I love high-level languages?

#41
post #37

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…

+1 on A Tour of C++. ~200 pages that do a fantastic job of introducing the language.

Re: Ask HN: How do I learn C and C++ when I love high-level languages?

#42

Earlier 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?

Performance reasons

Re: Ask HN: How do I learn C and C++ when I love high-level languages?

#43
I'd say you just get the book "C Programming: A Modern Approach" by K.N. King. At the end of every chapter there are some exercises & challenges.

It'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?

#44
You could try doing a cross-platform (iOS/Android) game with a C++ framework like Cocos2d-x. I read through Cocos2d-x By Example (http://www.amazon.com/Cocos2d-X-Example-Beginners-Guide-Enge...) last year and it was pretty good. Didn't assume a prior knowledge of C++

Re: Ask HN: How do I learn C and C++ when I love high-level languages?

#45

I 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…

There's also the advantage of sequential memory access, it's generally not idiomatic in higher level languages to use contiguous arrays.

Re: Ask HN: How do I learn C and C++ when I love high-level languages?

#47
Good C++ isn't that far from high-level languages. Look at the bullet points here:

http://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?

#48
Head First C is an excellent book. It introduces some concepts such as variadic functions and function pointers too early. You might need some supplements on them. I suggest reading through the head first c book and watching youtube videos on topics, you don't quite get at the first time.

Re: Ask HN: How do I learn C and C++ when I love high-level languages?

#49
Stop being scared of pointers, they aren't magic and you've been using them all along. In most high level languages you are using a pointer for any variable that's not a number. Which is why when you assign one variable to another and modify one it modifies it from the perspective of the other. Because they point to the same object.

Fundamentally, 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?

#50
I researched this same question back in 2011. One of the most recommended books is "Memory as a Programming Concept in C and C++":

http://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.

Post reply on HN