Link Details

The Ruby language is beautiful. And I think it deserves to break free from the Web. Unfortunately, I think the future of Ruby is firmly stuck in Web development, so I’m going to invest in a new language. This is a look at the fantastic language I came to from Java. It’s also a peek at a potential substitute.

Posted by mitchp  |   Nov 28 2010 / 16:57

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Comments

User 298727 avatar

ludni replied ago:

Wow, an article about ruby and python without any bashing. Ok, a diehard Java hacker would take the paragraphs describing the 'Java Verbosity' as an attack, but these guys will never take off their blinders ;-)
Sadly it's true, science, statistics and natural language processing seem not to be a core interest of the vibrant Ruby communitiy - especially in comparison with the wealth of libraries Python has to offer in these fields.

Reply 1 votes
User 161244 avatar

hohonuuli replied ago:

I agree, there was a lot of tedious Java bashing in the article. Yes, for the umpteen millionth time, Java has more bioler plate than most languages. But come on, how many articles do I have to read that complains about reading a text file with Java IO. Get over it, take 5 minutes and write a static IO method once that emulates Ruby's File.read in Java and reuse it, voila you'll never have to write the IO boiler-plate again.

Reply 2 votes
User 208597 avatar

sskjames replied ago:

DRY.

import org.apache.commons.io.FileUtils
.....

String fileContent = FileUtils.readFileToString(file1);

Reply 5 votes
User 187417 avatar

sproketboy replied ago:

Unless you don't want to have dependencies on Apache commons. There are a lot of reasons to not want the extra dependencies.

Reply 1 votes
User 237765 avatar

Mario Arias replied ago:

Lot of reasons?

Reply 0 votes
User 211643 avatar

zynasis replied ago:

only reason i can think of is commons-logging. curse that library and especially it being dragged in by the much more useful: commons-beanutils

Reply 1 votes
User 208597 avatar

sskjames replied ago:

Yes, commons-logging should be avoided. Fortunately, we have "slf4j".

Reply 0 votes
User 208597 avatar

sskjames replied ago:

I humbly believe having these extra dependencies is worth the time and effort than maintaining these ourselves. Nowadays I don't think I will sit and write all these stuff myself in any Java project. Instead, I would leverage stuff like commons-*, joda, guava etc.

Groovy users are fortunate to have these one liners and much more (especially xml stuff) built in without any dependencies.

And that's why I love Python too!

Reply 2 votes
User 161244 avatar

hohonuuli replied ago:

Yes, that's my point. There's off the shelf stuff that handles the IO boiler plate for you; or you can write it, it's very simple stuff, not sure you need to include apache jars for a simple IO method.

p.s. I think you meant NIH not DRY.

Reply 0 votes
User 208597 avatar

sskjames replied ago:

If you are going to use io in some simple use cases, may be you don't need all these. But these libraries bring in lot of value added stuff. Especially, I can't imagine working on a Java project without commons-lang.

I think the file input streams were not handled correctly in the article we are talking about. If you include stuff to handle that as well, there's even more
boiler-plate. Something like this...

try{
blah blah..
}catch(IOException ex){
blah blah
}finally{
if(reader != null){
try{
reader.close();
}catch(IOException ex){
logger.error("Some thing weird happened while closing this stupid stream", ex);
}
}

Whilst even if you want to read the file line by line or byte by byte in some use cases, commons-io has some handy methods to close the stream. It would go like this:

try{
........
}catch(Exception ex){
......
}finally{
IOUtils.closeQuietly(reader); //streams work as well
}
}

PS: I think JDK 7 has some improvements in this area.

Reply 0 votes
User 755021 avatar

devent replied ago:

He should try Groovy. Plus, I can use all Java libraries from Groovy.

def evenItems = [1, 2, 3, 4, 5, 6].findAll{it % 2 == 0}

println evenItems

Reply 0 votes
User 208597 avatar

sskjames replied ago:

Great..!

Reply 0 votes

Recommended Links

Scala
Written by: Ryan Knight
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Play
  3. Akka
  4. Debugging JavaScript
  5. Design Patterns
  1. Apache Hadoop
  2. REST
  3. Java
  4. Git
  5. Java Performance
Connect with DZone