Comment by 'Guest' on 2006-10-03 02:22:40 [list] [*] in Ruby, the constructing and initializing phases of an object are separate and both overridable. The initialization is done via the "initialize" instance method while the construction is done via the "new" class method. [B]Initialize is not a constructor![/B] [*] Mixins are examples of implementation inheritance, they are [b]not[/b] equivalent to Java interfaces [*] Ruby has first-class functions and closures with the so-called "blocks" [*] Ruby uses the interal iterator pattern a lot (instead of java's external iterator) [*] And Ruby overall uses blocks a lot to send operations to methods, which means that the methods themselves handle and automate housecleaning: you usually don't clean after yourself in Ruby, because that's handled by the class/method implementations you're using [*] Ruby doesn't use getters and setters, it uses "properties" which look and feel like public attributes, but are really methods under the hood. You can't create true public attributes, but Ruby has shortcuts to auto-generate properties if you need. [*] Strings are mutable, unless you freeze them, and nobody freezes them [*] Symbols are immutable interned strings, they're used to name objects of the language (methods, ...) [*] While Java nearly has none, Ruby has [b]a lot[/b] of litteral objects: litteral ranges [I](a..b)[/I] or [i](a...b)[/i], litteral regular expressions [i]/foo/[/i] (Ã la Perl), litteral arrays [i][a,b,c][/i], litteral hashes/maps [i]{:foo => "bar", :baz => "buzz"}[/i] etc... [*] Ruby's Arrays are [i]not[/i] Java's arrays. Ruby's arrays are equivalent to Java's ArrayList: they're mutable, variable-length, O(1) random access containers. [*] Constants are either PascalCased or UPPERCASED (a constant starts with an uppercase, and yes a class is a constant), class attributes are prefixed with @@, instance attributes are prefixed with @, globals are prefixed with $. [*] method/function names are not camelCased, Ruby's method names are underscore_separated_words. [*] Ruby favours unit testing. In fact, the standard Ruby distribution provides a unit testing framework out of the box (Test::Unit) [*] Ruby favours third-party modules in the form of [i]gems[/i]. Gem is like apt-get for Ruby, if you're looking for a third party module (say... Rails), just gem install it and it'll usually be found and installed for you. No more tedious installation. Furthermore, distributing your own packages as gems (even inside your own team) allow you to gracefully handle dependencies on first and third-party packages. [*] Compared to Java, XML is agile and flexible. Compared to Ruby, XML is a ball-anchor-and-chain bundle. This is why you use either Ruby or YAML to configure your applications. Use XML only when it's required, not when you think it'd somehow be a good idea (which it isn't). [*] There is almost no compile-time checking in Ruby, because there is almost no compilation. This means that your programs will err only at runtime. This means that you need to unit-test. [*] Ruby is a child of Perl. Ruby includes a lot of perlisms ($`, $_, $., ...). Perlisms are fine for 5-line shell scripts. Perlisms are not fine for anything above that. Don't use perlisms, they make code unreadable. [/list] |
Comment by taw on 2006-10-03 21:53:48 Actually there aren't. Ruby "private" means "calls to self only", works with subclasses (like Java protected), doesn't make method final, and doesn't put it in a different namespace. Ruby protected is broken and nobody uses it. Ruby public is actualy public. Anyway, this aspect of Ruby is completely different from Java, not similar. |
Comment by GUEST on 2008-01-08 20:54:16 ruby does not support the constructor overloading, and ++ operators. return statment will return more than one values.
|