6 ms·
Compare how thin is the C book from Kernighan vs the C++ book from Stroustrup. The result is that most people can fully understand C easily (if willing to), whi
by faragon 11y ago
Compare how thin is the C book from Kernighan vs the C++ book from Stroustrup. The result is that most people can fully understand C easily (if willing to), while the C++ case is impossible.
C is beautiful.
- kozukumi 11y agoIndeed. C is a beautiful language. Sure it has its problems if you use it poorly, which is very easy to do, but used properly it is still my favourite language. I find that problems I solve with C are generally solved better in the sense that simpler and easier to read and understand is better.
- MichaelGG 11y agoReally? I like C but I'm not sure it's beautiful, compared to a LISP or some sort of ML. And my limited experience says that C programs involve a ton of boilerplate code dealing with copying bytes around. Every time I see a loop doing a series of if/elseifs to parse command line options, I think this is very much not beautiful.
- vezzy-fnord 11y agoLisp and ML represent quite different models of computation. For a register machine, C can be pretty beautiful. It's funny you talk about parsing command line options. Plan 9 solved that problem well with the arg(2) macros. [1] In fact, Plan 9 in general is a premier example of really clean and elegant ANSI C-compatible code. [2] [1] http://man.cat-v.org/plan_9/2/arg http://man.cat-v.org/plan_9/2/arg [2] e.g. https://github.com/0intro/plan9/blob/master/sys/src/libndb/ndbhash.c https://github.com/0intro/plan9/blob/master/sys/src/libndb/n...
- kabdib 11y agoRead the V6 Unix sources. They are seriously pretty. A file system in maybe a thousand lines of code. A scheduler and swap manager, a TTY layer, and device drivers with nearly no waste. You can read the code in an afternoon and understand it and make changes to it. Even in crusty pre-ANSI C, it's very elegant stuff. (Then I look at the Bourne shell sources and weep. It's like the author of that was in denial of everything that made C a decent language and wanted desperately to be doing something else)
- comex 11y agoFor reference: https://github.com/swetland/xv6/blob/master/kernel/fs.c https://github.com/swetland/xv6/blob/master/kernel/fs.c https://github.com/weiss/original-bsd/blob/master/old/sh/cmd.c https://github.com/weiss/original-bsd/blob/master/old/sh/cmd...
- rdc12 11y agoHow would XV6 compare to V6 for code elegance? XV6 being a reimplementation, of V6 Unix with ANSI C and targeting X86 instead. But was done by different people as far as I know.
- coldtea 11y ago>Really? I like C but I'm not sure it's beautiful, compared to a LISP or some sort of ML. It's another sense of beauty, the one of talking almost directy to the machine, with few abstractions, and few wastage.
- justwannasing 11y agoC doesn't have any problems just because you use it poorly. The only thing with a problem would be the coder.
- coldtea 11y agoThat's actually ad-hoc cargo-cult, not a scientific assesment. If a programmer uses a language poorly it can be the programmer but in a lot of cases it can also be the language, that has poorly thought out, conflicting, etc constructs. There is a field called PL research (part of Computer Science) and researchers can all agree on several problems that C (and what would have been a better design). Some of the problems are so obvious that the creators of C admitted them too. Some have been corrected in later revisions (C99 etc).
- justwannasing 11y agoTo blame your tool when you don't use it correctly is a typical fallacy found on forums everywhere. You blame the car for your accident, your parents for being in jail, the hammer for breaking your thumb.
- stormcrowsx 11y agoI can actually blame my car for an accident if it didn't respond to my brake press. The hammer can be blamed if the head flew off mid-swing striking my finger instead of the nail. The tool can be the source of your issue if its not made correctly.
- justwannasing 11y agoYou're talking about tools that have broken. We're talking about tools that work as advertised.
- coldtea 11y agoThat's the thing: going beyond what the parent commentor said, tools that "work as advertised" can still be bad. "Pure wire-mesh electric blanket -- no insulation whatsoever! Only $20 dollars. Will raise the heat with sparks of electricity, plug directly into your 110v outlets!". Sure, works as advertised. But it's ill concived and will fry anybody trying to use it, either because he wants to or because he is forced to (by his boss or needing to deal with legacy code in the case of a programmer). The example is contrived to showcase the point, but the gist is: "works as advertised" doesn't mean much with regards to quality or well thought-out architecture.
- shepardrtc 11y agoYou should check out the new version of the C++ book by Stroustrup. After having stayed away from C++ exactly for the reason you speak of for probably 15 years, I gave it another try. I was very impressed at how C++ has changed with 11/14. Stroustrup had to essentially rewrite the book. Of course if you're simply comparing size, keep in mind that Stroustrup's book is aimed at beginners. And provides a thorough discussion of many things in the language. The C book is terse and not really aimed at beginners or students.
- irishcoffee 11y agoHmm, thats the C book I used in my intro to programming class as a first year EE major as UMD-CP. (If it matters, I later switched to Comp. Sci. because of that class) Why would it not be aimed at students?
- shepardrtc 11y agoBecause it doesn't teach programming, it teaches C.
- irishcoffee 11y agoUh, wat? If an EE and/or comp. sci. major can't grasp logic, they should not be in the class/major, and these classes are commonly referred to as "weed-out classes." "Programming" is derived from math (I'll provide source if you want), which is logical at its core. The keywords while, if, else, they're not hard to understand. I don't know what teaching "programming" means.
- deleted 11y ago[deleted]
- AnimalMuppet 11y ago> The C book is terse and not really aimed at beginners or students. I don't know about that. Knowing only a bit of Pascal (and Fortran and Basic, but they're less similar), I picked up K&R over a four-day weekend, and really understood it, without even a compiler to experiment with. (All except for argc and argv - had to try it out to see what was going on there.)
- wyldfire 11y agoC is excellent in its simplicity. C++ is valuable in its richness. Its richness comes at a price and indeed, fitting it all in one's head is very difficult.
- to3m 11y agoDon't worry, the gcc maintainers are working on this problem as we speak.
- andrewchambers 11y agoAgreed, the linux kernel isn't written in C, its written in gcC. A non standard difficult to implement dialect.
- andrepd 11y agoYou are doing it wrong. You are not supposed to "learn" C++, not entirely. C is simple in the sense that the amount of things that there are to know about the language are small (it's about as low level as you can get) and it is possible and required to learn its computation and memory model and all its features to work with it. In the case of C++, it's neither required, nor even possible to learn ALL of C++ (not without a couple decades of experience). C++ is a monster, a colossus, a many tentacled monstrosity of hundreds if not thousands of sometimes very complicated features. You cannot possibly master it all. Yet the barrier to entry is as high as C, if nothing at least because C is a subset of C++. You don't have to be a template metaprogramming wizard and make full benefit of the latest standards' new features in order to know C++. As an example, in my work in physics I use C++ consisting of C, templates, the STL and POD structs. I don't use C++'s immense OOP tools simply because I don't like/don't need them. Someone else might use the full OOP features of the language. Still someone else might reduce it to C with templating because they like C but hate not having generic programming. In short: C++ is what you make of it. Your C++ is a subset of the C++. It's your job to decide what features you want to learn and make use of. Don't feel like you don't understand C++ because you don't know Stroustroup cover-to-cover by heart.
- cma 11y agoThis falls apart as soon as you are working with codebases you didn't create all by your lonesome.
- qdog 11y agoIn fairness, C: A Reference Manual(Harbison and Steele) is now 560 pages. I agree C++ is pretty messy, but if we got a 3rd edition K&R it would be much larger than the original. Also no sure most people could understand C, but "most programmers" should be able to understand C if they tried. I concede I can barely understand C++, but I use a bare minimum of its features and write C when I can.
- krylon 11y agoC's beauty can be deceptive - it has its fair share of corner cases, and with compilers trying to exploit undefined behavior for more aggressive optimizations, these have become easier to run into. And having run into my fair share of memory-related problems in C, there are languages I much prefer for everyday programming (Go, Python). Ironically, the kind of issues a garbage collector addresses have never been much of a problem for me. But there have been times where I would have killed for a compiler switch to enable array bounds checks; this might reflect poorly on my programming skills, but this is by far the nastiest type of problem I have run into using C. But C makes it still much, much easier to form a reasonably accurate model of how your code will be executed on the computer at runtime than C++. Compared to the alternatives (C++, Ada, Rust come to mind), C is still a gem of simplicity, and it continues to be popular for a good reason.