This started off as an internal thread as to why C++ just downright sucks. There’s been a whole lot of hoopla around the security vulnerabilities while writing C++ code, specifically to do with delete and delete[]. I frankly think C++ for a large scale project is a big mistake.
Lately, we’ve been edging over to writing all our C code within the Ruby interpreter. There are a number of reasons:
- Within the Ruby interpreter, the language-stack frame (the interpreter uses alloca a lot) and the C stack frame are merged into one.
- In other words, the mark-and-sweep garbage collection walks the C stack frame and the language stack frame in a unified way to mark objects that are currently in use.
- The rb_hash_*, rb_str_* and the rb_ary_* API are as powerful, if not more as stl::map, stl::string and stl::vector and you get free regex support for the String objects that you create/manage.
- With rb_yield and rb_raise, you get iterator support, as well as exception handling without worrying about dangling pointers and unfree’d memory during stack unwinding.
- And yes, you get to ‘include Enumerable‘ (rb_include_module) into your class as long as you implement the each method in your Class, so that the caller can do obj.each to iterate over your internals. This, BTW, is essentially the Visitor pattern.
- It forces you to think about what you build as an Object giving you full OOP within C with no worries about vtables and the goriness of virtual functions. Just for the record, I hate when you override a protected method, have a typo in the method signature (missing const, for example) and debug for a few hours as to why your overridden method is never invoked.
- The code, without the all pervasive checks for errno’s and return values, actually makes it readable by anyone. All you do it invoke rb_raise to raise an exception when there’s an error condition and rb_rescue to catch it.
- Whatever you write is automatically scriptable, without having to build an explicit API. It’s amazing how many people spend time on taking an existing implementation to build an API on it.
- The previous point means, you can build runit
test cases to validate your code to make sure it works as expected.
If you are embedding the interpreter in your C code, just make sure you call ruby_init() in main() so that garbage collector doesn’t end up with negative offsets. More on this in a later blog.

Pingback: Buy Facebook Fans
Pingback: anal
Pingback: guaranteed rankings
Pingback: best supplements for muscle gain
Pingback: Dallas Boudoir Photographer
Pingback: Dallas Senior Portrait Photographer
Pingback: downtown dentist toronto
Pingback: pre workout supplements
Pingback: Non-Lethal Weapons
Pingback: best pre workout supplements
Pingback: Phil Cannella
Pingback: Phil Cannella
Pingback: stop smoking aides
Pingback: flights to pakistan
Pingback: Lowcost Cruises Deals
Pingback: womens boots
Pingback: noclegi zakopane
Pingback: SATNAV
Pingback: watch free movies online
Pingback: inkjet cartridges
Pingback: uzaktan egitim
Pingback: website
Pingback: Free Dell XPS M1530
Pingback: traffic
Pingback: engagement rings uk
Pingback: Cary Leung Sun Life
Pingback: Prenatal Massage NYC
Pingback: Vacation Rentals
Pingback: Lucia Emiraz
Pingback: Do follow backlinks
Pingback: iphone
Pingback: Escort girl Paris
Pingback: Merchant Services
Pingback: facebook smiley penguin
Pingback: western digital drives
Pingback: bingo game cards
Pingback: shutter graphics
Pingback: LED Tester
Pingback: omega fish oil supplements
Pingback: bsn syntha 6
Pingback: tanie noclegi zakopane
Pingback: Cheap Payday Loans
Pingback: what is serotonin
Pingback: Law Careers
Pingback: where to buy coleman grill
Pingback: motivation for weight loss
Pingback: haier portable air conditioner 9000 btu
Pingback: pain during intercourse after pregnancy
Pingback: commercial inspections
Pingback: New york city hotels
Pingback: Visit
Pingback: earn money
Pingback: cholesterol
Pingback: beauty therepy
Pingback: garbage disposal
Pingback: Scott Tucker Payday Loans
Pingback: Scott Tucker Payday Loans
Pingback: Mizuno Baseball Cleats
Pingback: Water Softeners
Pingback: electrician
Pingback: motivation for weight loss
Pingback: covers for iphone
Pingback: halloween costumes store
Pingback: best electric toothbrush
Pingback: holiday home insurance
Pingback: movies news
Pingback: Scott Tucker Racing
Pingback: Scott Tucker Racing
Pingback: http://freeipad2now.com/how-to-get-free-ipad-2/
Pingback: free ipad
Pingback: check out this website
Pingback: super bowl live streaming
Pingback: dunedin homes
Pingback: REO Real Estate Owned
Pingback: electric shaver
Pingback: BPO Companies
Pingback: broker opinion
Pingback: Website Hosting