Live data from Hacker News

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

news.ycombinator.com

31–40 of 62 posts

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

#31
Download a Commodore 64 emulator and learn ROM BASIC. Write a game in it. After that, try learning C again. You'll be infinitely thankful for such high-level constructs as functions and structs. And you'll understand what they do a bit better, probably.

Edit: I'm sorry if this sounds condescending, but I really mean it. Basic is about one step above assembler - you get variables and nice access to some basic IO, but it's much closer to the metal than C. It really doesn't even have functions, you have to do GOSUB/RET yourself. It's also an extremely simple language. But it will give you an idea on how computers work at a basic level. After that you should have a much easier time grokking C.

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

#32
post #25
post #17

Go to a code practice site like hackerrank or oj.leetcode (personal favorite but I suggest using an external compiler for it) and solve problems. Start from the simplest ones and make your way up. Once you solve a problem, go back the following day or week and without using a reference solve it from scratch. After solving a problem look at the solutions provided in the forums. A lot of the time they will be a lot mor…

four halves, huh?

What can I say, C++ isn't easy to learn :)

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

#33
Why do you want to learn C or C++ if you can't think of something you'd like to use them for? I've written a fair bit of assembler and occasionally still do tiny projects in C or C++, but my language of choice (by far) is the highest level general purpose one I've come across.

IMO you don't need to know either C or asm to be a great programmer. Read a book on operating systems instead and you'll know all you need to about hardware. Add a thorough coverage of algorithms and data structures, and you're in a better position to write effective software than many I've worked with.

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

#34

Do you really need to learn a another language, when you don't like its features? All general-purpose programming languages can solve the same problem.

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

#36

Get yourself an Arduino or some other similar cheap hardware dev kit and build some project for fun? It's a start.

That's what I was going to say - you can really appreciate when pointers are useful if you manipulate registers or memory-mapped I/O.

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

#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 some reviews of the book before you spend any time reading it. The mid 90's were a really bad time for C++ in my opinion since it was kind of a new language and being pushed heavily as the default 'learn computer programming' language (which Java later usurped). This means there are tons of very badly written and confusing resources that do more harm trying to teach C++ than actual good. Stuff like Deitel's C++ How To Program, etc.

For C++ in particular I can recommend:

Thinking in C++ (http://mindview.net/Books/TICPP/ThinkingInCPP2e.html) Although it's getting a little old, I think this is a great resource for someone just picking up the language.

A Tour of C++ (http://www.stroustrup.com/Tour.html) Great small intro to modern C++ programming, by the creator of the language.

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

#38
post #33

Why do you want to learn C or C++ if you can't think of something you'd like to use them for? I've written a fair bit of assembler and occasionally still do tiny projects in C or C++, but my language of choice (by far) is the highest level general purpose one I've come across. IMO you don't need to know either C or asm to be a great programmer. Read a book on operating systems instead and you'll know all you need to…

Because I don't want to get that feeling when I'm reading some C/C++ and have absolutely no idea what's going on.

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

#39
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.

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

#40

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.
Post reply on HN