Ruby-Talk – rb_str_new2 cleanup, ruby GUI libraries and Ruby vs Python

Note: This is a weekly round up of interesting stuff found on ruby-talk mailing list. You can subscribe to this list here.

1. Steven wondered whether it is necessary to clean up the string created from native C code(rb_str_new2) and passed to rb_funcall. Matz replied,

You don’t have to (and you shouldn’t) free string objects.

2. Mohsin asked which is the better Ruby GUI Library, Ruby-GTK or FXRuby?. Both seemed good candidates and there were some additional recommendations such as JRuby + Swing + Monkeybars(James). Daniel recommended WxRuby,

I’ve had very good results with WxRuby; It didn’t take long to learn, is NOT very rubyish (basically the C++ APIs are reimplemented in Ruby), but was very useful for cross-platform development. So you might want to consider that as a third option.

3. There was a big discussion (started by Marc) on differences between Python and Ruby. Michael had some good points on Ruby,

a. Flexible syntax of Ruby

b. Enough support for functional programming without having to fight with the language

c. A friendly community – he laments that this is on the decline!

d. No syntactic whitespace as in Python

As Ruby and Rails is becoming a mainstream language/framework it is only natural that you get more of the RTFM type of questions in the mailing groups. In my opinion there is no point in bitching about it, but rather politely point to the relevant documentation.

As far as Rails is concerned it is a big mess. The Rails 2 is out, but there is no documentation for a beginner in Rails 2. All the books are still stuck at earlier versions and for any documentation available online you need to pay! The only book available (3rd edition of Agile Web development with Rails) is still in beta and requires a lot of rewrite before it can be useful. So it is only natural that you get basic rails questions even on Ruby mailing lists and forums!

In another thread Mohit gives this explanation,

I see this as a sign that Ruby is picking up and gaining traction in other places.  There was a time when there were a lot of people who were discovering Ruby on their own free will and were looking at documents (online or offline) and trying out different things.  As it gains traction, it approaches the point where people are having Ruby thrust on them (possibly more Rails than Ruby) either due to preference of people further up in the food chain or due to clients (specially in the case of outsourced projects).  In such cases, it’s likely that the engineer is just venting frustration about the language on a forum cos it’s something they werem’t born to, or achieved – it was thrust on them.

4. Tim wanted to know the best way to delete every other value in a ruby array.  For example [a b c d e f g h i j k] becomes [a c e g i k]. There were a number of solutions proposed,


arr = %w[a b c d e f g h i j k]
p{|x| arr.index(x) % 2 == 0}


 a = %w(a b c d e f g h i j k)
1.upto(a.size/2) {|i| a.delete_at i}


a = %w(a b c d e f g h i j k)
n = (a.size/2.0).ceil
n.times do |i|
a[i] = a[2*i]

Leave a Reply