News for hackers. Stuff that matters.
Re:Streams in Java 8 by overgard on Sunday February 09, 2014 @05:51PM (#7207751)
Yay. They finally caught up to C# 6 years later.

[Edit: to the haters -- where am I wrong other than that I'm making fun of your favorite language?]

Re:Streams in Java 8 by discardorama on Sunday February 09, 2014 @06:12PM (#7207876)
(I did not downvote you)

Such jingoism adds nothing to the discourse. Someone can as easily find something in Java 1.5 that C# still doesn't have. So what does that prove? Nothing.

Re:Streams in Java 8 by overgard on Sunday February 09, 2014 @06:26PM (#7207953)
> Someone can as easily find something in Java 1.5 that C# still doesn't have.

Like what?

Re:Streams in Java 8 by javafu2 on Sunday February 09, 2014 @06:55PM (#7208094)
checked exceptions :), sorry just kidding.

mainly wildcards, you can design an interface which is covariant and contravariant, and real interference when calling a generic method.

Re:Streams in Java 8 by eropple on Sunday February 09, 2014 @08:31PM (#7208529)
The lack of wildcard types in C# consistently bothers me when I use it.
Re:Streams in Java 8 by bruceboughton on Monday February 10, 2014 @05:08AM (#7210094)
It looks to me like C# supports everything from http://docs.oracle.com/javase/tutorial/extra/generics/wildca... using generic type constraints: http://msdn.microsoft.com/en-us/library/bb384067.aspx

What am I missing?

Re:Streams in Java 8 by benjiweber on Monday February 10, 2014 @03:00PM (#7213322)
They added Covariance and Contravariance of generic type parameters in 4. http://msdn.microsoft.com/en-us/library/dd799517%28v=vs.110%...
Re:Streams in Java 8 by syjer on Sunday February 09, 2014 @06:36PM (#7208001)
static imports ?
Re:Streams in Java 8 by overgard on Sunday February 09, 2014 @06:41PM (#7208027)
You could add an extension method to object, if you want the same effect.

(Although: A workaround for java's bizarre stance that no function can exist without an object doesn't really strike me as a "feature". [Granted: this criticism is equally true of C#])

Re:Streams in Java 8 by inglor on Sunday February 09, 2014 @06:52PM (#7208077)
It's in C# 6 :)
Re:Streams in Java 8 by alkonaut on Sunday February 09, 2014 @06:12PM (#7207877)
Stream<T>, IntStream, LongStream, DoubleStream?

You can't make this stuff up.

EDIT: what I'm trying to say is: why his remark is inflammatory and unnecessary, it's also wrong. This API is perhaps the single worse example of why java makes API's look worse than C#, and there is nothing to be done about it until the JVM stops erasing types.

Re:Streams in Java 8 by pron on Sunday February 09, 2014 @06:18PM (#7207910)
Java's type erasure, while once considered a disadvantage, is now being recognized as one of the reasons other statically typed languages can be ported to the JVM. If Java reified types, it would make interoperability with other type systems extremely hard.
Re:Streams in Java 8 by overgard on Sunday February 09, 2014 @06:22PM (#7207927)
Yet somehow they made F# and scala run on the CLR. So: I'm calling bullshit.
Re:Streams in Java 8 by javafu2 on Sunday February 09, 2014 @06:51PM (#7208072)
F# team ask for modifications of the CLR (covariant delegates), porting a language on the CLR if you are not Microsoft is hard.

Scala never really run on the CLR, it's a vaporware, sorry a work in progress.

Re:Streams in Java 8 by adriaanm on Sunday February 09, 2014 @09:32PM (#7208740)
Yep, scala's .net back-end is discontinued, and one of the main challenges (I worked on it a bit) was indeed generating the proper generic signatures. (I hear people are using ikvm these days.)
Re:Streams in Java 8 by gracenotes on Monday February 10, 2014 @02:41AM (#7209661)
For more context on why F# does in fact run into problems, see https://visualstudio.uservoice.com/forums/121579-visual-stud.... To my understanding, F# only allows type variables to vary, not type constructors (all generic variables must be escorted by a concrete type), and to go a step further, it doesn't allow type constructors to be used as higher-kinded type variables, which is useful sometimes. I see no reason why these couldn't be implemented on top of the JVM, though.
Re:Streams in Java 8 by anaphor on Sunday February 09, 2014 @07:34PM (#7208295)
I've never understood why Java programmers dislike type erasure. In my mind, runtime type inspection is a bad idea for a supposedly statically typed language. It just seems like people are complaining that they can't do something they probably shouldn't be. If there's something you can't do without it then that means Java is poorly designed, not that type erasure is a bad idea.
Re:Streams in Java 8 by pron on Sunday February 09, 2014 @07:38PM (#7208309)
To be fair, erased generics force autoboxing of primitives. Anyway, Java's combination of static and runtime types, though not pure by any measure, has actually proven quite useful.
Re:Streams in Java 8 by kvb on Monday February 10, 2014 @10:10AM (#7211429)
I see this claim fairly often, but it seems like wishful thinking to me. There's nothing stopping a language targeting .NET from erasing its own generics to `List<object>`, `Map<object>`, `T<object>` if necessary, which would achieve almost exactly what you'd get with Java's erasure. And in the meantime, Java's approach requires any generic class containing arrays to box small value types, wasting large amounts of memory when those arrays are large.
Re:Streams in Java 8 by _pmf_ on Monday February 10, 2014 @12:27AM (#7209312)
> is now being recognized as one of the reasons other statically typed languages can be ported to the JVM

No, I really don't think so.

Re:Streams in Java 8 by barrkel on Sunday February 09, 2014 @07:52PM (#7208373)
Type erasure has ups as well as downs. For one, it means you can write runtime polymorphic code when you don't care about static types - something that requires extra effort and a non-generic base type in .net. Any time you pass an object through a runtime polymorphic "hole" (e.g. a location of type java.lang.Object / System.Object), you lose the ability to pass along type parameters. In .net, if you don't have that abstract base class / interface, your only fallback is reflection. In Java, you've got List<?> or whatever it is.
Re:Streams in Java 8 by kelseyfrancis on Sunday February 09, 2014 @07:29PM (#7208260)
Can you clarify your comment? I don't understand how those four types could be avoided with reified generics.
Re:Streams in Java 8 by pron on Sunday February 09, 2014 @07:33PM (#7208288)
Because then you'd only have Stream<T>; IntStream would be just Stream<int>. The problem with reified generics is that they bake a particular type system into the runtime. While once a desired feature, I don't think the wide JVM community wants that any more.
Re:Streams in Java 8 by darylteo on Sunday February 09, 2014 @09:29PM (#7208732)
To be fair, I don't think this is a problem with reified generics. The problem is that primitives cannot be erased to Objects in Java. Stream<int> only works in C# because int is an alias of Int32. Not because of reified generics.

The above should no longer be an issue when/if we remove the primitive types in Java 10(?) as we can safely use Stream<Integer> and Predicate<Integer> (or Stream<int>).

Re:Streams in Java 8 by alkonaut on Monday February 10, 2014 @04:06AM (#7209910)
The runtime type erasure would have to be quite clever to realize that a ArrayList<Integer> should be backed by a primitive array of ints? One alternative is to erase ArrayList<T> into all variants (One for objects and one for each primitive type).

(In C# System.Int32 is a value type, and an "int" is equivalent). A List<Int32> is equivalent to a List<int> and is backed by an array of ints.)

Re:Streams in Java 8 by lowboy on Sunday February 09, 2014 @06:15PM (#7207896)
To answer your question, your comment is just snark that doesn't contribute to the conversation. That's probably where you went wrong.
Re:Streams in Java 8 by overgard on Sunday February 09, 2014 @06:37PM (#7208007)
You can accuse me of trolling, but I think the fact that java took this long to adopt these pretty basic features isn't besides the point, it IS the point.
Re:Streams in Java 8 by jryle70 on Sunday February 09, 2014 @07:10PM (#7208170)
Java certainly moves very slowly. I recall reading debates on how to support Lambda long before Java 7.

The reasons, IMO, are twofolds: 1) The huge install base in enterprise: changing language feature is a big deal, and like it or not, enterprises are conservative in this aspect. One only needs to look at all the garbages included with Windows in the name of backward compatibility. 2) Design by committee: Many vendors have stake in Java eco systems, all with their own agendas. To get them to agree on something take time.

In some ways, Java is victim of its own success. On the other hand, JVM is a very solid platform. Those impatient can go with Scala or Clojure. I could be snarky like you were and said Scala was light year ahead of C# in terms of feature evolving, but of course I know C# is a fantastic language which serves its users very well.

Re:Streams in Java 8 by billsix on Sunday February 09, 2014 @10:48PM (#7208993)
since when are lambdas a basic feature? since scheme in the 70s? since smalltalk-80 in 1980? since ruby in 93? since Haskell 98? since c# in 2006?

if I got in my delorean, hit 88 miles per hour, went to Sun Microsystems in the early 90's and convinced Guy Steele that yes, we should include Guy's currently 15 year old research of lexically scoped, first class functions into this new language which is designed to drag C++ programmers halfway to lisp, then java would have not been widely adopted, and this run on sentence would never have been written.

Re:Streams in Java 8 by overgard on Monday February 10, 2014 @01:42AM (#7209521)
I mean, given your first paragraph I would say: yes. To like all of those. It IS basic. So yeah. It's been a basic feature since the 70s. I guess you can give a demerit to C++ for it being the one feature they didn't steal from elsewhere, but then again you can give C++ a black eye for a lot of things.

(And still: C++ managed to get lambdas before java did. How messed up is that? Extending Java is about 10x easier than trying to add something to the crufty minefield that is the C++ spec, and they still beat them to the punch.)

Re:Streams in Java 8 by rbanffy on Monday February 10, 2014 @12:12AM (#7209275)
If we assume C++ and Lisp are local maxima, dragging C++ developers halfway to Lisp may not be the best thing to do.
Re:Streams in Java 8 by javafu2 on Sunday February 09, 2014 @06:58PM (#7208110)
In my opinion, lambdas were not introduced in Java before now because Java as already anonymous classes that are at a high level conceptually the same things even if a lambda is more lightweight syntactically and at runtime than an anonymous class
Re:Streams in Java 8 by lowboy on Sunday February 09, 2014 @09:27PM (#7208724)
Sure, but you can make that point in such a way that it encourages dialogue. A good point won't need an overly edgy delivery.
Re:Streams in Java 8 by overgard on Sunday February 09, 2014 @09:55PM (#7208830)
I could, but I don't care to.
Re:Streams in Java 8 by lowboy on Monday February 10, 2014 @02:12AM (#7209594)
Then you don't really need the crocodile tears of "Why the hate, guis?". Just set phasers to Such Edgy and blast away!
Re:Streams in Java 8 by overgard on Monday February 10, 2014 @02:24AM (#7209620)
Context doesn't always come across on the internet, but there were no crocodile tears. I actually thought it was amusing that what I thought was a relatively tame comment got such a reaction. (If anything I'm more happy getting negative votes. I get really uncomfortable when I say shit that gets upvoted to hell because it feels like I'm just shouting into the echo chamber)
Re:Streams in Java 8 by smoyer on Sunday February 09, 2014 @06:13PM (#7207879)
According to TIOBE, it looks like C# stands no chance of ever catching Java. (End of troll feeding)

What I find really interesting about your comment is that I always thought C# was the closest equivalent to Java there was, and that I'd be happy using it if I was developing in the Microsoft eco-system (I gave up on QuickBasic/VisualBasic). It would make more sense if you were sniping at a language you felt was inferior if that language was also signicantly different than Java.

P.S. I didn't downvote you either

Re:Streams in Java 8 by overgard on Sunday February 09, 2014 @06:20PM (#7207916)
Preface: I am not a microsoft fan, or even really a C# fan, but: having used both languages C# is nothing like java except in the most superficial of ways. I'm just amused that the caretakers of java took half a decade to adopt a lot of proven useful features. I wish they'd steal more.
Re:Streams in Java 8 by matthewmacleod on Sunday February 09, 2014 @07:00PM (#7208119)
C# is more similar to Java than any other language.
Re:Streams in Java 8 by overgard on Monday February 10, 2014 @01:30AM (#7209486)
(Because you said so)

(Don't worry about, you know, backing up your point or anything silly like that. That might require that you know what you're talking about.)

Re:Streams in Java 8 by matthewmacleod on Monday February 10, 2014 @03:07AM (#7209727)
Gosh, aren't you a pleasant fellow to deal with? Try to assume good faith.

I'll bite. C# is syntacticly and idiomatically more similar to Java than any other language. I'm sure how I can prove this, beyond saying "look at them!" – is there a counter example I'm missing?

Re:Streams in Java 8 by syjer on Sunday February 09, 2014 @07:03PM (#7208137)
They still need to steal the properties so we can remove the getter/setter and the local type inference from c#.

I must admit that except for this two missing features, I'm quite happy with the java 8 release in term of features.

Re:Streams in Java 8 by kelseyfrancis on Sunday February 09, 2014 @07:32PM (#7208279)
It's still just too much boilerplate to define and use immutable types. Named parameters would help a lot. Something like Scala's case classes would help even more, and along with them, some kind of pattern matching.
Re:Streams in Java 8 by EtienneK on Monday February 10, 2014 @01:22AM (#7209465)
Take a look at Project Lombok: http://projectlombok.org/

A bit hacky, but it works.

Re:Streams in Java 8 by rbanffy on Monday February 10, 2014 @12:08AM (#7209266)
Does C#/.NET have a fully supported runtime for any operating system that can delete (or rename) an open file? ;-)

Quick advice: if you have a valid point, you should state it in a form more conducive to debate. I agree with you Java has some quirks "more modern" languages don't, including C#, which started its life, more or less, as a replacement to Microsoft J++ after Sun successfully made a painful point Microsoft could not "embrace, extend and suffocate" Java just because they wanted to.

Re:Streams in Java 8 by overgard on Monday February 10, 2014 @02:47AM (#7209679)
> Does C#/.NET have a fully supported runtime for any operating system that can delete (or rename) an open file? ;-)

Yes.

Thank you for the quick advice, I'll be sure to ignore it. Because I don't care.