I asked a question a few days ago about representing public static final
and private static final
fields in equivalent Ruby code. It got me thinking about what other syntax elements in Java might not translate directly to Ruby. Generics and Annotations come to mind. Anything else that would not translate well if you tried to port some Java code to Ruby?
views:
95answers:
3I'm not positive on this one but I think double brace initialization would not.
e.g.
HashSet<String> codes = new HashSet<String>() {{
add("XZ13s");
add("AB21/X");
add("YYLEX");
add("AR2D");
}};
Programming itself in Ruby is very different from Java (functional programming comming to mind). So it is not only about learning the syntactic differences, it's mainly about learning a different way to code.
If you program in Ruby like you would in Java, it will (probably) result in very bad code (even if you're a professional Java programmer).
With all due respect Ruby should be treated as a language that is different from Java. One should not try to find a one-one mapping between Java and Ruby. I once worked for a big database company who had migrated a lot of plsql developers to write Java based apps in 2000s when Java was the "cool" language. Result is till date they maintain code where a class has field variables like m_person_id, parameters like p_person_id and local variables like l_person_id.
The problem was this "mapping", while the prefixes p_ (for parameters), l_ (for local variables) or m_(field variables) served well in plsql with little or no IDE support, they made no sense in Java with IDEs like Eclipse where they can highlight stuff in different colours.
The example may be bad but trying to move from Ruby from Java is okay but learning Ruby by comparing it's corresponding feature in Java is not :)