Live data from Hacker News

Java 7 is now available

oracle.com

61–70 of 218 posts

Re: Java 7 is now available

#61
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…

To be honest your one liner takes me a while to parse and you forgot to close a parenthesis. OTOH It is really hard to read or write that switch incorrectly.

Re: Java 7 is now available

#63
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 say, I think it's easier to verify the correctness of

    [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30,  31, 31, 30, 31, 30, 31][M-1]
than your formula. Even a dictionary wouldn't be bad. And if it were wrong, it would be easier to fix it.

Re: Java 7 is now available

#64
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…

Why did you need string-switching? You could have created a Map lookup table.

Re: Java 7 is now available

#65

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).

> The community splintered, the language and platform really lost any ability to maintain momentum. This is the mindset I've never understood. Do you stop using a hammer to bang in nails because the hammer "community" has splintered, or the development of hammers has stagnated? No, you still use it to fulfill a job it solves.

Depends. What if your nails required newer hammers? Would you rather wait for a newer hammer from a company that hasn't been meeting needs for years, or buy one from the store that had them when the nails came out?

Perhaps a better analogy is a screwdriver. Apple came out with their "pentalobe" security screws a while back - is it reasonable to buy one of the screwdrivers that is made for it that are available now if you needed to (un)screw one? The other options are to use a philips and damage the screw and suffer a lot of frustration, or to wait until Craftsman makes one (probably never).

Re: Java 7 is now available

#66
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…

Using a contrived formula that's difficult to understand or quickly check for correctness to solve a problem whose answer doesn't come from anything mathematical (i.e., the number of days in each month were arrived at arbitrarily, not via any formula) and just happens to work is NOT good style. At best it's cute and irrelevant (and doesn't even work for all of the twelve cases...). Wow.

Edit: also, if you're mapping the month string to an integer anyway, I don't see how you're going to do that without doing basically the same thing as the switches you posted anyway.

Re: Java 7 is now available

#68
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"?

The OpenJDK may have more bugs. Check out [http://stackoverflow.com/questions/1977238/why-should-i-use-...].

Re: Java 7 is now available

#69
post #63
post #51

Earlier quoted context omitted.

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 say, I think it's easier to verify the correctness of [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][M-1] than your formula. Even a dictionary wouldn't be bad. And if it were wrong, it would be easier to fix it.

Correctness should be verified by tests not 'looking at the code'.

The aforementioned code can never be verified as correct because February requires a year to be present to know the number of days.

Doesn't java have a massive calendar library to address exactly these sorts of human questions?

I mean sure you'd still be looking at code like:

  public int getDaysInMonth(DateTime date) throws
    CalendarFactoryFactorException,
    DateOutOfRangeException,
    ArrayOutOfBoundsException 
  {
    CalendarFactoryFactory factoryMaker = new CalendarFactoryFactory("Western");
    GregorianCalendarFactory gregFactory = factoryMaker.getGregorianFactory();
    Calendar c = gregFactory.createCalendar(new DateTime());
    return c.getDaysInMonth();
  }
Post reply on HN