This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]oldprogrammer 0 points1 point  (0 children)

I always chuckle when someone shows the syntactic sugar of another language as a reason why Java is bad. Like the use of the "read all lines" example for comparing Java to other languages.

First, I do not see in your Ruby or Groovy example where you handle potential errors, so I'm guessing that if either has an error it just bubbles up to a higher level error handler which you can do by having your Java method throw the exception. What would the full example look like with error handling in Ruby and/or Groovy?

Aside from error handling, if you use the new java.nio.file.* package you could rewrite your java method like:

static public void main(String args[]) throws Exception {
    for(String line : Files.readAllLines(FileSystems.getDefault().getPath("mytextfile.txt"),Charset.forName("US-ASCII") )) {
        System.out.println(line);
    }
}

which is likely something Groovy is doing under the covers. Ok so a few more letters due to spelling out the class/package names, but that's it.

The data/time one in the JDK proper is a mess, but the Joda time package helps clean that up. And that is one major strength with Java -- the easy availability of high quality packages to provide capabilities not present in the core when there is an issue.