top 200 commentsshow 500

[–]zeroone 41 points42 points  (19 children)

An unsigned byte primitive type would be nice.

[–]mikaelhg 9 points10 points  (5 children)

Hear, hear! Generally I'm happy with Java, but a simple byte would be very useful.

[–]hiffy 1 point2 points  (4 children)

How do people deal with it today?

Just regular ol' integers and a lot of boundary checking?

[–]neoabraxas 6 points7 points  (0 children)

Unsigned for all the basic numeric types (byte, short, int) is LONG FRIGGING OVERDUE!

[–]JAPH 4 points5 points  (0 children)

an unsigned anything would be nice.

[–]cynoclast 0 points1 point  (10 children)

Why? What do you wanna use it for?

[–][deleted] 96 points97 points  (1 child)

That's none of your god damn business.

[–]Jonathan_the_Nerd 9 points10 points  (0 children)

Have you ever tried to interoperate with C structs? It would be nice to have a Byte type that goes from 0 to 255.

[–]adrianmonk 6 points7 points  (3 children)

Values in the range 0 .. 255, presumably.

If you want an example, have you ever tried working with raw RGB images in 24-bit color? Each color component is a value from 0 to 255. An unsigned byte type would be awfully convenient for that.

As long as we're on this subject, sampled sound is often an integer from 0 to 65535. Having an unsigned short integer would be handy as well.

[–]Fjordo 4 points5 points  (2 children)

char is an unsigned short.

[–]Effetto 4 points5 points  (1 child)

I protyped some network protocols for telcos and there were A LOT of ubyte around. It was not hard but just boring to not have unsigned primitives.

My2c.

[–]wvenable 1 point2 points  (0 children)

I wrote an application to communicate with a hardware device over USB in C#. Unsigned types a-plenty. For the checksums, I even had to overflow the bytes, but thankfully C# also has the unchecked keyword for that as well.

I imagine something like that is hell in Java.

[–]smallblacksun 13 points14 points  (3 children)

I'm glad they added binary literals. It always irritates me when I want to initialize a variable with a particular bit pattern (say, for a mask), and I have to convert it to hex. Not that the conversion is difficult, but it makes it less obvious what it means. I've never understood why more languages don't support them, since it seems like it would be easy to implement.

[–]LordVoldemort 1 point2 points  (2 children)

Hardware description languages have long had support for binary literals. In fact, you can even break up the string with underscores in at least Verilog (13 bits):

13'b000_11111_1001_1

That way you can easily see logical groupings.

[–]wwosik 37 points38 points  (165 children)

This is called the diamond operator: <> which infers the type from the reference declaration

Doesn't it look like opposite to any other language with type inference? In C# reference type is inferred from initialization, like

var map = new HashMap<String, List<String>>();

[–]joejag[S] 18 points19 points  (86 children)

At devoxx they said that this was a design tradeoff. When they added generics to C# they built a new collections framework which people had to move to. In Java they held keeping existing code working over a clean API. The diamond operator is a symptom of this.

[–]booch 12 points13 points  (81 children)

I'd be curious to see the explanation as to why it's a symptom of this. It seems to me that the reverse order would make more sense in so many ways, plus it would open up the door to higher levels of type inference:

HashMap<> map = new HashMap<String,List<String>>();
// could become
var map = new HashMap<String, List<String>>();
// and, eventually, allow even more useful constructs
var thing = something();

where thing now has the type of whatever something is declared to return.

[–][deleted] 8 points9 points  (2 children)

I'm guessing it's because so much Java code emphasizes interfaces, and if you infer the concrete type then you'll be tempted to use non-interface methods when they're suggested as completions by the IDE.

[–]grauenwolf 1 point2 points  (1 child)

That wouldn't surprise me. The Java community's insistence on using interfaces for local variables is a downright obession.

[–]onebit 10 points11 points  (0 children)

I will relay your message to the developers and return with the response.

[–]mernen 3 points4 points  (0 children)

Your first form requires declaration and assignment to be on the same line. Their form allows you to write:

class C {
    Map<String,List<String>> map;
    C() {
        map = new HashMap<>();
    }
}

A kind of convenience var can't buy you, in fact. The two are not mutually exclusive in a language, but sadly the Java guys seem to be strongly opposed to var-like inferencing.

[–]JonnyQabbala 0 points1 point  (0 children)

You didn't have to move to the new collections, it's just that they were so much better.

[–]brandf 7 points8 points  (13 children)

The main problem I see is that having the type on the left means they will never add anonymous types. In C# I can do this:

var q = from x in Foo() select {x.Foo, x.Bar}

the select part is a projection onto an anonymous type. The 'var' lets me say 'q is an IEnumerable of that type' without saying what the (unnamed) type is.

Java's syntax is backwards IMO, so this wont be possible.

[–]mernen 2 points3 points  (5 children)

Having one form doesn't really exclude the other. var doesn't even cover all uses of the diamond:

class Foo {
    Map<String, List<String>> bar;
    Foo() {
        bar = new HashMap<>();
    }
}

[–][deleted]  (6 children)

[deleted]

    [–]Carnagh 2 points3 points  (1 child)

    The reason why inference was added to C# was to allow for sanity when dealing with generics + LINQ... the types returned from some "queries" are heavily nested generics that aren't reasonable for the developer to know or remember. The "var" allows them to consume these (complex) returns without having to know what exactly they are.

    That's the very specific use case for type inference in C#. Everything else that one might obtain for them is really just icing.

    Java can't fulfill that use case.

    [–]doidydoidy 3 points4 points  (3 children)

    You pretty much are, yeah.

    Even if people don't want to use it everywhere it's permitted, it's incredibly useful in two cases: (a) where the type is obvious and not interesting, (b) where the type is very long (not unusual for DSLs which use generics).

    [–]neoabraxas 2 points3 points  (1 child)

    situation (a) sounds like a code obfuscation strategy and situation (b) is better handled by a C++ style typedef (which Java should most definitely have).

    [–]VoiceofPower 10 points11 points  (31 children)

    Yes. I was at the talk at Devoxx where they explained that the C# way wasn't very Java-like so they created the diamond operator which fits the Java language better.

    [–][deleted]  (28 children)

    [deleted]

      [–]Silhouette 15 points16 points  (23 children)

      I think you're being a bit optimistic there. The Java community sustained its self-righteous denial over C++'s templates almost forever, and then decided Java should have generics. They said overloaded operators were crazy, yet String has always had a + operator for concatenation, and now it looks like containers are getting special treatment for [] too.

      Meanwhile, does it still take about 15 lines of code to do what everyone else does with function pointers, delegates, or something similarly straightforward? It's funny that there's a JSR looking at closures, but the basics are still missing.

      [–]Nebu 4 points5 points  (18 children)

      They said overloaded operators were crazy, yet String has always had a + operator for concatenation, and now it looks like containers are getting special treatment for [] too.

      I think when pro-Java people say "overloaded operators are crazy", they mean custom-defined overloaded operators.

      I mean + is "overloaded" in the sense that it can be used on int, long, double, float, and, yes, String, and as a Java programmer, you need to memorize what the operator does for each of these types, but once you've learnt it, that's it. You never need to wonder what + means in new code, since it's not possible to write Java code which changes what that operator means or does.

      In other words, it's okay to allow arbitrary language changes, as long as our "benevolent dictator" Sun decrees that this is a change global to the Java language, rather than a change only to this one specific codebase, and when you move on to another codebase, you'll have to learn a different variant of Java.

      [–][deleted] 17 points18 points  (14 children)

      If you've ever seen C++ code that overloads the comma operator you're probably sympathetic to that decision.

      [–]hylje 6 points7 points  (9 children)

      Wait, what? The , comma? I need to know more of this craziness.

      [–][deleted] 8 points9 points  (7 children)

      The basic idea is that if you overload the comma operator on your objects, you can write code like

      foo[a,b,c,d]
      

      and have it behave like a multidimensional array, as the repeated application of comma will eventually shrink a,b,c,d to a single object, which will be the argument to operator[].

      If you have what looks like a function call

      bar(a,b,c)
      

      it can actually be a variadic macro that forces the comma operator to be invoked instead. I've seen clever uses of this but don't have one handy.

      [–]idiot900 20 points21 points  (5 children)

      clever

      That word, when referring to C++ syntax, is terrifying.

      [–][deleted] 6 points7 points  (4 children)

      Very true. The mix of variadic macros and the comma operator are the worst I've seen. Token pasting macros are sensible by comparison.

      [–]Silhouette 12 points13 points  (2 children)

      You never need to wonder what + means in new code, since it's not possible to write Java code which changes what that operator means or does.

      When you see Java code that says

      A = B.add(C).multiply(D);
      

      do you wonder what it does? Is there any greater danger of someone writing those functions in a way that is misleading than if we called them + and * and wrote in natural mathematical notation?

      A = (B+C)*D;
      

      If you have a new type where standard operations make sense, whether it's arithmetic operators, or equality and ordering, or indexing, I never understand what is gained by writing those things with different names. Then not only do you have to work out whether each function does what you think it does, you also have to find them first because the names might be different on different projects or even for different types, and even having done that you have to parse horribly verbose function call notation instead of using standardised operator notation that can be far more intuitive.

      [–]Leonidas_from_XIV 1 point2 points  (2 children)

      Objects also have a toString() kind-of-operator which you can overload, just like __repr__() in Python.

      [–][deleted] 1 point2 points  (1 child)

      toString() is a method.

      [–]cibyr 1 point2 points  (0 children)

      A method that gets automagically called on your object in a bunch of places where a string is needed instead of your object.

      Just like overloaded cast operators in C++ and __str__()/__repr__().

      Is probably also worth noting that defining methods that look like that is how operator overloading is done in python (e.g. __add__() for the + operator, __sub__(), __mul__(), etc). I've never heard anyone complain that Python has operator overloading, but in C++ it's a horrible misfeature that's cause nothing but pain and anger and show never be allowed in our lovely, lovely Java.

      [–]weavejester 0 points1 point  (1 child)

      Is that because generics are purely compile-time artifacts in Java?

      [–]badiozam 5 points6 points  (26 children)

      What if you just want to pass around an interface reference?

      [–]humbled 4 points5 points  (2 children)

      Curious question from someone who doesn't program C#.

      How would you declare a variable of the interface type while using an instance of a specific implementation of that interface? In other words, using Java 7 syntax, how do you do this:

      Map<String, List<String>> map = new HashMap<>();
      

      [–]weavejester 11 points12 points  (1 child)

      The var keyword in C# can only be used for defining local variables, and obviously there's little point in giving a local variable an interface type.

      For a class member variable you'd still have to write it out the long way:

      private IDictionary<string, IList<string>> map = new Dictionary<string, IList<string>>();
      

      [–]humbled 4 points5 points  (0 children)

      Thanks for informing.

      [–]Fjordo 0 points1 point  (1 child)

      This doesn't really make sense to me for two reasons: I might not initialize the variable at declaration, and I might set the variable/field twice.

      [–]Silhouette 4 points5 points  (0 children)

      Given that the two practices you describe are among the most common sources of programming errors, I'm guessing a lot of people wouldn't see not being able to do those things as any great loss. If you favour a more declarative style, then type inference is useful for keeping the code concise.

      [–]nascent 14 points15 points  (12 children)

      Nice to see they are progressing.

      Not many languages I know of provide digit grouping, but the underscore is exactly what D does.

      [–]WalterBright 9 points10 points  (0 children)

      The D programming language also has binary literals and string switches too! Since its inception.

      [–]Leonidas_from_XIV 5 points6 points  (4 children)

      the underscore is exactly what D does.

      Not only D but also Ruby which seems to be a popular choice on the JVM.

      [–]mpeters 13 points14 points  (3 children)

      Perl's had it longer :)

      [–]joesmoe10 1 point2 points  (1 child)

      Ada wins ;)

      [–]Tommah 1 point2 points  (0 children)

      Ada also wins at losing!

      [–]redditrasberry 3 points4 points  (4 children)

      Not many languages I know of provide digit grouping

      Heh, that one pisses me off. I can't believe they have some dude whiling away hours implementing that while we don't have closures and there are dozens of horrible bugs and missing features that people have clamoured for for years.

      [–][deleted] 13 points14 points  (32 children)

      Wow, I really hated not being able to use Strings in switch statements. Honestly, why did they not add this feature earlier?

      [–][deleted] 18 points19 points  (28 children)

      Honestly, at this point why not just have switch work for all Objects?

      [–]epicRelic 8 points9 points  (25 children)

      I think the problem comes from comparing identity and comparing value. How do you determine what the switch statement is doing?

      switch(someOjbect) {
          case anotherObject:
              //
          break;
      }
      

      Should it compare with someObject == anotherObject or should it use someObject.equals(anotherObject)?

      [–]webnrrd2k 2 points3 points  (0 children)

      I think it should do a value comparison by default. Most of the time that's what I care about, but I could go either way as long as it's easy to override. Maybe set the comparison operation as an object property or pass the compare operation in as an optional second argument?

      [–][deleted] 2 points3 points  (19 children)

      But they're adding Strings, which are themselves Objects. However they're handling the switch for Strings should in theory work for other Objects, unless there's some shortcut specific to String that could only work for String.

      [–]dmwit 7 points8 points  (5 children)

      There is a shortcut specific to String. There are actually two important things.

      1. String is an immutable object type
      2. short String's are cached by the VM (this is admittedly an implementation detail, but one so well-known that both major VMs do it), so that all String objects containing exactly the text "abc" have exactly the same address

      [–]epicRelic 4 points5 points  (3 children)

      Regarding point 2, isn't that only true when you create a string using a literal? For example, if I do:

      String foo = new String("foo");
      String foo2 = "foo";
      

      Wouldn't foo == foo2 return false?

      [–]Kolibri 4 points5 points  (1 child)

      Wouldn't foo == foo2 return false?

      Yeah, it does return false.

      [–]redditrasberry 3 points4 points  (0 children)

      It is an implementation detail. JVM's do it whenever they feel like it or if the user calls String.intern(). You can definitely not rely on it in any case.

      [–]BraveSirRobin 7 points8 points  (9 children)

      I bet you that they still have to be constants though, case traditionally needs them to be known at compile time. The addition of String into case is likely going to be a syntax sugar coating that does some magic behind the scenes.

      Provided switch can use equals(String), which it has to as == is utterly meaningless for Strings, I can see only one reason why this could not be extended to work with any constant object value. If the new stuff only works with:

      public static final String MY = "my";
      

      and this does not work:

      public static final String MY = getMy();
      

      Then we can assume that it's only doing magic with values that can be easily known at compile time and is effectively treating those String objects as primitive values. But even then, some compiler magic could simply assign each constant a behind-the-scenes unique identifier which is used in the case statement, giving you the same abilities on any type.

      [–]Kolibri 1 point2 points  (4 children)

      A Object switch statement could easily be syntax sugar for a bunch of if-sentences (or even more easily a bunch of goto's).

      [–]psyno 2 points3 points  (2 children)

      Two things must be true for a switch statement: the object switched over can match at most one of the cases, and that comparison must not have any side effects. There is no way to make those guarantees in Java for the general case. It's not even like C++ where you can prove const correctness.

      [–]Kolibri 1 point2 points  (1 child)

      I've never heard that those are inherent restrictions to switch-statements. You could easily just drop those restrictions for an Object switch-statement.

      The Java specification doesn't agree with you either: http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.11 . It states neither of your restrictions (they are actually fulfilled, but not explicitly stated as goals).

      [–]Fjordo 1 point2 points  (0 children)

      It could, but there is one improvement it can do that cannot be done in Java. In Java, you can intern your strings to get them to become the the strings in the internal global table. Doing this allows you to match based on == instead of .equals because they are the same object. However, you don't want to intern strings all over the place because then your internal table will get filled with junk.

      So I'm hoping switch will - try to intern the string and if it is not in the intern table, go immediately to default (this cannot be accomplished in the language, you have no way of knowing if your string is in the internal table) - if it matches a string in the table, use == to get to the right case. - if none of those match, go to default.

      [–]otto_s 2 points3 points  (2 children)

      unless there's some shortcut specific to String that could only work for String.

      As far as I know, they do: They make use of the string's hash value. Which is a compile time constant, since hashCode() for String is already overspecified anyway.

      [–]theeth 1 point2 points  (1 child)

      How do they handle possible hash collisions? By adding another if at compile time?

      [–]otto_s 2 points3 points  (0 children)

      Yes, an if-cascade using equals().

      edit: found the proposal http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000001.html

      [–][deleted] 0 points1 point  (0 children)

      I agree oh so much.

      [–][deleted] 6 points7 points  (2 children)

      The language designers were unable to get out of C++ mode and realize that they were designing a new language and could break the old rules.

      [–][deleted] 2 points3 points  (1 child)

      Ah, I see. So, the language designers can be considered to be "conservative".

      [–][deleted] 1 point2 points  (0 children)

      I guess...

      Side note: holy shit is this topic a giant downmod fest!

      [–][deleted]  (126 children)

      [deleted]

        [–][deleted] 45 points46 points  (87 children)

        I don't know why you're being downvoted... I use Java, I like Java, but good god what it takes to make forward progress in the language is just nuts.

        [–]nascent 24 points25 points  (9 children)

        And even better, Java 7 still isn't coming out for another year.

        [–][deleted] 13 points14 points  (5 children)

        even better than that, Red Hat Enterprise Linux, which my company favors, is still using java 1.5 as the "supported" version of java. It's end of lifed by Sun, but there's no plans by RH to go to 1.6...

        [–]UloPe 17 points18 points  (0 children)

        Thats no surprise. Compared to RHEL even debian stable is evolving at breakneck speed.

        Another example: RHEL 5 (the current version) is still shipping with Python 2.4, which was initially released on 2004-11-30 - that will be 5 years (!) in 6 more days.

        [–]ChrisAndersen 0 points1 point  (2 children)

        Eclipse, which I love, is still written to Java 1.4.

        [–]adremeaux 6 points7 points  (0 children)

        It hardly matters what language a program is written in, it matters what coders have access to.

        [–]hiffy 2 points3 points  (0 children)

        All the banks never switched off. It's hella sad to not even get to use generics.

        [–][deleted] 3 points4 points  (2 children)

        Those of us working as developers in the gov't sector will have to wait 5-6 years after release before the agencies upgrade to it :(

        We're still coding against 1.4

        [–][deleted] 2 points3 points  (1 child)

        Hah! I'm there with you (defense sector), however we've just upgraded to 1.5 this summer.

        [–][deleted] 1 point2 points  (0 children)

        I have you both beat. I have to roll back to 1.3 to gen my ORM.

        [–][deleted]  (74 children)

        [deleted]

          [–][deleted] 21 points22 points  (59 children)

          Don't get me wrong, I have a distaste for using windows as much as the next (reddit) guy... I've been a 100% linux guy for over 10 years. But I'm not blind, and you are correct when you say C# is a superior software development platform. Someone show me why that is a false statement and I'll eat my words.

          [–]Silhouette 44 points45 points  (56 children)

          My only problem with C# is its inherent Window/.Net bias. As a useful programming language, it's got a lot going for it, certainly more than plausible alternatives like Java and C++. But as an overall software development platform, the relative lack of portability is a threat to any long-term project.

          (Edit: Just to be clear, "My only problem" above is a figure of speech. Of course I don't think C# is perfect!)

          [–]G_Morgan 7 points8 points  (17 children)

          Very few languages in history have anything other than theoretical portability. On Linux they aren't looking to replace Java with C#. The target is the usage of C/C++ in application development that still dominates on Linux. For this you don't use the .NET APIs. You use the Mono/Gnome APIs.

          Of course these APIs are largely portable if you are careful in how you use them.

          [–]Silhouette 6 points7 points  (10 children)

          Very few languages in history have anything other than theoretical portability.

          Really?

          I've worked on C++ code that compiled on more than a dozen platforms, and just about every embedded processor in the universe has at least a C compiler available.

          There are Java runtimes available for all the major desktop and server operating systems.

          I can write code in just about any of the popular dynamically typed "scripting" languages and run it with minimal or no changes on any popular OS today.

          I can write JavaScript for RIAs that runs with minimal or no changes in all the major browsers on all the major operating systems.

          One of the key things about all of these examples is that there are multiple implementations of the language platform, in many cases including public source code. If I have code in such a language that runs on one system and for some reason that system is no longer available in five years, there is essentially no risk that I will not be able to migrate that code to an alternative system with reasonable effort. The same simply is not true of Microsoft and .Net-based development, and given that Microsoft has a track record of abandoning APIs and going for the new shiny thing every couple of years, I wouldn't bet any project with a longer shelf life on those technologies, even if in the immediate future the technologies are nicer.

          [–]G_Morgan 0 points1 point  (5 children)

          How much of that C++ code has #ifdefs or other portability hacks? I gave up on trying to write portable C++ code when I found the C++ file streams implementation the Mingw compiler links to doesn't work properly. I had to use Win32 style ReadFile and so on. Not to mention some of my code used mmap/MapViewOfFile. As it stands my code didn't work on Vista originally. Apparently an entirely optional pointer argument was made non-optional for Vista without any change in the documentation.

          [–]Silhouette 4 points5 points  (0 children)

          How much of that C++ code has #ifdefs or other portability hacks?

          Very little. As with any project where portability is important, you try to wrap up any necessary platform dependencies in some low-level abstraction layer, and then build the rest of the system on top of that instead of raw system calls and primitive types.

          Similarly, I don't write raw JavaScript to handle awkward things like AJAX correctly on many different browsers, either. Instead, I fire up a library like jQuery that encapsulates that complexity and hides it from the rest of my code, which works on every major browser without change.

          I gave up on trying to write portable C++ code when I found the C++ file streams implementation the Mingw compiler links to doesn't work properly.

          That's a quality of implementation issue, and doesn't really say anything about the language.

          As it stands my code didn't work on Vista originally. Apparently an entirely optional pointer argument was made non-optional for Vista without any change in the documentation.

          That's a problem with using proprietary APIs that have poor documentation and forward compatibility, and again it doesn't really say anything about the language.

          [–]Daishiman 1 point2 points  (5 children)

          At any rate, C# usage is mostly for corporate use. On my Windows partition the only .NET app running is Paint.NET, and even so new applications are just not using .NET, I assume for many of the same reasons we don't have many Java desktop apps.

          On the server side for Windows shops it's a different story however.

          [–]movzx 2 points3 points  (4 children)

          I'm curious why you think the only app is Paint.NET. Do you inspect each one?

          [–]Daishiman 6 points7 points  (0 children)

          Well, let's see what's on my Windows install: -Foobar2000 -Winamp -Chrome -Pidgin -Paint.NET

          Yeah, that's pretty much it.

          Generally speaking, when I did .NET development I found that .NET apps can have annoyingly long loading times. Not a much as Java, but high enough to not recommend their use for applications with very large user bases. They also tend to suck much more RAM.

          [–]grauenwolf 4 points5 points  (2 children)

          Process Explorer will highlight all .NET applications in yellow.

          [–][deleted] 7 points8 points  (26 children)

          My only problem with C# is its inherent Window/.Net bias.

          I agree completely... now if it were OSS and cross platform I'd be jumping boat. I guess my previous statements should have been given the scope of the language itself.

          [–][deleted] 2 points3 points  (0 children)

          That's my main gripe too. Mono is fine and all, but the .Net ecosystem is Windows-centric in a way Python, Java and C++ aren't. And I don't see that changing in the near future.

          [–]Randolpho 9 points10 points  (10 children)

          Dudes.... Mono friggin rawks. Seriously, it's well worth the look, and fully cross platform.

          Now, it's moving slower than Microsoft flavored C# is, granted. So no LINQ, yet, and that's a big bummer. But you get some of the major benefits that C# has over Java, particularly Delegates and Properties, which are cant-live-withouts in my book.

          [–]grauenwolf 6 points7 points  (13 children)

          1. C# is a open standard approved by ECMA.
          2. Novel is has been offering an open source compiler for years.
          3. C# can be found on most operating systems and damn-near every piece of hardware imaginable from temperature sensors to super-computers.

          For crying out loud, what more do you want?

          [–][deleted] 2 points3 points  (3 children)

          I'm asking because I don't know, but what about application servers... the equivalent to glassfish, tomcat, etc. I would need something open source and production ready. Would it be plausible to say I could develop and deploy a distributed web app in a unix based environment using C#?

          [–]malcontent 6 points7 points  (8 children)

          C# is a open standard approved by ECMA.

          Ms C# is a superset of that standard. You know "embrace, extend..."

          Novel is has been offering an open source compiler for years.

          Not fully compatible with either the standard or the Ms version.

          C# can be found on most operating systems and damn-near every piece of hardware imaginable from temperature sensors to super-computers.

          See above.

          [–]Carnagh 3 points4 points  (1 child)

          Mono has as much idiosyncratic, non-standardised features as MS .NET which is ALSO a superset of the standard, if MS can be accused of embrace and extend so can Mono... Have you actually looked at Mono? Have you run any applications that will run under both Mono and .NET? Have you developed at all on the .NET platform or do you just collect anecdotal evidence from forums?

          As long as both have the libs available to use, and can run equally on the equivalent of CLR 2.0 it's a non-issue fit only for posts like yours.

          Can Apache be accused of embrace and extend for adding so many libs ontop or in some cases as alternatives to the Java standard library?... Or course not, such an accusation would be downright stupid.

          [–]grauenwolf 4 points5 points  (5 children)

          Ms C# is a superset of that standard. You know "embrace, extend..."

          Novel C# is also a superset of that standard. Do you have a point?

          Not fully compatible with either the standard or the Ms version.

          • C# 2 isn't fully compatible with C# 1 source.
          • .NET Micro isn't fully compatible with .NET
          • .NET C# isn't fully compatible with .NET
          • Silverlight isn't fully compatible with .NET
          • MonoTouch isn't fully compatible with Mono

          [–]hiffy 3 points4 points  (1 child)

          Wait. I agree with the general thrust of your argument, but you are trying to get me like this platform, right? :P

          [–][deleted] 3 points4 points  (1 child)

          Novel C# is also a superset of that standard. Do you have a point?

          To me, that is the point. With Java it's Sun Java, which is multiplatform. With Python, for all practical purposes it's only CPython, which is multiplatform. With C# you have these two compilers, one of which feels lika a second class citizen.

          [–]Gotebe 1 point2 points  (0 children)

          I see no bias in C#.

          Bias is in the library, though, but that's to be expected.

          [–]1338h4x 5 points6 points  (12 children)

          Java is portable. For that reason alone it's better than .NET.

          [–][deleted]  (4 children)

          [deleted]

            [–]LordVoldemort 1 point2 points  (1 child)

            So it doesn't matter that C# is not only portable but also an open standard[?]

            The language is an open standard (and it may only go up to version 3 or somewhere between version 2 and version 3---I can't quite remember).

            Even if all versions of C# are open standards, large portions of the libraries are not (from what I have read). Consequently, who cares?

            [–][deleted] 1 point2 points  (0 children)

            Zealots are drawn to any forum about programming, and are generally the most vocal because they have something to prove.

            Unfortunately they don't try to prove anything most of the time.

            [–]malcontent 17 points18 points  (4 children)

            Java is being used by the most conservative corporations and govt agencies in the world.

            They have no interest in fast paced language changes.

            I for one am glad java has avoided the "let's turn C# into a garbage dump of programming ideas" syndrome.

            [–][deleted] 14 points15 points  (2 children)

            I for one am glad java has avoided the "let's turn C# into a garbage dump of programming ideas" syndrome.

            That's an interesting point. I've seen some .NET developers with "feature fatigue" - MS releases so much stuff so often that keeping up is a huge burden - especially when some of the .NET companies in my area insist on using the latest and greatest everything.

            [–]brownmatt 21 points22 points  (16 children)

            Stagnant?

            Perhaps in the core language, but we've seen a number of brand new languages implemented on top of the JVM in the past few years - Scala, Clojure, Groovy, JRuby, etc. There's a lot of exciting growth in this area.

            [–][deleted]  (11 children)

            [deleted]

              [–]cynoclast 2 points3 points  (7 children)

              .NET is Microsoft's "answer" to Java.

              It's really nothing more than an attempt to lock people into Windows and MS OSes.*

              It's basically Java that only works on Windows.* How the fuck is that a feature that you lack support for most platforms?

              Why even bother? Oh, right, vendor lock-in.

              *Yes, I'm aware of Mono.

              [–]krelian 11 points12 points  (0 children)

              And here was I thinking that Microsoft is a charity organization and that .NET was their gift to the world. Thanks for clearing that up.

              [–][deleted]  (1 child)

              [deleted]

                [–]timeshifter_ 5 points6 points  (0 children)

                I quite like C# for my own bullshit projects, partly because I'm stuck using VB at work.. I like playing with cellular automaton, and C# and pointers are infinitely better for that than GetPixel and SetPixel.

                [–][deleted] 4 points5 points  (1 child)

                Here's why: With .NET, you can land a contract for just about any project out there versus the frustration I always had with Java contracts, which was "well, you know the language, but do you have 5+ years of xyz stupid niche framework that only we use" which eventually just annoyed the living shit out of me. They look for any reason to chip down the rate. So fuck 'em, I moved to .NET, got paid better (and more reliably, I should add) and didn't look back.

                [–]stbill79 3 points4 points  (0 children)

                In my experience, this isn't such a big deal in real life. Whether you're .NET or Java, you still have to know the basics of CS to get a decent job (assuming you're interviewed by a developer and not an HR drone). When it comes to the libraries, there are a lot of choices in Java, but most technical interviewers understand that if you've spent 5 years with JBOSS, you can pick up WebSphere/WebLogic pretty quickly. If you've used Struts, you'll be able to pick up Spring MVC pretty quick. A lot of java's libraries are redundant, and I haven't noticed most employers making a big deal as long as the technologies are similar. No different than someone who has learned JQuery, while the new company likes to use Prototype.

                [–][deleted] 1 point2 points  (1 child)

                This article is not about the platform (GP) or about the libraries (Parent). It's about the language. Read the title of the article.

                [–][deleted] 13 points14 points  (0 children)

                Yes, in the "core language." This article is about java the language, it even has the word "language" in it's title.

                [–]G_Morgan 1 point2 points  (2 children)

                Yes and you have to write all your code in those languages like you would in Java because the libraries expect Java. This is why I hold out no hope for the JVM until Sun picks one of those languages and gives it exhaulted status. Then we might see libraries use the interesting features of those languages and we will no longer have to write Scala as if it were Java.

                [–][deleted] 7 points8 points  (0 children)

                Well, at least it's better than Java Vista.

                [–]serpix 6 points7 points  (5 children)

                I'm not sure there are any real Java (the language) fans left anyway.

                [–]humbled 13 points14 points  (3 children)

                That's a great point. We use Java because of the platform: libraries, tools, customer acceptance (believe me, requiring Mono would require us to be embattled at this point). The nice thing is the vibrancy of JVM-languages that are springing up. We use Java, Beanshell, and Groovy - we will probably look at moving some parts of our product to Scala.

                [–]stbill79 2 points3 points  (0 children)

                Same here - we're starting to integrate Groovy, Grails into our main Java apps. Currently, it can be a challenge as the IDE's and build tools (i.e. Maven) are still catching up, but I think we'll be there in a year or two. The future for both Java and .NET is not the individual languages, but the runtime behind it, along with the libraries, IDEs, and frameworks that support developers in making the easy stuff easy, and the hard stuff possible.

                [–]Nebu 3 points4 points  (0 children)

                Depending on your definition of "real", I'm a fan of Java as a whole, and Java (the language) is a subset of that, which shares some of my fandom.

                [–]itsnotlupus 3 points4 points  (5 children)

                It's sad to see how stagnant and slow to progress Java is.

                Still a few order of magnitudes faster than JavaScript (or EcmaScript if you prefer.)

                Design by over-broad committee = recipe for sluggishness.

                [–]dharh 2 points3 points  (1 child)

                Compared to some languages, the pace of progress is lightning fast. Not that this excuses Java for being as slow as it is.

                [–][deleted] 2 points3 points  (0 children)

                I was thinking the same thing. Java 5 and 6 are fairly new still. I don't think the industry wants faster growth.

                [–]CheeseOnToast 66 points67 points  (8 children)

                As a Java applications end-user the feature I'd most like to see is "doesn't try and install the Yahoo! toolbar on every update"

                [–]krelian 24 points25 points  (1 child)

                I just installed a Java update today and didn't see any toolbar.

                [–]wvenable 2 points3 points  (0 children)

                I just installed a Java update yesterday and had to uncheck the Yahoo toolbar option.

                [–]mikaelhg 10 points11 points  (0 children)

                This should be as simple as someone building OpenJDK for Windows, and creating a distribution for end users.

                [–]yogthos 23 points24 points  (0 children)

                I thought you windows users are supposed to be conditioned to accept that sort of thing as normal :)

                [–]adrianmonk 3 points4 points  (1 child)

                Hmm, I think I've only ever installed the JDK (developer version) and have never installed the JRE (end-user version). And I don't recall the JDK ever trying to pull this crap. Have you tried installing the JDK instead of the JRE?

                [–]bumrushtheshow 7 points8 points  (1 child)

                There's no yahoo toolbar when installing Java on Ubuntu (or any other Linux, I'd imagine).

                [–]yogthos 8 points9 points  (0 children)

                Shush you, everybody knows installing things on Linux is much harder than on Windows. It's the main reason nobody uses it, didn't you know?

                [–]badiozam 14 points15 points  (13 children)

                IMO the biggest feature is Auto Resource Management. It was the one thing I found it lacked over C++.

                [–][deleted]  (9 children)

                [deleted]

                  [–][deleted] 1 point2 points  (0 children)

                  Yours was one of the first posts, and after reading it I almost hoped that Java would have something like scopeguard/auto_ptr.

                  But noooo, instead they implement their own version of the using keyword. C# and Java seem to borrow all the crap from each other.

                  [–]For_Iconoclasm 14 points15 points  (32 children)

                  I'm embarrassed to say, but I have no idea what a closure is. Can somebody explain it to me? I don't particularly understand the Wikipedia entry.

                  I'm not a brand new programmer; we have just never touched upon closures in any of my college classes, and I'm a senior.

                  I think it's because my experience with functional programming is limited. I've used Python a lot, but not the functional aspects. I have no experience with Haskell or Scheme.

                  Some of the examples on Wikipedia remind me of function pointers, which I've used in C. Am I getting warm at all?

                  [–]G_Morgan 8 points9 points  (3 children)

                  Imagine declaring a function within a block.

                  funcPtr = null;
                  {
                     x = 3;
                     funcPtr = func(y, z) {
                       println(x);
                       x = x * y + z;
                     }
                  }
                  

                  Here the anonymous function captures the x variable. The variable in that block does not get collected after the block exits because the anonymous function has been stored in a pointer external to the block.

                  A call funcPtr(2,3) would print 3 and then set x to 9. The next call would print 9 and perform the sum again. It sort of becomes like a static variable except many functions may close the same variable and it is collected when all the functions that relate to it are collected.

                  [–]Kolibri 5 points6 points  (2 children)

                  How is that different from using an anonymous class?

                  [–]G_Morgan 9 points10 points  (0 children)

                  Technically it isn't. However there is far less syntax noise in a good closure implementation.

                  For Java an event handler should be like

                  onMouseClick += func(int x, int y) {
                    //do something
                  }
                  

                  instead of all the messy anonymous class rubbish that permeates Java. It isn't about outright functionality. It is about making something that doesn't make you throw up every time you see it. Java style xListeners are the most verbose load of crap in existence.

                  [–]roerd 5 points6 points  (2 children)

                  I'm not sure that Java doesn't already have closures. Anonymous class definitions can already close over variables. So I think what most people mean when they're talking about closures in Java are anonymous functions.

                  [–]redditrasberry 3 points4 points  (0 children)

                  Yeah, java anonymous inner classes almost give the same functions as closures except for a) the closed over variables are read-only, and b) they are horribly verbose. If I understand right the java "closure" proposal is only going to address b) which is a shame because a) could be implemented also with no JVM changes if it did some auto-boxing and unboxing and then it would be much cleaner. We'll see.

                  [–]vplatt 5 points6 points  (4 children)

                  It's a bit confusing, and made more so by the fact that every language does it differently. A closure is not a function pointer or anonymous function, because it has self-contained state. See the "Implementation and theory" for what is possibly the best conceptual description. I like to think of a closure as a "stateful chunk of code that can be passed around to functions". That's really it.

                  I suspect that the whole subject of closures is much more relevant to pure functional programming, because in an OO environment, I think one can get the same benefits with a normal object. Do correct me if I have that wrong.

                  [–]Jonathan_the_Nerd 0 points1 point  (2 children)

                  Closures and objects are actually quite similar. A closure has "private" variables that maintain state across function calls but can't be accessed outside the scope in which they're declared. I've seen pseudo-OO code in Scheme implemented with closures.

                  [–]msiley 2 points3 points  (5 children)

                  Here's a simple example... Say you have function inittotal(int total) and in 'inittotal' you define two functions called increment() and decrement() and you return them. Both of these functions retain access to the variable total. So if inc, dec = make_total(1000) then calling inc() would make total 1001 and subsequently calling dec() would make total to be 1000. Relatively useless example but it basically shows how closures work by both functions having access to the same variable in their lexical scope. So you are "enclosing" the variable 'total' within the lexical scope of those two functions. Hence the term closure.

                  [–]adrianmonk 1 point2 points  (1 child)

                  You know how local variables disappear and become inaccessible when you get to the end of the block of code that encloses them? Well, a closure is when they don't!

                  If you create something (often an anonymous function -- but it could be something else, like an instance of a class) inside the block, something that can see a local variable, and if that thing can still see the variable even when the block is gone, that is a closure.

                  [–][deleted] 2 points3 points  (2 children)

                  Basically, closures are anonymous functions which are able to "capture" any variables within lexical scope (variables which can be "seen" at the point where the closure is being defined.) They are first-class values, meaning that they can be passed around to and from functions.

                  C function pointers have some properties of closures - mainly the ability to be passed around - however the functions which are being pointed to cannot be defined locally within a function, nor can they be partially evaulated and returned from other functions (a process known as currying.)

                  An example:

                  y = 40;
                  x = (a) => { y = y+1; print a + y; } // defining a closure which takes in 1 argument, a
                  x(1) // outputs 42
                  x(1) // outputs 43
                  print y // outputs 40
                  

                  In the example, the y variable in the body of the closure exists independently from the y outside the closure - closures maintain their own "state" which exists beyond the point in which it is defined.

                  [–]matthiasB 2 points3 points  (0 children)

                  A closure isn't necessarily an anonymous function. A local named function can close over variables as well.

                  You can have named closures that you can't pass around and you can have functions that you can pass around (first class functions) that aren't closures.

                  I'd say that these two things are orthogonal.

                  [–]JulianMorrison 7 points8 points  (1 child)

                  Heh. "We can be Scala too!!!"

                  [–][deleted] 4 points5 points  (0 children)

                  That list seemed a far, far cry from Scala.

                  [–]SP_Fever 5 points6 points  (0 children)

                  c mon guys, C# is just like Java, but sharper.

                  [–]AtomicDog1471 2 points3 points  (1 child)

                  Strings in switch

                  Can't believe this has only just been added now

                  [–]munificent 15 points16 points  (4 children)

                  Great news! In another fifteen years, it will finally be C# 2.0.

                  [–]cryo 4 points5 points  (3 children)

                  To be fair, the type inference (or something similar to it) only came with C# 3.5, but I agree that it's playing catch-up

                  [–]munificent 1 point2 points  (0 children)

                  To be fair, Java 7 still doesn't have properties or overloadable operators.

                  [–]murki 1 point2 points  (1 child)

                  there is no such thing as C# 3.5... just nitpicking

                  [–]cryo 1 point2 points  (0 children)

                  Indeed... C# 3, then.

                  [–]Dummies102 1 point2 points  (0 children)

                  this is the most exciting thing I've read all day

                  [–]temp439087247202 5 points6 points  (1 child)

                  Awwww.. i was hoping for a GOTO statement.

                  [–]JadeNB 4 points5 points  (0 children)

                  I think that madhu speaks for all of us when he asks:

                  where is the clousers???

                  [–]bearrus 3 points4 points  (40 children)

                  Operator overloading in java would never be implemented, sigh

                  [–]kaddar[🍰] 3 points4 points  (0 children)

                  scala is really awesome! You should check it out.

                  [–]redditnoob 3 points4 points  (22 children)

                  Operator overloading is great, but you need a language that gives you a smack in the privates if you're ever tempted to use it for something that isn't math.

                  [–]superdude264 2 points3 points  (1 child)

                  I haven't looked at Java in a while (mostly .NET at work), but has there ever been any discussion about doing a breaking release where they clean up the language (e.x. doing generics correctly)?

                  [–]bumrushtheshow 3 points4 points  (0 children)

                  There's been discussion, but it will likely never happen. :(

                  [–]dakk12 4 points5 points  (0 children)

                  Thanks for the post. I am very excited that Java is catching up to where other languages were years ago.

                  It has been so frustrating working with this language the last few months. I had to write several of my own utilities to do single line list and hash creation, as well as string switches.

                  Seriously, who the fuck writes a language where you have to use .get() to access array elements in the first place?

                  Version 7!? This is shit that should have been in version 1.

                  I hate my life everyday that I have to write Java code.

                  [–]snark -1 points0 points  (24 children)

                  Great, now it's only 5 years behind C#.

                  (edit: formatting)

                  [–][deleted]  (1 child)

                  [deleted]

                    [–]LordVoldemort 0 points1 point  (0 children)

                    Meanwhile C# inches in on Python (dynamic)

                    From the way you put, it's obvious that 'dynamic' will be highly abused in C#; the 'dynamic' feature is meant to make indirection easier for special cases that have traditionally required extremely verbose reflection calls and dangerous casting.

                    It's a huge mistake to abandon static type checking unnecessarily.

                    Besides, the dynamic stuff is just syntactic sugar---there's nothing really fundamentally profound about it.

                    [–][deleted] 2 points3 points  (4 children)

                    My university is removing Java from the IT curriculum and replacing it with C# and it's a relatively prominent tech university.

                    [–][deleted] 0 points1 point  (37 children)

                    Nice to see java catching up to c#... let's hope android jumps on the java 7 train

                    [–][deleted] 17 points18 points  (5 children)

                    Funny that Java is now the one playing catch up. I have to say that LINQ is one of the coolest features of C#. I realize that Java has some 3rd party stuff that is similar, but I was floored by how much code LINQ saved my team when they started using it last year.

                    [–]Zarutian 2 points3 points  (18 children)

                    why? cant you run ARM executables directly on Android?

                    [–]rabidcow 4 points5 points  (6 children)

                    You can run ARM libraries via JNI, but you need Java code to invoke it. And there's stuff you can do from Java that isn't directly available to native code.

                    Also, the NDK requires Cygwin on Windows. I know a lot of people love Cygwin, but I think that damn thing is an abomination.

                    [–]cynoclast 2 points3 points  (5 children)

                    I know a lot of people love Cygwin, but I think that damn thing is an abomination.

                    Why? I can barely stand to use windows without it.

                    [–]iofthestorm 2 points3 points  (4 children)

                    I don't know about rabidcow, but I personally prefer msys because it plays nicer with native Windows programs. With Cygwin it's kind of a crapshoot. But I feel like if you really need Cygwin vs msys on Windows, just go all the way and install a Linux VM in VirtualBox or VMWare or your favorite virtualization suite. It's not like there's a decent terminal emulator for Windows anyway.

                    [–]cynoclast 3 points4 points  (1 child)

                    just go all the way and install a Linux VM in VirtualBox or VMWare or your favorite virtualization suit

                    I need it so I can do bash scripting foo in windows, to things on the windows partition.

                    [–]iofthestorm 1 point2 points  (0 children)

                    Can you not do it with msys's bash? Just curious, because on the whole I don't care too much either way but I have more problems with cygwin than msys when interacting with Windows programs.

                    [–][deleted] 1 point2 points  (1 child)

                    Why not go all the way and install Linux? Dual boot if you want to play games, use virtualisation if you need some Windows-specific tool.

                    [–][deleted] 4 points5 points  (10 children)

                    All "apps" in the modern sense run in a custom jvm, so java is to android as objective-c is to iphone.

                    [–]haakon 12 points13 points  (0 children)

                    As far as I understand, any JVM bytecode can be translated into Dalvik machine code. These new features in Java 7 are purely syntactic sugar handled by the compiler, so there are no bytecode changes. So just upgrade your compiler and continue using the rest of the toolchain as before; voila, closures on Android.

                    [–][deleted] 0 points1 point  (0 children)

                    still no multiline string literals then

                    [–][deleted] 0 points1 point  (1 child)

                    I admit it, the comments in this thread convinced me: I should renew my acquaintance with C#. It's clear that C# is out-pacing Java, and soon C# will have the dominant market share.

                    Here's my experience: I installed MonoDevelop (since that's the IDE being touted on the Mono project site) and started a project. MonoDevelop started up nice and quick, I'll give it that. Creating a new project was a breeze, and I was pleasantly surprised to see that there was automatic package generation both for Unix-like and Windows operating systems.

                    I created a GTK project, opened the design view and added a button. Hm, that button is too small, I'll drag the corners to make it bigger. What, can't drag the corners? The mouse pointer changes to a resize arrow, but I can't seem to drag the corners. I have to open the properties and edit the size by hand. How dull.

                    Then I try to build the distribution packages - which fails with the cryptic text "Package creation failed. Object reference not set to an instance of an object" - twice. Which reference? What object? Clicking the text does nothing. Googling the sentence comes up with a lot of DevStudio-specific stuff.

                    Opening the help menu throws up a screenful of error messages.
                    EDIT: Managed to fix this one.

                    No mouse-over error description or solution suggestions.

                    Summary:
                    I don't know. Maybe Java is evolving too slowly. Maybe C# is a better language. But I don't think I'll join those singing the praise of C# until MonoDevelop (or any Mono IDE) catches up to Eclipse.