7 ms·
Why I Chose to Learn C
- klrr 14y agoI learned C as first language. I haven't used it for any real-world work, but it was fun way to get into programming. K&R told me not just C but how to program, then I read TUPE which told me how to effectively use the best development environment, Unix.
- deleted 14y ago[deleted]
- nicholassmith 14y agoI know learning C might seem a bit of a waste of time, but given Obj-C, C++, Python and Ruby can leverage it for performance it's not a bad thing to learn.
- danieldk 14y agoObjective C and C++ can leverage it for performance? Objective-C is a strict superset of C and C++ a near superset. If you learnt Objective C or C++ properly, you already know C (!).
- yk 14y agoWhile your statement is technically correct, in practice C is a very different beast from C++/Obj-C. For example, in C dealing with global state is a important problem, while one would just encapsulate the state in a object in C++. So someone who learns just one of the supersets can easily miss all the details which the additional features of C++/Obj-C hide.
- pavanky 14y agoFrom my experience if you are familiar with both C and C++, you do not end up writing C++ code that is completely obnoxious.
- angersock 14y agoIndeed, given the option, you may not write C++ code at all!
- duaneb 14y agoI am a diehard fan of C, and even I think that C++ is preferable past a certain size of program. Classes and templates are far too powerful to not use; just consider things like `scoped_ptr`. Just because C++ has nasty parts doesn't mean you have to use them, in my experience most of my worst experiences with C++ come from reading other peoples' code (Boost.Spirit, I'm looking at you).
- rayiner 14y agoI'm going to be a contrarian, and say that I've just never found a program that was more readable with classes. Classes tend to rip up your algorithms to shreds and spread them over dozens of different files, which is really painful. I've been reading through the code in libfirm lately and it's incredibly refreshing. A pass is usually in a single file (how novel!) instead of being scattered around because of the visitor pattern.
- duaneb 14y agoReally? Classes never made source more readable? How on earth is `Vector<Int64>` or whatever less readable than rolling a custom struct and functions?
- duaneb 14y agoWho on earth thinks it's a waste of time? I think it's essential for every programmer. I certainly wouldn't consider someone fluent in the language (say, Python) until they understand how it is implemented. Also, C++ is arguably faster than C (for the effort put in) and Objective C is a strict superset. Saying either calls into C for performance reasons is pretty silly and doesn't make any sense.
- daenz 14y agoC really is fantastic language to learn. When I learned it, I also came from the scripting language world (Python, PHP). Having that as a base, then learning C, lead to revelations about how those scripting languages are created, and how the data structures I took for granted in a scripting language are actually implemented. From what I understand in formal CS courses, you learn from the bottom up, but learning from the top down was much more enlightening for me.
- PySlice 14y agoI went in the other direction and it was enlightening too. I learned how useful hash tables can be, and that a word count algorithm need not be a complicated assignment full of segmentation faults. :-) I also learned how data structure libraries can be separated from user code (when learning C in class we usually created ad-hoc data structures heavily coupled with the calling code).
- unlucky 14y agoI too started with scripting languages, and also learn in a similar way. Hearing the value that learning C provided you makes the decision to learn it myself a simple one. To those versed in C, is the tutorial linked in the original article a recommended one?
- silentbicycle 14y agoI would enthusiastically recommend Learn C the Hard Way, even over K&R (which hasn't aged well, for reasons LCtHW explains (http://c.learncodethehardway.org/book/krcritique.html) http://c.learncodethehardway.org/book/krcritique.html)).
- strudelfish 14y agoI personally didn't like Learn C the Hard Way at all. I can see the approach for Learn {language} the Hard Way (mostly examples and exercises) working well for languages like Python or Ruby but I felt that for C it was too vague and each exercise didn't really give me an idea of what I was learning/accomplishing. With the other languages you can get away with focusing on functionality but I think you really need a more indepth understanding in C to avoid headaches involved with the language. While C Programming Language by K&R is a little dated, I still think it gives you a better idea of learning the language or at the very least, how to navigate the code and find your answers better. Disclaimer: I already knew C fairly well and decided to go through LCTHW to see if I could pick up any hidden gems; might differ for someone with little to no experience.
- rayiner 14y agoWell now I feel old. When I was in high school, CS was a required course for graduation and it was taught in C++ (that being the pedagogical language of the APCS exam). It wasn't even that long ago (late 1990's).
- duaneb 14y ago> It wasn't even that long ago (late 1990's). Well if you consider that the computer is still less than a century old, 15 years is a long time in the computer world.
- epmatsw 14y agoI don't know when it switched, but my APCS exam in 2008 was Java. The sample program we had to learn for the exam was also in Java, so I assume that was the default language.
- rayiner 14y agoWikipedia says 2003.
- mturmon 14y agoHere's another surprising (but fully understandable) perspective given in the OP: "Function pointers — It was interesting to me to see that such a low-level language contained functional programming concepts." If you started from assembly and worked up, this looks very different, because at that very low level, functions and data look the same too. (Just like Lisp).
- rayiner 14y agoTo bring it full circle: Clinger's "Lambda: The Ultimate Label" (http://3e8.org/pub/scheme/doc/lisp-pointers/v7i3/p128-clinger.pdf http://3e8.org/pub/scheme/doc/lisp-pointers/v7i3/p128-clinge...), in connection with Steele's "Lambda: The Ultimate Goto" (http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AIM-443.pdf http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AIM-...) The punchline: "Since calls to known procedures are just gotos that pass arguments, lifted lambda expressions are just assembly language labels that have been augmented by a list of symbolic names for the registers that are live at that label."
- dkhenry 14y agoC programming is still alive and well is many parts of our profession. The biggest reason why is that even though c++ _can_ do memory management like C most of the time programs implemented in it don't and you can really start to loose a grasp as to what your asking the computer to do when you abstract away where your putting all the stuff your unknowingly asking it to make.
- mpyne 14y agoIn the other hand, I find that C++'s ability to add semantics to memory management is extremely valuable in doing the right thing at all times. unique_ptr<>, scoped_ptr<>, and shared_ptr<> all say different things about heap memory lifetime, and those make it easier to maintain your grasp on what you're asking the computer to do. Like many things in C++, you can do that in C too (e.g. by using a variant of Hungarian notation). But the important thing is to do it.
- drbawb 14y agoI've been playing w/ Rust this past week, and I've had something of an enlightening experience related to the pointer semantics you describe. Rust's memory management works similarly to what you describe in C++[0], but things like unique_ptr, et al. are baked into the syntax and compiler. -- It's basically syntactic sugar for memory semantics. Coming from a background of GC'd languages (Java, Go, and Ruby) these different allocation semantics were Very Hard(TM) for me to understand at first. I kept battling w/ the type checker, throwing different pointer types at it until the example compiled. (Rust's compiler is _very_ intelligent, w/o using "unsafe" code, you basically cannot have a "use after free" condition in Rust. -- It will not compile.) As the parent points out: I've never really spent any length of time _understanding_ the allocations I'm asking a computer to make. I just generate things, they become garbage, and the runtime cleans it up eventually. Once Rust "clicked" for me, I realized something: I know the lifetime of _every single variable_ in this piece of code. I know when it's allocated, where it's allocated, and when it gets freed. The reason it was so hard for me to initially grok Rust was because I'm _not used to reasoning_ about memory allocation. Once I understood the semantics though, it was as though I had an _entirely new_ level of abstraction at my fingertips. These semantics are definitely some powerful stuff, and I'm very glad I'm taking the time to try and understand them. [0]: http://pcwalton.github.com/blog/2013/03/18/an-overview-of-memory-management-in-rust/ http://pcwalton.github.com/blog/2013/03/18/an-overview-of-me...
- keithpeter 14y agoQuote below from Learning C the Hard Way "For Windows users I'll show you how to get a basic Ubuntu Linux system up and running in a virtual machine so that you can still do all of my exercises, but avoid all the painful Windows installation problems." A bootable Ubuntu USB stick with persistent storage might be easier to get started with? Can be created from a Live CD. Interesting idea.
- RegEx 14y agoI dual booted for about a year, and then I used virtual machines instead for the last year. Using virtual machines has been a LOT easier. I use Lubuntu on Virtualbox, and I don't plan on going back. Things that annoy me about Ubuntu dual boot * My Wacom tablet is terribly hard to configure on Ubuntu. * Flash support seems to be hit or miss in terms of out of the box functionality. Sometimes it works right when you install chromium, sometimes it doesn't * Windows weird partitioning. Windows will only let you have 1 or 2 of these special types of partitions on your HDD, and I somehow maxed out that partition count and couldn't fix it. It was very difficult to work with.
- keithpeter 14y agoWhatever works with your hardware and use cases! I was thinking more of a group of people meeting to work through the Learn C the hard way book, perhaps in a coffee bar or something, bringing their own laptops. A bootable stick might make a C environment more accessible to them. The puredyne project produced a bootable linux specifically to provide a common environment for training in audio production. Seemed to work for them.
- RegEx 14y agoIf you bring a copy of the ISO you can have them all on starting from the same Virtualbox install (takes 5 minutes to set up without knowing the software + Ubuntu installation time). But I've heard Vagrant is good for use cases like yours, though I haven't personally used it. That sounds like a fun activity by the way, have fun with that :)
- 14y ago
- dvt 14y agoThis entire post just seems like mental masturbation. Questions like this pop up on Stack Overflow all the time ("Should I learn C?") and there is a very solid consensus in professional software development circles: don't learn C unless you have to. Are you writing performance-critical functions for a game? Are you writing an operating system? Are you debugging legacy code? Maybe you have to create a custom allocator for an embedded system. Sure, use C. But the knowledge gained by learning C will almost never (ever) help you in "real life" development situations any more than learning assembly will (learning assembly is probably more useful, actually). If you're already familiar with C-style syntax (which like 90% of languages out there use), delving into C will teach you nothing about "code organization" like the author claims -- that's actually kind of laughable since C code is notoriously difficult to read. Not only that, but several "features" mentioned in the blog are known caveats of the language: varargs are bad (http://www.atalasoft.com/cs/blogs/stevehawley/archive/2006/03/16/9767.aspx http://www.atalasoft.com/cs/blogs/stevehawley/archive/2006/0...), function pointers are difficult to work with and error prone, memory allocation is interesting to learn about in CS 101, but no real programmer wants to deal with it in most production code (that's why we have languages like C# and Java). If you don't know C, you're not missing much. And unless you work in academia or very specific engineering fields, you don't need to know C. Want a challenge? Go rock climbing. Edit: almost forgot about various C/C++ preprocessor nightmares (see double evaluation, etc): http://www.nongnu.org/c-prog-book/online/x843.html http://www.nongnu.org/c-prog-book/online/x843.html
- RegEx 14y agoFor those who hit a wall with C when it came time to learn pointers, I'd like to plug a YouTube video I made that people seem to really like. https://www.youtube.com/watch?v=IkyWCOUY8V4 https://www.youtube.com/watch?v=IkyWCOUY8V4 The terminology may not be completely accurate (although I did try very hard to not say anything incorrect), but I honestly think it does a good job of showing you how to actually use pointers. I know the resident C experts will probably find something wrong, but I've received tons of comments and emails from people saying they finally "get it". It's something I'm proud of.
- barristan 14y agoPretty good, I prefer Binky myself (http://www.youtube.com/watch?v=f-pJlnpkLp0 http://www.youtube.com/watch?v=f-pJlnpkLp0), but to each their own.
- FreeFull 14y agoI have never understood what was so confusing about the concept of pointers. What I can see as confusing though is the way C's syntax works with declaring multiple levels of pointer indirection with arrays mixed in, although that can be mitigated with the use of typedefs.
- tlarkworthy 14y agoPointers to stack objects?
- RegEx 14y agoYou may be surprised how much a bad professor or tutorial can derail someone. Almost all concepts seems "obvious" or, HN's favorite word, "trivial" once you know it! But getting to the "a-ha" moment can take varying amounts of time depending on the quality of the presentation of the material.
- mrweasel 14y agoI never really got why people found pointers to be complicated. I suck at writing C code, but pointers are something I understood pretty easily. It in the name really, it's something that points to (the location of) something else. I doubt that anyone struggles to understand pointers, they/we struggle to understand the implementation of pointers in C, in some cases. If you want to explain pointers, to people from a object oriented programming background, you might start by comparing points to "by reference" and "by value". My issue has always be why I would care about the memory address of a variable, rather than getting the value as the default behavior, but that might be why I suck a C.
- sjtgraham 14y agoRe Valgrind: Last time I worked through CTHW, I couldn't use Valgrind because of missing OS X 10.8 support and I felt like I was missing a lot by not using it. I'm tempted to go back and work through it again, this time with a VM.
- pekk 14y agoThis is the kind of thing which makes OS X generally less productive for (non-Apple) development than it could be.
- zenbowman 14y agoSpending some time learning C, ML and Scheme is well worth it. Virtually all modern languages derive from these three languages - and all 3 of them are internally consistent enough to be beautiful.