Ten Things Every Java Programmer Should Know About Ruby

We will be introducing Ruby to our XP Users group in Cincinnati next week.
I thought it would be fun to create a list of "Ten Things Every Java
Programmer Should Know About Ruby" to help the transition. I've got a
number of things in my head, but would love to hear ideas from the mailing
list.

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

···

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

Well, it would obviously need to be adapted, but I loved this article:

   http://dirtsimple.org/2004/12/python-is-not-java.html

Nathaniel
Terralien, Inc.

<:((><

···

On Jan 27, 2005, at 12:55, Jim Weirich wrote:

What things should a Java programmer
be aware of when starting out in Ruby?

Hi,

We will be introducing Ruby to our XP Users group in Cincinnati next week.
I thought it would be fun to create a list of "Ten Things Every Java
Programmer Should Know About Ruby" to help the transition. I've got a
number of things in my head, but would love to hear ideas from the mailing
list.

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

1- Ruby does not have type casting.
2- Try to not think about interfaces, but enjoy fully the dynamic typing.
3- No overload of methods.
4- Enjoy closures/blocks.
5- Don't worry about performance until the program/library has been made.
6- Web-development is possible with other languages besides Java.
Enjoy FastCGI and mod_ruby. Give Rails a shot.
7- Ruby has O/R mappers, so find your Ruby "hibernate", but drop any
preconceptions.
8- Ruby has MVC and OO programming and libraries, but drop any preconceptions.
9- Ruby is a language to be used everywhere. You use it even in
templates. No need for "Velocity/JSP."
10- Ruby is not a Silver Bullet, unlike Java, right? :slight_smile:

Cheers,
Joao

···

On Fri, 28 Jan 2005 02:55:46 +0900, Jim Weirich <jim@weirichhouse.org> wrote:

1) Ruby rocks.

Seriously though... It's been a while since I've done any Java coding,
but, the first points that came to my mind are:

-In Ruby data is strongly typed, but variables are *not* (no messy
typecasting, yay!)
-No method overloading (probably as a result of the above, but that is
just speculation)
-*BUT* you can have variable number of parameters, and multiple return values

of course, the list of differences goes on and on, but those were the
first 3 that came to my mind.

···

On Fri, 28 Jan 2005 02:55:46 +0900, Jim Weirich <jim@weirichhouse.org> wrote:

We will be introducing Ruby to our XP Users group in Cincinnati next week.
I thought it would be fun to create a list of "Ten Things Every Java
Programmer Should Know About Ruby" to help the transition. I've got a
number of things in my head, but would love to hear ideas from the mailing
list.

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

Classes really are objects. this is the reason why e.g String.new makes
much more sense then Java's new String();

martinus

1. Once you start coding Ruby, going back to Java is painful.

Mike

···

On Jan 27, 2005, at 10:55 AM, Jim Weirich wrote:

We will be introducing Ruby to our XP Users group in Cincinnati next week.
I thought it would be fun to create a list of "Ten Things Every Java
Programmer Should Know About Ruby" to help the transition. I've got a
number of things in my head, but would love to hear ideas from the mailing
list.

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

Jim Weirich wrote:

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

Schwern's paper is written for Perl, but it rings of many Rubyisms.
<http://magnonel.guild.net/~schwern/papers/Why_I_Am_Not_A_Java_Programmer/why.html&gt;

_why

I would suggest that once you come up with the top ten list, it would
be really nice if you did post it to the mailing list. I'd like to
forward it to some friends.

Kind Regards,
Ed

···

On Fri, 28 Jan 2005 02:55:46 +0900, Jim Weirich <jim@weirichhouse.org> wrote:

We will be introducing Ruby to our XP Users group in Cincinnati next week.
I thought it would be fun to create a list of "Ten Things Every Java
Programmer Should Know About Ruby" to help the transition. I've got a
number of things in my head, but would love to hear ideas from the mailing
list.

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

--
Alcohol is the anesthesia by which we endure the operation of life.
-- George Bernard Shaw

That you can write Ruby in Java:

Cheers

···

On Jan 27, 2005, at 18:55, Jim Weirich wrote:

What things should a Java programmer
be aware of when starting out in Ruby?

--
PA, onnay equitursay
http://alt.textdrive.com/

Take a look at: http://fhwang.net/blog/40.html

Dan

Jim Weirich wrote:

···

We will be introducing Ruby to our XP Users group in Cincinnati next week.
I thought it would be fun to create a list of "Ten Things Every Java
Programmer Should Know About Ruby" to help the transition. I've got a
number of things in my head, but would love to hear ideas from the mailing
list.

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

Jim Weirich wrote:

We will be introducing Ruby to our XP Users group in Cincinnati next week.
I thought it would be fun to create a list of "Ten Things Every Java
Programmer Should Know About Ruby" to help the transition. I've got a
number of things in my head, but would love to hear ideas from the mailing
list.

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

One of my favorite features in Ruby is the fact that the object definition never closes. You can always add new methods, change methods and delete existing methods on an object at runtime even if that object is implement in C or is one of the core objects of the system.

The Ruby Facets library (http://calibre.rubyforge.org/facets/doc/index.html\) is a great example of doing this and anybody that has done even a minor project usually has augmented one of the core objects a little to make it fit in their application domain better. And since you are simply modifying a existing class and not creating a new (or subclassing a existing class) all your literals work still. So when you do:

foo = "A string of text"
foo.my_special_function

It just works. Just my 2 cents.

Eric

My 2 ¥

(1) No explicit types. Probably the most disconcerting thing for a Javahead.
(2) Because of (1), you cannot rely on the compiler to catch trivial mistakes.
(3) Think in terms of methods (behaviors) instead of classes.
(4) KISS.
(5) Discipline. Because of its inherent flexibility, Ruby require more self-discipline.

Cheers

···

On Jan 27, 2005, at 18:55, Jim Weirich wrote:

What things should a Java programmer be aware of when starting out in Ruby?

--
PA, onnay equitursay
http://alt.textdrive.com/

In addition to the many great suggestions already made, here are two more:

* Many things that you're used to thinking of as syntax are now just code.

* For good (but subtle) reasons, you have to leave the '++' and '--' operators behind. You can still use '+=' and '-=', though.

Although I understand the reasons for that last one, years of C, C++, Perl, and Java still lead me to try to use them in Ruby every now and then.

---Glenn

These are the concepts that got me interested, by leveraging my
Java/C++ heritage, my mild Perl experience, my Python experiment, and
the Smalltalk mystique that drifts back and forth across the computing
landscape...
1. you can fit in your mind and write code without looking at the docs
every six minutes.
2. less syntax and less typing
3. Fixed what's wrong with Perl
4. Fixes what's wrong with Python
5. It's super productive (like Perl, Python and Smalltalk)- maybe 5-10x Java.

This excited me, because I always wanted to learn Smalltalk...
= 6. Is a lot like Smalltalk, but doesn't look as funny

JavaScript gets some unfair knocks, so maybe best avoided...
+ 7. Is a lot like JavaScript, but more OO and more for ful app development

The following are cool when you know them, and in many ways the heart
of Ruby, but were meaningless to me until I banged my head against
them for a while. I think a lot of what is exciting about Ruby is
better learned then taught, much like Zen meditation. Just think what
marketing these concepts did for Smalltalk and Lisp- Java and C#.
* 8. Blocks and Closures
* 9. Open Classes
* 10. Duck Typing

Regards,
Nick

···

On Fri, 28 Jan 2005 02:55:46 +0900, Jim Weirich <jim@weirichhouse.org> wrote:

We will be introducing Ruby to our XP Users group in Cincinnati next week.
I thought it would be fun to create a list of "Ten Things Every Java
Programmer Should Know About Ruby" to help the transition. I've got a
number of things in my head, but would love to hear ideas from the mailing
list.

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

"Jim Weirich" <jim@weirichhouse.org> schrieb im Newsbeitrag
news:9813.192.223.163.6.1106848530.squirrel@weirichhouse.org...

We will be introducing Ruby to our XP Users group in Cincinnati next

week.

I thought it would be fun to create a list of "Ten Things Every Java
Programmer Should Know About Ruby" to help the transition. I've got a
number of things in my head, but would love to hear ideas from the

mailing

list.

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

There are no interfaces - and you don't need them.

There are anonymous functions, called "blocks" or "lambdas". Learn to use
them.

Use IRB.

"finally" is called "ensure". Use blocks for transactional behavior like
File.open() does.

Cou can find help here:
  http://www.ruby-doc.org/
  Ruby Programming Language
  news:comp.lang.ruby

Strings are mutable but can be frozen.

Don't worry if your Ruby program is half LOC of the same Java program. As
soon as you get experienced this will drop to one fourth or less. :slight_smile:

"Serializing" is called "marshalling" in Ruby.

You can keep your habit of ending every statement with a semicolon - but
without them Ruby code looks much better.

Kind regards

    robert

Jim Weirich wrote:

We will be introducing Ruby to our XP Users group in Cincinnati next week.
I thought it would be fun to create a list of "Ten Things Every Java
Programmer Should Know About Ruby" to help the transition. I've got a
number of things in my head, but would love to hear ideas from the mailing
list.

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

You will end up writing less code and it will do more.

An instance of a class can be extended to be subtly different, without needing to subclass.

···

On Jan 27, 2005, at 10:55 AM, Jim Weirich wrote:

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

Since all access to the inside of an instance is through methods, you can change your mind about whether .foo is a simple property or a complex method call, without affecting the interface to your class. Syntax sugar makes getter/setter methods indistinguishable from direct property access.

···

On Jan 27, 2005, at 10:55 AM, Jim Weirich wrote:

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

HEREDOC strings with variable interpolation make large chunks of output really easy to construct.

···

On Jan 27, 2005, at 10:55 AM, Jim Weirich wrote:

So go ahead and submit your ideas. What things should a Java programmer
be aware of when starting out in Ruby?

Edgardo Hames said:

I would suggest that once you come up with the top ten list, it would
be really nice if you did post it to the mailing list. I'd like to
forward it to some friends.

I'm going to collect responses in a public Ta-Da list at
Feedback on "Ten Things a Java Programmer Should Know About Ruby" (which is already way
over 10 items!). Later (possibly this weekend) I'll sort through the
collected suggestions, edit them down to my top ten and publish the
result.

···

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)