“The Java programming language has had an unprecedented run of success for vendors, customers, and the industry at large. But no programming language is a perfect fit for every job. This article launches a new series by Bruce Tate that looks at ways other languages solve major problems and what those solutions mean to Java developers. He first explores Active Record, the persistence engine behind Ruby on Rails. Active Record bucks many Java conventions, from the typical configuration mechanisms to fundamental architectural choices. The result is a framework that embraces radical compromises and fosters radical productivity.”
I have worked in many different langauges, and currently program in both RoR and Java. I personally like both a lot.
“The result is a framework that embraces radical compromises and fosters radical productivity.”
This quote is a fun one that I have hear almost every time someone tries to compair a scripting langauge to the strongly typed compiled langauge.
Even though I like Rails I do not generally like Bruces promotion of it. Bruce too often go out of his way to try to drum up as much drama possible. That being said this was a good article and worth the read, but when reading other Bruce articles make sure to have your drama meter and your grain of salt at the ready.
It must be a a complete nightmare.
Given that there are plenty of tools to create Java classes and Hibernate schemas from database tables, there is no major difference in the amount of upfront coding needed between RoR and contemporary Java. Of course, in the current version of Hibernate, making changes to the schema involves a lot of work, although that should be eased a good bit with Hibernate 3 (which uses Java annotations). Likewise, it’s as easy to express relationships using Java annotations as the variety of methods used in RoR
Indeed, it’s also possible to use Java annotations to provide validation: look at this article for somewhere to start http://java.sun.com/developer/technicalArticles/J2SE/constraints/an…
Consequently the two primary advantages given in the article don’t really hold.
Maybe I’m just old-fashioned, but I like the fact that it’s more clear what’s going on in the Java version. I always feel the extra “magic” thrown in by scripting languages can bite you when you’re not looking. For example, dynamic typing is great until you realise that: a) in JavaScript you have to use things like ParseDouble on function parameters to be safe and b) in PHP you have to use things like === to safely compare values, but can get away with == some other times.
It must be a a complete nightmare.
So you haven’t any personal experience? If you were right the web should be full of stories about Ruby programmers struggling to debug their programs. Would you like find some and provide links?
Of course there is a huge difference between code generation and the runtime dynamism that Rails uses, and Java annotations are not the same either.
Maybe I’m just old-fashioned
No, the idea of metaprogramming is as old as Lisp, and has been around for over 40 years. A lot of the serious weaknesses of Java stem from the lack of understanding of metaclasses by the initial designers (although obviously not people like Guy Steele who subsequently tried to sort out the mess).
For example, dynamic typing is great until you realise that: a) in JavaScript you have to use things like ParseDouble
No, Ruby is strongly typed with a more complete and consist type system than Java (eg no primitive types), and this problem doesn’t exist with it.
use things like === to safely compare values, but can get away with == some other times
So there are no similar problems with comparing things in Java?
I always feel the extra “magic” thrown in by scripting languages can bite you when you’re not looking
Maybe COBOL would suit you best, there’s even less ‘magic’ going on with that..
The subject of the post was a question, not a statement, so it’s reasonable to assume I don’t have any experience. The first sentence was an opinion, I admit; I should have said “It seems to be like it would be a complete nightmare from what I’ve just read”. I thought what I meant would be clear from the context in which the original sentence was placed.
As regards meta-programming, the ActiveRecord case is easy enough: if a property doesn’t exist, the first thing you do is check the DB you’re using. The general idea of code modifying itself at runtime, as a consequence of runtime inputs, seems a bit scary however. If an end-user finds a bug, figuring out how to reproduce it could be an enormous task.
I’d heard of meta-programming before using C++ templates, though not in the likes of Lisp etc. (the only functional language I’ve studied is Haskell). However it’s never, ever, caught on in mainstream programming. Perhaps “conservative” might have been a better description than “old-fashioned”, but there you go.
With regard to the dynamic typing stuff, I didn’t mention Ruby in any of the examples. I still prefer statically typed languages though. The only two dynamic languages I’ve ever used for major projects were Perl and PHP, and in PHP in particular I did run into a few problems with its dynamic typing (in particular the fact that every symbol has a defined value, so that not even the runtime catches typos). This would be an example of “magic” biting you.
I’ve also had problems with dynamic typing as implemented in JavaScript. A big problem here is that in a language with no explicit types, the + operator is polymorphic (working on both strings and numerics).
As for Java, I know there’s a problem with == and Object.equals(), but at least you can make some reasonable assumptions. If you look in the PHP library, they’ve had to add a == versus === disclaimer to a good chunk of the function documentation so people don’t get caught out. The problem here, like the auto-vivant variables, is that most of the time things will just work if you accidentally add ==, so tracking down bugs is hard.
Fundamentally, I don’t see explicitly naming the type as adding substantially to the amount of work the coder has to do, but it does: a) explain clearly what kind of value the original coder wanted to use and b) constrain the program so that when another programmer makes a change, the compiler will raise an error, alerting them to the assumptions the original programmer made.
Of course, this makes making changes to APIs significantly harder, but most IDEs have decent refactoring tools that negate that.
Speacking of IDEs, dynamic typing generally means that IDEs have a harder time providing an auto-complete feature (as it’s harder to infer the type). Given the huge libraries that come with most languages, not having auto-complete to fill in the gaps in your memory can be a bit of a productivity killer.
But that’s my dynamic languages rant…
For what it’s worth, Ruby does seem like a nice language, and the way in which it uses lambda expressions as a core, up-front part of the language is pretty cool. However for a statically typed bigot like me, languages like Scala and Boo seem nicer. I just prefer it when everybody working on a project has to clearly explain what they’re trying to do.
Speacking of IDEs, dynamic typing generally means that IDEs have a harder time providing an auto-complete feature
Yes, for it to work in Ruby you need to be interacting with running code. For instance, in irb ‘Interactive Ruby’ you have auto-completion available which isn’t possible in a plain text editor. So the challenge for making a killer Ruby IDE would be to make it work like irb, but with the graphic class browsers etc that you expect in a more static IDE like Eclipse or KDevelop.
For what it’s worth, Ruby does seem like a nice language
Yes, you seem just the sort of person who might like Ruby if you tried it!
I think the unfortunate experiences you’ve had with php or perl don’t apply to ruby. Those languages are dynamic but ‘weakly’ typed. For instance, to convert a string into a number in Ruby you have to call a ‘to_i’ method, it doesn’t happen automagically.
I personally find Java templates incredibly difficult to understand from the articles I’ve read about them (usually written by people who are struggling to understand them). So to me trying to understand how Java or C++ templates modify code at compile time, is harder to understand than Ruby modifying code at runtime.
In practice using Rails is easy, but understanding the Rails code itself is pretty hard (although it’s very well written). Similarly, I don’t mind using C++ templates as long as someone else has written the code. Just because a feature is in a programming language it doesn’t mean that every programmer has to make use of it in their own code. But if you leave out a feature like meta-programming, it makes it harder to produce powerful, flexible tools for ‘normal’ programmers.
However for a statically typed bigot like me, languages like Scala and Boo seem nicer
Yes, or ‘as nice’ perhaps – certainly not over verbose, and over complicated.