Live data from Hacker News

Ask HN: Should I learn C?

news.ycombinator.com

81–90 of 98 posts

Re: Ask HN: Should I learn C?

#81
post #80
post #45

Earlier quoted context omitted.

A good book that goes over both C and assembly is "Hacking: The Art of Exploitation". The first 100 pages alone will give you a solid understanding of what is happening behind the code.

I can't recommend that book for learning C and assembly. Its coverage is amateurish and unprofessional, which are indicative of or at least encourage fuzzy thinking. You can read it for a time-efficient overview, but please don't go thinking you know C or assembly if that's all you've read.

For clarification, the recommendation was not for learning C and assembly, but rather to get a good feel for what is happening at a lower level ie. stack frames, stack pointers, etc.

Re: Ask HN: Should I learn C?

#82
post #65

Yes, you should learn C. And enough assembly language to understand aspects of how C works, like what a "stack frame" is. Now is a great time to start. Go find K&R, fire up Linux and write and compile "hello, world". Then keep going until you experience your first segmentation fault. ;) (Do not study C++ at this point. Study C. These things turn out to be very very different.)

since I had to look it up, maybe others don't know: K&R refers to: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie http://www.amazon.com/exec/obidos/ASIN/0131103628/thedinosau...

I feel compelled to add that I tried to learn C from a half dozen other books over several years (starting in childhood, so it was probably a bit early), but it never made any sense until I worked through K&R. Suddenly, C seemed like a beautiful and simple language (which it is). There are many subtleties, particularly in the macro system, that are not covered at all by K&R, but it is, by far, the best choice for learning C.

In other words: Don't waste your time trying to learn from anything other than K&R, at first. It's just the most concise text available...C is a concise language, and it is not well-served by big fat books.

Re: Ask HN: Should I learn C?

#83
While you're at it you might want to pick up a copy of "Code: The Hidden Language of Computer Hardware and Software" by Charles Petzold. One of the most compelling and well written books on the subject I've read. Reading this along side learning C and Assembly language will make it all "click".

http://www.amazon.com/Code-Language-Computer-Hardware-Softwa...

Re: Ask HN: Should I learn C?

#85
Since everybody in here more or less agree, I will allow myself to counter just a little bit.

There is no doubt that C programming is a very good skill and if you see yourself programming a lot in the future, it is more or less a no-brainer. BUT it is still a trade-off. It will cost you time and this is time that you could have spent having fun, making money or learning some other skill instead. You could ask people in any field if X-basic-skill in their field is worth studying, and you would get similar answers.

But yeah, you should learn C :-)

Re: Ask HN: Should I learn C?

#86
post #21

C yes, C++ no. Make sure you're using a C compiler, not a C++ compiler Here is why not C++: http://news.ycombinator.com/item?id=1463592 and why not java Edit: Was there something wrong with my comment? Or were you downvoting merely because you disagree?

Those are not reason on not to use C++, but reason on why some people shouldn't be using C++ in the first place. Yes you can do it in python unless you want speed, if I am to interface my python code with C or C++ why can't I write them in C++ in the first place? Also if I were to interface any scripting language code with C I would probably go with Lua.

I'd say "It doesn't work well in most shops" is a damn good reason to not use something.

In general, very little of the program needs to be written in C to get great performance gains.

Additionally, python is vastly different from LUA. Lua is still a scripting language, ruby and python have moved past that.

For someone at age 18 or so, I'd say C is a much much better level of complexity to be tackling that C++

Re: Ask HN: Should I learn C?

#87
post #5

Even though C is used more and more rarely outside of systems programming, I definitely recommend learning it. Learning about pointer arithmetic, memory management, etc... will give you a depth of understanding in other programming languages that other students will be sorely lacking the first few years of college. Other than a little OS-hacking on the side, I've never used it for a project, but understanding how C w…

It's also very useful for extending other languages by binding a library.

Can you extend on this a bit.

Re: Ask HN: Should I learn C?

#88
post #47

Yes, you should learn C. And enough assembly language to understand aspects of how C works, like what a "stack frame" is. Now is a great time to start. Go find K&R, fire up Linux and write and compile "hello, world". Then keep going until you experience your first segmentation fault. ;) (Do not study C++ at this point. Study C. These things turn out to be very very different.)

At my university we have a course that goes over all the levels of abstraction between the hardware and systems-level UNIX programming. I never took the class, but I followed the course book on my own and it proved to be one of the most enlightening self-learning experiences I've had with programming. The book is Computer Systems: A Programmer's Perspective, and I highly recommend it. I've found that even though I no…

ISBN for anyone interested: 978-0130340740

Re: Ask HN: Should I learn C?

#89
post #28

In my opinion, instead of asking and spending time reading the comments of everyone saying why you should learn C, you should have actually learned C. It's a great language and learning it will surely help you in your career. Think of it this way: Why not learning it?

I asked this question for two reasons: 1) I had already started learning C. It is low-level, and I was getting disinterested. I wanted to know if it'd really be worth the work to learn it. (The answer is absolutely.) 2) So that other people, when wondering if they should learn C, would have a great list of hacker recommendations. (That has happened.)

If you are getting disinterested, do some project that C would be good at, like graphics, or a hardware driver, or an OS kernel.

Re: Ask HN: Should I learn C?

#90
Yes! In general, when asked "should I learn X | X is something that gives you a different perspective" the answer should be yes. In particular, C is excellent as it teaches you things must be understood even if you work with higher level languages: dealing with pointers, dealing with raw memory (allocation, deallocation, finding leaks), dealing with the I/O and VM sub systems of your operating system, understanding abstract data types.

On the educational side, you will learn about hardware works. Some will argue that there are better languages to learn these things and I'll agree: Forth could be better for learning about raw memory addresses and systems programming. Scheme could better for learning about data abstraction. However, C has several salient things going for it: C is UNIX (for good or bad, majority of serious non-embedded -- and even great deal of embedded -- programming outside of Microsoft or of Windows Desktop Application development targets UNIX) and C is the lingua franca of programming languages.

From the practical side, you will have an advantage too. Higher level languages generally still have pointers (Quiz: is Java pass by value or pass by reference? Answer: It's pass by value, just the value of anything other than the primitive types is a pointer). Higher level languages have built abstractions around I/O and VM but they typically fall under two categories: thin wrappers around C and POSIX APIS (Perl, Python, Ruby) or leaky abstractions that occasionally force you to use FFI to C (JVM based languages). In either case, if you are able to program C you have a competitive advantage against coders brought up purely on those languages.

C is also a good language to learn about data structures: partly because learning data structures in C is really about the data structures, abstract data types and algorithms and not (as C++ and Java centric courses often make it out to be) about OO. This is the book I recommend for data structures in C: http://www.amazon.com/Data-Structures-Pseudocode-Approach-C/... (I'm biased as I learned from it myself and have had classes taught by Professor Forouzan).

Note, I never said anything about performance. Just like it's nearly impossible to hand-write assembly that beats "gcc -O3" (not to say "gcc -O4" or icc) performance wise on modern hardware (out of order execution, NUMA, specialized instruction sets), I am pretty confident that languages will emerge that will beat C even for things like inner numeric loops by being able to reason more about mutability, side effects or lack thereof, exploiting parallelism and caching available in hardware. You won't be writing in C to make computation faster, you'll be writing in C to deal with I/O, memory and the like more efficiently: many times that will mean your code will run faster, but it won't specifically due to being written in C (to be blunt, it will be due to implements of runtimes and programming languages sheltering the languages/runtimes from the hardware/OS; that may not always be the wrong thing to do). See http://pl.atyp.us/wordpress/?p=2947 for a great discussion on this.

Finally in terms of C++: don't study it before knowing C and a non-C++ object oriented language. I was lucky enough to learn C before learning C++, but it was the first object oriented language I tried to learn. Because of that, I thought of OO as a black art. Oddly enough I truly learned about OO in Perl: I was writing Perl 5 (loosely adhering to Damian Conway's "Perl Best Practices") and despite OO in Perl being an ugly hack (it's similar to Python's, but without even the syntactic sugar that hides __dict__ away) the Perl code I was writing was far more OO than any C++ I wrote up until then. I then learned Python and Java; when I came back to writing C++, I was much better at it. Josh Bloch (along with Doug Lea, the author of Java's collections) in "Coders at Work" spoke of a similar experience (in his case, he didn't do any OO programming before Java) and likewise speaks very favourably about C.

I strongly recommend you do the same: learn C and do a non-trivial project in it (writing a compiler for subset of C in C did the trick for me) to truly grok it; continue building projects in Python (or another OO language e.g., Ruby, Java, Scala, Smalltalk, ObjC, Common Lisp+CLOS; pick as many of these as you'd like) to make sure you have a firm grasp of OO before you go after C++.

Post reply on HN