Ruby for Java Folks?

I’ve agreed to give a brief talk on Ruby for the Pikes Peak Java
Developers Group. I’ve done stuff like this before at work, but that
was for a crowd coming from a background of shell scripting and Perl.
I’m not much of a Java guy myself, but I know there’s a lot of overlap
between the Java and Ruby communities. I can easily spend 45+ minutes
on Ruby no matter what, but if any of you have any suggestions on what
an audience of Java programmers would be interested in, I’d welcome
suggestions.

Here’s some topics I plan to cover:

  • Everything’s a class.
  • Interpreted vs. compiled, and how that affects
    both language design and performance.
  • Static vs. dynamic typing, leading into
  • Duck typing.
  • Modifying library classes.
  • Modifying individual objects-- emphasis on
    using this for testing frameworks.
  • Briefly cover Test::Unit and maybe JRuby.

This is all subject to modification. I may bring Test::Unit in
earlier, when I tart talking about duck typing. I don’t, I think,
want to get into too much comparison between the two languages-- these
are very knowledgable Java people, much more so than I am. My best
approach, I think, is simply to present Ruby to them as a fun
language, perhaps for prototyping Java solutions, ideally as an end in
itself.

Any ideas on what else I should cover, or if I should de-emphasize
some of what I listed above would be welcome.

-=Eric

From: “Eric S.” [email protected]

I’ve agreed to give a brief talk on Ruby for the Pikes Peak Java
Developers Group. I’ve done stuff like this before at work, but that
was for a crowd coming from a background of shell scripting and Perl.
I’m not much of a Java guy myself, but I know there’s a lot of overlap
between the Java and Ruby communities. I can easily spend 45+ minutes
on Ruby no matter what, but if any of you have any suggestions on what
an audience of Java programmers would be interested in, I’d welcome
suggestions.

One possibility might be to show them JRuby? I used to do
that with Jython. Show Java people Python by running Jython
in interactive mode, and creating Swing or AWT windows right
from the command line. I presume JRuby has an IRB. . . .

If JRuby works like Jython, you can load any ol’ compiled
Java class and instantiate Java objects and call methods on
them interactively.

Back when I was programming in Java, I did as much coding in
Jython as possible, including writing all my unit tests in
PyUnit instead of JUnit. Far less tedious, from my point of
view. These days, I’d want to use JRuby instead of Jython…

Well, just a thought. . .

Regards,

Bill

One topic that I haven’t seen covered anywhere and would find useful is
a
mapping between java and ruby libraries, organised by application
domain,
and their differences in functional coverage: java is more than a
language,
it’s a platform and people spend more time learning libraries than the
core
language.
One common question for a java developer starting ruby is: in java I
would
use this lib to perform that task, what should I use in ruby?
I guess we should have a wiki page with that.

For example
domain: http
jakarta http-utils -> http-access2, open-uri

P@

On Thu, Mar 16, 2006 at 01:58:46AM +0900, Eric S. wrote:
} I’ve agreed to give a brief talk on Ruby for the Pikes Peak Java
} Developers Group. I’ve done stuff like this before at work, but that
} was for a crowd coming from a background of shell scripting and Perl.
} I’m not much of a Java guy myself, but I know there’s a lot of overlap
} between the Java and Ruby communities. I can easily spend 45+ minutes
} on Ruby no matter what, but if any of you have any suggestions on what
} an audience of Java programmers would be interested in, I’d welcome
} suggestions.
}
} Here’s some topics I plan to cover:
}
} * Everything’s a class.

Well, technically, everything’s an object, including classes. This leads
into everything else, so I agree that it should be first.

} * Static vs. dynamic typing, leading into
} * Duck typing.

I moved these two up. It is one of the most crucial differences between
Java and Ruby.

} * Interpreted vs. compiled, and how that affects
} both language design and performance.
} * Modifying library classes.
} * Modifying individual objects-- emphasis on
} using this for testing frameworks.

These are all pretty closely related. The unifying concept is that the
set
of methods on an object can be modified easily. Ruby is very similar to
JavaScript in this, though I like Ruby syntax better.

} * Briefly cover Test::Unit and maybe JRuby.
[…]
} Any ideas on what else I should cover, or if I should de-emphasize
} some of what I listed above would be welcome.

An incredibly important idea is that everything written in Ruby is
executed
code. When a class definition is read, for example, it defines the class
by
executing code, not by being compiled. That is why and how things like
attr_accessor work. It also means that when requiring files or including
modules order can matter, unlike Java’s import (which just imports a
namespace).

} -=Eric
–Greg

And let me add another one: “Coming to Ruby from Java”, by Francis
Hwang

http://books.rubyveil.com/books/ComingToRubyFromJava/Introduction/ComingToRubyFromJava

Best regards,

Julian I. Kamil [email protected]
http://pandora.rubyveil.com/ - Pandora Publisher
http://books.rubyveil.com/ - The Ruby Bookshelf

I agree with what others have said about presenting Ruby, and I’d sure
love
to find a good presentation I could give my own Java devs.

I’d want it to cover:

  • Ruby the language, Objects, Class, cool stuff
  • How Java features map to Ruby…someone else mentioned this, and it
    would
    be a huge help, especially with examples
  • JRuby would be very useful for demonstrating how Java devs can start
    using
    Ruby today. A lot of shops have standardized on “Java Only” and this is
    a
    sneaky way to get Ruby into the mix. If anyone complains about a
    non-Java
    language being used, you just have to mention SQL, XML, JavaScript, and
    so
    on.

For the first item, I’d hope someone has a good hour-long walkthrough of
Ruby and why it’s cool. I don’t know of any such document for the second
one. Finally, we have some good demos in JRuby CVS that might help you
with
that last one.

Hi Eric.

It’s safe to assume that your viewers will have seen this, and perhaps
you as well, but the Ruby Doc has a slide series entitled “10 Things
Every Java Programmer Should Know About Ruby”
(http://www.ruby-doc.org/docs/10%20Things%20Every%20Java%20Programmer%20Should%20Know%20About%20Ruby/10things.tgz).

It might prove useful for you insofar as what the author, Jim W.,
felt important to convey. Perhaps it’ll help you fine tune your
presentation.

“Wilson B.” [email protected] writes:

How about working through some of the examples from Refactoring by
Martin F., or Smalltalk Best Practice Patterns by Kent Beck, using
both Java and Ruby side-by-side?

Most of my good books (like Refactoring) are packed up, alas! But
I’ll see if I can’t come up with some simple examples of “Here’s how
you do it in Java, now here’s Ruby”. I want to avoid appearing to
diss Java at all; these are presumably smart people who don’t care to
have advocacy thrown at them; I just want to give them info.

One thing I really like about Ruby is that certain tasks (like
enumeration) have much less code overhead than in Java, which promotes
nice, small methods that are easy to refactor or rework. Even if it’s
only 6 lines, there’s some mental resistance to setting up a loop in
Java.

Yeah, I have to admit that, having done some C recently (had to
interface with a new device driver, and didn’t want to learn how to do
ioctls in Ruby at the time), I hate doing C/Java-style for loops like
this:

String [] fileNames = new File( “/home/emschwar” ).list();
for(int i=0; i < fileNames.length; i++) {
System.out.println(“directory entry named [” + fileNames[i] + “]”);
}

There’s no real reason for it, but it focuses my mind more on the
array (how I set it up, how I’m iterating over it) when I’m reading it
than in the Ruby below:

Dir.entries(‘/home/emschwar’).each { |e|
puts “directory entry named [#{e}]”
}

Here, I’m more focused on what I’m doing to each element-- this
reminds me a lot more of Perl’s map (and Lisp’s mapcar) function, but
when I use Perl, I feel like I’m turning the iteration inside out;
here it’s just a much simpler way of doing the same for loop above.
Without complaining about Java, showing how Ruby iteration eliminates
the need for explicit iterators would certainly be powerful stuff.

(personally, I prefer do…end, but used {} here to make Java people
feel more comfortable :slight_smile:

-=Eric

“Patrick Chanezon” [email protected] writes:

One topic that I haven’t seen covered anywhere and would find useful is a
mapping between java and ruby libraries, organised by application domain,
and their differences in functional coverage: java is more than a language,
it’s a platform and people spend more time learning libraries than the core
language.

Right. The problem I have is that I’m, as I said, much more of a
Perl/Ruby guy than a java one; they’ll know standard (and useful,
nonstandard) libraries better than I will.

One common question for a java developer starting ruby is: in java I would
use this lib to perform that task, what should I use in ruby?
I guess we should have a wiki page with that.

That would be useful. I’m giving the talk on Tuesday, though (I
volunteered as a last-minute replacement for the regular speaker who
had to cancel), so if someone has information like that, I can use it,
but I don’t think I have time to develop it on my own.

-=Eric

On 3/15/06, Eric S. [email protected] wrote:

This is all subject to modification. I may bring Test::Unit in
earlier, when I tart talking about duck typing. I don’t, I think,
want to get into too much comparison between the two languages-- these
are very knowledgable Java people, much more so than I am. My best
approach, I think, is simply to present Ruby to them as a fun
language, perhaps for prototyping Java solutions, ideally as an end in
itself.

Any ideas on what else I should cover, or if I should de-emphasize
some of what I listed above would be welcome.

How about working through some of the examples from Refactoring by
Martin F., or Smalltalk Best Practice Patterns by Kent Beck, using
both Java and Ruby side-by-side?

One thing I really like about Ruby is that certain tasks (like
enumeration) have much less code overhead than in Java, which promotes
nice, small methods that are easy to refactor or rework. Even if it’s
only 6 lines, there’s some mental resistance to setting up a loop in
Java.

Eric S. wrote:

Any ideas on what else I should cover, or if I should de-emphasize
some of what I listed above would be welcome.

Personally, I still think Stephen W.’ “Learn Ruby” slideset 1 is
really good for introducing or showing experienced programmers what Ruby
can do. I’d recommend at least skimming that, even if only to see what
topics you forgot to include. I point out that the Learn Ruby slideset
is predominantly code snippets and irb transcripts – and I think that’s
a good thing.

Patrick Chanezon mentioned building a mapping of Java stdlib to Ruby
stdlib. I think this is a good idea, too, not just for your talk, but
Rubydom in general.

Pistos

String [] fileNames = new File( “/home/emschwar” ).list();
for(int i=0; i < fileNames.length; i++) {
System.out.println(“directory entry named [” + fileNames[i] + “]”);
}

There’s no real reason for it, but it focuses my mind more on the
array (how I set it up, how I’m iterating over it) when I’m reading it
than in the Ruby below:

Dir.entries(’/home/emschwar’).each { |e|
puts “directory entry named [#{e}]”
}

File yourFolder = new File("/home/emschwar");
for (String n : yourFolder.list()) {
System.out.println(“directory entry named [” + n + “]”);
}

/// shorter:

for (String n : new File("/home/emschwar").list()) {
System.out.println(“directory entry named [” + n + “]”);
}

/// shorter:
/// using jakarta-commons-IO + Java 5 static-imports
/// I’m always using jakarta-commons

for (String n : list("/home/emschwar")) {
out.println(“directory entry named [” + n + “]”);
}

Greetings
Christoph