While reading one of DHH’s old blog post on the official Rails blog, I came across the following article from the late Jim Weirich, who lists 10 Things Every Java Programmer Should Know About Ruby. I think it applies equally well to C# developers.
Here is a list of things that resonated.
- Ruby classes are Objects (therefore
String.new
, notnew String()
) -
Everything is an Object
-
Compared to Java, XML is agile. Compared to Ruby, XML is Heavy.
-
Ruby does not have type casting.
- Don’t worry about interfaces, enjoy Duck Typing.
-
No method overloading.
-
Enjoy closures and blocks.
-
Don’t worry about early performance optimization.
-
Web-development is possible with other languages besides Java.
-
Ruby has MVC and OO programming and libraries, but drop any preconceptions.
-
Ruby is a language to be used everywhere. You use it even in templates.
-
Ruby is not a Silver Bullet, unlike Java, right? :-)
-
In Ruby data is strongly typed, but variables are not
-
you can have variable number of parameters, and multiple return values
-
Once you start coding Ruby, going back to Java is painful.
-
”.” (dot) is a method call operator. “::” (colon-colon) is a scope operator.
-
Java static methods do not (quite) translate to Ruby class methods.
-
CamelCase for class names, names_with_underscores for methods and variables.
-
local_variable, @instance_variable, $global_variable, Constants, (and @@class_variables)
-
Everything is an expression.
- stop writing so much code
-
That you can write Ruby in Java ( http://jruby.sourceforge.net )
ri
is your friend.irb
is your other friend.-
Reflection in Ruby is much easier than in Java, and more deeply into the language than the java.lang.reflect tack-on.
eval
-
the builtin classes are much faster because they’re written in C and not Ruby
-
Boolean methods end in
?
. Dangerous methods end in!
-
Avoid external utility classes.
-
You probably don’t need Factories.
-
Enumerable is your friend.
-
Typing is the enemy.
-
No external configuration files.
method_missing
-
Ruby classes are always “open”.
-
Singleton methods
-
no semi-colons, optional parenthesis
-
Ruby packaging vs Java packaging
-
you can use string interpolation, ex: “x: #{@myvar}” instead of having to say “x:” + myvar’
-
ruby has multiple inheritance through mixins (this is sooo nice to have)
-
ruby has shortcuts for accessor methods which reduces alot of redundant coding in java
-
writing code in ruby, can improve the code you write in java
-
No explicit types. Probably the most disconcerting thing for a javahead
-
you cannot rely on the compiler to catch trivial mistakes
-
Think in terms of methods (behaviors) instead of classes.
-
KISS
-
Discipline. Because of its inherent flexibility, Ruby require more self-discipline
-
Ruby is agile, perfectly suited for XP
-
Ruby is dynamic. You can add, remove and modify objects, classes and methods at runtime.
-
Ruby has extensive reflection capabilities
- Ruby is strongly typed, not statically typed
-
For good (but subtle) reasons, you have to leave the ‘++’ and ‘–’ behind.
-
you can fit in your mind and write code without looking at the docs every six minutes.
-
less syntax and less typing.
-
Fixes what’s wrong with Python.
-
It’s super productive (like Perl, Python and Smalltalk)- maybe 5-10x Java.
-
Is a lot like Smalltalk, but doesn’t look as funny.
-
Is a lot like JavaScript, but more OO and more for full-app development.
-
Blocks and Closures
-
Open Classes
-
Duck Typing
-
Use blocks for transactional behavior like like File.open does.
-
An instance of a class can be extended to be subtly different, without needing to subclass.
- you can change your mind about whether .foo is a simple property or a complex method call, without affecting the interface to your class.
Hope this helps.