Hacker News new | past | comments | ask | show | jobs | submit login
C for Rubyists (omniref.com)
178 points by montanalow on Sept 30, 2014 | hide | past | favorite | 27 comments



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.


In fact, such a book has been written before already: http://patshaughnessy.net/ruby-under-a-microscope


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]

[0] http://www.halogenandtoast.com/reconstructing-ruby-our-first...


That's a great book -- highly recommended. But there's plenty more ground to cover!


Thank you. I just found that that title is included in O'Reilly's Safari.


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:

http://stevenjewel.com/2013/11/detecting-headphone-use/


Thank you for linking that.

I always imagined that ruby and c were worlds apart, and that it took a crazy level of mastery to make them work together.

That thought led me to this article about embedding rust in ruby

http://brson.github.io/2013/03/10/embedding-rust-in-ruby/


Great format! And Ruby source is good for learning C. I really got into it with Matz ruby source code.

For anyone intersted how Ruby parser works, I've written small article about patching ruby syntax: https://zarkzork.com/extending-ruby.html


Very pretty C code. Rarely I find myself thinking 'C is beautiful'


I thought the same thing. It's like Matz writes C the way he'd like to write ruby. I also see some smalltalk inspiration in his style.

Very neat.


If I was able to write that kind of C code, I'd never feel the need to use ruby, python maybe even lisp :)


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....


In what way is it beautiful? I had a look and found it to be covered in nasty #ifdefs.


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.

[1] https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#...


Can anyone point to something parallel for Python? Python-experienced C-neophyte feeling envious over here.


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.

[0]: http://cffi.readthedocs.org/en/release-0.8/


I'd be pretty interested in the former, but C isn't my forte. :(


I was thinking the former, but the latter is also of interest. Thanks!


Strange, with the Disconnect extension enabled, all I saw was the code, and not the annotation which I think is the meat of this submission.

If you don't see anything, try disabling social-blocking extensions.


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.


Glad you finished all your high priority tasks and made it to working around extensions doing funky things ;-)


I can only see the code, without blocking anything. Should I sign in or something?


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.


there are tons of general purpose c tutorials out there; this one is specifically for rubyists looking to learn how to write extensions in c




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: