Slashdot Mirror


Love and Hate For Java 8

snydeq writes "Java 8 brings exciting developments, but as with any new technology, you can count on the good, the bad, and the headaches, writes Andrew C. Oliver. 'Java 8 is trying to "innovate," according to the Microsoft meaning of the word. This means stealing a lot of things that have typically been handled by other frameworks and languages, then incorporating them into the language or runtime (aka standardization). Ahead of the next release, the Java community is talking about Project Lambda, streams, functional interfaces, and all sorts of other goodies. So let's dive into what's great — and what we can hate.'"

42 of 434 comments (clear)

  1. Finally Fixing the Date stuff by CastrTroy · · Score: 4, Informative

    Proper date and time handling is one of the reasons I really prefer .Net to Java. The support for dates is just deplorable in Java. One shouldn't have to use an external dependancy, like JodaTime to handle basic date operations. If they could also add a "Decimal" data type, that is, a base-10 decimal primitive datatype, I think Java would be a much more useful language for day to day programming. Almost all the programming I do I would rather use a Decimal data type rather than a float data type, but very few languages support it as a native data type. .Net is one of the few environments where they got this right.

    --

    Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    1. Re:Finally Fixing the Date stuff by msobkow · · Score: 3, Insightful

      I'd hardly call it "difficult" to use, any more than it is to use the wrappers for the native types. Still, it would be *nice* if you could use "+" instead of "add()", but really that's just syntactic sugar.

      --
      I do not fail; I succeed at finding out what does not work.
    2. Re:Finally Fixing the Date stuff by Anonymous Coward · · Score: 5, Insightful

      I'd hardly call it "difficult" to use, any more than it is to use the wrappers for the native types. Still, it would be *nice* if you could use "+" instead of "add()", but really that's just syntactic sugar.

      To some extent, anything beyond raw binary notation used by your processor is just some form or another of "syntactic sugar" transformed by some intermediate tool.

    3. Re:Finally Fixing the Date stuff by petermgreen · · Score: 5, Insightful

      People like to dismiss syntactic sugar as unimportant but IMO it's the difference between code that is pleasant to read and write and code that is a PITA to read and write.

      I wish some fork of java would happen and take off that adds back in the basic features sun left out. Stuff like properties*, user defined types without an implicit reference, unsigned numeric types, operator overloading, parameter pass by reference etc. Some of that is syntactic sugar, other parts not so much. Ideally these features would be done in a way that could somewhat work on existing VMs though some features would likely require VM enhancements to operate efficiently.

      Unfortunately MS has already taken the name J++ :(

      * No that javabeans shit doesn't count.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    4. Re:Finally Fixing the Date stuff by viperidaenz · · Score: 5, Informative

      New Java Date Time API for Java8: http://openjdk.java.net/jeps/150
      AKA JSR 310

    5. Re:Finally Fixing the Date stuff by Alomex · · Score: 3, Insightful

      Actually it isn't. The add() method belongs to the first parameter, whereas the native '+' implementation (used to) belong to neither and if you think about it really should be that way.

      '+' is not a method or property of the first parameter. the correct interpretation of a+b is that this creates a unnamed virtual object number tuple with the method add.

    6. Re:Finally Fixing the Date stuff by Alomex · · Score: 4, Insightful

      Academic types have rejected 95% of all real advances in programming languages for nearly 4 decades as "syntactic sugar" while they carry on with their abstract type theory which has had rather limited impact in the real world in the same time span.

      Do yourself a favor and do away with the "syntactic sugar" crutch and try to judge a language proposal on it's own merits. Is it better to write 3+5 than 3.add(5) ?

      The answer is obviously YES, so who the hell cares if it is syntactic sugar, syntactic salt or syntactic coconut sprinkles.

      If it makes life better it should be adopted. End of story.
      p.s. there are potential drawbacks with operator overloading, but "syntactic sugar" ain't one of them.

    7. Re:Finally Fixing the Date stuff by bzipitidoo · · Score: 3, Insightful

      What bugs me about operator overloading is how tediously verbose it can get. For example, say you define operator functions for < and ==. You still have to do <=. Even when all the <= function is is: return this < that || this == that;, you still have to write it. It's so tempting to skip writing the code for an unused operator that many programmers do so. Languages are mostly unable to automatically fill in obvious code of that sort. C++ does have a default assignment operator function, but that's all. Too much chance of the obvious being wrong, so they opt not to do anything.

      To make matters worse, the above implementation of <= is inefficient. Down at the machine level, the computer does not stupidly require 2 separate comparisons to test <=. It has instructions such as JLE. The above function will at the least result in the computer having to do JL; JE;. While JE may be executed only 50% of the time that JL is executed, depends entirely on the data and code, it's still a waste. Further, two branches takes more space in the CPU's branch prediction, and the extra instruction takes more space in cache, so JL; JE is not as good as 50% slower.

      I find your gratuitous slur against "academic types" unwarranted and unfair. Academia has produced much innovation in programming. Do you forget the proof that Structured Programming is sufficient, and GOTOs are not necessary? All the work done on Turing machines, and universal computation? Automata Theory, with the classification of grammars into such categories as "context free"? BNF? Without that academia you sneer at, we couldn't be sure of all that. What of the entire concept of OOP? Where did that come from? And functional programming and LISP? It's easy for some hack to bang out a programming language built around what he feels are a few good ideas, drawn from perhaps years of experience. But without careful examination of the problems, insightful modeling that leads to good, pertinent questions which can be proven one way or another, we would just be flailing around even more than we already do. We might all still be trying to program in ALGOL. I put more trust in academia's ability to create a good programming language than I do a modern corporation with its dismissive attitude towards fundamental research.

      --
      Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
    8. Re: Finally Fixing the Date stuff by gmueckl · · Score: 3, Insightful

      Clearly you have not yet had a chance to write code that does real maths with real mathematical types like vectors or matrices. This is wheree operator overloading really shines. You don't want to implement complex formulas with tons of explicit function calls. With overloaded operators you can basically transfer the formulas you calculated on paper into machine code almost exactly. Without them, it's a sad mess of nested function calls, long lines, superfluous temporary variables and almost inevitable mistakes in code that nobody wants to read.

      Of course there are times when operator overloading is exactly the wrong thing to do. But if it is used the right way, it is an amazing feature.

      --
      http://www.moonlight3d.eu/
    9. Re:Finally Fixing the Date stuff by smittyoneeach · · Score: 3, Funny

      Well, you have to instantiate a BigDecimaFactory in the inversion-of-control container and pull in a lot of org.apache.whizbang.dont.we.love.us.some.nested.hierarchies code, plus update your ant scripts to maven, and don't forget to feed the Tomcat, but, with sufficient struggle, you can still get to "Hello World 1.0" in Java.

      --
      Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
    10. Re: Finally Fixing the Date stuff by matfud · · Score: 3, Insightful

      As soon as you get beyond complex numbers you rapidly find out that there are not enough operators to overload for operator overloading to make much sense.
      is "*" the dot or cross product or is it convolution or is it correlation or autocorrelation?

      There are not enough operators to make it useful so you have to have method calls anyway. If you are calling methods then it is clearer to always call methods

  2. Re:Gawd by jcr · · Score: 5, Insightful

    Java is a real language, and a lot of real programs have been written with it. It's not a good language, but that doesn't make it trivial.

    -jcr

    --
    The only title of honor that a tyrant can grant is "Enemy of the State."
  3. Re:I'm disappointed by msobkow · · Score: 3, Interesting

    I think the bigger reason they probably didn't do it is that Erlang only lets you assign a variable once, so there are no concurrency issues with read/write of variables. One of the neat side effects of this is that a service/method which takes a lambda argument can be parallelized behind the scenes without changing the meaning of the code execution.

    Another thing that puzzles me is that Java lambdas seem to be based on the idea of overriding a method of a class. That seems to me to be a critically limiting way of implementing them vs. function prototypes/templates, as there is no way to specify multiple lambdas being passed to the evaluator.

    --
    I do not fail; I succeed at finding out what does not work.
  4. Re:Gawd by multiben · · Score: 4, Funny

    So you're saying that *all* programming languages are exactly as good each other then? Perhaps you are spending too much time in the "real" world?

  5. Re:Gawd by CastrTroy · · Score: 5, Insightful

    I would almost agree, that any language is as good as any other. With a few exceptions, like "whitespace" which isn't meant to be a practical language anyway. What really sets languages apart is the tooling that's built up around them. The debuggers, the IDE, the profilers, etc. Also, the consistency and extent of the standard API plays a huge role in how useful a language is. I would rather use Brainfuck with an amazing tools and a rich API than use Java, Python, or Ruby with bad tools and an inconstent and incomplete API.

    --

    Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
  6. Re:Gawd by cheesybagel · · Score: 3, Insightful

    Well its a mixed bag really. It is a lot more verbose than other recent languages. The type system is inane. The main advantage is you have binary portability across platforms and a really huge standard API to use.

  7. Re:Gawd by hey! · · Score: 5, Insightful

    Newsflash: People write major systems in Java that work pretty well. People do mission critical, bet-the-company stuff in Java, and it works. *Your* mileage may vary, but it always does.

    This doesn't mean it' the best choice for everything, because *nothing's* the best choice for everything

    And it doesn't mean Java doesn't have serious flaws. There's something deeply ingrained in Java that encourages over-engineering. But every language has its pitfalls.

    --
    Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
  8. Re:Java? by wmac1 · · Score: 3, Insightful

    Oh boy!! If that's what you understand of java...

    FYI, You are still using java every single day (as in websites using Java in server side, on phones, on smart cards, on home appliances, ...).

  9. The old adage comes back and back by countach · · Score: 5, Insightful

    The old adage is always applicable: Those that do not use LISP are condemned to reinvent it. Badly.

    1. Re:The old adage comes back and back by ebno-10db · · Score: 5, Funny

      Sure: reimplement it in Java.

      That's called Clojure.

      Even better, use it within J2EE so that it takes 45 seconds to start up.

      They sped it up?

  10. Re:Gawd by Anonymous Coward · · Score: 5, Insightful

    I think one of the big problems is that programmers are very much biased towards thinking that what should be considered matters of preference are absolute right/wrongs, and most of the differences between major languages themselves are simply matters of taste or convenience. It's why you can get almost any software engineer to tear apart someone else's code, even if the code is written as well or better than anything they've written: there's pretty much always small differences that the engineer will find offensive even though there's no practical impact.

  11. Re:Gawd by jythie · · Score: 4, Interesting

    That was my general thought. Most languages are pretty much interchangeable. What tends to set them apart is the ecosystem they exist in... not just in terms of the 'hard' things like libraries and tools, but the 'soft' things like how much of a developer community (and candidate pool) exists for any particular domain.

    Which kinda makes me wonder why language designers bother with these updated versions out side some fetishistic desire to make their language of choice more complicated. Though I guess it does help separate out the 'elite and in the know' from the 'newbies and outsiders'.... though I think C++ really takes the cake in that regard.

  12. Re: Gawd by S.O.B. · · Score: 5, Insightful

    I used to work on a Java transaction processing application at a major financial institution that handled more than 1,000,000 transactions a day that consolidated data from Unix, mainframe and Windows systems. The transactions came from batch and online, client-facing applications that had five nines uptime requirements.

    I don't know, sounds major to me. And we had no more "major system problems" than any other app and less than most.

    It's not to say that Java is the answer to everything because nothing is. But it is definitely capable of doing the heavy lifting.

    --
    Some of what I say is fact, some is conjecture, the rest I'm just blowing out my ass...you guess.
  13. Re:Gawd by ebno-10db · · Score: 5, Funny

    May you spend 100 years in purgatory, writing AI programs in COBOL.

  14. Re:Gawd by ebno-10db · · Score: 5, Funny

    Lisp may be an interesting language, but Lispers scare me. The glow in their eyes when they evangelize about the Mother of All Languages reminds me of Village of the Damned.

  15. Seems familar... by ndykman · · Score: 3, Informative

    I remember when C# and .Net first came out, it was noted that it was just borrowing (some said stealing) from Java. When C# first came out, I didn't see it as becoming a leader in new language features, but it is clearly is, as Java 8 addresses a lot of things that been part of C# for a while.

    Streams: Similar to IEnumerable and parts of LINQ (LINQ to Objects). Of course, IEnumerables are less strict on multiple enumeration (it may work). Being a bit more strict on this as Streams isn't a bad idea. Functional Interfaces; The article was light on details, but it seems to address the use cases that extension methods in C# addresses. Interesting that the body of the method appear in the interface. The ability for a class to override this default is a new idea, it will be interesting to see how this plays out. Not a bad way to go about this at all. Lambdas:Well, it's -> versus =>. I can't imagine the discussions that occurred over which one to choose.

    I'm not sure about the JavaScript in Java feature. But, I've always said being able to execute Scheme in .Net would be useful to me, so this something that MS may have to address down the road.

    For me, Java still needs some catching up in terms of parallel programming versus the Task Parallel Library (and the Dataflow Extensions). This is especially true with C# 5.0. Async and await are powerful language features. Personally, I'm still prefer C#. I like having first class generics, the full LINQ library (Expressions) and libraries like Reactive Extensions and Code Contracts (plus the static verifier) are nice features. But, all this in Java 8lis a step in the right direction. I just hope it isn't a case of too little, too late.

    1. Re:Seems familar... by hibiki_r · · Score: 4, Interesting

      More than reacting to C#, they seem to be reacting to other JVM languages that are just more attractive for any shop with experienced people.

        The JVM is often used to write large amounts of business crud: Take a parameter, query a database, process a list. Make a service call, transform the result into a slightly different list, merge the results with a different service, then return. You could write that kind of computation in a functional way using Groovy or Scala in half the number of statements. And if there's one rule for programming productivity is that the less statements you need to write, the faster the job can be written, and the less bugs you get.

      When the people using your virtual machine start migrating to other languages you do not control, you are at risk of having the people building the language just porting the language away to a different one, and poof, Java becomes obsolete. Therefore, Oracle just has to improve Java.

  16. Re:Gawd by Coryoth · · Score: 5, Insightful

    And it doesn't mean Java doesn't have serious flaws. There's something deeply ingrained in Java that encourages over-engineering. But every language has its pitfalls.

    I don't think there's much in Java the language that encourages over-engineering; it's more in the community that surrounds Java. It's in the tutorials, and books, and code examples and discussion groups . It's in the frameworks and libraries.

    The reality is that a "language" is as much shaped by the community that grows up around it as by the actual language itself. Perl doesn't have to be particularly unreadable, but the culture that grew up around perl in the late 90's that was obsessed with cute hacks, fewest keystrokes, and self created obscurity created a state where anyone learning perl was immersed in that culture and came out writing a lot of unreadable stuff. It is my understanding that since many of those programmers left perl for other languages perl has been remade as "Modern Perl" which is largely the same core language, just with a different and libraries, and is quite readable.

    Conversely python can be made quite diabolical (just through together chains of nested list comprehensions and single character variables for example), but because it grew up with a culture of "one obvious way to do it" and readability most code you'll see tends to eschew such things, and strive to read like pseudo-code. Again, there's not that much inherent in the language, it's the cultural conventions surrounding the language that enforce much of that.

    Java fell in with the Enterprise crowd, and consequently found itself immersed in a culture obsessed with design patterns and over-engineering. Had things gone a little differently with, say, in browser applets somehow becoming the primary driving force for java (let's assume they ran better say) then I doubt java would be known for over-engineering.

  17. Re:Gawd by gnupun · · Score: 5, Insightful

    I would almost agree, that any language is as good as any other. With a few exceptions, like "whitespace" which isn't meant to be a practical language anyway.

    This is a false statement, they are not as good as the other. Each language is designed to be strong in certain areas while weak/ignoring other areas. As an example, C promotes code close to machine language while Java shields the programmer from manual memory management (GC). There are many such design issues that make a language a natural fit for certain applications while making other languages ill-fitted.

    What really sets languages apart is the tooling that's built up around them.

    While tools may be important, they are of a secondary importance.

  18. Re:I'm disappointed by binarylarry · · Score: 3, Funny

    They're still waiting for the application with the answers to start up.

    --
    Mod me down, my New Earth Global Warmingist friends!
  19. Unsigned by jbolden · · Score: 3, Informative

    I'm not sure how that connects to the GPs request. Anyway Gosling didn't include it because the behavior aren't defined in CPU independent ways.

    32-unsigned 0 minus 32-unsigned 1 = ?
    where ? is CPU dependent. Some you'll 0xFFFF other 0x8001 others 0xFFFE. That's precisely the sort of thing JAVA was designed to abstract away. And if you don't want unsigned to be doing raw CPU arithmetic on primitives then you can just use a library.

  20. Re:Gawd by Anonymous Coward · · Score: 4, Insightful

    Lisp is the perfect example of CastrTroy's point -- for a long time the interesting development tools were proprietary, expensive, and obscure.

    That's not the real problem with Lisp, Smalltalk etc though.

    The real problem is that you don't get to benefit from their strengths unless you live completely in their environment. Working with Lisp in a C* based world is like driving a car in the ocean.

  21. Re:Still 32GB barrier by Anonymous Coward · · Score: 3, Funny

    Java 8 is still limited to 32-bit array indexes, meaning, e.g. that arrays of doubles are limited to 32GB. Java won't get true 64-bit support until Java 9 in 2016.

    32GB should be enough for anybody.

  22. Re:I'm disappointed by pspahn · · Score: 4, Funny

    "Knock Knock..."

    "Who's there?"

    ...

    ...

    ...

    ...

    Java!!!

    --
    Someone flopped a steamer in the gene pool.
  23. Re:Gawd by viperidaenz · · Score: 3, Informative

    A lot of medical devices are built using Java.
    First Google result: http://www.oracle.com/us/technologies/embedded/embedded-java-for-healthcare-433550.pdf

    It's been used in medical devices since the late 90's, shortly after it was invented.

    For those applications, Java is purpose built.

  24. Re:Still 32GB barrier by GodfatherofSoul · · Score: 3, Funny

    Why would you need an array longer than 2^32? Unless...wait, are you sequencing alien DNA????

    --
    I swear to God...I swear to God! That is NOT how you treat your human!
  25. Re:Gawd by gigaherz · · Score: 4, Interesting

    Try "debugging with print statements" when the codebase takes over 10 minutes to compile, and that's when the resources don't need to be re-processed. After you admit to that, the rest of the post can't possibly be taken seriously.

  26. Re:After years of saying java didn't need C# featu by benjymouse · · Score: 3, Informative

    Right, lets pretend Microsoft invented all of those things.

    If you had been following the language discussions for (for instance) lambda-J you would realize that there is a LOT more to it than simply deciding that a language must have this or that feature.

    Specifically, both Java and C# are statically typed languages (although in C# a variable can be statically typed to be dynamic, but I digress) with advanced multi-generation garbage collection, structured exception handling, generics etc. Any new concepts introduced into the language must respect the concepts already there. Designing new features for Java or C# requires significant amount of innovation to solve the interference problems and maintaining the "feel" of the language.

    LINQ is a real accomplishment, one that I have not seen put together like that in any other language. Yes, list comprehensions existed before. Yes, expression trees (ASTs) have been used in LIST and several other languages before. Don't know about extension methods, but I'm sure that there must be some research language. Yes, type inference had been used before. Yes, inferred classes must have been used in some language before. Certainly lifted types are well-known in certain other languages. But putting the whole package together and make it fit seamlessly with (and complement) the existing features and at the same time keep it so simple and generic that the useful parts are actually library features, that is a real accomplishment.

    Reactive Extensions is real research (primarily by Erik Meijer who has regrettably now left Microsoft to return to academia). Not least because it ties to beautiful in with LINQ. It is entirely new? No, as Erik himself would say, IEnumerable is just a monad. IMHO that does not take away from the accomplishment.

    Async and await are *really* cool and have inspired Scala to create something similar.

    No, Microsoft didn't invent "all of those things". But fitting them in with a curly-brace, statically typed language is real innovation.

    --
    Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
  27. Re:Still 32GB barrier by countach · · Score: 3, Funny

    I'm sequencing alien DNA you insensitive clod.

  28. Re:Answer not obvious by gbjbaanb · · Score: 3, Insightful

    no, all you "know" is that there is a method called "add" on the object named 3 that is being called with the parameter 5.

    So the 'add' method could easily carve 3 and 5 on a tree. You have no way of knowing what it does just from the method name. The classic example is string::add(). Does "hello".add("world") produce "hello world" or does it only apply to "3".add("5") to produce "8"? You may criticise operator+ for this reason, but note that the add() method is just as bad.

    So there is no difference between the operator+() method, and the add() method (except the name chosen, and the way its written by the developer).

    Now we've established that there is no difference between the two, we can say that as normal humans are the ones that read and write code, the former, operator, mechanism is easier to read, write and understand, then it is the one that should be preferred.

  29. Re:Gawd by serviscope_minor · · Score: 3, Interesting

    I don't think there's much in Java the language that encourages over-engineering; it's more in the community that surrounds Java. It's in the tutorials, and books, and code examples and discussion groups . It's in the frameworks and libraries.

    Indeed. The C++ world used to be like that. The sort of people who read the treat the design patterns pook not as a useful guide and taxonomy but as a way of life. They used to do the same stuff in C++ with massive class heirachies. I think they tend not to be very good programmers and they migrated en-masse to Java since it has fewer pitfalls. The C++ community has changed considerably since then and the modern style is very different.

    I don't think that really says anything about the C++ language or the Java language. As a dyed-in-the-wool C++ programmer, going over to Java, I was firstly not at all surprised by the legendary overengineering, but was surprised that there seemed to be nothing in the language making people write overengineered code.

    Don't get me wrong. It's not my favourite language: I find it a little dull and a little verbose, but it does not seem to be bad.

    It is my understanding that since many of those programmers left perl for other languages perl has been remade as "Modern Perl" which is largely the same core language, just with a different and libraries, and is quite readable.

    Much the same thing is happening in C++. The community (myself included) went mad with excessive template metaprogramming shortly after the mad with design patterns crowd left. It all seems to be calming down and the modern "Stroustrup style" (as it's known and given the name given to it is probably not all that new) of basically doing the sensible thing seems to be slowly taking over.

    --
    SJW n. One who posts facts.
  30. Re: Gawd by RabidReindeer · · Score: 3, Informative

    So, 6,000,000 orders per second on a single Java thread on commodity hardware isn't good enough for you?

    http://martinfowler.com/articles/lmax.html

    Java does major heavy lifting, and is extremely fast, if you know what you're doing.

    You can try to make minor parts of the program faster by calling C++ via JNI, but you risk harming performance in the long run, because then the JIT compiler can't inline or otherwise optimise that part of the code.

    Of course, you can make any language slow if you mess up enough.

    Benchmarks have been done and Java can often out-perform C (and C purists will point out that C++ has its own inefficiencies). The reason being that in addition to garbage collection, modern-day JVMs often "waste" time analysing code execution and re-optimizing dynamically, which is something that C cannot do.

    A lot of things that are more efficient done small-scale become relatively less efficient when done large-scale. So much that the large-scale applications can actually benefit even further from processes that would be prohibitive on the small scale (such as on-the-fly re-optimization).

    Even memory management can sometimes be more efficient when garbage-collected if the dynamic memory base is large enough and organized in the right way, replacing thousands of small memory transactions with one big one that reclaims whole blocks of memory at a swoop.

    There's simply no one absolute answer. Only fools look for silver bullets or the One True Religion. But Java found its niche in high-performance, high-reliability backends and so it has received a lot of attention over the years towards making it handle that sort of stuff well.