Live data from Hacker News

Java 7 is now available

oracle.com

51–60 of 218 posts

Re: Java 7 is now available

#51
post #16

You can now finally use a string in a switch statement, hurray (it's the little things that make me happy)! http://download.oracle.com/javase/7/docs/technotes/guides/la...

God, I seriously hope string-switching doesn't catch on.

In a prev job, I saw this block of code -

-------

public int getDaysInMonth( String month ) {

  if( month.equalsIgnoreCase("january")) return 31;

  else if( month.equalsIgnoreCase("february")) return 28;

  else if( month.equalsIgnoreCase("march")) return 31;

  else if( month.equalsIgnoreCase("april")) return 30;

 ...
}

-------

My eyes bled. I said folks, just map the month to an int M in range [1..12] and simply write 1 line of code

return 30+((M+Math.floor(M/8))%2;

( except for 2, which is 28 or 29 depending on a leap year)

I was overruled. "We are programmers, not mathematicians" was the response!!!

Now they'll happily use this string-switch to do

---------

switch( month.toLowerCase() ) {

  case "january" return 31;

  case "february" return 28;

  case "march" return 31;

  case "april" return 30;
...

  default : return -1;
}

-------

which is an even nastier abomination :(

Re: Java 7 is now available

#52
post #33

Earlier quoted context omitted.

For dynamic JVM languages, the new invokedynamic bytecode is a huge performance boost.

Probably not. See what Rich Hickey said about this: http://clojure-log.n01se.net/date/2008-09-03.html#09:13a

I'm a little disappointed that people are still talking about tagged ints. There are so many better ways to avoid the overheap of integers being a refrence type (namely type specializing everything under the sun, particularly your JIT'd code and data structures).

Re: Java 7 is now available

#54
Looks like this version is not open source. Is there an open-source version of Java 7? Edit: Yes! http://openjdk.java.net/ has an announcement at http://mail.openjdk.java.net/pipermail/announce/2011-July/00.... So why would anybody "accept the Oracle Binary Code License Agreement for Java SE"?

Re: Java 7 is now available

#55

Meh. The world turns. I spent a decade developing primarily in Java, and the last few years were really disappointing. The community splintered, the language and platform really lost any ability to maintain momentum. I might have been stoked about Java 7 three years ago (when it should have come out).

I don't know if I agree. The Java language has floundered (I've been stuck coding in it for the last couple of years), but I think the platform/JVM has started becoming used more and more often for new + exciting language options. The new release should make implementing dynamic languages on top of the JVM easiser, and could open the doors for a lot of interesting options.

I don't think I would say it's floundered. I came back to Java last year after 10 years of C++, and was really pleasantly surprised: Programming in Java now is a nice experience. I would say it has matured, not floundered.

Re: Java 7 is now available

#56
post #51
post #16

You can now finally use a string in a switch statement, hurray (it's the little things that make me happy)! http://download.oracle.com/javase/7/docs/technotes/guides/la...

God, I seriously hope string-switching doesn't catch on. In a prev job, I saw this block of code - ------- public int getDaysInMonth( String month ) { if( month.equalsIgnoreCase("january")) return 31; else if( month.equalsIgnoreCase("february")) return 28; else if( month.equalsIgnoreCase("march")) return 31; else if( month.equalsIgnoreCase("april")) return 30; ... } ------- My eyes bled. I said folks, just map the mo…

Are you serious? An "abomination"? The switch statement is fine, and using an array [31, 30, 31 ...] would be fine as well. Your 1 line isn't really 1 line because you have to convert the month to an integer anyway, and then the array lookup is even shorter than your solution.

Re: Java 7 is now available

#57
post #32
post #27

So for languages like Clojure,Scala does this offer any new feature for them?

Yes [1]. Invokedynamic (JSR-262). Quote from an older article [2]: "... enable[s] implementers of compilers for dynamically typed languages, that is, the people who develop compilers for languages such as JRuby and Jython, to generate bytecode that runs extremely fast in the JVM." [1] http://blogs.oracle.com/jrose/entry/jsr_292_launched_in_java [2] http://java.sun.com/developer/technicalArticles/DynTypeLang/...

Indeed, As Charles Nutter (JRuby) wrote:

"There’s a very real chance that invokedynamic could improve JRuby performance many times, putting us on par with our statically-typed brothers like Java and Scala. And that means you can write Ruby code without fear. Awesome."

http://www.engineyard.com/blog/2011/jruby-1-6-released-now-w...

Re: Java 7 is now available

#58
post #54

Looks like this version is not open source. Is there an open-source version of Java 7? Edit: Yes! http://openjdk.java.net/ has an announcement at http://mail.openjdk.java.net/pipermail/announce/2011-July/00... . So why would anybody "accept the Oracle Binary Code License Agreement for Java SE"?

It is called openjdk: http://openjdk.java.net/

Re: Java 7 is now available

#59
post #51
post #16

You can now finally use a string in a switch statement, hurray (it's the little things that make me happy)! http://download.oracle.com/javase/7/docs/technotes/guides/la...

God, I seriously hope string-switching doesn't catch on. In a prev job, I saw this block of code - ------- public int getDaysInMonth( String month ) { if( month.equalsIgnoreCase("january")) return 31; else if( month.equalsIgnoreCase("february")) return 28; else if( month.equalsIgnoreCase("march")) return 31; else if( month.equalsIgnoreCase("april")) return 30; ... } ------- My eyes bled. I said folks, just map the mo…

Your one-liner is more difficult to understand. The string switch is very explicit and understandable.

Re: Java 7 is now available

#60
post #51
post #16

You can now finally use a string in a switch statement, hurray (it's the little things that make me happy)! http://download.oracle.com/javase/7/docs/technotes/guides/la...

God, I seriously hope string-switching doesn't catch on. In a prev job, I saw this block of code - ------- public int getDaysInMonth( String month ) { if( month.equalsIgnoreCase("january")) return 31; else if( month.equalsIgnoreCase("february")) return 28; else if( month.equalsIgnoreCase("march")) return 31; else if( month.equalsIgnoreCase("april")) return 30; ... } ------- My eyes bled. I said folks, just map the mo…

I have to admit - I never even thought that there would be an easier math-formula way to calculate it. Though I would have written the switch:

  case "september":
  case "april":
  case "june":
  case "november": return 30;
It's sad, but still need to go through the poem in my head to remember most of the time.
Post reply on HN