7 ms·
Going back to C
- ErrantX 17y agoThere was a guy in our university tutorial support group (a PHD grad) who, in the first session said, "I only do C, Im your speed guy". We all hacked around with other languages and implementations. And when we needed some fast and efficient little "thing" to plug in we went to the "C guy". He was by far the most important guy for all the teams there :) (save me countless hours in writing a non-crucial but useful optimized array sorting algorithm to work with our program)
- barrkel 17y agoI find the hubris of a C guy saying "I'm your speed guy" amusing. I could contrive of several scenarios where said C guy would be somewhat chastened, perhaps involving applications for polymorphic inline caching, or runtime code generation with applications to sorting or searching, etc.
- brg 17y agoNear the end the author looks towards the future and writing a small compiler. He mentions "Modern compiler implementation in C," and I was aghast. That was one of the worst textbooks I ever had to suffer through.
- lzm 17y agoWhy, if I may ask? My memories of that book are mostly positive.
- brg 17y agoI am speaking from memory, and perhaps should revisit the text to see if these same criticism still hold years out. As part of a series, "Modern Compiler Implementation in..." the C version came across as a poor translation. I would say this is akin to Sedgewick's earlier version of his "Algorithms in..." texts, of which one was high quality but the translations were not. Where Sedgewick seems to have first written in Pascal, Appel seems to have first written in Java. The constructs that Appel places on top of C to make implementation discussions easier did not help. While they attempted to make it object oriented, they made it messy and not "C" friendly. For the basics, I kept referring to the Dragon book for better explanations then were provided there. I did not find it encouraging that this book drove me to the text it is trying to out-date. I had bought it for the last half, since texts on modern compiler design are rare (functional languages, optimizations, garbage collection). But I recall the algorithms discussion to be subpar in that it was neither clear nor deep. I still like the idea of structuring a compiler book around the semester long project of building one from the ground up. However, I think both the Tiger language and this text could have used another year of revision.
- silentbicycle 17y ago> Appel seems to have first written in Java. Given that Appel works on SML/NJ, I think the ML one is probably a better choice. (That one's really good, IHMO. Haven't read the other two.) There aren't a whole lot of books specifically about GC, but I really like Richard Jones's _Garbage Collection: Algorithms for Automatic Dynamic Memory Management_.
- eru 17y agoInteresting. I also tried reading the Dragon Book, but I found it quite stale. I really enjoyed "Modern Compiler Design" (http://www.few.vu.nl/~dick/MCD.html http://www.few.vu.nl/~dick/MCD.html). They also talk about implementing functional languages. And if you already know how to write a lexer and a parser, "The Implementation of Functional Programming Languages" by Simon Peyton Jones is worth reading.
- loup-vaillant 17y agoI fond that "implementing functional languages: a tutorial" is even easier. Now, these books are not for eager languages.
- silentbicycle 17y agoReading between the lines, it sounds like the author came back to C after learning to program, and sees quite a bit more in it than he did as a teenager. I had the same experience - I had a lot of fun writing programs as a kid, and taught myself C/C++ * . Still, I didn't learn anything about good coding conventions, programming in-the-large, etc. until a couple years later, when I discovered Linux and Perl (no waiting to compile!!!), and later Python, Emacs Lisp, Scheme, OCaml, Erlang, Prolog, ... Nowadays, my first choice is usually a mix of Lua and C, but I've learned a ton from every language along the way. C is useful for many things, but it's probably a terrible first language - until you have a fair amount of experience, there are just too many aspects of it that will bite you in the ass. Pointers are sharp tools, the type system is a joke, etc. * Quite literally, a mishmash of C and early C++. Hey, I was a kid learning from library books in the early nineties. That's what I think of when people say they program in "C/C++" - a naive mix of C and C++.
- malkia 17y agoC with a decent dynamic language (C + Lua for example) make a better choice, than C++. Or Objective C, or C+Python, C+Perl, C+WhateverElseDynamic.
- blasdel 17y agoA few of those work well starting from C, like: C + Lua or Objective-C For most of the rest it's possible to start in C and link in the language runtime, it's much easier to start in the runtime and extend it with C modules. From experience this is especially true for Python: I've used both ctypes and SWIG to turn the guts of existing native programs into Python libraries. I'm sure it's probably the case for Ruby and Perl as well. You could also just use Go by itself :)
- nfnaaron 17y agoWhy?
- silentbicycle 17y agoYou can write the stuff that needs to access system calls, deal with hardware, heavy number crunching, etc. in C, but use a language with garbage collection, real strings, and a REPL for all the stuff that doesn't need to be chiseled out of diamond (and will probably change, anyway). For many things, slow prototypes are good enough. When you could do 95% of a project quickly in Python/Lua/Ruby/etc., writing everything in C anyway has the same downsides as any other form of premature optimization. As a bonus, the border between the two languages often settles along conceptual seams in the codebase -- your low-level graphics rendering code shouldn't be tangled up with your enemy AI or UI templates, for example. Rather than writing everything in a language that tries to do everything and winds a mess (C++), you can use two smaller, more focused languages.
- nfnaaron 17y agoAh, my mistake. I thought you were contrasting C+Lua with all the other C+language pairs, C+Lua with C+C++.
- bonsaitree 17y ago1. Programmer has a domain problem ill-fitted to his current programming language of choice and knowledge is said language's libraries. 2. Programmer switches languages to one well-suited to the domain and his current knowledge. 3. Miraculously, the domain's previous speed and abstraction munging issues suddenly disappear. Why is this news? Use the right tool for the right job. Syntax matters. Baked-In abstractions matter. Standardized library interfaces matter. This is precisely why the number of programming languages has grown, not shrunk, over time. For the most part, programming languages aren't "better" or "worse"; than each other; they're simply "different". Let that same programmer attempt to leverage C against an entirely different problem domain, such as a 3D physics simulation, and watch how rapidly the language's merits suddenly dissolve.
- silentbicycle 17y agoThat's not what the post is about. He's surprised how different C seems now to how it seemed when he was younger and new to programming. (C would definitely not be my first choice for a compiler, though.)
- jrockway 17y agoSo he can figure out how to write the algorithm in Haskell, but he can't figure how to use "`par`" instead of "`seq`" to allow ghc to auto-parallelize the code? And then rewrites the whole thing in C, which doesn't have any language support for automatic parallelization? I guess this kind of upsets me, but whatever. It's his own life he's wasting. (Don't get me started on writing a compiler in C. Then I really will get mad.)
- jerf 17y agoI'm asking the author directly: http://www.reddit.com/r/programming/comments/aue06/going_back_to_c/c0jgji8 http://www.reddit.com/r/programming/comments/aue06/going_bac... I mean, I know Haskell isn't the answer to everything (what is?), but this is a very odd complaint.
- ajross 17y agoWith all due respect, I think bland whining about C and its partisans isn't really a productive way to advocate for your language ("wasting his life"? good grief). C is, after all, what the world is built on. If you really want to show us a better way, you'd be better served by trying to help build that world. How about just one core library that does something useful and irreplacable on a modern system, and that works significantly better than the dinosaur code you keep complaining about? We've seen enough toy implementations and cute hacks (and, gack, web frameworks!) to last a lifetime. How about a clean, bug-free and parallel implementation of zlib instead? Or a better h.264 codec? Or a crypto/TLS implementation that beats openssl? Regular expression engine better than pcre? World-class numerics library? GUI framework? SVG implementation? HTML parser? 3D modeling and rendering framework? ... Anything that isn't mostly a joke compared to the standard C junk you keep sneering at? Seriously guys: get off your butts and write some real software. Most of us tolerate the sniping most of the time, but this bit was just over the line, sorry.
- jrockway 17y agoSeriously guys: get off your butts and write some real software. http://github.com/jrockway/ http://github.com/jrockway/ Oh.
- aditya 17y agoI suddenly realized that everything I wrote would be inside the program's code, and that nothing more would. Uhh... what does this mean?
- silentbicycle 17y agoI think he means is something like, "...the program would be what I wrote, no more, no less". Pretty ambiguous, though.
- mru 17y agoI think he means C doesn't require a framework or VM of monstrous proportions in order to do its thing.
- techiferous 17y agoHN is turning into Reddit.
- brianobush 17y agoand comments like this one (and unfortunately, mine) do not help the situation. Constructive comments, criticism and information is all we need to avoid becoming reddit.
- ecyrb 17y agoIs there a "personalized" social news site that shows me stories based on their user-vote correlation to the stories that I vote on?
- loup-vaillant 17y agoWhile such a site may please you more, you would be less likely to discover new things. Is this what you want?
- ecyrb 17y agoWhat I'd really like is to reduce the noise. Yes, it's iPad day (now), but I fail to see why 1/3 of the 30 links are Apple related. I don't need to know about the new SDK being available, I don't need to see an old Paul Graham essay, I don't need to see the FSF's reaction, and I don't need to see a poll on whether or not people are going to get one.
- squidsoup 17y agoYou say that like it is a bad thing :(
- Locke1689 17y agoIt is. In the history of social news aggregators, and social networking sites in general, the quality of the user generated content on the site tends to go down as the number of users increases. I think the first example of this was Digg. When I first started frequenting Digg in the beta phase there were many technically interesting stories and bright people. When more people showed up the general tenor of discussion and submission started to fail. The same trend happened soon after in sites like Youtube and Reddit. As Paul Graham has written, Hacker News is an experiment in social news/networking—can a social news site continue to keep a high standard of discourse despite increasing population? If HN follows the Reddit path, then it seems PG failed.
- samuel 17y agoI don't know if C is the best answer for him. Ada has most of C advantages(unless you are doing "dirty" C tricks), while retaining type safety, exceptions, bound checking... (Haven't used it in years, though).
- noverloop 17y agoI suppose I've had a partial rediscovery of C this year. It was all nice and fast until I needed to code up a binary search tree using structures and perform lookups and rebalancing... performance tanked, and I spend quite a lot of time debugging this pointerfest. One of the main reasons to use C nowadays is performance, and if that's the case you'll likely need datastructures. So,I would advice against C and go with C++ (or any other C variant that has objects) in almost all cases...
- vannevar 17y agoThere are no fast languages, only good compilers. C is fast because there are decades worth of work put into its compiler. If someone put the same effort into a javascript compiler, javascript would be just as fast.