This is really, really cool. If I could make one recommendation, after finishing the tutorial it wasn't clear to me what do next. I want to keep learning more C and about the Ruby source code but it just sort of leaves me hanging.
Thanks wasd. The next thing you could do, is highlight some C and ask the community any questions you have. I intend to keep writing the series, since there's easily enough material there for a book. If you signup for an Omniref account, you can follow the project and you'll be emailed whenever I post new content.
This is an awesome book, and I highly recommend it. Just be aware that very little of the book concerns itself with C. The majority of the book is an excellent tour of the internals of the Ruby interpreter.
Also of interest might be this series of blog posts currently being written: Reconstructing Ruby in C [0]
Being able to rewrite a small section of ruby code in C is a great way to speed up some types of manipulations. This has yielded me two magnitudes of speedup multiple times in my career so far.
Here's an example using RubyInline, which is a gem that handles the compilation step for you:
Sorry, I have to disagree with you there, as someone with decades of C and c++ experience, this is very dense, averagely-tidy, but using some very-definitely-bad-practice macros (See the definition of "SHOW").
C and C++ can look a hell of a lot better than this....
As someone who has written C professionally in the past, I agree. IMO this is fairly ugly C. Definitely can't see why someone would consider it to be beautiful.
That said, there are some neat things I've seen in the ruby C code in the past. I thought [1] was pretty clever (this pattern shows up several times in the ruby source) the first time I saw it, since it lets you access the members of the union like `foo->as.thing`, which is fairly pretty IMO.
Do you want to learn how CPython internals work or do you want to learn how to bind C code with Python? If it's the latter, I can point you to the excellent CFFI library[0], the documentation is pretty clear and it's pretty easy to get going.
Yes, the disconnect extension has a bug that breaks the site JS. It's on our to-do list, but working around extensions that are doing funky things has not been our highest priority.
Update: I've got a fix for this going out now. Let me know if it's still broken.
This is pretty neat. Mucking around with ruby-c connections and python-c++ connections via SWIG have been some of the most nightmarish things I've ever worked on, so it's cool to see effort aimed at making that sort of connection more comprehensible. Are there other similar things you're thinking of doing next?
We're planning a C memory management follow up, with a focus on Ruby GC and its recent improvements. We're also looking for authors to feature who write similar content, so if you wanted to do a series on a particular chunk of C you've worked with, that'd be sweet too.
I really dislike that this teaches you how to use the Ruby virtual machine in C rather than just C itself. If you tried to hop from this over to a real, true C project, you would be totally lost, which isn't what you want from a tutorial.