3 ms·
Why a Beginner Programmer Should Learn C
- getlaura 12y agoRelatively new programmer. Would appreciate any thoughts, edits, or critiques!
- tbirdz 12y agoC was my first language as well, though this was a while back now. I found it was very valuable. It taught me many things and sparked my interest in computer programming. While my own experience with it was good, I hesitate when recommending it to beginners, especially now in the year of 2014, when machines are much faster and there are so many other exciting languages. C, however, has a lot of traps and pitfalls that can be confusing or discouraging to a beginner. I think there are lot of people out there who gave up on programming because their first experience was in C. Weird operator precedence, automatic type conversions, the c preprocessor, differences between pointers and arrays (especially in regards to multidimensional arrays), the #include guard dance around header files, the way #include and header files works in general... There's just a lot of cruft and things about C that complicate the language beyond the inherent complexity of the machine itself. It can also be difficult to learn how to get the whole environment set up, learning about the process of compiling, linking, make, libraries, etc. I don't think that C is the best first choice of a language for a beginner. Instead I would recommend a language that encourages algorithmic problem solving and computational thinking, something that is a further abstraction from the machine. Then after the student is comfortable with abstract problem solving, and "thinking like a programmer", you can introduce her to see what goes on "under the hood", so to speak, and delve into the lower levels. I would recommend C more as a good second language.
- getlaura 12y agoGood points! I especially agree with the preprocessor argument. Kind of forgot how confusing that was at first. But like everything with C, it does make you think about what's really going on. I like the title... Why C Should Be The Second Language You Learn.
- ivan_ah 12y agoIf may add a 6th reason, the low-level nature of C code gives you a very realistic model of computation---you see how long operations take because you often have to do them manually. High level languages like python hide this complexity from you (e.g. python dictionaries / arrays / string manipulations). They make life easier, but in a isolated-from-the-machine-in-plastic-wrap kind of way, whereas C makes me feel I'm touching the CPU.
- tbirdz 12y agoThis is true up to a point. But C is based on an abstract model of a machine, which doesn't really map closely to today's machines. For example, C's memory model basically assumes a contiguous array of bytes, but with modern systems there is a huge difference in speed between main memory and L1,L2,L3 cache. So in order to avoid costly cache misses you have to access your data in cache friendly ways, as all memory accesses are not equal as in C's model. Also consider things like vectorization (SSE, AVX, NEON, etc), memory fences, atomic operations, or threading which are not in C's machine model. Various intrinsics, standards (POSIX), and libraries exist to remedy this, but the fact remains that's C's abstract machine model is getting increasing distant from actual modern hardware.
- dickbasedregex 12y agoI call BS. You can learn from C but in the beginning it's far more important to keep forward momentum. If you don't have something forcing you through the frustrating and boring parts (like school), you're probably going to lose interest pretty quickly. Pick a sane and relatively painless language like python or ruby. Once you've become earnestly proficient in one of those AND some of their tool chains and frameworks then you can get froggy.
- brendanashworth 12y agoDefinitely agree with what you're saying here! Maybe I wouldn't say its for beginner programmers - many might immediately be scared by the idea of a bitwise operator or raw memory access - it should definitely be somewhere in the ladder for learning new languages. Some people simply don't understand that C is actually everywhere around them. They don't understand that either the language they use is built in C, or the language THAT was built on was built in / on C, etc etc. Simply the importance of the language in history may just be a powerful point on its own. If someone knows quite a few languages and doesn't yet know C, I kind of don't understand why - they do not yet understand the importance of lower level operations, like the functioning of a garbage collector or why their pre-mature optimizations shouldn't even be attempted. Great article, over all - I really liked it.
- getlaura 12y agoThanks! The reality is that I probably don't realize how much I already know. I've been programming on and off for a couple years now so I was probably already hooked on coding in general before learning C. C just opened my eyes to a lot of things. I kept having the feeling of 'how do I not already know this'. And it really clicked when I had to learn PHP and was like 'oh, so this is just a cleaner version of C'. Anyways, thanks again!
- informatimago 12y ago1- if you are short on time and have no need practical need for C, then learn some simplified assembler (eg. MIIX, or a subset of a real processor). Write one real little program in assembler. 2- if you have time, learn the assembler of a real processor (my favorite is 680x0 but nowadays that would rather be x86-64 or ARM), and write an application in assembler. 3- if you are short on time or have a practical need for it, like a C job, or you want to maintain some C software (eg. the Linux kernel, Xorg X11 server or something like that), then go ahead learning C. Otherwise, learning assembler (and never again writing another assembler program) would be a better learning experience thant learning C. I've known numerous programmers having learned C who were still confused, but never an assembler programmer being still confused.
- joshdance 12y agoLearning C is good. Learning Objective C is good. Learning Ruby is good. Learning Python is good. The best way to learn is closed rapid feedback loops. Getting something to work, then getting it to work better. Whatever language you chose to make those loops is great. Really beginner programmers should use whatever language their friends use so they can get help when they are stuck and close those feedback loops. I liked the article and the header image. :)