Live data from Hacker News

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

news.ycombinator.com

11–20 of 62 posts

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

#11
I would usually think of myself as a high-level langauge developer. I've recently been working my way through http://buildyourownlisp.com/ - Which I'm seriously enjoying.

It's doing a great job of teaching me C, while also reminding me how great high level languages actually are!

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

#12
I'd say just find a good tutorial type book. I got an adequate understanding of pointers from reading C++ for Dummies. Anyway, don't be afraid. Pointers require care to avoid various issues, but they're fundamentally a simple concept. You'll be fine.

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

#14
You don't necessarily have to do low level stuff with C/C++. Sure you'll still be dealing with pointers etc, but my point is it doesn't have to be very low level just because it's C/C++. Depending on what you want to implement it might be a good idea to use a framework such as Qt. http://qt-project.org/

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

#15
Take a job where you'll have access to senior C++ programmers who'll mentor you. One good way to do this is to get a frontend/webdev job at a company that also does some hardcore C++ backend development, then once you're in the company, offer to start fixing bugs in the core product as long as you get some mentoring/code reviews for them. Most devs don't turn down an offer to help.

You really want to work with people who have done C++ before, because there are a number of tricks (RAII, ownership conventions, using const references and references to signal ownership conventions, smart pointers, unique_ptr, etc.) that are common industry practice but aren't all that well-documented on the web. C++ differs from Java or Python in that often the hard part isn't figuring out how to do something, but figuring out what not to do.

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

#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 more elegant and contain things you haven't considered or seen before.

This is only half of it. The second half is to choose a mid size project, write yourself something that resembles a spec, and code it up from scratch. It could be some sys util or perhaps a video game (this will require you to learn library linking).

The third half is to read online articles and tutorials while you do the two things above.

The fourth and final half is to get yourself a book once you have a grasp on the language(s) and learn some of their more complicated idioms and pitfalls.

Also as a side note, at this point in time I don't think the "C/C++" conglomerate make much sense any more as modern C++ looks very different from C. Unless you explicitly need C, I would suggest learning C++ first as it's higher level (and also much larger). Though, idk, maybe learning C first is better as it's the foundation for C++... I guess either is fine, just not both simultaneously.

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

#18
Telling us what type of personal projects you liked doing in the past would be very helpful.

Pick something fun to write (to you) that is normally written in a lower level language.

For me C and C++ were fun to learn by writing graphics applications (ray tracers are great for this) and physics simulations (a solar system simulation maybe). Optimizing these to be as fast as possible is a great way to learn about pointers and manual memory management.

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

#20
I think to learn C/C++ it's helpful to have a mindset of wanting to understand the machine rather than build code. It's of course great fun to use Python's built in maps etc (and C++ has equivalents) but what you can do in C/C++ that you can't in Python is create the raw data structures down to the exact memory locations where they'll be used. One of the ways to learn C++ is make a relatively complex data structure (red-black tree, or bloom filter) and then throw as much data as you can inside it, see when you cross a threshold of memory usage -- then see if you can improve on that.

Having said that, C++ has come a long way, despite what haters say. I program primarily in C++ and very rarely have to use pointers. C++11/14 has excellent features (lambdas, initialization lists etc) which can make programming almost seem like writing a Python or Ruby script.

You may also have some luck with Bjarne's smallish "Tour of C++" book -- http://www.stroustrup.com/Tour.html

Post reply on HN