Quantcast

Ruby on Rails, Io, Lisp, JavaScript, Dynamic Languages, Prototype-based programming and more...

Technoblog reader special: $10 off web hosting by FatCow!

Friday, June 09, 2006

Ruby vs. Java: A matter of taste

"Jesus reflected on his situation and felt irrepressible sadness. His tear-ducts filled to a point where they could hold no longer and had to be released."

versus

"Jesus wept."

I prefer the later. My favorite author is Hemmingway and my favorite programming language is Ruby. My girlfriend hates Hemmingway, and that's fine. It is all a matter of taste.

A lot of heated debate is going on between the Ruby on Rails camp and the Java camp. In those debates, the dreaded "lines of code" (LOC) comparison frequently shows up in the Ruby side, and the equally misguided response "lines of code mean nothing" statement frequently shows up in the Java side. Usually, when there are arguments of this sort, the truth lies somewhere in the middle and emotions tend to make the arguments lean a little this way or a little that way. Here I will make a level-headed attempt to sketch both sides of the argument and try to pull out a deeper root.

Several times a week, the official Ruby on Rails weblog tends to post a story ala Apple's switch campaign where a deep rooted Java programmer "sees the light" and never wants to program in Java again. Many times, and by many people, the statement has been made that working in the Rails framework provides almost a 10x gain in productivity. Java people like to say that David (the creator of Rails) has brainwashed these people or that this is all hype [1]. Another typical response is that there is no such thing as 10x more productive than Java, that people have been claiming this for years and there is always a catch. In any case, these statements generally degenerate into the following arguments.


LOC don't matter


You can't compare one language to another by lines of code. Look at Perl for example. Many people say that you can develop something quickly in few lines of code, but that you can never maintain it. There are much more important ways to compare languages: can it scale? is it enterprise?, is it maintainable?, how many programmers can I find to finish the job?, etc. [2] Lines of code comparisons are completely meaningless compared to these factors. They just take code out of context.


LOC matter


You can compare LOC because the less code you write, the fewer bugs you will tend to have. Also, as a matter of common sense, it takes less time to write less code. If I can write a program that does the same thing as yours in less lines of code, it will be easier to maintain and add things because I will have to do less searching and I won't have to remember as much to find out how to change things.


When worlds colide


One thing that Ruby and Java people can all agree on is:

"Ruby is a very elegant and descriptive language, which makes Ruby versions of Java code generally shorter and more readable."

Ruby code usually makes sense when read out-loud whereas Java code is over-laden with patterns and when it comes down to it, usually meant to be read by a compiler. That is one of the reasons Ruby people love to show code comparisons, it makes Java look over-complicated and unnecessary. Neither of these is the case, there are things you can do in Java that are simply unavailable to Ruby developers. However these comparisons ultimately lead to clashes like the following where emotions escalate and each tries to show why one is better than another.

Ruby Zealot: (excited about his discovery) hey, look how many fewer lines of code I wrote

Java Zealot: (heard this before, what does the magazine [1] say again?) that's stupid. it doesn't scale and you can't maintain it. you don't know what you are talking about.

Ruby Zealot: (on the defensive) what do you mean? of course I know what I am talking about. your stupid

Java Zealot: (on the defensive) LOC don't matter. no silly scripting language can scale and be maintainable. you'll never get a job with your toy language.

When it comes down to it, the essential feature that the Ruby people are claiming is that Ruby is terse. Rails makes web development terse. In Rails, the framework does the heavy lifting for you. Java people can't be expected to understand what this means unless they try doing their day to day work with Ruby. They can't understand this because Java was never meant to be terse. In fact, after many years of mastering the language, many Java developers revel in its verbosity. Java people like writing out System.out.println("Hello World!"); Some like it because they want to see and constantly be reminded of everything that is going on in their programming environment. Some like it for the same reason that people learn Klingon. Some like it because they don't know there is any other way.

Everyone is entitled to their opinions. My girlfriend thinks that overuse of terseness is a horrible way to write. I guess I am just lazy. I don't want to write for the computer, I want to write for me. I don't want to write 900 lines of Java and XML so that the computer can understand it easier, I want to write 600 lines of Ruby that I can read out-loud to myself because I love to program. I want to let Ruby do the heavy lifting for me, and I hate repeating myself. It is from this train of thought that Rails grows and flourishes.

Nobody's opinion can be forced one way or the other, but many humans prefer to be lazy and let machines work for them. Rails is the natural extension of this for the web-based programmers. That is why you will tend to see Java developers turning into Rails developers and not the other way around. This scares the Java community. Sure some Java developers will look at Rails and say, "that's not for me, I am already comfortable", but I can't imagine many Rails developers saying, "please let me work harder to do the same amount of work".

With regard to the bulk of websites, from low to high complexity, anybody that says that (Rails|Java|PHP|Python|etc.) can't cut it is ignorant and afraid to learn anything that he doesn't already believe in. These people are stuck in their ways and don't have anything constructive to say that transcends their day to day lives. Ebay and Amazon use Java, Yahoo and Friendster use PHP, Google uses Python, Livejournal uses Perl. Rails has been around for only 9 months, but it will have a household name backing it soon too. It has a lot to do with taste, although if you are talking about time-to-market, this changes the playing field. As Paul Graham has shown, terseness in programming has a lot of strong advantages.

In sum, Java zealots, please stop complaining any time David posts stories about people changing their opinions, he has a right to be proud of his hard work just like you do. Ruby zealots, let's be understanding that there are some people who happen to like excessive typing more than us.

[1] Food for though: Rails has no substantial corporate backing. It has no million dollar marketing campaign. These are regular programmers from many different backgrounds coming forward about Rails. They are the ones that you work with every day. Many of them to this day probably have not read David's blog, they simply send their stories to David who rightfully enjoys publishing them. Nobody is paying these people or twisting their arms, because there is nobody to do either of these things. Sun pays a lot of people to say a lot of things. Many companies like Java because they know Sun in a company like them. Companies twist arms, lie, and deceive every day in the name of their shareholders.

[2] From whom do you hear these questions most often: managers or programers? Who are the ones that take out advertisements proclaiming (not explaining) the answer on the pages of PC Magazine and Doctor Dob's Journal?

You should follow me on twitter here.

Technoblog reader special: click here to get $10 off web hosting by FatCow!

20 Comments:

Anonymous Anonymous said...

"Rails has no substantial corporate backing."
Although there is some truth to this, the hype behind Ruby and Rails is not completely without corporate backers. O'Reilly, for example, seems pretty keen on keeping the Rails hype machine going.

5:39 PM, August 18, 2006

 
Blogger Dave said...

"Rails has no substantial corporate backing."

This might have been true at one point, but I have personal knowledge of at least a half-dozen RoR jobs at different non-startups, including two large telecom firms and one government agency.

6:59 PM, August 18, 2006

 
Blogger Klondike said...

dave, I believe by saying Rails has no substantial corporate backing, he meant that development of the language/framework itself has no major corporation funding or otherwise financially encouraging it.

O'Reilly is encouraging it, but not especially more than any other hip new language or technology that comes along, like Ajax or (at one time) Java.

8:20 AM, September 08, 2006

 
Anonymous Small Business Hosting said...

All I'm saying is, K.I.S.S.

6:20 AM, October 01, 2006

 
Blogger Alan said...

Rails has substantial corporate backing, but Java has extraordinary corporate backing. Sun and IBM. It's huge.

Java is a great language for the sort of design by committee that takes place in corporate environments.

I think that Ruby is on the rise because Perl put itself into vaporware mode, by going into the redesign.

Ruby is the answer for people looking for a scripting language that can do more than the web. It's not angle-brackets first, like PHP.

Java doesn't have to be as painful as it is. It's mostly people taking the language to seriously. Lot's of contradictory axioms, while Ruby has the attitude of let the language do the work.

Also, the K.I.S.S. post above is spam, delete it.

10:49 PM, November 29, 2006

 
Blogger Tjerk said...

Look System.out.println may look verbose but it hide some crucial point:

See this code:

System.out=someOutputStream;

Look now the System.out.println prints to the new outputstream, so it is crucial and it may look verbose: it is actually better maintainable.

8:25 AM, March 04, 2007

 
Blogger Lucas Carlson said...

In Ruby, $stdout = someOutputStream does the exact same thing.

9:29 AM, March 04, 2007

 
Anonymous Tjerk said...

Ok.. you got a point.

I just dont like ruby because it is dynamically typed.. this introduces a lot if potentiel errors that the java compiler would detect in java programs.

6:32 AM, April 11, 2007

 
Blogger Archer said...

That always happens - new languages born, become mature and die under the pressure of another new languages. Like the stars ;)
Lets think from RAD point of view: when I need to develop something quickly, I'll not look for new language with super-short syntax. I would use what I know already, what is mature, what has dozen of great RAD tools which I'm using (these tools generates 20-30% of code, exactly the same amount of syntax Ruby wins against Java), well-documented frameworks, forums and other developer resources. Yeah, Ruby looks prominent and I wish this language to get mature in years. I will switch and use it then. But now, as for me, that's just not possible to use it in complex developments which, (of course), has tight deadlines, require further support and maintenance.

3:06 PM, April 29, 2007

 
Anonymous Anonymous said...

Ruby is fun to do today. Java was fun 10 years ago. Is the real reason for this new-found interest in Ruby could be that we are bored with Java? I know in my case it is partly true.
Puns aside, I have found the power of scripting languages in bash and korn shells. I used Perl as a user. That is; someone else had written short Perl scripts that I used (given to me by a friend who has given these scripts by another friend..you get the idea). These Perl scripts were incredibly useful in my work as developer in the Enterprise security group of a large company. I had trouble reading those scripts though. I must admit I do not know Perl, but came to appreciate its power especially in server-side work. Ruby strikes me as as capable as Perl, much more readable, even more object-oriented (do not know SmallTalk, but have heard it to be pure object oriented language), and functionally capable as Lisp (ruby Arrays are the most useful implementation of Arrays that I have ever seen, same for Hashes to a certain extent).
Actually, I don't think that it is going to be Ruby versus Java anymore. Soon, it will be Ruby and Java or Java and Ruby. JRuby is getting close to the finish line and important vendors like Sun are lining up to provide decent support. I have a feeling that the flood-gates are about to open.
Well, before we get too enthusiastic, us geeks get bored with the "old" technologies and are always looking to play with new technologies since that is more fun. So the real reason might be in one word "boredum".

4:00 PM, May 21, 2007

 
Anonymous Anonymous said...

jeez so many monkeys. Ruby is a dynamically typed language and will therefore never be significant. It really is that simple (even though there are a host of other reasons). Static languages have always dominated enterprise environments for a reason (java, c, c++). There has never been a dynamic language that made even remotely significant headway into the enterprise class level software or packaged software.

12:06 PM, August 26, 2007

 
Anonymous Anonymous said...

What about interacting with databases? How does it stack versus java?

6:00 AM, August 29, 2007

 
Anonymous dbennett455 said...

Your example text is a perfect example of the difference of strongly typed and weakly typed languages. When you state "Jesus Wept" we don't know the context of why he wept, was he happy? Did someone step on his foot?

The required information is in the surrounding context.

In dynamically typed languages, the developer is not explaining the context of their code. There is no implicit documentation on the data they are managing or the results they are generating. It may make the lazy developer happy that they don't have to explain their code, however, long term maintenance of the code suffers.

I have been a fan of languages in both camps for over 10 years. And I still use perl for writing scripts that no one else will need to maintain.

Dynamically typed languages are best for single developer environments where no one else will ever touch the code (rare these days).

I have seen what happens to dynamically typed projects when move them into the team environment and it is not pretty.

--Dave Bennett
Bensoft, Inc.

9:52 AM, December 30, 2007

 
Anonymous Osman Din said...

Google uses Java too

9:15 PM, February 23, 2008

 
Anonymous Anonymous said...

I like Ruby, I love Java. Java is a different kettle of fish to Ruby. Java was designed and can be used to write everything from applets right through to multi tier enterprise applications. Java has massive corporate backing and thus has long term stability guaranteed, thus if I develop with it now I am pretty sure in 5 years time it won't be hype that has died down and is now obsolete and unsupported. Java evolves in a much more structured way allowing developers to continually move their platform to the latest version pretty easily.

Ruby is great for kocking out applications faster and I have used it with great success numerous time, but I am also skeptical of dynamic applications in that so many errors aren't caught until run time which a compiled language would've been able to spot. I also find static typing a lot better when I am using an IDE which consequently lowers my actual input effort while still yielding the verbosity of Java. Eclipse is a great example of a fantastic development tool, which in all honesty has taught me more Java thn any other source. In dynamic typed language, how can my tool know what type that object is if it's never set in stone? It can only make assumptions and only really works under certain circumstances, eg when I create a new object in the same variable scope.

In the end, if I were to develop a website I would start with Ruby... if i required more power from my application I would move to Java. If I knew it was going to be a big hit from the start I would go with Java.

6:32 AM, June 15, 2008

 
Anonymous Anonymous said...

The stuff with "you write less boilerplate code and code in general" is a little bit besides the point, and does have anything to do with the time to market. We don't write code these days with Notepad, there are IDS around and they are here to help.

Besides the fact that System.out.println("whatever") has its reasons to look like that (already dealt with in previous comments), this is not an issue: go in Eclipse, configure a macro, and you are done. You make it work under some short word and then you are done. You write less code. And the result is not unreadable.

Same works for other boilerplate code - accessors, mutators, all this stuff is done automatically. It's been at least 7 years since I don't code accessors and other stuff in Java. Learned the shortcuts in the IDE and everything goes smooth.

There are though other issues with scripting technologies that I would like to bring to attention. They are not a matter of taste, in my opinion

1. Weak typing - I believed I got rid of Variant type when I worked VB last time, some 10 years ago, however it seems this is back to stay with scripting in general, Ruby in particular. Basically when you look at a scripting variable, you don't know what type it is. Scripting supporters say this is better, because this also require less code to be written and more flexibility. This flexibility comes at a very high cost: everytime you look at a variable, you gotta go back where it was instantiated in order to see what's in it. The IDE won't help you either (except in a couple of situtations) because he does not know the variable contents either. So you are stuck with your flexibility

2. Performance usually is worse than in the case of JVM based technologies which are all Jitted at this moment.

3. Not only you don't know what a variable type is, but you can even alter the structure of an object without altering the structure of the underlying class. So now you look at an object, you know it is of a certain class, however it is possible that THAT PARTICULAR object has one or two methods added on the top of what the classed offered in the first place. That is another bad thing. You mentioned that Ruby is better because it is easier to maintain and to read than Java. This contradicts your opinion: looking at an object and not being able to be sure of its structure is way less readable than the opposite situation.

I don't have anything against Ruby in particular. I am a java programmer and do some php for my personal web needs (java hosting sucks, you need your own server), however I fail to see any value in Ruby. I don't say php is better because it isn't; but I don't see Ruby gaining on Java too often.

Also, how do you comnment on Zed Shaw rant he published on his website? This is not reassuring...

11:34 AM, June 20, 2008

 
Blogger Zhenhong Bao said...

toms outlet
michael kors online
ralph lauren uk
coach factory outlet
tory burch outlet
replica watches
toms shoes
fitflops sale
coach outlet
michael kors factory outlet
oakley sunglasses wholesale
longchamp handbags
air max 90
michael kors handbags wholesale
louis vuitton sunglasses
michael kors outlet online
louis vuitton bags
oakley sunglasses
ray ban sunglasses
fitflops clearance
chaussure louboutin
swarovski crystal
michael kors outlet store
michael kors outlet sale
chrome hearts outlet
louboutin pas cher
coach outlet online
louis vuitton outlet
louis vuitton neverfull sale
ralph lauren outlet
rolex watches
swarovski outlet
nike huarache
oakley sunglasses
ralph lauren outlet
20160531zhenhong

6:22 PM, May 30, 2016

 
Blogger Hua Cai said...

fitflops sale
ugg outlet
mulberry handbags sale
true religion outlet
michael kors outlet clearance
true religion jeans
new balance outlet
michael kors outlet clearance
ferragamo outlet
christian louboutin shoes
links of london
michael kors wholesale
tory burch outlet online
prada sneakers
true religion outlet
swarovski outlet
jordan pas cher
nike air force 1
calvin klein underwear
louis vuitton pas cher
true religion jeans
ferragamo outlet
ferragamo shoes sale
louis vuitton outlet store
tiffany and co
coach outlet store
gucci outlet
louis vuitton outlet
oakley sunglasses uk
true religion jeans
michael kors outlet online
mulberry outlet
nike free 5
celine outlet online
louis vuitton bags
20160804caihuali

10:43 PM, August 03, 2016

 
Blogger Fangyaya said...

beats outlet
abercrombie & fitch
toms shoes
michael kors handbags
ugg outlet
coach outlet store online
toms shoes
nike outlet
cheap uggs
louis vuitton outlet
kate spade handbags
coach factory outlet
michael kors handbags
nike tn pas cher
ugg boots
adidas uk
insanity workout
canada goose coats
gucci belts
coach factory outlet
cincinnati bengals jerseys
louis vuitton
louis vuitton
chicago bulls jerseys
giuseppe zanotti sandals
gucci uk
uggs outlet
uggs outlet
adidas ultra boost
chenyingying20160908

7:17 PM, September 07, 2016

 
Blogger chenlina said...

coach outlet store online
denver broncos jerseys
ray-ban sunglasses
ugg boots uk
ray ban sunglasses
uggs outlet
coach factory outlet
coach outlet store online
longchamp outlet
louis vuitton outlet
chenlina20161018

7:52 PM, October 17, 2016

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home

 

If you like this blog, you might also like top photography schools.