Live data from Hacker News

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

news.ycombinator.com

21–30 of 62 posts

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

#21
Look into more recent language features:

https://stackoverflow.com/questions/3016107/what-is-tagged-s...

http://www.stroustrup.com/C++11FAQ.html

Also, the Boost library is worth a look. C++ is fairly expressive if you wield it properly, and it offers several ways to minimize the pain of memory management. I would hesitate to call C++ "low-level". (C is another story.)

Other than that - C/C++ are used to solve different problems from Python, Ruby, etc. It is a common problem that people used to a particular toolset have difficulty identifying tasks that are suited to other tools. The suggestions to write C extensions or ports of command line tools are good ones - these will give you a taste for where C/C++ shine on a much more gradual learning curve than trying to write device drivers or kernel extensions.

Another example of practical C++ usage: in the past, I've often prototyped algorithms in Python, then rewritten them in C++ once the major bugs are ironed out. YMMV, but I found this to be faster than writing directly in C++.

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

#22

C/C++ didn't truly click for me until I had learned assembler. (Helped my understanding of every other language too.)

Assembly didn't really click for me until I learned computer architecture :p

You can always go one level down, but I would hardly say you need assembly for c or c++.

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

#23

C/C++ didn't truly click for me until I had learned assembler. (Helped my understanding of every other language too.)

This. Learn Assembly together with C.. it will make C much more clear to understanding.. and then he can go for C++.

For instance, in assembly you push/pop from stack, or you move things into the registers and from memory, you will have to deal with memory address, etc..

So he will learn the most important background about thinking in C, like stack vs. memory allocation, and what pointers really are under the hood (the memory address of a thing)

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

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

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

#27
Work your way through "A Book on C"? That's how I did it...

Actually, I think the best approach would be to pick a project for which you can construct a believable (by you) reason why it should be in C. Some possible reasons:

1) You need precise control of hardware

2) You're running in an environment where higher level languages are not available

3) You need precise control of latencies

4) You need the absolute maximum possible performance

There are various projects with these requirements of various difficulties. I would say that it might be hard to simultaneously convince yourself that a project needs the maximum possible performance and also that it is tractable for you as a newbie C developer.

A simple kernel module might not be a bad thing, if you can do your development in a VM to recover from the inevitable crashes. The reason for C will be quite clear, but tooling will suffer.

Targeting microcontrollers will be similarly well motivated at a higher degree of awkwardness.

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

#28
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?

And on the other hand...

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

#29

I don't think that C/C++ is different, this is exactly how I learned those as well. Be aware though, that C++ and C are very different languages and you should choose one. If you want to do kernel-level stuff or embedded code, C is probably a better choice than C++, whereas if you want to go into gaming or complex desktop applications (think Photoshop), C++ might be the one to choose. Pointers may be scary but they a…

C++ is also very applicable in kernel programming. See: Haiku, Darwin, Windows. I would not write a C kernel now; Linux and *BSD only maintain relative security and dearth of bugs through years of maintenance and rigorous code guidelines. C++ (even as only a thin layer over the C code) can provide ridiculous modularity and safety that C alone cannot—think RAII and parametric allocators. From a software engineering perspective alone, I think C++ is the win.

C is much better as glue code between languages than anything else.

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

#30

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

Post reply on HN