Live data from Hacker News

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

news.ycombinator.com

1–10 of 62 posts

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

#1
I've been developing using languages like Python, Java and the like with automatic memory management for the past few years. The way I learned these languages was - read their language definition from learnxinyminutes.com, think of personal projects I wanted to make/port, google the API and done.

C/C++ is different, I'm afraid of pointers. I can't think of anything that I will like to make in C/C++ since it is so low-level. What I can do in one line in Ruby will take dozens.

I will really appreciate any pointers on how do I learn them. (no pun intended)

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

#3
Find a slow part of your Python/Ruby/Lua application that could use some speeding up and then write an extension for it in C.

Some useful reading:

http://www.swig.org/

http://dan.iel.fm/posts/python-c-extensions/

https://blog.jcoglan.com/2012/07/29/your-first-ruby-native-e...

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

#7

Find a slow part of your Python/Ruby/Lua application that could use some speeding up and then write an extension for it in C. Some useful reading: http://www.swig.org/ http://dan.iel.fm/posts/python-c-extensions/ https://blog.jcoglan.com/2012/07/29/your-first-ruby-native-e...

I agree with @hackerboos, definitely write a c-extension. It will not only enhance your knowledge of python but you will also learn C/C++ during the development. I did something similar wrote a ruby c-extension https://github.com/chaitanyav/fibonacci for fun. Also, checkout the CS107 videos on youtube which are C based (look for cs107 stanford).

you can also try writing the core utils using your newly learned C/C++ skills.(https://github.com/chaitanyav/cprograms)

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

#8
The other answers sound like they're from people who aren't new to the idea of pointers...

Try simple data structures first. Having linked list nodes that actually uses minimal memory (pointer to next node, a data field) is actually pretty exciting. Implement all the operations (get index i, remove index i, etc) because that's where a lot of the insight will come from. Then you can move onto binary search trees and other more complex stuff.

One of the most useful insights I've read was from "Effective C++", which said (paraphrasing) "C++ is a federation / family of languages which work together". Learn the C subset of it first so you're not overwhelmed with available features, and then you can get back to using templates / STL / the other languages later.

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

#9
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 are just a concept that you need to grasp, like recursion. You first read about it and kind of get it, then you apply it over and over until suddenly you realize that you have developed a true understanding that allows you to build new abstractions on top.

You will hear people telling you to start with C first because C++ is a superset of C, but I always advice against this. Memory management is "manual" in both, but the idioms you apply are very different between the two. Unless you are looking to truly spend years perfecting both, pick one and go with it.

Post reply on HN