By mitchp
via allthingsprogress.com
Published: Nov 28 2010 / 16:57
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.
Comments
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.
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.
sskjames replied ago:
DRY.
import org.apache.commons.io.FileUtils
.....
String fileContent = FileUtils.readFileToString(file1);
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.
Mario Arias replied ago:
Lot of reasons?
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
sskjames replied ago:
Yes, commons-logging should be avoided. Fortunately, we have "slf4j".
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!
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.
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.
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
sskjames replied ago:
Great..!
Voters For This Link (36)
Voters Against This Link (3)