Archive

Posts Tagged ‘Ruby’

Ruby on .NET?

December 7, 2005 Leave a comment

I appears that researchers at QUT‘s Programming Languages and Systems group are working on an implementation of Ruby for .NET. The “secret” is reveal on this page. The work is support by Microsoft Research. Davis Thomas also mentions it in an article about the emergence of agile languages. There seem to be no other sources of information at present.

It turns out that John Gough organised a birds of a feather for Implementing Dynamic Languages on the .NET CLR at the Dynamic Languages Symposium back in October (2005).

QUT is my old university and John Gough my was my favorite lecturer. I studied compiler construction under John and later wrote a small compiler under his supervision in C# targetting .NET (and using his book Compiling for the .NET CLR as a resource). It’s a small world. I’m working in the UK at the moment. The guy who sits next to me at work comes from South Africa. He studied under Pat Terry at Rhodes University. Pat is also a compiler guy. John and him were involved on the Modula-2 language commitee. Turn’s out that I used Pat’s Coco/R (C# version) on that project.

Dependency Injection – Vitally Important or Totally Irrelevant

October 25, 2005 Leave a comment

Jim Weirich has an excellent presentation that will make Java developers think differently about dependency injection.

Java…Ruby…Groovy

http://onestepback.org/articles/groovy/groovyspeed.html

If you read the entire article above please note that closures have *indefinite* extent , not *dynamic* extent.

Continuations for curmudgeons

April 24, 2005 Leave a comment

Sam Ruby has a much praised blog entry entitled “Continuations for Curmudgeons“.

I didn’t like the tone of the article which seem to treat the C programmers as some kind of dinasaur with no interest in other languages (or language features).

There was no mention of Scheme. When learning about continuations I think it’s best to learn from the source. That source appears to be the Scheme programming language. R5RS includes call-with-current-continuation function usually shortened to call/cc. A really good introduction to Scheme with coverage of continuations for non-trivial applications is contained in Dorai Sitaram’s Teach Yourself Scheme in Fixnum Days (TYSiFD).

Sam seems to have some confusion about continuations and there relationship to closures, iterators, generators and coroutines. Just because a language has a “yield” keyword doesn’t mean it has first class continuations. Yield is usually used for generators. One of the highlights of TYSiFD is implementing coroutines with continuations.

Ruby supports first class continuations. The callcc method is available from the Kernel class. I played around with the code from the Ruby documentation of the Continuation class. You really don’t need call/cc for the contrived example there:

original_guys = ["Freddie", "Herbie", "Ron", "Max", "Ringo"]

puts "method 1: (first-class) continuation"
guys = original_guys.clone
callcc{|$k|}
puts(message = guys.shift)
$k.call unless message =~ /^R/;

puts
puts "method 2: continuation with different way of setting global"
guys = original_guys.clone
callcc{|k| $k = k}
puts (message = guys.shift)
$k.call unless message =~ /^R/;

puts
puts "method 3: just a loop"
guys = original_guys.clone
loop {
  message = guys.shift
  puts message
  if (message =~ /^R/)
    break
  end
}

puts
puts "method 4: (tail) recursion using methods/functions"
puts "          Ugly - needs guys to be global variable."
$guys = original_guys.clone
def myloop
  message = $guys.shift
  puts message
  unless message =~ /^R/
    myloop
  end
end
myloop

puts
puts "method 5: (tail) recursion using blocks"
guys = original_guys.clone
myloop = Proc.new{
  message = guys.shift
  puts message
  unless message =~ /^R/
    myloop.call
  end
}
myloop.call

puts
puts "method 6: using each and catch/raise"
guys = original_guys.clone
catch (:early_exit) {
  guys.each {|item|
    puts item
    if item =~ /^R/
      throw :early_exit
    end
  }
}

Static versus dynamic attitude

February 22, 2005 Leave a comment

I think Bill is dead-on-the-money with the different-language, different-mindset thing. Java can make you feel guilty alright :-). Even when you can get over your own guilt, there’s the struggle with your colleagues who may not have a dynamic mindset.

I’ve been programming in JavaScript lately (actually more ActionScript 2.0 but some browser based JavaScript too). You’d probably return a single object there rather than multiple:

    var context = ExamplePage.process();

followed by code using context.forumID, context.reply, context.subject and context.body.

Single objects are constructed easily in JavaScript:

    function process() {
        // Do some processing...
        return {
            forumID: ...,
            reply: "a reply",
            subject: "a subject",
            context: "a context"
        }
    }

This is a very lightweight approach. Another poster had a similar solution in Python. There must be a similar way of doing this in Ruby or Groovy.

It would be great to use Ruby/JRuby, Groovy, JavaScript, Python/Jython or whatever on the Java platform. What’s needed for adoption is buy-in by vendors like Sun and IBM (so that project managers and other developers don’t have a fit when something without the .java or .xml file extension is checked into the repository). It would be nice to have support for these languages in Eclipse (say) with all the usual bells-and-whistes Java programmers have come to rely on to get stuff done – code completion, Javadoc lookup, hyperlinking, refactoring etc. Groovy seems to have alot of momentum including a JSR thing – so maybe something along these lines is not too far away. Maybe it’s already there and I just haven’t looked!

BTW – have you heard about NoXML? It’s this great new XML technology…