Forum: Ruby Ruby for Java Folks?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4df2f657ab76cbe68ad71628b24d2c91?d=identicon&s=25 Eric Schwartz (Guest)
on 2006-03-15 18:04
(Received via mailing list)
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
4feed660d3728526797edeb4f0467384?d=identicon&s=25 Bill Kelly (Guest)
on 2006-03-15 18:20
(Received via mailing list)
From: "Eric Schwartz" <emschwar@fc.hp.com>
>
> 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
09e350bfc64f256f1ff126f767f67597?d=identicon&s=25 Patrick Chanezon (Guest)
on 2006-03-15 18:29
(Received via mailing list)
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@
Bf6862e2a409078e13a3979c00bba1d6?d=identicon&s=25 Gregory Seidman (Guest)
on 2006-03-15 18:38
(Received via mailing list)
On Thu, Mar 16, 2006 at 01:58:46AM +0900, Eric Schwartz 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
90ebe8da17aabd36cc30d9f96a530e6f?d=identicon&s=25 James H. (Guest)
on 2006-03-15 19:59
(Received via mailing list)
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%2...).

It might prove useful for you insofar as what the author, Jim Weirich,
felt important to convey.  Perhaps it'll help you fine tune your
presentation.
Bea287582f4125fa81a2ca945bd48753?d=identicon&s=25 Julian I. Kamil (Guest)
on 2006-03-15 20:34
(Received via mailing list)
And let me add another one: "Coming to Ruby from Java", by Francis
Hwang

http://books.rubyveil.com/books/ComingToRubyFromJa...

Best regards,

Julian I. Kamil <julian.kamil@gmail.com>
http://pandora.rubyveil.com/ - Pandora Publisher
http://books.rubyveil.com/ - The Ruby Bookshelf
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles O Nutter (Guest)
on 2006-03-15 21:27
(Received via mailing list)
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.
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-03-15 21:58
(Received via mailing list)
On 3/15/06, Eric Schwartz <emschwar@fc.hp.com> 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 Fowler, 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.
4df2f657ab76cbe68ad71628b24d2c91?d=identicon&s=25 Eric Schwartz (Guest)
on 2006-03-15 23:30
(Received via mailing list)
"Wilson Bilkovich" <wilsonb@gmail.com> writes:
> How about working through some of the examples from Refactoring by
> Martin Fowler, 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 :)

-=Eric
4df2f657ab76cbe68ad71628b24d2c91?d=identicon&s=25 Eric Schwartz (Guest)
on 2006-03-15 23:36
(Received via mailing list)
"Patrick Chanezon" <chanezon@gmail.com> 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
0868c9f925306d2f86ae5383c3b21a5f?d=identicon&s=25 Christoph Hess (Guest)
on 2006-03-16 12:06
(Received via mailing list)
> 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
A402df36168b81b31c17adcbb5ae8cf4?d=identicon&s=25 Pistos Christou (pistos)
on 2006-03-16 15:41
Eric Schwartz 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 Waits' "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.

[1]: http://www.waits.net/~swaits/LearnRubyTalk/learnruby.html

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
This topic is locked and can not be replied to.