Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Google   


Ruby for Perl Programmers

News

Recommended Books

Recommended Links

Recommended Papers Reference FAQs
Iterators Coroutines Exceptions Namespaces Humor Etc

Ruby is an interesting Perl derivative with some OO-bent created by Yukihiro Matsumoto (aka "matz"). Ruby the first major scripting language from Japan:

Ruby's syntax and design philosophy are heavily influenced by Perl. It has a lot of syntactic variability. Statement modifiers (if, unless, while, until, etc.) may appear at the end of any statement. Some key words are optional (the ``then'' in an ``if'' statement for example). Parentheses may sometimes be elided in method calls. The receiver of a method may usually be elided. Many, many things are lifted directly from Perl. Built in regular expressions, $_ and friends, here documents, the single-quoted / double-quoted string distinction, $ and @ prefixes to distinguish different kinds of names (but with different semantic) and so forth. Like Perl, Ruby has very good text processing facilities. Like Smalltalk, everything in Ruby is an object, and Ruby has blocks, iterators, meta-classes, operator overloading, etc.

Ruby supports coroutines and exceptions out of the box like any modern language should. Among attractive Ruby features:

Ruby like Smalltalk, provides closures and code blocks and uses them in the same way. The Ruby collection classes and iterators are more powerful and elegant than similar Python constructs (lambdas and list comprehensions):

File.open(file, mode) do |f|
# do something with f (= file handle)
end

# f is closed automatically at this point


Look at this for example:

http://www.rubyquiz.com/quiz70.html

There are several useful documents about ruby written for Perl programmers. For example documentation To Ruby From Perl lists several differences:

I would add that unlike Perl, Ruby has no variable declaration. This means there is no local variable scope. The first variable assignment defines its scope. There is no operators ++ and --  (may not yet :-). Also methods cannot be used before definition (one pass syntax analyzer).

Here is the list of gotchas from Ruby (programming language) - Wikipedia, the free encyclopedia

Gotchas and possible surprises

Although Ruby's design is guided by the principle of least surprise, naturally, some features differ from languages such as C or Perl:

In addition, some issues with the language itself are commonly raised:

A good list of "gotchas" may be found in Hal Fulton's book The Ruby Way, pages 48-64. However, since the list in the book pertains to an older version of Ruby (version 1.6), some items have been fixed since the book's publication. For example, retry now works with while, until and for, as well as iterators.

See also Ruby for Perl programmers and Intro to Ruby for Perl programmers

Similarities
As with Perl, in Ruby,...
Differences
Unlike Perl, in Ruby,...

A constant is a variable whose name starts with an upper case letter. In older Ruby implementations, when a constant was assigned a new value, a warning was issued. In newer Rubies, constants may not be reassigned from within instance methods, but can otherwise be changed at will.

Any Perl programmer who wants to start with Ruby should first get the Ruby source distribution and read README.EXT. This is a good document, not only if you're writing an extension library, but also if you want to understand Ruby more deeply. Next, have a look at the source of the interpreter itself, and at the various supplied extensions in the ext/ directory. You'll also find good examples under contrib/ on the Ruby ftp sites.



Notes:
  • Those pages are written by people for whom English is not a native language. Some amount of grammar and spelling errors should be expected.
  • This is a Spartan WHYFF (We Help You For Free) site. It cannot replace the best teachers and the best books.
  • The site contain some obsolete pages as it develops like a living tree... Some links on older pages are broken. Please try to use Google, Open directory, etc. to find a replacement link (see HOWTO search the WEB for details). We would appreciate if you can mail us a correct link.

Search Amazon by keywords:

Google   
Open directory

Research Index

 

Old News

[Mar 12, 2008] Tiny Eclipse 3.3.2  by Eric Suen

About: Tiny Eclipse is distribution of Eclipse for development with dynamic languages for the Web, such as JSP, PHP, Ruby, TCL, and Web Services. It features a small download size, the ability to choose the features you want to install, and GUI installers for Win32 and Linux GTK x86.

 

[Oct 29, 2006] Maybe it's Not Just Ruby on Rails - O'Reilly ONLamp Blog by chromatic

October 27, 2005 (O'Reilly ONLamp Blog) In comments on Curt Hibbs’s What is Ruby on Rails?, he and Aaron Trevena, maintainer of Perl’s similar Maypole project have debated whether Ruby or Rails are doing anything particularly new.

For people who’ve only ever seen complex “enterprise-class” frameworks and libraries and designs as usable, certainly watching any of the Rails movies might give some evidence that being able to solve the 95% of all possible web programming problems that don’t need huge application servers and complex transactional and messaging systems with a fraction of the effort and perhaps fewer lines of code in general than the complex system requires lines of XML in configuration files is a good thing.

Of course, anyone using a decent set of libraries in Perl, Python, Ruby, or PHP probably already knew this.

Ruby does bring certain advantages; I much prefer the ActiveRecord syntax and introspection over that of Perl’s Class::DBI, but they’re both fantastically useful. They’re equivalent enough that neither offers an order-of-magnitude improvement over the other.

Where something like Python’s Django might invent and polish a new idea, the amount of time and work necessary to do something similar in Perl or Ruby isn’t large either. I don’t have enough practical experience with PHP 5 to judge there, but I’m sure it’s also flexible and dynamic enough to work.

In my mind, the issue isn’t “Ruby on Rails is more flexible and capable than standard J2EE or .NET for any project under a (very high) threshold of complexity”. The real point is that the simplicity, flexibility, and abstraction possibilities offered by dynamic languages and well-designed libraries — as well as a talent for exploiting radical simplicity, extracting commonalities from actual working code, and knowing when too much flexibility makes you less agile — offer a huge advantage over languages and libraries and frameworks and platforms that assume you need a lot of hand-holding to solve a really hard problem.

Yes, Ruby on Rails does what it does very well. It’s not the only thing that does, though. I wonder perhaps if some of the buzz and glow is that it’s new and shiny (in comparison), so that people haven’t already formed their own opinions about it, as they may have with Perl (oh, you can’t write readable and maintainable code), Python (all the fun of the Lisp community without half the things that make Lisp special), and PHP (a language that needs to grow up).

Fortunately, a lot of smart people already understand this. It would be nice to have the right debate, though.

Am I wrong? Is it really Ruby and Rails, or is it the dynamicism, flexibility, and better opportunitites for abstraction of dynamic languages that provide so much of the benefit?

[Oct 26, 2006] DougHolton Re: The departure of the hyper-enthusiast

Ruby user's guide:
http://www.rubyist.net/~slagell/ruby/
10 things every java programmer should know about ruby:
http://onestepback.org/articles/10things/
Coming to ruby from java:
http://fhwang.net/blog/40.html

Things I like:
-blocks
-you can be more expressive in ruby and essentially twist it into different domain-specific languages, see: http://blog.ianbicking.org/ruby-python-power.html
-I like how standalone functions essentially become protected extensions of the object class (like C# 3.0 extension methods):
http://www.rubyist.net/~slagell/ruby/accesscontrol.html
-using "end" instead of curly braces (easier for beginners and more readable)

Things I don't like and never will:
-awkward syntax for some things like symbols and properties
-awful perlisms like $_,$$,$0,$1,?,<<,=begin
-80's style meaningless and over-abbreviated keywords and method names like "def", "to_s", "puts", etc.
-:: (double colon) vs . . (period).

Ruby is definitely better than python, but still not perfect, and
still an order of magnitude slower than statically typed languages.

[Oct 25, 2006] DDJ's Portal Blog/Sun Gets Ruby-fied By Jon Erickson 

On the heels of last weekend's Ruby Conference in Denver (for a report, see Jack Woehr's blog), Sun Microsystems made a Ruby-related announcement of its own.

Led by Charles Nutter and Thomas Enebo, the chief maintainers of JRuby, a 100% pure Java implementation of the Ruby language, Sun has released JRuby 0.9.1. Among the features of this release are:

In related news, Ola Bini has been inducted into JRuby as a core developer during this development cycle.
Details are available at Thomas Enebo's blog and Ola Bini's blog

OSCON Day #4 Ruby for Perl Programmers (by Jeremy Zawodny)

Intro to Ruby for Perl programmers

Ruby in a Nutshell Chapter 4 Excerpt Standard Library Reference

[Nov 16, 2005] ONJava.com -- Ruby the Rival  By Chris Adamson

Bruce Tate's Beyond Java singles out Ruby as a top contender to displace Java. Tate, James Duncan Davidson, Robert Cooper and Bill Venners weigh in with their opinions on Ruby and its challenge to Java.

[Nov 09, 2005] XML.com: REXML: Processing XML in Ruby By Koen Vervloesem

Ruby web apps, including those built with Rails, don't always use XML to represent data. But sometimes you just don't have a choice. Koen Vervloesem shows us how to process XML in Ruby using REXML.

[Nov 18, 2004]  ONLamp.com -- Extending Ruby with C By Garrett Rooney

Garrett Rooney presents a case study of extending Ruby with C by wrapping the GenX XML creation library.

[March 20, 2002] Ruby: Productive Programming Language

Short positive overview, explains Ruby by comparing with some other languages; focus on production; code samples, forum with many comments. -- Linux Journal

Recommended Links


In case of broken links please try to use Google search. If you find the page please notify us about new location
Google     

The Ruby Programming Language The Ruby Programming Language

Thirty-seven Reasons I Love Ruby

Programming Ruby - Second Edition

Do I really have to learn _another_ programming language :-), April 24, 2005
 
Reviewer: Randall Helzerman (campbell, ca) - See all my reviews
(REAL NAME)   
If you are like me, a busy programmer, I know you are wondering when you hear about Ruby, "Do I really have to learn yet another programming language?" I mean, Java, C#, Python? When will it ever end?

Well, it ends when you die, and yes, you do have to learn another programming language :-) But you'll like Ruby, I promise. Things I like about Ruby:

0. As easy to write scripts in as Perl, but it really scales.

1. Exceedingly self-consistent. Ruby has fewer syntactic warts than any programming language I'm familier with. All the features hang together very nicely.

2. Duck Typing: If you use a variable like a string, its a string. If you use it like a float, its a float. If you are familier with Haskell or or similarly typed languages, you get the idea. Ruby gives you about 80% of what Haskell gives you here.

3. Nice module system. This implements a nice mix-in facility--which gives you the power of C++ templates, with more structure. Also eliminates the need for multiple inheritance.

4. Wacky features like call/cc for the true language freaks.

Oh, so you want to know about the book too? Well, I agree with some of the reviewers here who describe the book as less of a tutorial/visionary screed/inspiring gospel and more of a reference manual. But I don't think this is a fair critique of the book. Back in the 60's, before the internet, a language needed a book to do for it what K&R did for C, or what Clocksin & Mellish did for prolog.

But today, you learn about a language by surfing the web. Instead of just duplicating what is available on the internet, this book complements the web, by supplying in a nice portable package what you need to know about Ruby which _can't_ be (easily) gotten from the web. Its a "post-internet" volume in this fashion.

Really the only critique of the book I can offer is that its description of Ruby/TK, the default GUI programming library for Ruby, is a bit abbreviated. It gives you the basics and the refers you a book about Perl/TK for the details. Please guys, in the next edition expand on this!

Ruby is a language which is as object-oriented as SmallTalk, as flexible as Scheme, has the scriptibility of Perl, and a nice C-ish syntax. What's not to like? This book is the book to buy if you decide to learn Ruby.
Not a Good Introduction or Reference, July 8, 2006
Reviewer: stlreader "stlreader" (St. Louis, MO USA) - See all my reviews
Ruby and the Rails framework (Ruby on Rails) have gotten major attention in the past year, primarily as an alternative to the complexities of using Java and J2EE APIs for typical N-tiered web applications using a Model / View / Controller framework.

"Programming Ruby" is supposed to be a combination of primer and reference for the Ruby language. Compared to some of the "classics" in programming such as "Programming PERL" (Larry Wall), "The C Programming Language" (Kernigan & Ritchie) or "The C++ Programming Languate" (Stroustrup), this book falls way short as both a primer or reference.

First of all, if you're interested in Ruby at this point, you're probably interested in using the Rails framework built using Ruby. This book provides NO information about Rails at all. This isn't a fault of this book, it's just something you need to know because many code examples you'll find on the web aren't "Ruby" examples per se, they are examples of using APIs within the Rails framework. Another book by this author is due out shortly covering Rails but based on the organization of this book, I would browse it in a bookstore before buying.

I've learned multiple programming langues over the years (Pascal, C, C++, a bit of Assembler, UNIX shell, PERL, Java) and I think most programmers expect any book on a programming language to tackle the material in the following order:

* installing the language
* running or compiling a basic program
* data types for the language
* variables, assignment and data structures / objects
* conditional expressions / control structures
* unit / module organization for source code
* advanced class / object concepts
* standard libraries for DB, network, security functions, etc.

As another reviewer stated, this book doesn't explain the Ruby language's use of symbols (:somesymbol) until page 323, even though it would be logical to explain symbols at the same time Ruby's hash type is explained. The difference between this variable, @thisvariable and @@thisvariable is explained very early but seems out of context because the scope of these variable types isn't clarified until the reference section. I think most experienced programmers will find the sequencing of chapters in this book confusing.

You can definitely learn key aspects of Ruby from this book but this will definitely not be the only book you'll want or need if you are learning Ruby to use Rails. Rails itself definitely shows some promise for simplifying some aspects of web development but I presume it will take another 2 years or so for the framework to stabilize and useful documentation to emerge. It definitely isn't clear from this book how Ruby as an underlying language for the Rails framework was a better or needed choice over implementing something like Rails with PHP or PERL that have already achieved wide familiarity.
Good both for learning Ruby and comparing it to other OO languages, May 26, 2006
 
Reviewer: calvinnme "Texan refugee" (Fredericksburg, Va) - See all my reviews
(TOP 500 REVIEWER)   

This book is an excellent one on learning the Ruby language if you already know object-oriented programming and are coming from the C++ or Java world in particular, since the authors often compare how you do something in Ruby to those two languages. If you don't already know object orientation I think you'll be lost. This is a book not only about the Ruby language and its syntax, but Ruby and its environment. There is an entire chapter entitled "When Trouble Strikes" that talks about the ruby debugger, interactive Ruby, profiling to look for code bottlenecks, and a common list of mistakes that Ruby programmers make. In "Ruby and the Web" the book shows how easy it is to write HTML forms using Ruby, and in a reverse move, how easy it is to embed Ruby in HTML by using eRuby. In "Extending Ruby" it is shown how Ruby itself can easily be extended by writing extensions in the C programming language.

This book also helped me compare Java and Ruby as languages to the point that I can now see the various advantages that Ruby has over Java. For example, built-in lists/arrays and hashes/dictionaries in Ruby are a big win over Java and its library-based collections. Java 5.0 fixes some of this but, in Java, collections still seem tacked on rather than integrated as in Ruby. Another big win of Ruby over Java is its ability for dynamic code loading. You can do it in Java but again, it seems tacked on. Also, Ruby object-oriented completeness over Java's dichotomy between primitive types vs. objects is a big plus for Ruby.

If I have any criticism of this book, it is that although complete, the chapters seem somewhat out of order. In particular quite a bit of the material in part 3, "Ruby Crystallized", seemed to only be repeating material in part one. However, it is still the best book out there for getting a detailed look at the language and its environment. I notice that Amazon does not show the table of contents for this book, so I do that here:


PART 1- FACETS OF RUBY
1. Getting Started
2. Ruby.New
3. Classes, Objects, and Variables
4. Containers, Blocks, and Iterators
5. Standard Types
6. More About Methods
7. Expressions
8. Exceptions, Catch, and Throw
9. Modules
10. Basic Input and Output
11. Threads and Processes
12. Unit Testing
13. When Trouble Strikes
PART 2 - RUBY IN ITS SETTING
14. Ruby and Its World
15. Interactive Ruby Shell
16. Documenting Ruby
17. Package Management with RubyGems
18. Ruby and the Web
19. Ruby Tk
20. Ruby and Microsoft Windows
21. Extending Ruby
PART 3 - RUBY CRYSTALLIZED
22. The Ruby Language
23. Duck Typing
24. Classes and Objects
25. Locking Ruby in the Safe
26. Reflection, ObjectSpace, and Distributed Ruby
PART 4 - RUBY LIBRARY REFERENCE
27. Built-In Classes and References
28. Standard Library
APPENDICES
A. Socket Library
B. MKMF Library
C. Support
D. Bibliography

Recommended Papers

The Ruby Programming Language The Ruby Programming Language

Delightful Languages: Ruby - Medium length positive review, with code samples, references; PDF format. [The Perl Review] (November 1, 2002)

 Reference

Ruby QuickRef



Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Last updated: June 02, 2008