views:

132

answers:

6

A few years ago a friend of mine suggested I learn Ruby. I've since learned PHP and VB.NET but I never got around to Ruby. Where can I start with Ruby?

Also, as a side note:

What is Ruby primarily used for? How would you describe it in comparison to PHP? Python? VB?

EDIT:

How can I get it set up on Ubuntu 9.04? Vista or 7 Home Prem? Can I set up Rails in an existing (Apache) virtual server on a "internetless" box?

+1  A: 

You can start learning ruby at ruby-doc.org which contains the first edition of Programming Ruby (slightly outdated, but still quite a good resource to learn ruby) as well as the official API docs. If you're willing to invest some money, you can also buy the current edition of Programming Ruby or The Ruby Programming Language.

As to what ruby is used for: I suspect it's most often used for web programming. And second most often as a scripting language for system administration, log file processing, web scraping etc.

sepp2k
+3  A: 

Getting started resources


The 'Pickaxe book' is the best resource I've found for learning the language. For free resources, Ruby-doc is hard to beat - plenty of getting started info. There are a lot of great web sites but Ruby Inside is great for general news on Ruby.


Ruby is good for ...


Really Ruby is a general programming language so can be used for all of the areas you mentioned. In particular, there is a very popular Web programming framework known as Ruby on Rails.


Ruby compared to ...


Comparing programming languages is always contentious but Ruby can be described as a pure Object-Oriented language with very strong dynamic programming aspects. It's in the same vein as Smalltalk. You'll find that Ruby is a very concise language i.e. less keyboard-bashing than Java ;-). It doesn't execute as quickly as Java, C or PHP but generally is fast enough for all but systems programming.

Chris McCauley
+2  A: 

I found that the single best source for learning to program in Ruby is the Ruby website itself, in particular the 1st edition of the 'Pickaxe' book, available freely online.

I am a C++ programmer, and I use Ruby extensively for testing my applications, and for writing quick utility apps. I have also used it to write testbed applications for demonstrating projects before I get in to writing the C++ version of the app.

John Dibling
+4  A: 

Ruby is best suited to I/O-bound tasks where raw computational speed isn't an issue. Fortunately, the vast majority of real-world programming problems are I/O-bound, with web applications being a particularly good example. The Ruby community spends most of its time and effort on writing and releasing code that's designed to run on web servers, so that's where it really shines, but I've successfully written desktop applications in Ruby. MacRuby is a really great example of Ruby being put to good use in a desktop environment. For web servers, you have great projects like Rails, Sinatra, and the rest of the Rack ecosystem. Projects like Data Mapper are great for both desktop and web server usage. Ruby is rarely used in a mobile environment because performance is such an important issue there, but it can be done if you're determined.

Compared to VB, well... VB comes up wanting in a big way. I would describe VB as well-suited to beginners, but with little room for personal growth. Whereas Ruby is good for beginners who haven't previously been exposed to anything — it can be challenging for people who have already become used to the style of some other language. However, Ruby won't limit your growth as a programmer: Ruby has almost every programming language feature you could want for (with a few notable exceptions like pattern matching and multiple function parameters). And realistically speaking, these are trade-offs; no programming language can give you everything. Compared to PHP, Ruby mops the floor in every area except maybe web server deployment. PHP is everywhere. In most cases, you can just assume it's installed by your web host by default. Ruby, on the other hand, requires a fair bit of experience to get deployed right, though Phusion Passenger has dramatically improved the situation. Compared to Python, well, to be honest, they compare very well. In the interests of not starting any flame-wars with the "Snakes", and because I use both Ruby and Python myself, I'll call it a draw. There are very good reasons to use both, and in most cases, they can be used interchangeably. There are very few applications for which Ruby is well-suited that Python could not perform just as well, and vice-versa. On balance, I prefer Ruby myself, but there are a lot of things I admire about Python, and I write a lot of Python on account of Google App Engine. That said, you can run Ruby in that environment too via JRuby.

If you want to get started with Ruby, the best place to go is Try Ruby (in your browser). That should give you a taste and let you evaluate the language. If you like it, get yourself a copy off the official site. As others have mentioned, the "Pickaxe" book is great. There's a free version online, though it applies primarily to older versions of the language. The "dead-tree" edition should be up-to-date. If you're just getting started, I highly recommend using 1.9. There are still many libraries that aren't compatible with 1.9 yet, but if you're just getting started, all the ones you're likely to care about should be current with 1.9. It's best to avoid having to re-write a lot of code later if you don't need to, plus 1.9 is substantially faster.

In terms of installation, on Windows, it's best to use the "One Click Installer". On OS X, it should have come pre-installed with some special OS-X-specific tweaks. On all other platforms, I highly recommend compiling the latest stable version from source. You can use apt-get, and that will work and it's certainly much easier, but now and then you'll run into difficulties because the Ruby community and the Debian folks tend to disagree on where stuff should be installed, and sometimes library authors make faulty assumptions. If you compile from source, everything will end up in the default locations, and you'll have the most up-to-date code available. Don't forget to sudo apt-get install build-essential first if you're on Ubuntu.

Bob Aman
Have you ever looked at the performance of something like `ruby -e "while x=STDIN.read(1024); STDOUT.write(x); end"`? ruby's IO performance is so poor.
johannes
That's not actually what I meant. The point is that if I/O is your bottleneck, computational performance isn't as big a concern.
Bob Aman
I wouldn't even agree with that conclusion.
johannes
For the vast majority of applications, that conclusion is quite valid. Working around Ruby's I/O issues isn't necessarily trivial, but for most purposes, the work has already been done. Stuff like Unicorn (http://unicorn.bogomips.org/) already exists, and can easily dish out thousands of requests per second. If you need raw speed, there are solutions for that. They may not be immediately accessible to a newbie, but they do exist.
Bob Aman
+1  A: 

Ruby is a general purpose scripting language, so it can do almost anything. But one of the things that really made Ruby as a language take off is Ruby on Rails

In comparison to Python, I'd say Ruby is Python's little sister. VERY similar syntax, uses, etc. Some might like Ruby (because, say, it's easy to build Domain Specific Languages with it), some might like Python (because they like being explicit, let's say). I always recommend reading the Zen of Python: if you agree with most of it, learn Python, and if you have major issues with many of the points, try Ruby.

In comparison to PHP: Ruby is a scripting language without the curly brace heritage of C, and with OO design much more center stage (Yes, I know you can do OO in PHP)

In comparison to VB: It's not BASIC? It runs on Unix and poorly on Windows? (vs VB that runs great on Windows and poorly on Unix). It's not as easy to put together a GUI program with Ruby... but, we're on Unix after all.

RyanWilcox
+1  A: 

Related question for what is ruby used for: http://stackoverflow.com/questions/150638/ruby-off-the-rails

Related question for how to learn: http://stackoverflow.com/questions/6806/what-is-the-best-way-to-learn-ruby

Andrew Grimm