18 ms·
New school C
- null_ptr 14y agoC is still my favourite language of its style, and so far I also worked on C++, C#, Java, and Python projects. None other is as simple and direct. Looking at the book's TOC it looks like there's a bunch of interesting ideas in there, I'm tempted to pick it up.
- cms07 14y agoI've got it, and though I haven't read much yet, it's definitely got some good stuff.
- meaty 14y agoI bought a copy after it was discussed here a while back. Overall it's a very good book and is worth purchasing IMHO. There are some notable holes and assumptions but it's probably the best attempt for a number of years.
- hailkuato 14y agoI love C for its simple syntax and "charm" (can a programming language be charming?) While the book does look fascinating, I can't help but wonder if it would be easier to go with languages like "Go" which was supposedly designed with 21st century considerations in mind?
- jsaxton86 14y agoYeah, I had the same thought. In fact, in the interview, the author actually picks up a copy of K&R C and looks through the index for "threading" and finds nothing, whereas Go was designed with concurrency in mind. On the other hand, as the author said, C is over 40 years old. Many consider that a weakness, but he considers it a strength, given the large number of C libraries available, whereas you don't have the same number of libraries with native Go bindings. Ultimately, of course, it comes down to using the right tool for the job. That may be C, that may be Go, that may be a higher-level language like Python, Ruby, etc.
- dualogy 14y agoJust to be fair though, binding 90% of C libs out there to your Go project is fairly painless & straightforward -- if a tad tedious for bigger libs.
- jlgreco 14y agoI've heard that doing that with Wayland's libraries is a royal pain because Wayland makes extensive use of function pointer based callbacks. So Go calling C calling Go. I'm not sure to what extent this sort of thing is common though, I haven't seen it often myself.
- cageface 14y agoThese days I won't even consider a language for serious work unless it has a reasonable set of built-in datastructures and algorithms. I'm just not interested in shopping around for a basic vector or hash or tree container or for a compatible set of elementary searching and sorting algorithms. I know you can find implementations of all of these in C but this is the kind of thing that really needs to be built in to any modern language. C is fine for writing device drivers etc where you can't really assume anything about your environment but for anything else it seems too bike-sheddish.
- aaronblohowiak 14y ago... then use glib, apr or acf.
- cageface 14y agoAnd hope that any client libraries and APIs I want to use made the same choices I did. Code reuse at the level of strings and containers is essential for any kind of higher-level programming. C fails here.
- jlgreco 14y ago> bike-sheddish It seems this term has evolved beyond any recognition to me. In what way is choosing C over another language that may provide more built in "arguing over something trivial/tangential"?
- jlarocco 14y agoFWIW, some of the advice in the book is pretty bad. The most unbelievable is to ignore memory leaks under 100Kb, but there are a lot of other examples. The first half of the book covers Git, autotools, Makefiles, and random topics tangentially related to C. If you're unfamiliar with those, it's an okay introduction to them, but there's some dubious advice in those sections, too.
- aidenn0 14y agoI consider "use autotools" to be dubious advice anyway.
- charlieflowers 14y agoThanks for sharing. Now I know not to waste time on the book. If I want to learn about Git, I'm not looking to learn it from a book about "Modern C".
- PommeDeTerre 14y agoWhy do people act surprised that C and C++ are still as viable as ever, and still very widely used? Do they not know that basically every important piece of software today is still written in those languages? Has this realization somehow been lost over time with the rise of languages like Java, PHP, JavaScript and Ruby, even though the major implementations of those languages are themselves built using C and/or C++?
- berntb 14y agoI remember how shocked I was ten years ago when talking to a newly educated guy about languages -- and he didn't know any C?! Then I realized... "of course, they only learn Java now". I left for scripting a long time ago, but still: Sad.
- gnuvince 14y agoI think a lot of people are surprised that C and C++ are still widely misused. Certainly for a lot of domains, their performance characteristics are not only attractive, but essential to the success of the application. But in many other domains, they could be replaced with other languages that would offer performances that are just as good, and be safer. For example, I go on IRC with weechat, which is written in C. An IRC client spends most of its time idling, waiting for network data or input from the user, so certainly it could be written in a language like OCaml.
- alexchamberlain 14y agoModern C++ is just as safe as any language. Unfortunately, you need to find a good tutorial that doesn't go low level before you need it.
- tptacek 14y agoThis is simply not true.
- PommeDeTerre 14y ago
- digeridoo 14y ago> today’s programmer can even go so far as to question the usage of malloc In old school or new school C, there's every reason to minimize the use of malloc and it's easy to avoid.
- huhtenberg 14y agoDo give the top 5 list of such reasons.
- aidenn0 14y agoI'll give one for old-school: heap fragmentation. You can't fragment a stack, block allocators have predetermined fragmentation behavior, heap is "who knows" It is possible to malloc() and free() for a very small net-total, and yet be no longer able to allocate a contiguous region that is a significant fraction of the heap. With a modern VM system, it's not quite as big a deal since your heap is effectively infinite for many applications. It is still an issue on embedded systems, and was a problem back in the day too.
- vrwarp 14y agoEven with a virtual memory addressing system, fragmentation still leads to space wasted. IIRC, fragmentation was one of the reasons firefox had reaaaally bad memory usage: http://pavlovdotnet.wordpress.com/2007/11/10/memory-fragmentation/ http://pavlovdotnet.wordpress.com/2007/11/10/memory-fragment...
- jonathanyc 14y agoIs it really down to you remembering correctly if you have a blog post to link to? :P
- alinajaf 14y agoQuestion from a newbie C developer: How can you avoid using malloc? Are you finding some clever way to do everything on the stack? Or are you perhaps allocating a large block of contiguous memory and slicing it up on your own? I've heard of both of those approaches and they sound pretty hard, so I'd be interested to hear your thoughts/be pointed to good references on the topic. Thanks in advance.
- amcintyre 14y agoThere is quite simply a vast array of libraries out there that every developer has access to. As Ben points out at the 10:50 mark, looking at GitHub we can find something on the order of 150,000 C projects. That's great, unless your employer/client/etc. is allergic to open source. I really can't consider something part of the language unless it's in a standard library that comes out of the box with the major compilers.
- jlgreco 14y agoMost anything that you might want will be BSD-style licensed without the attribution clause. If your employer is allergic to that... then your employer is an idiot. GPL'd, even LGPL'd, libraries are fairly few and far between.
- kabdib 14y agoI wrote kernel-level code for quite a few years. There, barebones C makes a lot of sense. (I can make a case for a subset of C++ that avoids many C++ issues, including use of RAII and similar things that get you into trouble in environments where /nothing/ is free, and you have to think carefully about the teardown strategy of every single allocation). Don't confuse "easy" with "simple". That's my latest mantra.
- huhtenberg 14y ago> a case for a subset of C++ Do elaborate. I come from the same background and I've been contemplating forking C for several years now. What you said sounds all too familiar to my own reasoning, so I'd be very curious to know what you have in mind. In broad strokes.
- jitl 14y agoTake a look at the C++ coding standards adopted for high-reliability areas. For example, the coding standards for the Joint Strike Fighter: http://www.stroustrup.com/JSF-AV-rules.pdf http://www.stroustrup.com/JSF-AV-rules.pdf
- kabdib 14y agoThose were mostly good (a little bit of crazy, but not much). The Google guidelines are okay for non-kernel work. I've worked on three teams that have independently converged on very similar guidelines (at Apple, a start-up, and a group in Microsoft). I find that convergence quite interesting.
- vvhn 14y agoa restricted subset of c++ (embedded c++) is exactly what is used to write drivers for Mac OS X. http://en.wikipedia.org/wiki/I/O_Kit http://en.wikipedia.org/wiki/I/O_Kit The kernel itself is in C though.
- alinajaf 14y agoCould be a coincidence, but I've been chanting that mantra at everyone who will listen after watching this talk by Rich Hickey: http://www.infoq.com/presentations/Simple-Made-Easy http://www.infoq.com/presentations/Simple-Made-Easy
- runn1ng 14y agoWhen I look at the page of the book itself http://shop.oreilly.com/product/0636920025108.do?intcmp=il-code-books-ben-klemens-code-podcast http://shop.oreilly.com/product/0636920025108.do?intcmp=il-c... what I noticed was > Use Autotools, C’s de facto cross-platform package manager. Seeing the word "autotools" sends familiar, but scary shiver down my spine. After some years with maven and CPAN, I don't ever want to go back to autotools, no thanks.
- psykotic 14y agoIt's also hard to think of anything less new school than freaking Autotools. There's a good kind of old school (C, UNIX, Audrey Hepburn) but Autotools isn't it.
- ikhare 14y agoWe use C quite heavily at Bump in our mobile apps. With our recent app Flock, we wrote nearly all non UI logic in C to be shared between iOS and Android. This made moving to a new platform much faster and easier than in times past. A lot of this core code is also used on the server to manage incoming connections from the clients as well. Aside from the ability to share code, it also makes sure that we are not using anymore memory than we really need. Avoiding unnecessary GCs is an important concern in writing performant Android Apps. Having the core C layer only hold on to as little memory as possible is a huge win. On a less objective note: When I left undergrad I thought I'd never write C again, but it was such a pleasure working with it again. Knowing (almost) exactly what operations your code is doing is quite liberating after working with so many other higher level languages and frameworks.
- jlgreco 14y ago> Knowing (almost) exactly what operations your code is doing is quite liberating after working with so many other higher level languages and frameworks. This is exactly why I still enjoy programming in C so much. Even compared to other languages that I adore and voluntarily use often, programming in C and programming in anything else feels like the difference between treading water in a swimming pool, and treading water in a murky lake. I just have a just a much greater, rather comforting, sense of situational awareness while using C.
- zanny 14y agoI have this same sentiment, but I use C++ just because templates, classes, smart pointers, lambdas, and namespaces are such huge productivity gains.
- antidoh 14y agoI keep on thinking I want to pick up C again (made a living with it 20 years ago), then I remember all the goodness that C++ adds (made a living with it 10 years ago), then I remember that C++ is huge and cryptic and I get all depressed again.
- kgabis 14y agoI love programming in C, however I'm getting the impression that right now almost every open job position is for java/.net/web developers. Besides embedded, where are C programmers needed?
- ramchip 14y agoFinance, mobile, desktop applications. In my (limited) experience most people use a C++ subset though.
- sramsay 14y agoLanguages are among the more religious topics in modern computing, and sometimes it can be hard to talk about them without immediately provoking a tedious flame war. I can only say that for myself, after programming for twenty years in every hot language you can name (really), that I now find myself going back to C more and more. Why? Because while others are writing Javascript-like languages that compile to Javascript, debating the merits of Rust vs. Go, insisting that a language without monads is unusable, arguing over whether a language without support for multiple inheritance can be "real OO," claiming that homoiconicity leads to mystical union, and proudly stating that x language is "almost as fast as C" -- while all of this is going on, there are legions of people who have been quietly building nearly every significant piece of the infrastructure of modern computing in a language that is now over forty years old. They don't whine, they don't go chasing after "frameworks," and they don't succumb to the twenty-one-days model of learning. They just build shit. Lots and lots of it. In fact, you're all soaking in it. Like I said, it's a religious subject. But as for me and my house, we will use C.
- charlieflowers 14y ago"But as for me and my house, we will use C." I had to upvote you just for that. (Not that I necessarily agree ... just that it's a hell of a clever ending).
- dlisboa 14y agoI read these types of comments by some people from time to time, usually from programmers who have been in the industry for a long time. They're always semi-derogatory towards new technology and carry a disclaimer the author has used said technologies. But, always, old ones are better. Usually for the sake of being older, not any inherent quality the comment has elicited. I love C above almost all languages you subtly referenced. I disagree with a lot of what you said, and a lot of what you implied. I just wish I never become that guy.
- sramsay 14y ago"I just wish I never become that guy." But hopefully you will, and I can tell you why. After a long and painful apprenticeship, you finally realize that being a great programmer has nothing to do with the language or its features. You get to the point where you're completely done learning this or that new technique (which, by the way, is nearly always an old thing for someone else). Your "profound enlightenment experience" with Lisp is ten years old; your copy of Design Patterns looks like an old Bible; you've had dozens of dirty weekends with stack-based languages, declarative languages, experimental languages, etc. You've been all of those places and done all of that. Many, many times. At that point, the pros on cons have fully evened out, and what you want is a tool that you can completely and totally master. You've stopped searching for tools without warts, edge cases, and gotchas, because you know those do not exist. What matters is community, ancestral memory, stability, maturity, docs. Above all, you just want to build something really great. It is at that point that you become that guy. You might well turn to C, as many before you have. Maybe, maybe not. Lots of us have. We aren't crusty old neanderthals, though. We're just at the logical end of the process.
- primitur 14y agoI've been a C programmer since 1984, and have been happily ignoring a lot of new-school language fads as a consequence. I've found that there's very little reason not to use C - it is small, it is fast, and with 30+ years of experience now, I don't get tripped up at all by any of its thorns. For me, now, new school C can be expressed in one word: Lua. Everything I need C++ to do, I can get Lua+C-bindings to do easier, with less fuss, and more productively in the short as well as long run due to the ease of use of the language. For almost every modern project I've worked on, the combination of a powerful C library collection and the Lua VM wrapper to make it all scriptable has been absolutely unbeatable. Sure, I write Python .. I've done more than my share of Ruby projects, and I could definitely spend a few years working in pure C++ if it were necessary. But the point is that none of these languages have been necessary recently, with my Lua+C skills ..
- skrebbel 14y agoI'm curious, could you write a bit more about how you do this? Do you write Lua programs with performance-intensive parts written in C? Or more like C programs with some component wiring in Lua? Where do you draw the line, and why? And what kind of software do you make this way?
- mikec3k 14y agoAt my last job (developing cross-platform mobile games for iOS & Android), we wrote our game engine in C++ with Cocos2d-X, with Lua bindings for every OS feature, such as in-app purchase, HTTP client, all Cocoas2d objects, etc. with all of the game logic written entirely in Lua. As long as you stay entirely in Lua, the performance is excellent. The only time you take a hit is when you call between Lua & C++. Generating the Lua bindings is very easy - there's a tool called ToLua++ which reads a simplified C++ header and generates the C code for the bindings.
- alinajaf 14y agoAs a newbie C developer I'd for one would really appreciate a follow-up to this if primitur has the time.
- schiang 14y agoC is a great language. I first learned programming with C back in college. After a few years off, I decided to pick up programming again but there aren't many resources for learning C. Most of the tutorials out there are for Ruby and Python. I have been learning Ruby for a while now and I'm now starting to go back to using C. I think if there were more educational websites teaching C, more people would use it. I think new programmers will appreciate coding a lot more if they learned C instead of using Ruby.
- eberfreitas 14y agoSlightly off-topic but as a primary PHP developer, how can I get into C? Are there any free resources or good books to get started?
- antidoh 14y agoK&R, and Harbison & Steele were my two favorites. HN says that Learn C The Hard Way by Zed Shaw is good. http://www.hnsearch.com/search#request/all&q=%22learn+c%22&start=0 http://www.hnsearch.com/search#request/all&q=%22learn+c%... http://news.ycombinator.com/item?id=1027549 http://news.ycombinator.com/item?id=1027549 As with any new language, once you're comfortable with a small core of the language, start working on your own problems. Start with little made up problems, and move on to useful tools as soon as possible. You don't have to be a master to write your own tools, and you won't become a master until after you've written your own tools.
- wmat 14y agoAnd here's a review of '21st Century C' from Andrew Binstock at Dr. Dobb's: http://www.drdobbs.com/architecture-and-design/developer-reading-list/240145159# http://www.drdobbs.com/architecture-and-design/developer-rea... Note that the review is on Page 2 of the article.
- bhrgunatha 14y agoSo learning C is on my list of things to do in 2013. I'm pretty experienced as a programmer, but mostly higher level languages than C. Would this book be a good place to start? What other recommendations could experienced C programmers offer. I'm not simply asking about the language, but best practices for memory management and toolsand above all, practical advice.
- leif 14y agoIMHO you're not an experienced programmer, but there will always be someone below you on the stack, so I should shut my loud mouth before someone puts my words in it. To your request, this is not a good place to start. By the table of contents, it appears to assume a working knowledge of C. Here are some ideas you can use to design your own "teach me C" course. Read K&R, and write some simple toys. Write your own "cp". Handle some errors, add some options. Try out fread(3)/fwrite(3), then try read(2)/write(2). Then write "mv" and do the same. Now make it fast within a filesystem. Or work across filesystems (depending on your first implementation). Then write an encryption or compression program. Now write a simple library, make a red/black tree. Store ints first, but then later, store generic objects (design your API carefully!). Make two iterators, one using a callback and one using a next() function. Decide which you like better. About now you may start to find your development environment lacking, do you use Make? Autotools? Something else? Go learn one and update your old projects to use it. While you're at it, write some tests for them. Did you handle command line options for your version of "cp"? Did you use getopt_long(3)? Might be a good idea. Oh by the way, does it support "-R"? Hmm...and your tree isn't reentrant either, better go learn about pthread locks. After a while, you should start learning some other libraries (because you want to do real work): curl, libxml, sqlite (hey these are in that book!). Study their code, their build systems, their test harnesses (oh man, especially sqlite's) and incorporate the ideas you like into your own work. Use them to build something cool, maybe a web crawler or whatever. Do you like music? Learn an audio library and make something. From here, you should direct yourself to what you like building, because you probably have enough tools to do the learning on your own. HTH
- subsection1h 14y ago
- sh_vipin 14y agoI have seen no system failing because it used C instead of C++. But I have seen many systems failing because of the improper use of C++. - http://syncfin.com/facebook-promote/ http://syncfin.com/facebook-promote/
- JoeAltmaier 14y agoSystems in C are not as ambitious, for good reason. So not a fair comparison. I've never seen a gingerbread house fall in; but lots of wood ones do!
- sh_vipin 14y agoNot ambitious !!! If it makes you feel happier , I will say , Linux, Gcc , valgrind .... all were NOT ambitious projects. But everybody knows what the FACT is !!
- JoeAltmaier 14y agoI design ambitious systems for a living. Quarter to half million lines of C++. Not possible to have made in C, in anything like the same time frame. So yes, 1000 monkeys on 1000 typewriters can make something large in C. But one guy (or a small team), properly trained and experienced, can move mountains with a high-leverage language.
- sh_vipin 14y ago"Not possible to have made in C." -- Is it really true ?? I don't need the answer. You need to answer yourself. "one guy (or a small team), properly trained and experienced, can move mountains with a high-leverage language." -- But if guy is not properly trained he can create a mess which is hell to clean also. "1000 monkeys on 1000 typewriters can make something large in C" -- Every time you are using an STL container, that container has already been written by someone else. Every template you use, compiler generates the actual code for it. Every time you include a library , it was written in actual C/C++ code by someone else. Use g++ -E option to compare the "pre processed" code and compare the things.