JRuby article

JRuby article here.

http://www-106.ibm.com/developerworks/java/library/j-alj09084/?ca=dgr-lnxw07JRubyIntro

···

--
( o _ カラチ
// trans.
/ \ transami@runbox.com

I don't give a damn for a man that can only spell a word one way.
-Mark Twain

JRuby article here.

IBM Developer

Thanks T.

It's good to see articles like this. It's a shame that they all use such
unidiomatic Ruby, like

  print "Hello, world!\n"

instead of

  puts "Hello, world!"

and 'if not' instead of 'unless'. Oh well... at least it's going to
encourage me to try it out!

Cheers,
Gavin

trans. (T. Onoma) wrote:

JRuby article here.

IBM Developer

Great find, thanks.

Gavin Sinclair wrote:

> JRuby article here.
>
>
IBM Developer
dgr-lnxw07JRubyIntro

Thanks T.

It's good to see articles like this. It's a shame that they all use such
unidiomatic Ruby, like

  print "Hello, world!\n"

instead of

  puts "Hello, world!"

and 'if not' instead of 'unless'. Oh well... at least it's going to
encourage me to try it out!

I think its because the authors are not really Rubyists. I didn't recognize
the names of the authors so I did some googling. For the first author,
Michael Squillace, I could not find any web references that included Ruby
except for this article. And it looks like the second author, Barry
Feigenbaum, has a penchant for scripting languages implemented in Java --
he's also written articles on JPython and Groovy.

But the having more press for Ruby is always good and who knows, maybe these
two authors will become smitten by Ruby from this experience! :slight_smile:

Curt

Gavin Sinclair wrote:

It's good to see articles like this. It's a shame that they all use such
unidiomatic Ruby, like

  print "Hello, world!\n"

instead of

  puts "Hello, world!"

and 'if not' instead of 'unless'. Oh well... at least it's going to
encourage me to try it out!

The downside, though, particularly the use of $globalVariables, is that it makes the language look ugly to people scoping out Ruby for the first time.

(I confess I have not taken the time to read the article, only skim it. But the $camelCase stuff jumped out. There may be a good reason to use globals, perhaps related to having to deal with some Java stuff; the company you keep and all that. Otherwise, though, some of the code looks bad.)

James

Gavin Sinclair wrote:

It's a shame that they all use such unidiomatic Ruby, like

print "Hello, world!\n"

instead of

puts "Hello, world!"

and 'if not' instead of 'unless'. Oh well... at least it's going to encourage me to try it out!

IRTIAMTOWTDI - In Ruby there is also more than one way to do it.

I think that there is good reason *not* to use 'puts' and 'unless'
because:

a) Using 'print' plus backslash escapes demonstrate more language
    capabilities than use of 'puts'. Same holds for 'if not' in place
    of 'unless'.

b) The most widely used scripting language is Perl. The 'print'
    example shows that one need not change output statements when
    porting from Perl to Ruby. Concerning the 'if not': I am pretty
    sure that every (former?) Perl programmer will try out if 'unless'
    can be used as well.

c) If you use more than one programming languages it is a matter of
    memory efficency *not* to keep in mind those language constructs
    that are special to a certain language but those that are common
    to several of them - unless of course these constructs are the
    reason why you use that certain programming language for a certain
    purpose.

Just my 0.02 EUR.

Josef 'Jupp' Schugt

Curt Hibbs wrote:

Gavin Sinclair wrote:

JRuby article here.

IBM Developer
dgr-lnxw07JRubyIntro

Thanks T.

It's good to see articles like this. It's a shame that they all use such
unidiomatic Ruby, like

print "Hello, world!\n"

instead of

puts "Hello, world!"

and 'if not' instead of 'unless'. Oh well... at least it's going to
encourage me to try it out!

I think its because the authors are not really Rubyists. I didn't recognize
the names of the authors so I did some googling. For the first author,
Michael Squillace, I could not find any web references that included Ruby
except for this article. And it looks like the second author, Barry
Feigenbaum, has a penchant for scripting languages implemented in Java --
he's also written articles on JPython and Groovy.

But the having more press for Ruby is always good and who knows, maybe these
two authors will become smitten by Ruby from this experience! :slight_smile:

Curt

Some people dislike this "many ways to do the same thing". I read the book which uses puts but then I found elsewhere that print did the same thing. Which was nice for me since I'm a Python native.

James Britt wrote:

(I confess I have not taken the time to read the article, only skim it. But the $camelCase stuff jumped out. There may be a good reason to use globals, perhaps related to having to deal with some Java stuff; the company you keep and all that. Otherwise, though, some of the code looks bad.)

Yes, they have a good reason for it. In JRuby it doesn't seem possible to create a Ruby class which directly inherits from a Java class.

From the article:
"The next bit of code may seem unusual to the Java programmer. We first define a global variable for the main calculator window by prefixing the identifier with a dollar sign ($). This class definition is known as an anonymous class in JRuby. Essentially, we want to create a class based on or inheriting from the object we've just created. (Due to limitations in the implementation of inheritance in JRuby, we cannot define a class that directly inherits from a Java class.) In defining our new subclass, we write an init method (since the initialize method has already been called in the creation of the $calculator object). We will need to call this method upon completing the class definition. (To some extent, this is akin to calling super() in a Java class constructor and then proceeding with the initialization of that class.)"

Regards,

Peter