From: Ben Giddings Date: 2005-08-16T04:14:25+09:00 Subject: Re: comp.lang.ruby FAQ On Monday 15 August 2005 13:45, hal9000@hypermetrics.com wrote: > RUBY NEWSGROUP FAQ -- Welcome to comp.lang.ruby! (Revised 2005-4-14) Hey Hal (and everybody else), It seems to me the FAQ is in need of a bit of an update. For one thing, Matz isn't really all that a prolific poster (and hasn't been for a couple of years). In fact, according to recent stats he doesn't even make the top 10 posters. Maybe the question should just be reworded as "Who is this 'Matz' guy that people keep mentioning?" Also, maybe we could reduce the number of duplicate threads on Ruby vs. [Foo] and benchmarking Ruby if we addressed them in the FAQ. Something like: 3. Comparing Ruby and other languages 3.1 How does Ruby compare to Python? 3.2 How do I make Java-like "Interfaces" in Ruby? 3.3 How does Ruby's Object Orientedness compare to Java? 3.4 How fast is Ruby? (and other benchmarking issues) 3.1 Ruby and Python are very similar, so they are often compared. In summary, they are similar languages with slightly different approaches. Python emphasizes uniformity of code over options (there should be one -- and preferably only one -- obvious way to do it). Ruby, on the other hand, emphasizes practicality over uniformity, and has multiple ways of doing the same thing. In the end, it's a matter of personal preference. Read more about this ongoing discussion here: http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/125682?125671-126412 (maybe a few more links to classic discussions) 3.2 As a statically typed language, Java requires interfaces to enforce type-checking rules, and because of that, has Interfaces. Ruby uses dynamic typing, and so interfaces are less useful. Instead, Ruby most often uses so-called "duck typing". If it walks like a duck, and quacks like a duck, it's a duck. What that means is that Instead of checking to see if an object you are passed is of the type you expect, the duck-typing way is to try to treat it as if it's the right type, and then recover gracefully from any errors that may result. This makes your code much more flexible. See more on Duck Typing at: http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/100511?100299-101528 3.3 After a certain point, trying to decide whether language A or language B is more "Object Oriented" is an exercise in futility. Having said that, there are significant differences in the Ruby approach to Object Oriented programming, as compared to most other languages. For example, in Java there are two things used to represent integers. One is the primitive type "int", the other is the class "Integer". While Java 1.5 introduced autoboxing (automatically converting between the two) the distinction is still there, and can lead to some confusion. In Ruby, every object is a descendent of the "Object" type. This means that not only are variables containing integers objects, but bare numbers are objects as well, allowing you to do things like: 3.times { puts "Hello!" } 3.4 As the saying goes, "There are Lies, Damn Lies, and Benchmarks". To be perfectly honest, Ruby scores fairly low on most benchmarks. Despite that, the number of people using Ruby keeps growing. Why? Because, for the most part, benchmarks don't really reflect real-world use. Aside from that, benchmarks also don't include development time, debugging time, or any other factor that is a real cost of development. Ruby is an interpreted language, and has about the speed you would expect from that sort of language. In particular, it is significantly slower than programs compiled to native machine code (C, C++), slightly slower than byte-code compiled programs (.NET, Python, Lisp), and slightly faster than most interpreted languages (PHP, Javascript, interpreted Lisp). If speed is truly a major concern, Ruby has a very clean C interface, allowing speed-critical code to be compiled and run in machine language. ***** Also, should probably have a Rails question/answer in there, so that people know about the Rails lists. Feel free to correct/enhance/update/change, etc. I just think it would help to have some kind of FAQ entry on these things to reduce some of the more frequent threads. Ben