6 ms·
I hated and feared C for years. Then I finally learned it and fell in love with it. Now other languages seem like too much work. I'm only a hobby programmer so
by anigbrowl 14y ago
I hated and feared C for years. Then I finally learned it and fell in love with it. Now other languages seem like too much work. I'm only a hobby programmer so that devalues my opinion somewhat (insofar as I don't have to support large production systems or please committees), but one of the things I love about C is that once you have something working in C, you're likely done - if you need to go faster or better, then either your understanding of the problem or the algorithm you're employing is flawed, or maybe you need to do some bits of it assembler (DSP for example).
The other thing is that even though C is old it still work great. I don't know how you web guys keep up with so many 'frameworks of the month' and so forth. I took up C mainly because I was tired of things becoming obsolete before I had got around to learning them properly.
- tptacek 14y agoOne of the greatest things about coming back to C from years of Ruby is that you can constantly tell yourself "I don't need to worry about performance because there's no way what I'm doing here could be worse than what Ruby was doing for me". It's hard to fully articulate the feeling but it's great; it's like a cure for premature optimization.
- euroclydon 14y agoIs it possible to need C and not know it, or if I need it will I know it? Because I can't think of anything I'd use it for. You guys speak of it and other higher level languages as if you use them interchangably for the same tasks.
- tptacek 14y agoI use Ruby for things that deal with the web, for utility programs, and (most often) for software I'm not going to need to support long term, such as clients for bizarro network protocols I encounter on penetration tests. I used to use C for everything else; I'd reach for Go first now, but I still love C. One way to think about C vs. (say) Python is that it's like the relationship between an FPGA and an ASIC: you prototype in a high level language and you write C when you really know exactly what you need your program to do. C is not a great exploratory programming environment, but it is excellent when you have a specific plan.
- lelandbatey 14y agoIt'd like to thank you for that description. The first analogy that came to mind was play-doh vs marble, but that's a rather blunt one that connotes all sorts of negative things that I don't really mean. Yours description is spot on!
- yuushi 14y agoAnd this is what I don't really understand. Python or Ruby are excellent in the domain you talk about, but I would always, always reach for C++ over C if given the choice. The C++ standard library for me alone makes this such a simple choice. A lot of C code to me just looks horribly ugly these days - stuff like: int compare(const void *a, const void *b) { return *((int*)a) < *((int*)b); } Yuck.
- tptacek 14y agoOn the other hand, the mechanism by which that code works is simple to understand and keep in your head at all times, and isn't inelegant. I find that very valuable.
- yuushi 14y agoExcept it has absolutely no type safety whatsoever. With modern-style C++, you can do the same thing in exactly 1 line: std::sort(begin(array), end(array), [](int a, int b) { return a < b; }); Versus: qsort(array, MAX_VAL, sizeof(int), compare); With compare as defined before. I mean, sure, it's just sorting and it's a tiny example, but to me it shows a lot about why I prefer C++ over C: typesafety, readability, reduced possibility of buffer overflows, reduced possibility of segfaults based on incorrect element access, speed thanks to code inlining vs function pointers...
- temujin 14y agoYes, std::sort is better than qsort on simple types, but that's an isolated case. I'm currently working on a major "C++" project where literally the only C++ dependency is std::sort right now.
- SCdF 14y agoOT: I haven't touched Ruby for 5 years, but I thought JRuby had really helped the whole performance thing?