Slashdot Mirror


Summary of JDK1.5 Language Changes

An anonymous reader writes "Over at java.sun.com, there's an informative article about the new features in JDK1.5. Some of the changes like generics are nice and should make some things easier. Some of the enhancements to me are purely sugar, like enumerators. When it comes down to it, once the code is compiled, it's the same. The thing I hope is, some of this new syntactic sugar doesn't result in more obfuscated code. Unlike some people, I feel using programming shorthand leads to increased maintenance. This is especially true when you have to debug a complex application."

829 comments

  1. enumerators by billnapier · · Score: 4, Insightful

    enumerators are much better than just plain ints. Even though they may compile to the same thing, the compiler can do a little more checking on the enumerators, since it know the valid ranges for the enumerator so you don't have to explicitly check the range. You do check to make sure you get passed a valid value for all your int-as-enumerators? Don't you?

    1. Re:enumerators by Anonymous Coward · · Score: 0

      Considering Java's performance, I wouldn't bet against those enumerators staying as actual objects with an Integer object for a count.

    2. Re:enumerators by Anonymous Coward · · Score: 2, Insightful

      It's preference right. Forcing some one to explicitly check isn't necessarily a bad thing. Iterators get too much flack, but it does change the programmers mindset. I would prefer programmers think carefully about what they are doing and not rely mainly on convienance, because when a bug does appear, it is harder to debug. But it all goes back to good programmers. bad programmers will make any language a nightmare.

    3. Re:enumerators by MilesParker · · Score: 2, Insightful

      Ya, its funny, enumerators were always one of the first things to gome up when people were griping, and has been the source of a lot of discussion re: workarounds. IIRC, Gosling wanted this in from the beginning, but they ran out of time..

    4. Re:enumerators by SpanishInquisition · · Score: 1

      You sound like an 80's Ada Manual

      --
      Je t'aime Stéphanie
    5. Re:enumerators by customiser · · Score: 4, Informative

      It's good to see enumerators formally supported, but you were not really _forced_ to use plain ints up to now. It is just some sort of an anti-pattern, which everybody seems to be using happily.

      The type-safe enum pattern shows the correct way of handling enumerations. And you can the Jakarta Commons Lang library to make it a bit easier.

    6. Re:enumerators by iabervon · · Score: 4, Interesting

      They're actually objects (you can put them in collections, for instance), they can have fields, methods, and constructors, etc. It's just that the compiler takes care of creating the instances and all, plus you can use them in swtch statements because the compiler knows they're enumerated.

      Evil thought: you could get relatively nice-looking static instances with methods if you combined enums with anonymous inner classes...

    7. Re:enumerators by bluetea · · Score: 1


      The type-safe enum pattern shows the correct way of handling enumerations. And you can the Jakarta Commons Lang library [apache.org] to make it a bit easier.


      The typesafe enum idiom is broken. It looks pretty but it's not a substitute for real first-class enumerators. In many cases it is actually worse than using plain ints as it can lead to very subtle bugs.

      This article discusses some of the problems with it.

    8. Re:enumerators by ProfKyne · · Score: 5, Interesting

      I don't use ints for my enumerations anymore after reading Josh Bloch's Effective Java. The type-safe enum pattern he recommends is fantastic.

      For those not sure exactly how it works, you simply create a class to represent an instance of the enum, and you make the constructor private so that no one can create their own instances. Then you just provide a public static instance of the class for each enum.

      I used this pattern simply to achieve its intended effect of providing an enumeration, and then later found that by adding methods to the class, I could even give behaviors to the enumeration instances! Try doing that with an int. This was far more elegant than creating a giant "if" statement and performing conditional logic to test the value of the enumeration, because I simply used a polymorphic method call.

      An example:

      public class SenseEnumeration {
      // the action associated with this enumeration
      private java.lang.reflect.Method sense;

      private SenseEnumeration(Method m) {
      this.sense= m;
      }

      // assuming we've already created some
      // Method instances to use here
      public static SenseEnumeration TASTE
      = new SenseEnumeration(myTasteMethod);
      public static SenseEnumeration HEAR
      = new SenseEnumeration(myHearMethod);
      public static SenseEnumeration SMELL
      = new SenseEnumeration(mySmellMethod);

      ...etc...

      public Method getSenseMethod() { return this.sense; }
      public void invokeSenseMethod(Object target) {
      sense.invoke(target, null);
      }
      }

      You get the main idea. No, not as fast as an int, but far more powerful.

      --
      "First you gotta do the truffle shuffle."
    9. Re:enumerators by slagdogg · · Score: 4, Interesting

      This is a fine alternative ... but cumbersome, and indeed once you add the toString() methods and other such niceties, it's approaching messy. The fact that a single statement now can offer all of these features is outstanding.

      It's nice to see Java stealing something from C# for once ;)

      --
      (Score:-1, Wrong)
    10. Re:enumerators by etedronai · · Score: 2

      It seems a little bit evil that the compiler is creating object instances under the covers for you. One of the great things about c++ enums is that they are still primitives. By making them objects you have to worry about the compiler creating a lot of extra objects behind your back especially in tight highly used loops. Java is already a bit of "magic" language anyway but adding in "magical" object creation where you don't expect it doesn't seem like a good thing in all situations.

    11. Re:enumerators by revscat · · Score: 4, Insightful

      The article makes no claim about the typesafe enum pattern being broken, it just points out that you have to be careful if you use it and implement Serialzable. This is something that Bloch specifically addresses in Effective Java, and does not mean that the entire pattern should be scrapped. You just have to be aware of potential problems.

    12. Re:enumerators by Zeinfeld · · Score: 1
      It's nice to see Java stealing something from C# for once ;)

      Actually they also stole the dotNET concept of metadata. This is much bigger news than the enumerator which is merely syntactic sugar. Metadata is a major advance if you know how to use it.

      Hopefully C# will quickly steal the Java concept of what we used to call functional types, so you have List (Foo) is a list of objects of type foo.

      I don't like that being made mandatory on introduction as the article seems to suggest though, I would prefer that the default is the bottom type so old stuff compiles and then have a compiler warning. Otherwise switching from an new compiler back to an old one is not possible. Someone please tell me that it is not so!

      I would hope that dotNET causes Java to advance and vice versa. Lots of us tried to get Gosling and co to do this sort of stuff back when Java launched but they were not willing to give anyone time of day. So we had to go bug the Microsoft folk instead. BTW the metadata concept is not new to dotNET, there was a similar concept in the Lisp Machine.

      --
      Looking for an Information Security student project suggestion?
      Try http://dotcrimeManifesto.com/
    13. Re:enumerators by Anonymous Coward · · Score: 0

      enums were invented in c# now, really? this is mighty interesting.

    14. Re:enumerators by liloldme · · Score: 1

      I don't want more primitives in the language. I wish they'd get rid of even the existing ones.

    15. Re:enumerators by billnapier · · Score: 3, Funny

      That's what we've been using but my fingers get tired from typing all that extra crap in...

    16. Re:enumerators by Anonymous Coward · · Score: 0

      enumerators are much worse than just plain ints. They don't compile to the same thing, and the compiiler doesn't do any more checking on the enumerators, because it doesn't know the valid ranges for the enumerators. It has to look up the enumerator in a symbol table which is created at compile time. So it has to perform a run time check on the symbol type (probably only a second int) anyway. The whole point of a switch statement is speed.

      With java enumerators, now, instead of a single efficient switch algorithm, the has to break it down into a series of if statements and individual equality comparisons, and then copy the result from the symbol table to your integer.

      There are probably some caching tricks to help speed this up, but it's also probably not in the spec (nor should it be; you should specify functionality, not implementation, but here java (JDO) has failed too.) For all I know, the jvm is doing string comparisons in my switch statement, which is what I wanted to avoid by using an Enum in the first place.

      ps. That symbol table is taking up memory too. If I have 100 Enumerated values, that's at least 200 extra bytes, on top of all my Enumerator instances, unless they waste more CPU comparing equivalent enums packed into the same register.

      All you really need to do to avoid the 'problems' this fixes is to use the magic 'namespace' character in your integer enums already reserved in java: The underscore '_'

    17. Re:enumerators by Anonymous Coward · · Score: 0
      there was a similar concept in the Lisp Machine

      MOP?

    18. Re:enumerators by Anonymous Coward · · Score: 0

      um... you can autobox ints now, so collections aren't a problem anymore. Really it's collections that were broken anyway

    19. Re:enumerators by bnenning · · Score: 3, Insightful
      By making them objects you have to worry about the compiler creating a lot of extra objects behind your back especially in tight highly used loops.


      I would think they'd have to be like singletons, with the compiler creating exactly one instance of each enum value.

      --
      How to solve most of our problems: 1.Lots of nuclear plants. 2.Cure aging.
    20. Re:enumerators by badmonkey · · Score: 1

      Cute until you realize you can't use a switch statement!

    21. Re:enumerators by Mindbridge · · Score: 4, Interesting

      Metadata has been supported by the Java VM since the beginning, and JSR 40 (the metadata stuff in the language) has been around since 1999. It is _very_ doubtful that Java got this from C#. I will grant you that it probably forced issues a bit, though :)

    22. Re:enumerators by Mindbridge · · Score: 3, Interesting

      Using the switch statement automatically means the programmer has slept through the OO class.
      You simply do not need to use switch when you have polymorphism, which is a much more powerful mechanism and allows for much nicer scalable, maintainable, and readable code. Of course, this assumes that one has an understanding of OO.

      If there is a problem with safe enums, it is with serialization and deserialization. There are a number of solutions available for that, however. Personally, I feel that those should have gotten in the Java libraries, not enums in the language, but oh well.
      available such as , something that the safe enum provides, unlike the enumerations.

    23. Re:enumerators by Admiral+Burrito · · Score: 1

      You should also declare them final: "public static final SenseEnumeration ...". This prevents accidental re-assignment of the field (reports an error at compile-time), and allows the compiler to do some optimizations because it knows the field will never change.

    24. Re:enumerators by Jorrit · · Score: 1

      There are still many cases where you need to use switch in Java. For example, many Java classes (like in Swing) use final int constants and sometimes you want to switch on that.

      Also there is a basic problem with polymorphism which is that you can't change the type of an object once created. i.e. you can't change the class of an object. But you can change the value of an integer. So sometimes you have an integer containing some state (which can change) and you want to switch on that state.

      Greetings,

      --
      Project Manager of Crystal Space (http://www.crystalspace3d.org). Support CS at http://tinyurl.com/cb3x4
    25. Re:enumerators by Mindbridge · · Score: 1

      For the first thing I completely agree, but I think the right solution would be to fix those classes. (then again Sun want to make GUI stuff as fast as possible, so perhaps they would be against that, even though the cost would likely be low).

      The second one smells like bad design to me. Personally, I cannot think of a situation in which one cannot implement what you just described in a way that is clean and would make polymorphism natural.

      At the end of the day, some of the changes made in 1.5 were definitely targeted towards the wider audience, and as such switch is useful -- a proper OO design is not suitable for every situation and every programmer. And yet, I do not think they should have thrown this to the garbage. Instead, they could have made a construct that looks like an enum, but can scale up to the real stuff. It's not that hard.

    26. Re:enumerators by iabervon · · Score: 3, Informative

      The instances are created when the class is loaded, and there's only one copy of each value. It's essentially like you're using int constants, except they're pointer constants instead, so you can dereference them to get more information than just equality. It's essentially the same as

      public class Season {
      static public final Season spring = new Season();
      static public final Season summer = new Season();
      static public final Season fall = new Season();
      static public final Season winter = new Season();

      private Season() { }
      };

      Except it's only one line, there are useful additional methods (like a toString), and you can use it in a switch statement.

    27. Re:enumerators by lokedhs · · Score: 1

      You will be glad to hear that the typed collections are completely optional. The default is the same old. You can even do this: // declare a typed list
      List foo = new List(); // assign it to a normal list
      List bar = foo; // Doing it the other way around requires a cast:
      List foo = new List();
      List bar = (List)foo;

      All very logical, isn't it?

      Download the preview and try for yourself.

    28. Re:enumerators by lokedhs · · Score: 1

      (of course I was in such a hurry to post my last message that I missed the fact that I got all the html messed up. Should be fixed now) You will be glad to hear that the typed collections are completely optional. The default is the same old. You can even do this: // declare a typed list List foo = new List(); // assign it to a normal list List bar = foo; // Doing it the other way around requires a cast: List foo = new List(); List bar = (List)foo; All very logical, isn't it? Download the preview and try for yourself.

    29. Re:enumerators by Billly+Gates · · Score: 1
      That is alot of code to type.

      Enumerators make this alot easier and quicker.

      Your way is alot more object oriented and powerfull but is a little overblown for most situations and requires more time to write.

    30. Re:enumerators by spells · · Score: 3, Insightful

      Polymorphism is a single tool in the belt and doesn't replace switch statements.
      Although I agree every instance of a switch statement can probably be implemented with polymorphismc some times you will end up with a worse design using polymorphic solutions that haven't placed enough emphasis on encapsulation and connascence. Options are good.

    31. Re:enumerators by Anonymous Coward · · Score: 0

      This is such a joke: For years and years the SUN spin meisters are telling us that enums are bad / evil and MS. That is why Java didn't have them. Now all of a sudden they are put in. and guess what: It's supposedly the greatest invention since sliced bread.

    32. Re:enumerators by j7953 · · Score: 2

      Apache's org.apache.jakarta.commons.lang package contains an abstract base class for typesafe enumerations (Enum), which contains a toString method and a readResolve method (to allow safe serialization of enumeration constants). The only disadvantage is that it also implements the Comparable interface, which sucks if you have an enumeration that doesn't really have a natural order.

      --
      Sig (appended to the end of comments I post, 54 chars)
    33. Re:enumerators by dspeyer · · Score: 1

      I maintain that C does enumerated types the right way. They are ints, but you don't have to specify their values. This lets you use as indecies them in arrays, iterate over them, and categorize them with standard comparison operators. No object-oriented trickery can match the flexibility of a simple C enum.

    34. Re:enumerators by fforw · · Score: 1

      .. and it handles serialization/deserialization without producing new instances which is an important aspect.

      --
      while (!asleep()) sheep++
    35. Re:enumerators by #!/bin/allen · · Score: 1

      And the perl version 4 explanations.

      Not necessarily a bad thing.

      --
      sed 's/commun/terror/g' mccarthy > bush; sed 's/terror/saddam/g' bush > bush_wacked
    36. Re:enumerators by angel'o'sphere · · Score: 1

      >

      Please elaborate: what do you call a "type save enum", btw: are people talking about "enums"/enumerations or enumeratORs? The difference is HUGHE :-)

      And please elaborate furhter: what kinds of subtile bugs do you reffer to? I would be interested in hearing some samples.

      Thanx,
      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    37. Re:enumerators by angel'o'sphere · · Score: 1

      Completely right.

      Exept e.g. that the visitor pattern does not work with plain enums.

      So ... where was the flexibility an enum gives you, again?

      Something wich is an int is as flexible as an int, in plain words: its not flexible at all.

      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    38. Re:enumerators by angel'o'sphere · · Score: 1

      Come on:

      Either get a clue or stay silent. The compiler creates exact one object for every enumeration - VALUE!

      That means the enum type { a, b, c }; has 3 objects.
      and the variables:
      type x = a;
      type y = a;

      share the same object. There is absolutely no "hidden compiler secret conspiracy" behind he scene creating "magic objects".

      I think you never heared about the "enum pattern".

      If you do not like enums like they are used in Tiger, use the old way. Surprisingly your comment falls apart when looking at the fact: the old way works like before.

      Regards,
      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    39. Re:enumerators by angel'o'sphere · · Score: 1


      The typesafe enum idiom is broken. It looks pretty but it's not a substitute for real first-class enumerators. In many cases it is actually worse than using plain ints as it can lead to very subtle bugs.


      Please elaborate: what do you call a "type save enum", btw: are people talking about "enums"/enumerations or enumeratORs? The difference is HUGHE :-)

      And please elaborate further: what kinds of subtile bugs do you reffer to? I would be interested in hearing some examples.

      Thanx,
      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    40. Re:enumerators by angel'o'sphere · · Score: 1


      Evil thought: you could get relatively nice-looking static instances with methods if you combined enums with anonymous inner classes...


      You can do that. A enumeration is only a set of classes with an int field where every enum value is a single object of its own class.

      Regards,
      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    41. Re:enumerators by ProfKyne · · Score: 1

      That's what we've been using but my fingers get tired from typing all that extra crap in...

      Write a perl script.

      --
      "First you gotta do the truffle shuffle."
    42. Re:enumerators by ProfKyne · · Score: 1

      You're right, I completely forgot about that step. And you might want to declare the class itself final so that it can't be subclassed by someone trying to subvert the code (and pass in their own enumeration rather than one that you've specified).

      --
      "First you gotta do the truffle shuffle."
  2. Looking to Get Back into Java by ackthpt · · Score: 1, Offtopic

    I worked in Java a few years ago and haven't kept up much with development kits, etc. The language I could pop right back into, but could use some advice on good/affordable IDE.

    --

    A feeling of having made the same mistake before: Deja Foobar
    1. Re:Looking to Get Back into Java by stevenknight · · Score: 5, Informative

      check out eclipse -- a very sweet java IDE.
      http://www.eclipse.org/

    2. Re:Looking to Get Back into Java by ackthpt · · Score: 1
      check out eclipse -- a very sweet java IDE. http://www.eclipse.org/

      Thanks for the tip. The last IDE I used was Kawa, it was OK, but have no idea where it's at (in terms of function and features) these days.

      --

      A feeling of having made the same mistake before: Deja Foobar
    3. Re:Looking to Get Back into Java by pygeek · · Score: 2, Troll

      Emacs, of course. Syntax highlighting, integrated compiling, etc.

      *puts on flamesuit*

    4. Re:Looking to Get Back into Java by gray+peter · · Score: 4, Informative
      The language I could pop right back into, but could use some advice on good/affordable IDE.

      http://www.xemacs.org
      what more do you need? ;-)

      If you want a *real* IDE, I'd check out IntelliJ's Idea product. It's a few hundred $$$. Lots of folks like Netbeans and IBM's Eclipse as well (sorry, no url to eclipse, but I'm sure you can find it). The latter 2 are opensource.

      --
      May no camel spit in your yogurt soup.
    5. Re:Looking to Get Back into Java by Schezar · · Score: 4, Informative

      Eclipse is "the awesome." It's feature-filled and relatively easy to use. Being free is a nice plus, too.

      My roommate told me about it, and once I started using it I never looked back.

      --
      GeekNights!
      Late Night Radio for Geeks!
    6. Re:Looking to Get Back into Java by Anonymous Coward · · Score: 1, Informative

      How does free sound? http://www.eclipse.org/

    7. Re:Looking to Get Back into Java by Anonymous Coward · · Score: 0

      i do agree, especially since the emacs from cvs is very pleasing to the eyes. I know thats not everything, but it sure makes it comfortable for me to learn. Emacs is just one of those things that can help in the future. maybe it wont, but hey its still versatile and powerful.

    8. Re:Looking to Get Back into Java by KDan · · Score: 1

      In the non-affordable range, try JBuilder 8 Enterprise Edition. But Eclipse is pretty sweet.

      Daniel

      --
      Carpe Diem
    9. Re:Looking to Get Back into Java by Anonymous Coward · · Score: 0

      I would also suggest eclipse. The lastest version 2.1 is really nice and is better than JBuilder in my biased opinion. I used to use the free version of JBuilder, but since I switched, there's no comparison.

    10. Re:Looking to Get Back into Java by ChristTrekker · · Score: 1

      That's what we're using here at work. It's OK, but seems a bit flaky at times, to me. I'm currently wrestling with a corrupted XML file. No idea how that happened.

      I haven't tried Eclipse yet (no time), but I've heard enough good things about it that it's probably what I'll use for personal development.

    11. Re:Looking to Get Back into Java by Anonymous Coward · · Score: 0

      Use vim or netbeans.org
      Both are free.

    12. Re:Looking to Get Back into Java by p5 · · Score: 1

      You will want to check out jGrasp;

      http://www.eng.auburn.edu/grasp/

      Nice IDE, free, works with windows and about everything else.

      Does nice things with projects and other stuff you might be interested in.

    13. Re:Looking to Get Back into Java by Anonymous Coward · · Score: 0

      If you're looking for a Java Programmers IDE (i.e. not one that has a Swing/AWT dialog designer type thing), look at IDEA. It's worth every penny of the price. Eclipse is catching up to a lot of IDEA's features but doesn't stand a chance for a while to come.

      My $0.02 C
    14. Re:Looking to Get Back into Java by Anonymous Coward · · Score: 0

      Try out Netbeans. www.netbeans.org. It's a bit of a memory hog, but it has a lot of nice features. Especially integration with Tomcat, Ant, Junit, and a lot of other downloadable modules. Eclipse is ok, but it is lacking in a few of the features that I really like about netbeans.

    15. Re:Looking to Get Back into Java by not+Mr.T · · Score: 1

      Emacs...hmmm. I'm contemplating mentioning a two letter acronym that starts with V and ends with I. But Smokey told me not to play with fire, and if it came from a talking bear it must be good advice. Regardless of which IDE you use, make sure that it's got decent integration with ant. Ant is part of the jakarta project and allows you to write build scripts in XML. Having your own scripts that can update and commit to cvs, run junit tests, generate javadoc, deploy components to application servers, etc., allows you to be much more productive, regardless of the IDE you choose. I think you'll find ant fits nicely with the other recomendations you've got so far. And if your projects rely on Ant scripts, they'll port nicely to another IDE if you decide to switch.

    16. Re:Looking to Get Back into Java by FortKnox · · Score: 1

      Netbeans? Too slow!
      Eclipse? Too Bulky!

      The answer is JBuilder. If you want to spend some cash, get the professional (or enterprise) edition. They are simply the best and easiest IDEs to use in Java.

      And the standard edition you can get for free from Borland (although you do need to register).

      --
      Good quote, too many chars. Seriously, the slashdot 120 char limit sucks!
    17. Re:Looking to Get Back into Java by los+furtive · · Score: 1

      My recommendation is IntelliJ's IDEA. I've used JBuilder, JDeveloper and plain old Ultra-Edit, and IDEA has made me the happiest...it has definitely made my job easier and made me more productive. Plus if you're good you'll never touch a mouse again.

      --

      I'm a writer, a poet, a genius, I know it. I don't buy software, I grow it.

    18. Re:Looking to Get Back into Java by Kleedrac2 · · Score: 1

      My favorite JAVA IDE is still Textpad ... aside from highlighting syntax you're just a couple of shortcut keys away from compiling and running! Plus you can evaluate it for free at http://www.textpad.com/ Try it for a while and you'll see that it's a worthwhile investment.

      Kleedrac

      --
      Sure we wang, can.
    19. Re:Looking to Get Back into Java by Anonymous Coward · · Score: 0

      Check out www.intellij.com. Has all the features of eclipse and then some. Easier to use and very programmer friendly. Pretty much every thing is customizable.

    20. Re:Looking to Get Back into Java by Anonymous Coward · · Score: 0

      Or wait for JBuilder 9, which is just now hitting the shelves.

      http://news.com.com/2110-1012-999967.html?tag=sa s_ email

    21. Re:Looking to Get Back into Java by JackMonkey · · Score: 1

      I use jEdit at work for pretty much everything. It has a load of plug-ins that make my job easier, such as tools for: Ant, SpeedJava, FTP, Telnet, CVS. It's about the best IDE I've used for development in any language.

      www.jedit.org

    22. Re:Looking to Get Back into Java by dasmegabyte · · Score: 1

      Netbeans is a FABULOUS IDE...until I used .NET, the best I'd ever seen. .NET's only major wins are in the realms of usable screen space and speed. Netbeans is slow on the fastest java systems I've seen. It's got so many abstraction layers between it and the hardware (not the least of which being the VM, jrocket doubles the speed easily but its still too slow), i don't think it'll ever speed up. The hiding in .NET is the awesome. I have a single bar on the way left of my screen with every possible window I could want docked to it, from the help browser to the preferences window. There's even a full screen mode and key combos for freakin' everything. So you have productivity combined with ease of use...MS finally fucking got something right. I guess $1800 or whatever is a lot for an IDE and a VM when Java is free. But it wasn't my money not my decision.

      Netbeans has the .NET ide beat HANDS DOWN for functionality, though. New modules come out just about every second and get organized as updates, new feature, beta features and alpha features. It is the only IDE I have seen that helps you do everything Java can do, from emulating embedded systems running J2ME, to running j2EE server apps.

      Plus, Netbeans is also an application PLATFORM. Meaning you can write your apps to fit snugly inside netbeans, and a lot of the tough work of designing new controls and common dialogs is done for you.

      --
      Hey freaks: now you're ju
    23. Re:Looking to Get Back into Java by slagdogg · · Score: 1

      Actually, with JDE mode XEmacs makes a very fine IDE ... it even offers interactive debugging, though less advanced than the capabilities offered by the commercial IDEs.

      I use XEmacs for all of my Java development, mainly because the Java IDEs are typically written in Java, and thus terribly slow, even on powerful hardware.

      XEmacs is fast, extensible, free, and ... well, it's Emacs, damnit!

      --
      (Score:-1, Wrong)
    24. Re:Looking to Get Back into Java by JackMonkey · · Score: 1

      The problem I had with JBuilder is that it throws too many proprietary libraries into the fray. I designed a Swing app with it and it added so much extra crap that I decided to use something else and build it manually. As far as the GUI app creator for JBuilder goes, I consider it to be on par with FrontPage.

    25. Re:Looking to Get Back into Java by richieb · · Score: 3, Informative
      If you are willing to spend some money check out IDEA from IntelliJ. It's great!

      http://www.intellij.com/idea/

      --
      ...richie - It is a good day to code.
    26. Re:Looking to Get Back into Java by Dj · · Score: 1

      Well, I have two IDEs on my desktop; IDEA and Omnicore's Codeguide and it's CodeGuide I keep coming back to.

      --
      "You know you want me baby!" - Crow T Robot
    27. Re:Looking to Get Back into Java by doublem · · Score: 2, Funny

      I consider it to be on par with FrontPage.

      Harsh.

      Very cruel man.

      --
      "Live Free or Die." Don't like it? Then keep out of the USA
    28. Re:Looking to Get Back into Java by Anonymous Coward · · Score: 0

      Don't forget JDeveloper or just download it from http://otn.oracle.com/software/products/jdev/

    29. Re:Looking to Get Back into Java by CowboyBob500 · · Score: 1

      JBuilder 8. Great until you try and do what it's name suggests, build.

      It's interaction with source code control is a nightmare. When you get some updated source from the repository, often it has an older date than the last compile time, so JBuilder will ignore it. You have to manually clear out the cache.

      Also, try using it's WSDL generation wizard with Apache Axis. Buggy is a kind word for it.

      Bob

    30. Re:Looking to Get Back into Java by neurojab · · Score: 1

      agreed. Eclipse has powerful refactoring tools that really speed your development. Imagine being able to highlight a section of code and clicking "extract method" and having the IDE replace your code, now calling the method? Eclipse can do it... and it actually WORKS!

    31. Re:Looking to Get Back into Java by aardvarkjoe · · Score: 1

      How about ed? Lightweight, fast, unobtrusive, and nearly universally available.

      --

      How can we continue to believe in a just universe and freedom to eat crackers if we have no ale?
    32. Re:Looking to Get Back into Java by Billly+Gates · · Score: 1
      Try netbeans if you find eclipse to overwhelming with pane windows everywhere.

      Eclipse is new and is a little buggy on Linux/FreeBSD. It is alot faster since the gui portition does not use swing but a wrapper around a native toolkit.

      Eclipse is argueable more powerfull because of its many plugins but netbeans is what forte is based off of from Sun. Its simpler and comes with syntax highlight, a debuger, and a menu which you can create wizards from. It also includes tomcat which Eclipse does not have for j2eee development.

      Since they are both free download both!

    33. Re:Looking to Get Back into Java by mobiGeek · · Score: 2, Informative

      Don't forget about the JDEE!

      --

      ...Beware the IDEs of Microsoft...

    34. Re:Looking to Get Back into Java by rutledjw · · Score: 1
      INFIDEL! Don't you know that the great vi is King? All you little Emacs folks need to get with the program...

      Because really, what is /. without some trivial arguments like vi vs. emacs? ;)

      Actually I got on the vi bandwagon for 2 reasons:

      • Regular Expressions
      • When I was a blood-sucking contractor, IDE would change across clients, but finding a good "vi" or Windows port (Lemmy) was easy.

      On that note, I haven't messed with emacs, but probably should...
      --

      Computer Science is Applied Philosophy
    35. Re:Looking to Get Back into Java by Billly+Gates · · Score: 1
      Without creating emacs jokes, emacs is a text editor not an ide.

      However gVIM is different since we all know that Emacs is quite underpowered compared to the allmight force of VI. ;-)

    36. Re:Looking to Get Back into Java by J.+Random+Software · · Score: 1

      Out of the box Emacs offers a class browser, reindents source, jumps to compiler errors, and integrates version control systems and debuggers. In what sense is that not an IDE?

    37. Re:Looking to Get Back into Java by djcinsb · · Score: 1

      Not only is it "non-affordable", but Borland releases a new version every 6 months or so, at a hefty upgrade price, making Eclipse even more attractive.

      --
      A signature always reveals a man's character - and sometimes even his name. -- Evan Esar
    38. Re:Looking to Get Back into Java by Billly+Gates · · Score: 1
      Agreed! Its a real ide I can add autoword completion just by typing.....

      df4=meta ddfdfd
      dfsaf - meta 43576v
      dkccnb-meta 34xfg
      dfdfddf-meta dfdsf
      dfdfd-meta dfdst55hjk
      dfdf-meta dfsdfgha
      45tvg-meta dfdsg456

      Uh, thanks but no thanks. If you want to learn emacs you might as well learn a whole new language, environment, and way of doing things which makes Unix look easy.

      There is a theory why Emacs users prefer to stay in emacs to do everthing because they get use to the reflexs and commands of it and its different from Unix.

      The Unix haters manual smirks at Emacs quite a few times. There should be a whole chapter to this.

    39. Re:Looking to Get Back into Java by zenz · · Score: 1

      No doubt:) It's the official java IDE in my software engineering class :)

      --
      ----- It is as it is; it will be what it must be.
    40. Re:Looking to Get Back into Java by malachid69 · · Score: 1
      I have used JBuilder and NetBeans. I have tried Eclipse and Visual Age (MicroEdition).

      Now, I just use JCreator. It doesn't include a lot of the things that NetBeans does (like GUI-creation tools), but it is fast (BIGGEST reason I use it), has syntax highlighting (which is why I switched from Programmers' Editor), allows you to add new syntax, can run ant from F7/button, etc... The author also seems very receptive to emails.

      Let's put it this way, I actually registered it.

      On Unix, I usually use pico or vi, but I have heard really good things about KDevelop.

      Malachi

      --
      http://www.google.com/profiles/malachid
  3. i'm excited by neonprimetime · · Score: 1

    i love java, and i'm excited for the new version to arrive

    1. Re:i'm excited by Anonymous Coward · · Score: 0

      I'm excited that you're excited.

  4. Generics by boxhead609 · · Score: 3, Interesting

    I think Generics is going to be a really nice long awaited feature. I am wondering if this type of change is going to require a modification to the bytecode specification. If that is the case, then new code bytecodes will not work with older bytecodes. Does anyone think that Sun can pull this feature off without a change to the bytecode spec? Would this be major compiler change?

    1. Re:Generics by gray+peter · · Score: 5, Interesting

      Agreed that it's a great feature. I use collections all the time and not only is it time consuming to keep casting (especially when you write out long class names like I do...) I'd say a huge % of my runtime errors are from bad casting. I'm definitely looking forward to this. As far as the bytecode specs go, I don't see that this will cause much change at all. The compiler should do the same thing it's always done.

      --
      May no camel spit in your yogurt soup.
    2. Re:Generics by Erwos · · Score: 0, Redundant

      I have this same problem, but I have no idea what "generics" are. Care to enlighten me?

      -Erwos

      --
      Plausible conjecture should not be misrepresented as proof positive.
    3. Re:Generics by gray+peter · · Score: 3, Insightful
      Read the article :-)

      --
      May no camel spit in your yogurt soup.
    4. Re:Generics by Caoch93 · · Score: 1
      I don't think that adding generics requires a change to the bytecode. IIRC, Java generics are actually just a pre-processing of the source to apply the correct type at compile time. The end result is that, at the bytecode level, nothing changes.

      In many ways, I am actually for something of this nature. Runtime typecasting isn't the most efficient use of processor time, and this pushes back the type check to compile time. All in all, this should be a Good Thing.

      I could be off my rocker on this one though. I have nothing to cite, and I'm only going by what appears in this strange thing I call my memory.

    5. Re:Generics by Erwos · · Score: 1

      I am chastened, thank you :).

      Now, however, I am extremely excited. Generics are exactly the kind of feature I've been looking for for a while. Hell, I just wrote a project that could have used them pretty effectively.

      -Erwos

      --
      Plausible conjecture should not be misrepresented as proof positive.
    6. Re:Generics by blamanj · · Score: 4, Informative

      No bytecode changes are required. There have been "test" implementations out since Java 1.2. You can get the current 1.3 release at
      http://developer.java.sun.com/developer/earlyAcc es s/adding_generics/

    7. Re:Generics by forgoil · · Score: 2, Insightful

      It looks like Java's generics are much like C++'s templates. This means that it is a compiler feature, and not a runtime feature. This is not a step forward, but a way to keep the VMs still working. A trade off.

      For some interesting words on generics, and implementation for both Java and M$ CLR take a peak at this link:

      http://msdn.microsoft.com/library/default.asp?ur l= /library/en-us/dv_vstechart/html/vbconCProgramming LanguageFutureFeatures.asp

      All you "I hate M$" people out there will more than likely scream about how horrible they are and how we must use Java. If you hate M$ I would suggest you go take a look at mono instead. The CLR together with C# completly owns Java, and when generics are added it will be even sweeter. I program both Java, C#, and C/C++ daily, and it gives a very good view on what language is the easiest to work with and use.

    8. Re:Generics by justins98 · · Score: 3, Interesting

      I don't think it will require a bytecode change. I don't know the details of how it works, but my guess is that the compiler will simply insert the casts for you. For example, when you say:

      List<Foo> list = new ArrayList<Foo>();
      list.add( myFoo );
      Foo otherFoo = list.get( 0 );

      The compiler will interpret the second and third lines as if they said:

      list.add( (Foo)myFoo );
      Foo otherFoo = (Foo)list.get( 0 );

      It's a pretty elegant way to incorporate type-safe generics without imposing any changes on the VM. I think the compiler changes would be relatively easy to implement -- nothing more than inserting casts at the appropriate places.

    9. Re:Generics by Anonymous Coward · · Score: 0

      Let's say you're using a Vector. It can become a Vector to prevent you from having to cast.

      Wait, there's more!

      Let's say you write a List class. You can write a List class, and have a List. getFirst in List will return an Object of type T, getRest returns List. You've replaced the need for an entire set of casts. When you get into the Visitor pattern, this can be really valuable.

      The strangest one looks like this. Let's say you're writing a regular method that has a genericly typed argument, like a Visitor. Your accept method will look like

      RetType accept( Visitor ){ ... }

      The first instance says, "Hey, there's going to be generic types here!" Then the second occurance is actually binding.

      As has been mentioned elsewhere, it's an attempt to get a great deal more type safety at compile time. It doesn't attempt to replace run-time errors, that's just silly.

    10. Re:Generics by KDan · · Score: 1

      Better than that. Because it can do this at compile-time, it will be able to check for illegal casts at compile time. No more ClassCastException's.

      Daniel

      --
      Carpe Diem
    11. Re:Generics by Anonymous Coward · · Score: 0

      this pushes back the type check to compile time
      Actually I believe all objects are type-checked at run-time, even if the casts were determined to be safe at compile time, but maybe there's a way to optimize that out.
      Anyhow I think templates/generics was one of the main features missing from Java w/r/t C++ (working with collections was just a hell of type casts). I also would have liked overloaded operators but I guess it's a matter of taste.

    12. Re:Generics by Anonymous Coward · · Score: 0

      Generics have been a loooong time coming.

      Unfortunately, adding such key ideas into the language in its fifth iteration is what really burns my ass about java.

      Its nice to be able to write machine independent code. But, worrying about what compiler/interpreter versions are installed on the target machine absolutely kills the platform independence benefit.

      Java done right would have had this in the first go-round.

    13. Re:Generics by CognitivelyDistorted · · Score: 3, Informative
      Pretty close. For "list.add(myFoo)", it won't add a cast, because the type checker verifies that myFoo is-a Foo. The compiler will also add "bridge methods" for classes that implement a parameterized interface:

      class Byte implements Comparable<Byte> {
      ...
      public int compareTo(Byte obj) {
      return this.value - obj.value);
      }
      }

      The method compareTo is supposed to override the method in Comparable, which takes an object. So they create a bridge method that overrides it normally:

      class Byte implements Comparable<Byte> {
      ...
      public int compareTo(Byte obj) {
      return this.value - obj.value);
      }
      public int compareTo(Object obj) {
      return this.compareTo((Byte) obj);
      }
      }
    14. Re:Generics by Mindbridge · · Score: 2, Insightful
      It looks like Java's generics are much like C++'s templates

      No, they are not. In fact, they are very different. C++ templates are heterogenious (every parameter set means a new class, hence you get lots of additional classes); Java generics are homogenious (one class serves all parameters). C++ templates' requirements for the parameters are "as they come" -- the code is simply recompiled with the new parameter classes; Java generics' parameters need to implement interfaces/extend classes if a particular method of the parameter is to be used (which is much neater from a design perspective, if you appreciate this kind of thing). The only thing in common is the first glance appearance.

      The CLR together with C# completly owns Java

      Yes, it is a better solution in some respects and much worse in others. Given that it was designed 5 years after Java, the first was to be expected, the second was not. It merits a look, until you realize that any advantages are only marginal, and that there is only one company that provides major products for it (like application servers) and defines its interfaces. Given the fact that the company has a long notorious history and it has standardized less than 10% of the API does not make things better. And then there is Mono that now has to rely on Wine... Ah well.

    15. Re:Generics by MillionthMonkey · · Score: 2, Interesting

      Actually I believe all objects are type-checked at run-time, even if the casts were determined to be safe at compile time, but maybe there's a way to optimize that out.

      The JVM executes a checkcast bytecode instruction wherever there is a cast. It either does nothing or it throws a ClassCastException at you. (The instanceof instruction works the same way, except it puts a boolean on the stack instead.) But with generics, a runtime cast is never required IIRC. The compiler generates a one-shot collection class based on the generic that ONLY handles members of the type you've specified (e.g. String) and returns objects of that type, so the type checking is done statically. The entire purpose was to eliminate the runtime cast.

    16. Re:Generics by Caoch93 · · Score: 2, Insightful
      It's not possible to engage in the level of typechecking you're talking about with generics. All objects go through a typesafe container having the type of java/lang/Object. Java, right now, cannot check at compile time whether or not a call to get(), returning java/lang/Object, will yield an object of java/lang/String in the typecast. This is preceisely why ClassCastExceptions at runtime is such a big deal.

      By comparison, by telling the compiler that you want all of the objects in some container to be of type java/lang/String, the compiler can provide checks against it because the expected type is now a facet of the method signature. To engage in the kind of typechecking at compile time that I'm talking about without programmer clarification (via generics) would require the compiler to have a guaranteed knowledge of a lot more than it does. For example...

      If, in one piece of code you insert a java/lang/String into an ArrayList, then in another piece later, it is clobbered and replaced with a java/math/BigDecimal, and then in another piece, get() is called and the retrieved java/lang/Object is cast to java/lang/String, the compiler, to provide type-checking and catch this class cast failure, would have to be able to prove that, every time that specific get() was called, something other than a java/lang/String came out of it. To do that would requrie a lot of information about the dynamic state of the program at that time.

      In fact, depending heavily on the method in question, it may be impossible to guarantee the permitted type of the object available when you cast/miscast it. Consider a multithreaded environment. You're fast reaching a place where the only way to know what the type of the object is is to actually wait and see each time, which is what runtime casting is.

      You are correct that certain forms of type safety can be found at compile-time. For example, type safety in passing parameters, assigning values from a return, etc, can be tested. Likewise, a type saftey check of this nature is trivial:

      ArrayList l = null;
      String s = new String();
      l = s;

      However, there reaches a point where runtime type safety has to take over, and most of the cases of improved type safety thanks to generics is a matter of moving more type checks away from runtime and into compile time.

      And generics does not have to be "a hell of type casts". It can be a preprocessor hack where, at compile time, the types are provided in a special syntax and the generics (or template) code is then used to generate a unique piece of source code from those types. This would clearly make your compiled code size bigger, but avoids excessive use of the runtime type system.

    17. Re:Generics by Caoch93 · · Score: 1
      Whoops, that should read "All objects go through a type UNSAFE container"...

      Don't leave me in charge of those containers. I can't tell the safe ones from the unsafe today. ;)

    18. Re:Generics by Anonymous Coward · · Score: 0

      And generics does not have to be "a hell of type casts"
      What I meant is that generics precisely removed this hell (I said WAS).
      Whether they just add casts for you or do something more subtle, which would remove runtime type checks, is another matter ; as you pointed the first solution doesn't remove type checks while the other might increase code size (while improving speed). The latter is for instance what is used for C++ templates (code is generated for each template parameter given ; this leads to a lot of problems if one wants to have template libraries ; usually the code is in the headers).

    19. Re:Generics by Anonymous Coward · · Score: 0

      so in essence, java generics are just another namespace substitute (with typecast checking and syntactc sugar) nothing like the power of real generics.

    20. Re:Generics by Anonymous Coward · · Score: 0

      so a preproccesor and hungarian notation would take care of it?

    21. Re:Generics by Caoch93 · · Score: 1
      That'd be an ass-backward hack of a way to do it, but ass-backward hacks tend to be popular enough...

      You'd have to make the preprocessor engage in some very specific activities, though. And the Hungarian notation would have to express full typing information.

      Or you could just use generics.

    22. Re:Generics by orthogonal · · Score: 1

      List<Foo> list = new ArrayList<Foo>();
      list.add( myFoo );
      Foo otherFoo = list.get( 0 );

      The compiler will interpret the second and third lines as if they said:

      list.add( (Foo)myFoo );
      Foo otherFoo = (Foo)list.get( 0 );


      But if a List<Foo> is-a List, I can do this:

      List<Object> haha = (List<Object>) list ;
      haha.add( new String( "haha!" ) ;

      If I can cast a "typesafe" list, it's not really that typesafe; imagine that I don't do this maliciously, but do it inside some called function in an object, MyCollections, which is like java.util.Collections:

      MyCollections.reverseAndAppend( List l ) {
      java.util.Collections.reverse( l ) ;
      l.add( "This this was reversed" ) ;
      }

      On the other hand, if the compiler enforces the rule that a List<Foo> is-NOT-a List, all of a sudden I can't pass it to any function that takes a List, either mine or in the Java standard library.

      C++, for code size efficiency reasons, has a common base class for templated container classes, but the base class is privately inheirited, so that outside of the class, users can't cast it to the base class. In other words, the implementation is inheirited, but the interface is not. That's not a problem for C++, because functions are templated too.

      Even if Java templates functions too, the problem remains: functions written pre-template either can't take a templated List -- and the functionality must be re-written --, or they get it cast to List<Object> and can violate its contract.

    23. Re:Generics by CognitivelyDistorted · · Score: 1
      Yes, that's a problem. For the reasons you give, List is not a subtype of List. They included a feature called "raw types" to allow interfacing with legacy code. The raw type would be List, so you can do this:

      List<Foo> list = new List<Foo>;
      List haha = list;
      haha.add("haha!"); // unchecked warning

      The compiler will generate an "unchecked warning" because List.add and List.add have different argument types. GJ also has a way of retrofitting existing classes to make them work like generics, which they've done for the standard library, but I'm not sure this is going to be in Java 1.5.

    24. Re:Generics by g4dget · · Score: 1

      No, the way Sun has implemented it, it does not require modification to the JVM. That's a problem because it ends up being not entirely type safe across compilation boundaries, and because it is less efficient than it could be otherwise.

    25. Re:Generics by angel'o'sphere · · Score: 1


      But with generics, a runtime cast is never required IIRC. The compiler generates a one-shot collection class based on the generic that ONLY handles members of the type you've specified


      Unfortunatly that is not the case. Sun descided for some strange reasons that their generics implementation is based on a concept called erasures. That emasn everywhere where you say T as a type parameter, the compiler says: Object.

      A collection of Strings is still a collection of objects and the compiler introduces a typecheck and even issues exceptions when that collection is accessed to extract a String.

      You can even do:
      void func(Collection x) {
      Collection[String] y = x; // not even a cast needed
      String s y.get(0); // my fail!!
      }
      The [] are ment to be less and greater ...

      As you can call func() with any collection type the compiler inserts class checks.

      IMHO, that aproch is so braindead that Java will get a very bad reputation. Its easy to route parameters into a library and get ClassCastExceptions out instead of the wanted actions performed. What is the use of generics if they are NOT type save?

      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  5. Give billg his due... by PHAEDRU5 · · Score: 2, Insightful

    ...he's forcing improvements in Java.

    --
    668: Neighbour of the Beast
    1. Re:Give billg his due... by gl4ss · · Score: 1

      well, how else would billg get new features to rip into his .net_2005_gold_edition?

      it's a joke.

      --
      world was created 5 seconds before this post as it is.
    2. Re:Give billg his due... by rpk · · Score: 2, Informative

      Not knowing much about C#, is Java 1.5 "borrowing" features ?

      I see two trends: being a better C++ (typesafe enums and parameterized types), and borrowing features from Lisp (code metadata, auto boxing/unboxing). I don't like to tie developments like this to particular people, but I wonder how much Guy Steele has do to with the Lisp-like features, if in fact he is still working at Sun.

    3. Re:Give billg his due... by Anonymous Coward · · Score: 0

      I am confused - how is BillG helping?

      Generics are inspired by C++, and BillG still hasn't been able to put out a fully compliant implementation of generics in C++.

    4. Re:Give billg his due... by Chokolad · · Score: 1

      >>> Not knowing much about C#, is Java 1.5 "borrowing" features ?

      ----
      One may say so. You see, C# had all features mentioned in article excluding generics since Beta 2. I think this is more than a year.

    5. Re:Give billg his due... by Hobbex · · Score: 4, Insightful

      One may say so. You see, C# had all features mentioned in article excluding generics since Beta 2. I think this is more than a year.

      It's more that C# includes a bunch of features that some java programmers had been asking for, and so does java 1.5. It's not like any of these features were out the blue in C#, they are mostly things people have been missing from other languages.

    6. Re:Give billg his due... by Grievance · · Score: 2, Interesting

      I see all six of the enhancements described in the article as coming directly from C#, and I think they're all Good Things. (i don't remember enough from my Lisp days to know if some ultimately derive from that most elegant language.)

      i've been a Java programmer (primarily) for 8 years, and just recently did a project in C# -- which i was dreading, but the language turned out to be OK, like Java with sops thrown to C++ diehards.

      now, if Sun adds operator overloading (*shudder*), i'm jumping ship.

    7. Re:Give billg his due... by Anonymous Coward · · Score: 1, Informative

      But don't forget that features like Metadata have been a part of Java for at least a year via the widely used open source XDoclet project. It's only now being added to the Java standard because XDoclet is so popular and it makes writing EJBs *a lot* easier. XDoclet's ideas about metadata came from the Aspect-Oriented-programming movement, not C#.

      The idea of autoboxing came from C++ where you can define your own conversions. Autoboxing becomes necessary to reduce syntax clutter when you add Generics to Java. This is because the Java implementation of Generics only works for Objects, not base types.

      Foreach and enum is in more languages than you can shake a stick at, so you can't say they came from C#.

      The "static import" idea is new. If C# has it, then it's likely Java took it from C#. Other than that, I can't see anything that Java took from C#.

    8. Re:Give billg his due... by Grievance · · Score: 1

      > I see all six of the enhancements described in the article as coming directly from C#, and I think they're all Good Things.

      err, except for the generics, duh. which i think is just an OK Thing.

    9. Re:Give billg his due... by Anonymous Coward · · Score: 0

      Its true.

      Regarding all the other comments:

      I don't think anything is taken from C# directly. I don't think there is a single new idea in C#, but if MS hadn't come up with .NET and was still pushing COM do you think Java implementors would be hard pressed to update as they are now?

      C# and .NET is just a better originized and designed Java.

    10. Re:Give billg his due... by Glock27 · · Score: 1
      Its true.

      Negative.

      Regarding all the other comments:

      I don't think anything is taken from C# directly. I don't think there is a single new idea in C#, but if MS hadn't come up with .NET and was still pushing COM do you think Java implementors would be hard pressed to update as they are now?

      Yes, this stuff has been on the roadmap since JDK 1.2 (before .Not).

      C# and .NET is just a better originized and designed Java.

      That'd be great if .Not had an open specification. It doesn't.

      Don't settle for a single platform solution. You'll end up regretting it.

      --
      Galileo: "The Earth revolves around the Sun!"
      Score: -1 100% Flamebait
    11. Re:Give billg his due... by Jhan · · Score: 1

      It's more that C# includes a bunch of features that some java programmers had been asking for, and so does java 1.5.

      ... and the features would have been in Java 9.15 if it weren't for C#. There are certain nagging things about Java that developers have been complaining about since day one. The whole int/Integer thing is a biggie.

      Sun has responded with "not a priority", "would require VM changes" (= "Evil, evil, evil, stupid!"). Then, .net/C# came along, implementing many of the things Java programmers complained about. Hey presto! Java got boxing. Hopefully we didn't lose to many developers in the meantime.

      Auto-enumerating fors look very useful, and I think C# does not have them, ditto with the enums. Good work, Sun.

      Still waiting for auto getters/setters/events/handlers a-la C#... Unless that's covered by the funky new '@' notation.

      --

      I choose to remain celibate, like my father and his father before him.

    12. Re:Give billg his due... by DogIsMyCoprocessor · · Score: 1

      The only important one, generics, has been in the works long before C#. The others are just to achieve buzzword equivalence with C#.

      --

      "And this is my boy, Sherman. Speak, Sherman." "Hello." "Good boy."

    13. Re:Give billg his due... by Anonymous Coward · · Score: 1, Informative

      It's called competition and it's a good thing. That's why, ironically, Linux will be a good thing for Windows users. It won't be good for MS's finances but that only impacts MS stock holders, employees and suppliers so I could care less.

    14. Re:Give billg his due... by Anonymous Coward · · Score: 0

      IEnumerable interface in C# allows foreach to iterate over objects in a collection

    15. Re:Give billg his due... by M.C.+Hampster · · Score: 1
      Auto-enumerating fors look very useful, and I think C# does not have them, ditto with the enums. Good work, Sun.

      I'm not a big C# developer (yet), but C# does have the auto enumerating. See "foreach". I don't know about enums. And except for generics, C# has all the rest, including the metadata feature.

      --
      Forget the whales - save the babies.
    16. Re:Give billg his due... by slagdogg · · Score: 1

      Hopefully we didn't lose to many developers in the meantime.

      Oh yeah, most definitely ... I mean seriously, this whole platform independence thing ... and all those other great things about Java ... weak! C# has autoboxing! Woo! I'm jumping ship! Yeah baby!

      --
      (Score:-1, Wrong)
    17. Re:Give billg his due... by arkanes · · Score: 1
      How many people actually USE the "platform independence" of Java? Seriously, I'm curious. I know theres some uses - for example, all of Oracles admin/installation tools are in Java. On the other hand, they also suck really, really badly, so I'm not sure it's the best example.

      I know whenever I see an app that advertises itself as cross-platform, but turns out to be written in Java, I tend to kind of dismiss it.

    18. Re:Give billg his due... by slagdogg · · Score: 2, Insightful

      I couldn't agree more with your view of the Oracle tools ... but I really do use Java's platform independence all the time, and for non-GUI applications I think it works beautifully. The key here is the 'non-GUI' ...

      Actual example, I recently developed a servlet-based application, and given the hardware and time constraints I was under I developed on Linux, performed functional testing while deployed on Windows, and finally deployed on Irix. There was no change in behavior with the application other than performance, and it was a complex, multi-threaded application.

      --
      (Score:-1, Wrong)
    19. Re:Give billg his due... by mingot · · Score: 1

      That'd be great if .Not had an open specification. It doesn't.

      What exactly do you mean by "open specification"?

    20. Re:Give billg his due... by autopr0n · · Score: 1

      How many people actually USE the "platform independence" of Java? Seriously, I'm curious

      Well, it's nice to be able to run one binary on any box I can get my hands on. I've always been able to do that with java so I'm not sure exactly what you mean. It's nice to be able to run the same code on my desktop running windows and a server running Linux. I suppose I could run the same OS on all my crap, though.

      --
      autopr0n is like, down and stuff.
    21. Re:Give billg his due... by Grievance · · Score: 1

      I agree that generics is the only enhancement that's not just sugar, and i incorrectly implied in my comment that generics were part of playing catch-up with C#.

      that said, i do think all the C#-style sugar is well thought-out, and doesn't oversweeten the language -- so while the sugar isn't as "important" as the generics enhancement (i was doing just fine without it), it still should reduce vebosity (and certain common errors) in some common idioms.

    22. Re:Give billg his due... by DogIsMyCoprocessor · · Score: 1

      I agree that the typesafe enums, foreach iteration, and auto-boxing are good ideas. The jury might still be out on the meta-data thing. Also, I couldn't agree more about operator overloading.

      --

      "And this is my boy, Sherman. Speak, Sherman." "Hello." "Good boy."

    23. Re:Give billg his due... by Anonymous Coward · · Score: 0

      Yeah thats pretty vague.

      CLI is open.
      C# is not owned by MS. .NET is being developed for *nix as MONO and is already used in production by some.

    24. Re:Give billg his due... by Anonymous Coward · · Score: 0

      Yes, this stuff has been on the roadmap since JDK 1.2 (before .Not).

      Why the drag? And why are they implementing it now?

    25. Re:Give billg his due... by sheldon · · Score: 1

      "I know whenever I see an app that advertises itself as cross-platform, but turns out to be written in Java, I tend to kind of dismiss it."

      Sadly, you are correct.

      I was recently evaluating IM solutions, and every one I encountered that was written in Java was sold as "cross-platform". After evaluation it quickly became apparent it sucked for one reason or another.(usually kludgey UI)

    26. Re:Give billg his due... by bnenning · · Score: 1
      How many people actually USE the "platform independence" of Java?


      Our company develops on Mac OS X and deploys on Linux and Solaris. We'd never consider locking ourselves into Windows with .NET.


      I know whenever I see an app that advertises itself as cross-platform, but turns out to be written in Java, I tend to kind of dismiss it.


      Sure, Java mostly sucks for traditional desktop applications (with a few exceptions). But it's great for servers and back-end apps.

      --
      How to solve most of our problems: 1.Lots of nuclear plants. 2.Cure aging.
    27. Re:Give billg his due... by willtsmith · · Score: 1

      .net is no longer constrained to Windows only. There are two open source source projects of note.

      1) mono - .net on Linux. Apparently they're kicking ass and have most everything implemented by now. I don't think there will be any question about .net functionality on linux platforms.

      Beyond that they have an interpreter (no JIT compiling) available for Unix and OSX platforms.

      2) GNU Portable.net - These guys are developing for EVERY platform. They report that there stuff works on OSX, Unix, and WinCE. They don't seem to be as far along as Mono is.

      Beyond that there are rumors that Microsoft may port a .net run-time developed for BSD Unix to OSX.

      I really don't think that .net will be considered proprietary for much longer as more platforms embrace the forthcoming flood of .net applications.

      --
      -------- -------- Support Wesley Clark for president!!!
    28. Re:Give billg his due... by Anonymous Coward · · Score: 0

      Try writing Enterprise applications that have to run on mainframes, midrange computers AND pc's. Then try that 'cross-platform' doesn't matter opinion. It's Java, or multiple development languages for the same job. Your choice.

    29. Re:Give billg his due... by __past__ · · Score: 1
      Guy Steele did answer some questions on his role in Java development, most of it should be available on the web. IIRC, there were quite some things where he disagreed with Gosling, he likes to make it clear that his job was to document the language, not to design it.

      BTW, what do you mean with "code metadata" being a feature of Lisp? In Lisp, code is data in a lot of interesting ways (like that Lisp code is expressed as Lisp lists, and can be manipulated as such using Macros, or that functions are objects that can be treated just like strings, passed around, stored in variables etc.), but - as a Lispnik - I don't see much data about this data anywhere. Are you talking about reflection/introspection?

    30. Re:Give billg his due... by rutledjw · · Score: 1
      How about for different environments? Some developers use Windows, some use Linux. We then deploy some projects on WebSphere / AIX and others on WebSphere or Tomcat and Linux.

      That's all server-side, web service, messaging and middleware. But it's still a big chuck of what happens.

      I know whenever I see an app that advertises itself as cross-platform, but turns out to be written in Java, I tend to kind of dismiss it.

      Are you serious or trolling? I've seen numerous apps that are fine and are written in Java. The GUI (Swing and whatnot) can be goofy, but I don't think it's that bad

      --

      Computer Science is Applied Philosophy
    31. Re:Give billg his due... by SnapShot · · Score: 1

      How many people actually USE the "platform independence" of Java?

      Every Applet on the web...

      Whether there are very many useful Applets is a different question.

      --
      Waltz, nymph, for quick jigs vex Bud.
    32. Re:Give billg his due... by fantastic · · Score: 1

      What about ant, it works on everything unlike make

    33. Re:Give billg his due... by Jord · · Score: 1
      My company's flagship product is written entirely in Java because it is cross platform. We run server-side software against databases on AIX, HP-UX, Sun, Microsoft, Linux, etc. and have to have a cross platform solution.

      In addition, many of the software products that I use are written in Java and them being cross platform was one of the reasons I chose to use them. Made my switch from Windows to Linux and Mac OSX much less painful that it would have been.

    34. Re:Give billg his due... by g4dget · · Score: 1
      borrowing features from Lisp (code metadata, auto boxing/unboxing)

      For just about every language feature, you are going to find some Lisp variant that had those features. But these particular features are not all that characteristic of Lisp and lots of other languages have had them, too. Since several of the JDK 1.5 features are exactly where C# differs from java (e.g., foreach, metadata, autoboxing), it stands to reason that the adoption of them in JDK 1.5 was in reaction to C#.

      And what the hell is wrong with that? Sun has been dragging their feet far too long. If Microsoft finally forces them to get their stuff together, all the better. Unfortunately, even the 1.5 changes still leave many very serious problems with Java unaddressed.

      being a better C++ (typesafe enums and parameterized types)

      Neither Java nor C# are a "better C++", they are completely different languages with a somewhat similar syntax.

    35. Re:Give billg his due... by davesag · · Score: 1
      How many people actually USE the "platform independence" of Java?

      Well me for one. I work on my Mac, my client's staff all run various windoze, the other coders on the project use either windoze or slackware/suse linux. We host on slackware linux for staging and i am not exactly sure what the final decision will be for hosting the live site. Probably slackware linux. The point is I don't need to care. For presentations however the screen snaps all come off the Mac cos the app, a web app, looks that much better in Safari than IE or Netscape.

      I am at a loss to know why anyone would code in any language that does not allow the developers to use their OS of choice, and host on their client's OS of choice. Unless you have no choice of course :-)

      --
      I used to have a better sig than this, but I got tired of it
    36. Re:Give billg his due... by deanj · · Score: 1

      Yes, I do all the time. Work, compile and test on Linux, deploy on Windows. Minimizes my Windows exposure.

      When I do have to work under Windows, I can use the same IDE between that and Linux too: JBuilder.

      Works for me. /shrug

    37. Re:Give billg his due... by malachid69 · · Score: 1
      How many people actually USE the "platform independence" of Java?

      Most people that have larger products. Here at work, all of our Java code is compiled on Windows, Linux, AIX, Solaris -- and there are rumors of more needed soon. Oh, and my own BSD box at home.

      Malachi

      --
      http://www.google.com/profiles/malachid
  6. Programming shortcuts by GGardner · · Score: 5, Funny
    I feel using programming shorthand leads to increased maintenance

    I agree. This is why I never create my own functions or methods. Evey program should be just one big function.

    1. Re:Programming shortcuts by NReitzel · · Score: 5, Insightful

      During my time at telco, development costs were always a fraction of maintenance costs. Producing write-only code may be cute, and may cut back on other people using it, but it also cuts back on your own people being able to maintain it.

      Oh, do I agree, in boldface.

      --

      Don't take life too seriously; it isn't permanent.

    2. Re:Programming shortcuts by eGabriel · · Score: 3, Interesting

      It's true that wading through 20 different ways of doing the same thing in one program can really be maddening, but within reason some of these shortcuts should exist, and should have from the beginning.

      Every language has idioms, and a programmer should use those idioms in preference to other allowable ways to do things unless they have a good reason. It's all just part of good style.

    3. Re:Programming shortcuts by Angry+White+Guy · · Score: 2, Funny

      Makes for great job security!

      You wanna fire me? Have fun sorting out my code! It's commented in yiddish, if at all!

      --
      You think that I'm crazy, you should see this guy!
    4. Re:Programming shortcuts by f00zbll · · Score: 1

      this would be more funny if I never have to read another class that has everything in one method. it's still funny, except when I remember the times I've had to fix other people's code.

    5. Re:Programming shortcuts by radish · · Score: 4, Insightful

      Of course maintenance costs more than development, that's a given. But the thing which reduces maintenance costs is easy to read and understand code, coupled with good documentation.

      The ultimate removal of "syntatic sugar" would take you down to raw machine code. I do not believe that would be easier to maintain than Java, or pretty much any higher level language. The aim of syntatic constructs is (or should be) to make it easier for the developer to express the algorithm clearly. It's not about saving typing (unless we're talking perl) and not about being smart for the sake of it, it's about making it easier to read and understand.

      --

      ---- Den ene knappen er powerknapp, den andre er Bender voice knapp "Bite My Shiny Metal Ass"

    6. Re:Programming shortcuts by cabalamat2 · · Score: 1

      I agree, too. That's why I write all my programs in machine code.

    7. Re:Programming shortcuts by DunbarTheInept · · Score: 3, Insightful

      The problem is that some syntatic sugar doesn't actually increase readability. Consider operator overloading. If your language has that, you can never again know what on earth is going on when you see x = y + z, unless you are aware of every operator overload which was used. Let's say y is a char* and z is an integer. Normally then the expression (y+z) would mean in C++ "a char pointer which points at the character at index 'z' of the string stored in y." But with operator overloading in the language, you can never be too sure. Maybe somewhere in the code the programmer thought it would be a good idea to say that char* plus int really means "convert the string to integer with atoi(), then add the integer second argument to it, then convert back to string form and return that."

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    8. Re:Programming shortcuts by Arandir · · Score: 1

      So stop abusing operator overloading. When you overload '+' for char* you are abusing the mechanism. However, overloading '+' for string makes sense.

      The syntactic sugar I would really like to see for C++ is the ability to write your own operators. Then you could use statements such as "x = y cat z". (of course what I really want is a readable object oriented functional language suitable for systems programming)

      --
      A Government Is a Body of People, Usually Notably Ungoverned
    9. Re:Programming shortcuts by slagdogg · · Score: 2, Funny

      The problem is that some syntatic sugar doesn't actually increase readability. Consider operator overloading.

      Maybe it's just me, but I think operator overloading is closer to syntactic poison than syntactic sugar ...

      --
      (Score:-1, Wrong)
    10. Re:Programming shortcuts by dasmegabyte · · Score: 3, Interesting

      "Shortcuts" are not the problem. Stupidity is the problem. A good programmer, or at least a kind programmer, uses "shortcuts" so that somebody else can figure out what's going on without having to everything about an object.

      Enumerated types will save your ass the first time you change databases or some project manager adds a new "status level" in between DONE and FINISHED. They are much faster than using internalized strings, which is how I had been testing for this crap. Remember, once they hit the object code they're just constants anyway...

      Foreach was easily the coolest thing about C# when I started using it, indexers were the second, and the code they create is FAR more maintainable than for(Object o = someList.FirstItem(); o != someList.LastItem(); o = someList.NextItem()){ ...}.

      Automagic "boxing" is a beautiful thing for newbie coders...I have had to teach so many the difference between a Byte and a byte that it isn't funny. I intend to use it, too...we pass in and out of the classes for char, int, byte, bool etc so often it makes sense to have the compiler/VM do our dirty work for us.

      And generics...well, they look real queer in Java, where we've never used the syntax before. But they will save our behinds on reuse! Besides no doubt being faster, it will make more sense when typing collections of inherited objects. We have a BaseRecord class. We have an optimized BaseRecordColl class, usually full of different types of ChildRecord classes. If we can write the one collection class, and not have to explicitly cast each child op, it will save time, space, and hassle...and avoid calling the superclass methods of uncast subclasses!

      Metadata is the only ingredient here that seems like it could cause trouble, and if it does it will be because people are using it wrong. Java is not a language that inlines...that's the whole idea of the JIT...and with today's cut and paste GUI IDEs, there's no need for programmers to use the lazy C declarations of the past. If people start doing so because it's neat, just nip it in the bud. Find/Replace when the code hits your desk. Eventually they'll get the hint.

      --
      Hey freaks: now you're ju
    11. Re:Programming shortcuts by battjt · · Score: 1

      Uhm. Large projects have lots of programers who are not in a position to dictate how things are put together and have to use what they are given.

      Though I've always thought that arbitrary operators would be nice, I wouldn't take that code to work.

      Joe

      --
      Joe Batt Solid Design
    12. Re:Programming shortcuts by Ed+Avis · · Score: 1

      Using shorter notation does not lead to increased maintenance. Of course using shorthands stupidly is a maintenance headache, but so is doing anything stupid.

      Far more of a problem in maintenance, I have found, is wading through pages of boilerplate code when a couple of function definitions and maybe macros or code generation would have let the same ideas be expressed much more concisely and with less repetition.

      --
      -- Ed Avis ed@membled.com
    13. Re:Programming shortcuts by p3d0 · · Score: 1
      Right. So what languages need is the ability to make rules. Fred Brooks' visionary superstar programmer (with the brains of ten ordinary programmers) can make rules that the compiler enforces. The rest of the team then must follow the rules, or else (1) their code won't build, or (2) they must negotiate the rules with the superstar.

      In your case, you need a rule like "overloading + is disallowed except in the following specific cases: (...)". Then the superstar could see to it that the few exceptions won't surprise anyone. If the compiler enforced this rule, you wouldn't constantly need to worry about that harebrained strangeness any dummy on the team might come up with.

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    14. Re:Programming shortcuts by Anonymous Coward · · Score: 0

      If y is a char* and z is an int, then evaluation of (y+z) has nothing at all to do with operator overloading. Operations on builtin types are defined by the language, you cannot change them. If you are indexing into an array then you should not be using an int. Strings in C++ are not represented using null terminated char arrays. All of that aside, I fail to see any substance to your argument. It seems the same thing applies if I say a.function(). Now I can never be too sure what this is going to do... unless of course I take the time to look at the interface for the given type, which will also contain any overloaded operators.

    15. Re:Programming shortcuts by Ed+Avis · · Score: 2, Insightful

      No - distinguish between syntactic sugar, which gives you a new syntax to express what you could have said anyway, and real language features.

      For example array access with [] in C is syntactic sugar, since you could do the same with pointer arithmetic - a[b] is exactly equivalent to *(a+b). However a declaration of an array variable:

      int a[1000];

      is _not_ syntactic sugar, since there is no other way to reserve space for a thousand contiguous integers on the stack. You could use malloc() from the standard library, but as you know that allocates on the heap and you have to free the memory afterwards.

      (OK you could have a thousand 'int' declarations but I don't think it's guaranteed they will be a contiguous block in memory.)

      As an example of a language with no syntactic sugar, look at Unlambda (although you wouldn't want to program in it). The language syntax is minimal but semantically it is a long way off from raw machine code.

      --
      -- Ed Avis ed@membled.com
    16. Re:Programming shortcuts by p3d0 · · Score: 1
      Metadata is the only ingredient here that seems like it could cause trouble, and if it does it will be because people are using it wrong. Java is not a language that inlines...that's the whole idea of the JIT...and with today's cut and paste GUI IDEs, there's no need for programmers to use the lazy C declarations of the past. If people start doing so because it's neat, just nip it in the bud. Find/Replace when the code hits your desk. Eventually they'll get the hint.
      I'm sorry, this whole paragraph just went over my head, but it sounds insightful, so I'd like to understand it.

      What does "with today's cut and paste GUI IDEs, there's no need for programmers to use the lazy C declarations of the past" mean?

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    17. Re:Programming shortcuts by Grievance · · Score: 1

      Hear, hear!

      when i see a programmer's method named DoSomething, i instinctively ask myself how much i trust the programmer -- does the method really Do Something? does it (also) Do Something Else that's not documented?

      having to ask the same questions of a language's operators ("does + have side-effects here?") is anathema...

    18. Re:Programming shortcuts by willtsmith · · Score: 2, Insightful

      Any language feature can be abused and used in inappropriate ways. I once knew a programmer who included comments like the following. // I'm really tired now. ... // Gosh gotta go to the bar ... // I'll never do this again // Source control is my enemy, they'll know who writes all these stupid comments ....

      Obviously he wasn't using comments correctly. And sometimes would even obfuscate by not modifying comments to reflect code changes.

      However, this is not a reasonable arugment for why comments should NOT be part of a higher level language. Some people actually write usable comments that add something to code.

      Same thing is true with operators. The fact that some yahoos assign weird functionality to operators doesn't diminish the uses for operators AND the ability to write large volumes of code shorthand through operators.

      As far as syntactic sugar goes, as long as the compiler processes it correctly, it's good. Writing the same pieces of code OVER, and OVER, and OVER, and OVER, and OVER, and OVER, and OVER is a waste of time (AND MONEY!!!!). It's a job better left to a compiler. If a programmer can't grasp or understand newer constructs (beyond cut and paste :-), they should question whether they're in the right field.

      --
      -------- -------- Support Wesley Clark for president!!!
    19. Re:Programming shortcuts by Anonymous Coward · · Score: 0

      I feel using programming shorthand leads to increased maintenance

      I agree. This is why I never create my own functions or methods. Evey program should be just one big function.


      Thats why I ditched assembly and program on the bare metal, baby!

    20. Re:Programming shortcuts by Anonymous Coward · · Score: 0

      Your post makes no point. If you can't trust other people's methods/operators, feel free to write everything yourself...

    21. Re:Programming shortcuts by atomray · · Score: 1

      The syntactic sugar I would really like to see for C++ is the ability to write your own operators. Then you could use statements such as "x = y cat z".

      Declaring your own operators, huh? Is it really that hard to type a couple brakets?
      x = cat(y, z);

      --
      take your sig and shove it
    22. Re:Programming shortcuts by radish · · Score: 1

      I'm pretty sure, if you were willing to go through the right hoops, you could get a block of 1000ints on the stack without using int[]. Find out where the stack is, start rewriting the frame yourself...etc? Please forgive my lack of C knowledge - I've been a Java boy for too long ;)

      I guess my point goes back to Turing. When it boils down to it your C or Java or anything else gets turned into little processor ops. The whole notion of assembler is a syntatic sugar for machine code - it doesn't let you do anything new. A compiler on top of that again doesn't let you do anything new - it just makes it easier. Someone COULD rewrite the whole linux kernel in 1's and 0's, but doing it in C is easier.

      I do see your point about the difference between fundamental features and sugars within a particular language, but I guess I feel that on a wider scale the whole notion of lanugages is a sugar in itself.

      Anyway to get back to the original point - I do have problems with operator overloading (at least the free-for-all you get in C++), but generics has a better feel around it. That will allow people to more clearly express their algorithms (there's nothing worse than an undocumented method which just takes a List!) and will also allow more type checking to be done at compile time.

      Hey ho :)

      --

      ---- Den ene knappen er powerknapp, den andre er Bender voice knapp "Bite My Shiny Metal Ass"

    23. Re:Programming shortcuts by Ed+Avis · · Score: 1

      Of course every language feature 'just makes it easier' in some sense, and there's nothing you can do in a high-level language that can't be done in assembler. But it will confuse people if you describe these things as 'syntactic sugar'. That's the point.

      Actually I would dispute that assember is wholly a syntactic sugar for machine code - consider labels for example, there is no way to put labels in the middle of your raw machine code and have them automatically be updated to a new address when you inser some code before them.

      --
      -- Ed Avis ed@membled.com
    24. Re:Programming shortcuts by Anonymous Coward · · Score: 0

      Except that operators can only be overloaded in C++ when one or both of their operands is of class type. You can't overload operator+ for char* and int operands.

    25. Re:Programming shortcuts by hoop33 · · Score: 1

      Evey program should be just one big function.

      I once worked with a PowerBuilder point-and-clicker, and he was complaining that he couldn't edit his "code" anymore. It turned out that he had stuck all his code inside one button, so the code was exceeding the char limit on a text field (Win 95--I think it was 32K) and crashing PowerBuilder. I told him to break his stuff out into functions.

      He said, "Huh?"

    26. Re:Programming shortcuts by jtdubs · · Score: 1

      You seem to be advocating the perspective that "any feature which can potentially be abused should just be removed preemptively."

      I think that's bullshit.

      Used responsibely, operator overloading can be a wonderful thing. In particular, overloading the mathematical operators for classes like Matrix and Vector. Also, overloading the [] operator for collections as well as the aforementioned Matrix and Vector classes.

      As long as you follow the principle of least surprise and don't overload the + operator to take square roots it's really not a problem.

      Justin Dubs

    27. Re:Programming shortcuts by jcast · · Score: 1

      In that example, no. But consider something like (a.toString () cat c.toUpper () cat ", " cat b.toLower ()) vs. cat(cat(a.toString (), c.toUpper ()), cat(", ", b.toLower ())). Still don't think it's a big deal?

      --
      There are reasons why democracy does not work nearly as well as capitalism.
      -- David D. Friedman
    28. Re:Programming shortcuts by lokedhs · · Score: 1

      The problem is that you can't force library writers to follow your rules. Case in point: iostream

    29. Re:Programming shortcuts by be-fan · · Score: 1

      Since all overloaded operators require at least one class arguement, your example can't really exist. Thus, what you're left with is that you have to be aware of what operator overloads are in place for the class you're using. At that point, it's really no harder than just remembering what methods do. Say you have to Matrix classes. You see:

      a = b + c;

      Is that really any more ambiguous than:

      a = c.addTo(b)

      Now if you have multiple overloads in effect, then yes, things can get ambiguous. But IIRC, Java has function overloading, so over-loaded code can occur just as easily in that language. In fact, since operators are just a specialization of functions, it's not orthogonal if you can overload functions but not operators.

      --
      A deep unwavering belief is a sure sign you're missing something...
    30. Re:Programming shortcuts by atomray · · Score: 1

      new StringBuffer().append(a).append(c.toUpper()).appen d(",").append(b.toLowerCase()).toString();

      --
      take your sig and shove it
    31. Re:Programming shortcuts by dasmegabyte · · Score: 2, Informative
      Let's say you have a really complex, but SMALL, algorithm that you do all the time. Going into a new function takes resources even when compiled (basically, the CPU pops your current work onto the stack, flushes the current command queue and any fancy branch prediction going on, and moves to the memory location of the function EACH TIME it's called)...so C programmers invented this method called inlining.

      (this next bit is a very simple and very halfassed explanation in pseudo C. flames from C programmers about the bad syntax will be ignored. i got a D in C so F it)

      Inlining works like this. You write a function and assign it a variable name. Then, any place you want that function, you use the variable name. The "precompiler" converts any instance of the variable name into the original function. EX:
      #DEFINE PISETUP
      int pi;
      pi = 22/7;
      #ENDDEF
      Later, if you use the term PISETUP it will be replaced with that code by the precompiler.

      This was a good way to facilitate rewriting the same thing over and over, while maintaining speed, and a single location to change/fix the function. Unfortunately, it was also a good way for lazy programmers to obfuscate code by creating precompiler directives and variables for common language patterns. EX:
      #DEFINE STARTIF
      if (
      #ENDDEF
      #DEFINE CLOSEIF
      )
      {
      #ENDDEF
      Used to make:
      if ( true )
      {
      beep;
      }
      into:
      STARTIF true CLOSEIF beep; }
      Shorter, yes. But harder to read, much harder to understand, and absolutely confusing for the poor newbies. Kind of like learning how to read from logs of an AOL chatroom.

      One of the big "innovations" of Java was the elimination of the precompiler, which made sense. Java runs object code, not directly runnable byte code, so it is in essence already performing the tasks of the precompiler. The virtual machine "compiles" the code while it is running, to optimize for the individial physical machine, no matter what it may be.

      The idea worked IMO because, now that you can cut, paste, and find and replace (with regular and replace expressions), you don't really need these replacements. Might as well just be verbose as you want to be. Might as well use tiny little functions since inlining doesn't work anyway.

      Besides, since Java is interpretted and recompiled while it's running, you don't gain anything from inlining. Any "contextual" function (the function as written in the code) might become "inlined" when run by a good virtual machine program that performs "Just In Time" (JIT) compilation. Call void incrememtI(){ i++; ) a lot? The compiler will notice this, and replace calls in the stack to incrememtI() with the actual code this function contains. .NET does this with simple Properties...which results in a sincere benefit to using Properties for ALL inter-class data assignment and for some intra-class assignments as well.

      This is why Metadata is a bad idea, or could be. No real benefit to the code, not much of a benefit for the "thorough" developer, and yet there's a real chance for lazy folks to create disgusting, hard to maintain code. This is never a good idea...a lot of coders think that obfuscated code makes them more valuable to employers. Not half...they'll axe you first if they think you're playing the obscurity game and will not give great references if you leave first.

      Of course, if all Metadata does is replace:
      // @Property:int ID
      with:
      private int id;
      void setID(int value){ id = value; }
      int getID(){ return id; }
      Then it may be worthwhile. Time, and the Java Community, will tell.

      (PS: Used to work for/with a Pat Doyle, but he's not you)
      --
      Hey freaks: now you're ju
    32. Re:Programming shortcuts by n.wegner · · Score: 1

      Alloca will reserve space on the stack, but not if you're using MS' CRT.

    33. Re:Programming shortcuts by Anonymous Coward · · Score: 0

      Well, the whole point of operator overloading is to increase readability. If people abuse it, it will decrease it. But I much prefer comparing strings with "=" as opposed to calling String.equals, as you're required to do in Java.

    34. Re:Programming shortcuts by radish · · Score: 1

      Fair enough - I used the wrong term :) I guess I should have paid more attention when my Modula-2 lecturer kept using the phrase ;) It was his favourite (came in just above my Smalltalk lecturer's obsession with a Whale called Momo).

      --

      ---- Den ene knappen er powerknapp, den andre er Bender voice knapp "Bite My Shiny Metal Ass"

    35. Re:Programming shortcuts by OeLeWaPpErKe · · Score: 1
      NO language has matrices built in as a primitive. Which is clearer :
      • a.multiply(b).add(de).multiply(c).add(d)
      • (a * (b + de) * c) + d

      I wouldn't dismiss them so easily. Finding bugs in formulas is a bitch. Finding bugs in reverse-polish-notation formulas is ... let's not go there.
    36. Re:Programming shortcuts by DunbarTheInept · · Score: 1

      I'm not complaining about code *I* write. The point is that it lets other people write code that is slow to read and understand. Just because *I* would never use overloading that way doesn't mean I won't be affected by it when someone else does and I have to deal with their code.

      I do agree about being allowed to write your own operators. It would be nice. And it gets around the overloading problem. (You know it's a made-up operator because it's using a syntax not in the original language.) The reason this hasn't been done is how incredebly hard it is to implement it. You need to tell the scanner of the compiler about the new operator so it can return it as a different kind of token from just plain 'identifier'. Consider your "y cat z" example. If "cat" is a user-defined method, then the scanner will return that code as just "identifier, identifier, identifier" - leaving the parser with no clue what to do with it. So for this idea to work, the parser has to be able to tell the scanner to make changes to itself partway through the run. As in, "Hey scanner - from now on when you see "cat" I want you to return that to me as a binary operator token." then y cat z would become "identifier binary_op identifier". And I haven't even really touched the issue of operator precedence.

      These I think are still solvable problems, though, if someone was ambitious enough to work on them. (The operator definition would also need a way to define precedence - perhaps as a simple integer where the smaller the number the 'tighter' the precedence for that operator, and if two operators of equal precedence cause an ambiguity, then resort to left-to-right evaluation.)

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    37. Re:Programming shortcuts by DunbarTheInept · · Score: 1


      As long as you follow the principle of least surprise
      and don't overload the + operator to take square roots it's really not a problem.

      please refer to my example. The problem comes when you overload an operator that already has a different meaning, confusing anyone reading the code who doesn't know about your overload. In my example, the operator '+' already meant pointer-offset arithmetic. I changed it to mean "numerical addition to the string interpeted as an int". It's a valid understanding of what '+' could mean. It's logical. But it's getting in the way of an existing operation.

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    38. Re:Programming shortcuts by bmckeever · · Score: 1
      > But with operator overloading in the language, you can never be too sure.

      You are not allowed to overload operators that take 2 build in types for this very reason. You can declare a class, and try to get an implicit conversion into the mix, but I don't think it works. Do you have an actual code sample, or is this FUD?

      --
      Your favorite .sig sucks
    39. Re:Programming shortcuts by Anonymous Coward · · Score: 0

      Yeah, at the company I had worked for, they were removing my very well written structured classes with methods and writing whole thing into a single method in one of the available classes and naming it in the source tree - 'We optimized it'. If you make a civil engineer the head of the software development, that is what you get. .

    40. Re:Programming shortcuts by jtdubs · · Score: 1

      Right. Your example would violate the principle of least surprise. You /expect/ pointer arithmetic to work in C. So, it is a bad use of operator overloading.

      However, I can't think of any times in which it is a good idea to do pointer arithmetic on a pair of Matrix* objects. So, I have no big problem with overloading the + operator for these types. At the very least it should be safe to overload them for const Matrix&'s.

      So, the result in my mind is that operator overloading can be mis-used in horrible horrible ways, but that shouldn't prevent people from using it the few ways in which it is useful.

      Justin Dubs

    41. Re:Programming shortcuts by rsborg · · Score: 1
      Any language feature can be abused and used in inappropriate ways. I once knew a programmer who included comments like the following. // I'm really tired now. ... // Gosh gotta go to the bar ... // I'll never do this again // Source control is my enemy, they'll know who writes all these stupid comments ....

      Your example is pretty weak (aka, a strawman). In the case of operator overloading, the code that looks like one thing can mean another. In your poor example, comments can be simply ingored (a 5 line perl program can strip out the useless comments), and don't affect the code operation. There's a big difference between cruft and intentional misinformation.

      --
      Make sure everyone's vote counts: Verified Voting
    42. Re:Programming shortcuts by krumms · · Score: 1

      Well, yeah - but adding a char* to an int doesn't really make sense anyway.

      Abstraction should mean that the operators make sense. I don't mean mathematical sense, I mean common sense.

      For example, the String/std::string/string + operator you find in Java/C++/C# respectively is a good example. It makes sense to a reader that seeing a += b (where a and b are strings, of course) means 'append b to a'. It's obvious.

      Operator overloading is a tool of abstraction. Use it where it makes sense.

      Otherwise, don't.

    43. Re:Programming shortcuts by lsdino · · Score: 1

      Wow, you said a lot, and didn't really describe anything very well.

      First you're blending inlining and macros. Beginning with "Inlining works like this" and ending with "since inlining doesn't work anyway" you're talking about macros. Your next paragraph talks about inlining - in that a JIT can perform this optimization. But nearly all compilers perform this simple optimization all the time, including a JIT, because it's also a compiler.

      So, now that we all know that inlining is moving functions inline within other functions, either by programmer or compiler, we can move onto macros, which the bulk of your post discusses. The idea that "today's cut and paste GUI IDEs" can replace macros is insane. Macros provide a feature that functions cannot. While your trivial examples (and your quote was originally about C, yet your code is not C) don't demonstrate this at all. A more common example would be "#define max(a,b) ((a)>(b))?(a):(b)"

      This is an extremely typical use of a macro. And it's bad & wrong. A function would be much better here, would be inlined by the compiler (in either Java or a traditional compiler), and wouldn't have problems when you did "foo = max(x++,y++);" where you end up doing an accidental double increment.

      So, a little off topic, but macros do provide functionality that is not otherwise available. As one of your snippets begins to show it allows you to redefine the language. For example, let's say I want to add exception handling to C. I make a few macros:

      #define TRY { int error = 0; {
      #define CATCH } {\
      catchlabel:
      #define ENDCATCH } }
      #define THROW(errNo) error = errNo; goto catchlabel;

      Sure, it's primitive, but I also spent 5 minutes typing it into a little tiny window on Slashdot, so what do you expect? If you work with it you can do more. You could get crazy & start using setjmp & longjmp for your error handling needs to make it work cross-function. And while Java may offer such functionality, there is other functionality it does not offer that could be "added" using macros (eg contracts).

      So why is this better than copy & paste? When you copy & paste you make mistakes. (Ever seen someone screw up copy & pasted error handling code? It happens all the time, and error handling code never gets tested. Easy mistake, you forget to update a variable name). Second it allows changes in one central location. Sure, max is never going to change. But my error handling routines might change. And other extensive "language features" I may want to add should be contained in a central location similarly.

    44. Re:Programming shortcuts by Anonymous Coward · · Score: 0

      how wrnog wrnog wrnog! every function should be only one line, such as "oneTrueObject.doProgram()" and "subthing.recursiveDelegate()" and loops calling "pixel.drawSelf()"

    45. Re:Programming shortcuts by pyrrho · · Score: 1

      >you can never again know what on earth is going on when you see x = y + z, unless you are aware of every operator overload which was used.

      You just have to know the types of the variables, a reasonable requirement in making any data manipulation.

      --

      -pyrrho

    46. Re:Programming shortcuts by creinig · · Score: 1

      In the case of operator overloading, the code that looks like one thing can mean another. In your poor example, comments can be simply ingored[...]

      MyString foo = "Hello";
      foo.concat(" World");

      Looks pretty clear, right? Well, unless you are aware of that:

      class MyString extends String
      {
      public String concat(String aString) {
      return aString + this;
      }
      }

      Of course I'm aware that this will not occur as likely as operator overloading misuse, but I think you get my point. I personally prefer using a language that aims to fit the needs of competent programmers over one that tries to be something even lawyers can use ;)

    47. Re:Programming shortcuts by vanyel · · Score: 1

      Although an amusing statement, I've also seen code that abused subroutines to the point of making it really hard to figure what the heck it was doing. Part of it (actually, probably a large part) was bad naming and bad structuring, but every guideline needs common sense applied to it.

    48. Re:Programming shortcuts by p3d0 · · Score: 1
      Wow, was I ever wrong. Maybe you're playing a joke on me, but I'm going to assume your post is a serious attempt to explain inlining and the perils of metadata.

      To begin with, I'm a JIT compiler developer. I know what inlining is. That's not what I was asking.

      Second, your claims are wrong in almost every sentence. For instance, here is one particularly attrocious paragraph:

      Inlining works like this. You write a function and assign it a variable name. Then, any place you want that function, you use the variable name. The "precompiler" converts any instance of the variable name into the original function. EX:
      #DEFINE PISETUP
      int pi;
      pi = 22/7;
      #ENDDEF
      Later, if you use the term PISETUP it will be replaced with that code by the precompiler.
      What's wrong with this?
      • Functions are assigned function names. Variables are assigned variable names. They are two different things.
      • In C, it's called a "preprocessor", not a "precompiler", though I guess the latter makes just as much sense.
      • Your example is not a function. It is a variable declaration with an initialization. Therefore inlining doesn't apply.
      • The preprocessor has nothing to do with inlining. What you're describing is macro expansion.
      • pi is not 22/7!! :-)
      A few more remarks:
      One of the big "innovations" of Java was the elimination of the precompiler, which made sense. Java runs object code, not directly runnable byte code, so it is in essence already performing the tasks of the precompiler. The virtual machine "compiles" the code while it is running, to optimize for the individial physical machine, no matter what it may be.
      Java is a language, and doesn't run anything. The Java Virtual Machine (JVM) runs bytecode, not directly runnable object code. The virtual machine may or may not use a JIT compiler to optimize for the individual machine. Any half-decent JIT compiler performs inlining, or else performance would be terrible; however, inlining is not what you think it is.

      The idea worked IMO because, now that you can cut, paste, and find and replace (with regular and replace expressions), you don't really need these replacements. Might as well just be verbose as you want to be. Might as well use tiny little functions since inlining doesn't work anyway.
      Hot damn, I hope I never need to deal with any code you write. This attitude is appalling. I'm going to go out on a limb and guess that you are not a professional software developer?

      When you said "Java is not a language that inlines...that's the whole idea of the JIT" I thought you were correctly pointing out that Javac doesn't (and can't) do inlining. Apparently I was mistaken.

      Anyway, thanks for taking the time to explain yourself.

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    49. Re:Programming shortcuts by p3d0 · · Score: 1

      You mean, you can't do it in C++. I agree. I was speaking more generally about the kinds of things programming languages should be able to express.

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    50. Re:Programming shortcuts by Anonymous Coward · · Score: 0

      In Haskell, user-defined infix operators are surrounded by `backticks`.

    51. Re:Programming shortcuts by Anonymous Coward · · Score: 0

      Actually, Java strings are interned, so strings that are equal will have the same reference, so string1 == string2 will work.

    52. Re:Programming shortcuts by Bingo+Foo · · Score: 1
      Operator overloading is a tool of abstraction. Use it where it makes sense.

      Otherwise, don't.

      Stop it. Now. This is Slashdot, you can't be that reasonable and concise here.

      --
      taken! (by Davidleeroth) Thanks Bingo Foo!
    53. Re:Programming shortcuts by TenDimensions · · Score: 1

      Same thing is true with operators. The fact that some yahoos assign weird functionality to operators doesn't diminish the uses for operators AND the ability to write large volumes of code shorthand through operators.

      But you didn't post a reason to include operator overloading in a language other than not having to write the same pieces of code over and over and over again. At the same time I think you refuted your own argument - copy & paste allows me to refer to the same method call as often as I want with the same amount of keystrokes if I had overloaded &&.

      Overloading operators always just seemed like a feature that normally powerless geek programmers existing in reality could use in order to make themselves feel so much more powerful in the abstract cyber realities of silicon.

    54. Re:Programming shortcuts by Anonymous+Brave+Guy · · Score: 1
      The problem is that some syntatic sugar doesn't actually increase readability. Consider operator overloading.

      OK. I claim that operator overloading can be used sensibly, and that contrary to claims of its detractors, this seems to happen most of the time even in C++. I further claim that when used sensibly, operator overloading significantly increases readability and maintainability. It is also a necessary feature to co-ordinate with writing generic algorithms using tools like C++'s templates. (Yeah, they have nasty syntax at times, but they're way better than nothing.)

      Let's say y is a char* and z is an integer. Normally then the expression (y+z) would mean in C++ "a char pointer which points at the character at index 'z' of the string stored in y." But with operator overloading in the language, you can never be too sure.

      Of course you can be sure. You can't overload operator+(char*, int) since it takes two built-in types and overloaded operators must use at least one UDT. You can overload operator&&, which in my view is a flaw in the current C++ scheme, but this is a well-known issue and standard practice is not to do it.

      If you really think operator overloading is a bad thing, perhaps we should all give up forming strings using "Hello, " + name + ", how are you?" and go back to good ol' strcat and friends? Of course, Perlesque interpolation ("Hello, {name}, how are you?") is often cleaner still in this particular case, but one thing at a time! :-) (And it has its own disadvantages too.)

      In general, the overloading of arithmetic operators for numeric classes such as matrices or complex numbers, the overloading of indexing operators for container classes, the overloading of increment/decrement/dereferencing operators for iterators and such all lead to code that looks more consistent than if you have a mishmash of arbitrarily named functions for each type to do the same thing.

      As long as the person who writes the overloaded operators does so sensibly -- and you can write any function to have stupid side-effects, so this is no different to writing any other code -- the benefits in consistency are valuable aids to readability and maintainability. Don't look at what can be in the worst case, look at what can be in the best case, and most important of all, what actually happens. In this case, history amply demonstrates that operator overloading can be of genuine value in real world projects.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    55. Re:Programming shortcuts by Anonymous Coward · · Score: 0

      You can stop abusing operator overloading. I can stop operator abusing it. But can you stop every programmer in your organization (even the most ignorant/beligerant) from ever doing the wrong thing with regards to this and similar language features?

      Until you can, you're better off without operator overloading and other obfuscating features if you work in an organization of any size. Else maintenance becomes a real nightmare!

      Would you rather use a language without this stuff or invest a lot of time/money in automated code policing? Personally, I'd just rather not have it in the language to begin with -- unless I'm writing code all by myself. Then *and only then* all these language features are cool.

      As a language, C++ is really quite cool for some things if you're the only one writing code for a project. The multi-programmer issues that arise can be a big of stumbling block, however. All this pales when compared to 2 issues, however:
      * memory management headaches
      * lack of simple object persistence [or even good language support on which to base this], cross-platform GUI libraries, etc, etc, without wedding yourself to Microsoft (and thus throwing out cross-platform), re-inventing the wheel from scratch, or paying through the nose to a bunch of 3rd parties..

      C#, etc, seem to be inheriting some of these issues by providing operator overloading, automatic/hidden get/set accessors, and not dealing with GUI's outside the context of Microsoft Windows. The only one of these big issues addressed by C#, et al, is memory management -- and one can still duck into unsafe land and screw oneself with pointers

    56. Re:Programming shortcuts by rsborg · · Score: 1

      Thank you for agreeing with me. How again can comments be dangerous?

      --
      Make sure everyone's vote counts: Verified Voting
    57. Re:Programming shortcuts by alder · · Score: 1
      Consider operator overloading. If your language has that, you can never again know what on earth is going on when you see x = y + z, unless you are aware of every operator overload which was used.
      This is a very popular argument in operator overloading detractors. Yet it is illogical. Operators have a predefined meaning, and semantically correct overloading will not change it, i.e. overloaded operator will be read consistently and similarly to those provided by a language. Incorrect overloading is possible, but is it any different from ignorant misuse of other features of any language, including assemblers and machine codes? :-)

      Maybe somewhere in the code the programmer thought it would be a good idea to say that char* plus int really means "convert the string to integer with atoi(), then add the integer second argument to it, then convert back to string form and return that."
      The very same argument can be applied to incorrect naming of a method. Will the described scenario be any different if instead of overloading "operator +" a developed creates a method "plus(int)", or "add(int)", but really means something else? Operators are just convenient shortcuts, symbols that we agreed to use within a cernain context and in a certain way. They are not any different from words we use to name methods. They are just shorter, and(!) if used corrently they really and dramatically improve readability.
    58. Re:Programming shortcuts by alexo · · Score: 1

      > NO language has matrices built in as a primitive

      APL?

    59. Re:Programming shortcuts by J.+Random+Software · · Score: 1

      Strings constructed at runtime aren't interned, only literals and constants. Otherwise they wouldn't have had to provide an intern method or override equals.

    60. Re:Programming shortcuts by angel'o'sphere · · Score: 1


      Maybe somewhere in the code the programmer thought it would be a good idea to say that char* plus int really means ...


      Well, you are wrong. Your fear is the precise reason why you can not redefine(not overload :-), but redefine) existing operators.

      (char *) + (int) is an existing operator.

      If you fear that (Matrix) * (Scalar) is not what every mathematics would expect ... then you are paranoid. In case you are right, the provider of the operation has made a fault. Both is fixable :-)

      regards,
      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    61. Re:Programming shortcuts by Minna+Kirai · · Score: 1

      Today, some people virtually consider MATLAB to be a programming language. It finds its way into large engineering projects via a MATLAB->C compiler. And of course, it has native support for matrices.

  7. Everything must change... by Toy+G · · Score: 1

    ... for the things remaining the same.

    It seems to me that the suggested syntax for generics simply moves the pain from casting at retrieval time to casting at declaration time. That is, dynamic typing is still far away. Sigh.

    --
    -- Let's go Viridian.
    1. Re:Everything must change... by Grievance · · Score: 3, Insightful

      As others have pointed out, moving move type information into the declaration allows the compiler to help eliminate several kinds of type errors generated by programmers.

      Now, if you want a weakly/dynamically/non-typed language, you should use one, and deal with the inevitable tradeoffs. It's not like there's a shortage of non-strongly-typed languages out there.

    2. Re:Everything must change... by Malc · · Score: 2, Insightful

      Personally I like strong typing. The current approach of casting to (implicitly) and from (explicitly) Object violates this. IMHO, static typing saves far more pain in the long run than dynamic casting. If you like the general language, use JavaScript if you want to throw all that away.

    3. Re:Everything must change... by trout_fish · · Score: 1

      Is dynamic typing a good thing? Many would argue that it is not.

      Also, you generally declare data structures once, but use them many, many times.

    4. Re:Everything must change... by __past__ · · Score: 2, Insightful
      Java isn't strongly typed. It has static, or manifest, typing. Those two qualities are orthagonal.

      In a strongly typed language, there are no cast operators, and hence no ClassCastExceptions. You don't have these even in dynamically-but-strongly typed languages, like Lisp or Python.

      Java doesn't give you type safety, just type errors when you try to be smarter than the compiler, which isn't that hard. That is no surprise - it has been shown that proper type inference runs into the halting problem, by research on languages that at least try to be helpful rather than just annoying while maintaining static typing (like ML or Haskell). In this regard, Java combines the worst of both worlds, just like C and C++, even if it is otherwise better than them in almost everything.

    5. Re:Everything must change... by lokedhs · · Score: 1
      It's a good thing... At times... Those times you write your code in Lisp, or Smalltalk, or whichever weakly types language you prefer.

      At other times a strongly typed language is what you need. Then I use Java. WHich happens to be most of the time, for me.

      When is it a good time FOR YOU to use a loosely typed language? Hell should I know, you're the guy doing the programming.

    6. Re:Everything must change... by Anonymous Coward · · Score: 0

      It's not really casting if it happens at declaration time, but aside from that, I still think it's a real improvement. For one thing, there are cases when parameterized types are exactly what you need. In those cases, it's much clearer to declare the type of the variable once and then not have to add a cast every time it appears in an expression.

      If you really want dynamic typing, make all your variables of type Object. Java, unlike some other languages, does store the values' actual type information at runtime (otherwise there would be no way to generate exceptions due to bad casts), so it essentially is dynamic typing. Is there any real difference besides the fact that you must sometimes cast?

      Furthermore, Java provides a sort of middle ground between dynamic typing and static typing, which is interfaces. When declaring a variable, you can give an interface as its type. It can then store references to variables of any type that implements that interface. If you only do things that the interface describes (which IMHO makes the code clearer), you have almost all the benefits of both static and dynamic typing at the same time. You can treat your data very generically, but you get some verification that your generic data really has the set of properties you're expecting.

      Of course, I could be wrong about some things. It's been like a year since I've actively programmed in Java or in a dynamically typed language. But, when I learned Java, I was coming mostly from a Perl background (definitely not a lot of static typing there), and I just never felt like Java's type system was preventing me from doing useful things.

  8. Agreed.. by MilesParker · · Score: 5, Insightful

    ..Thought C# has some nice innovations, one of my big problems with it is that so many of its new 'features' are so much syntactic sugar. One of the big things I appreciate about Java is that there is typically onyl one right way to do something; a big change from C++ for example. Plus, modern IDEs like IntelliJ make it very easy to construct iterators and such [Ctrl-j itar..] That said, I don't think that the majority of the Java improvements are really sytactic sugar; things like generics will be very positve improvements. And its very important that Sun keeps up these improvements -- as long as they continue to be well thought out. Ideally we will continue to have a fairly state-of-the art language without any fluff.

    1. Re:Agreed.. by Erwos · · Score: 1

      "One of the big things I appreciate about Java is that there is typically onyl one right way to do something; a big change from C++ for example"

      This hasn't been my experience at all. There's rarely ever any one right way to do things in any language.

      Let's take a simple one in C: int x needs to become one larger. You get a few options:
      1. x++;
      2. ++x;
      3. x+=1;
      4. x=x+1;

      All of them are "the right way" of simply incrementing x. And, if the simple stuff is this varied, I have a hard time believing that more complex code won't have similar divergence from "the one path". Java is similar.

      -Erwos

      --
      Plausible conjecture should not be misrepresented as proof positive.
    2. Re:Agreed.. by MilesParker · · Score: 0

      Sorry, I should have been clearer; let's say one "best" way. You know like on the SAT, when they ask you what is the one best word and two or three of them sort of fit?

      In this case, the one righ (ok, best) case is always nearly always the simplest, least obsfucated and, most importantly, the most expected. In this case, that is clearly:

      1. x++.

      I'd be delighted to address more compex examples.

    3. Re:Agreed.. by stratjakt · · Score: 1

      each of your examples, by itself, is functionally equivalent, but completely different depending on it's use.

      while (++i 10) { } (preincrement)

      vs

      while (i++ 10) {} (postincrement)

      vs

      while (i 10 ) { i+=1; } (assignment with register increment)

      vs

      while (i 10) { i = i+1; } (assignment)

      They refer to the pre and post increment operators present on most CPUs and post increment with a register vs straight assignment in memory. C is inherently a lower level OS, and things like this are greatly useful when optimizing code.

      In a high level pseudo-interpreted language like Java, it's useless. But it serves its intended purpose when it comes to systems level programming.

      There's a fine line to be tread between orthagonality and optimization. Of course, these days, we just throw a faster CPU and more RAM at the problem, which is akin to "the door i bought doesnt fit in the opening of the house, so lets buy a new house"

      --
      I don't need no instructions to know how to rock!!!!
    4. Re:Agreed.. by Fnkmaster · · Score: 1
      Agree with you 100% here. Generics are a huge improvement, and I cannot possibly say how many times I have longed for them in Java.


      Recently I've been working in C++ again after many years away from it, and the things I miss most are the simplicity of learning a new API (nice, beautiful, clear, simple, hyperlinked Javadocs - and when the fuck will C++ people learn that you don't have to use every feature of the language in a public API), and beauty of IntelliJ. I mean, Visual C++ has some nice features (I find its debugging to be simple, and powerful), but god do I miss the beautiful syntax highlighting, drop-down completion and refactoring capabilities of IntelliJ. I, for one, would appreciate having an "IntelliC++". Having to manually reorganize code again feels like moving back to the fricking stone age. I'm sure the syntactic complexity of C++ makes this harder to achieve in a generalizable programmatic fashion. I think IntelliJ has made one of the strongest cases yet for Java by showing how the language lends itself to powerful IDE features that I haven't seen anywhere else (outside of the Java world).

    5. Re:Agreed.. by DunbarTheInept · · Score: 4, Interesting

      I'd say that "++x" is actually the "best" way because it puts things in verb-noun order, which I'm used to as an English speaker. "x++" is noun-verb, which feels strange to me. "++x" reads as "increment X", while "x++" reads as "x. increment it".

      (Just goes to show there will be differences of opinion and no such thing as "the" right way. Here's another example:

      if( x == 5 ) { do something }
      versus
      if( 5 == x ) { do something }

      Some prefer the second way because it puts the term which cannot be a valid lvalue on the left side, thus if you make the common typo of "=" instead of "==", you will get a compile error from it, which wold not happen for x = 5. But, it looks very odd to write it 'backward' like that, so some say the readability of doing it the 'dangerous' way makes it worth doing it that way.

      There is no such thing as "the" best way, not even in Java.

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    6. Re:Agreed.. by DunbarTheInept · · Score: 1


      pre and post increment operators present on most CPUs

      It's been ages since I did anything in ML or assembler, so my knowlege is rusty there, but why on earth would there be two seperate operators for increment in a CPU - one for pre and one for post? I would think all increment operators would operate on a single operand - either a register or memory location. They don't really "return" things like an expression in a high level language does, so the notion of a CPU instruction "returning" the incremented value or the pre-incremented value makes no sense to me. The notion of throwing a return value onto the stack after the operation is finished is a more high-level concept than the CPU deals with, or so I would think. CPU instructions operate on registers and memory locations in-place. Thus the difference between pre and post increments is what order instructions get called, not which instructions get called. For example:

      (foo++)
      load foo to accumulator
      push accumulator on stack
      increment accumulator
      store acculutator to foo

      (++foo)
      load foo to accumulator
      increment accumulator
      push accumulator on stack
      store accumutator to foo

      Same instructions, different order.

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    7. Re:Agreed.. by Shackleford · · Score: 1
      I'd have to say that some of those "new features" most certainly are syntactic sugar. Such as iterators in loops for example. My opinion is that there wasn't any need for the sort of shorthand that they added. I personally find that explicitly declaring the iterator in the loop makes the code more readable. I don't find it "ugly" as Mr. Bloch says it is. In addition, I usually prefer having only one way of doing everything. With different ways of writing code that performs the same task, it takes longer to parse the source code. So as it has been said before, it seems as though Java is becoming more and more like Perl.

      But there are definitely some new features that you have to like. Such as autoboxing/unboxing. I have always found it tedious to use wrapper classes when working with int/Integer.

    8. Re:Agreed.. by farnsworth · · Score: 1
      modern IDEs like IntelliJ make it very easy to construct iterators and such [Ctrl-j itar..]

      While it's cool that IDE's make stuff like this easy, it's really not much more than fancy copy-n-paste style coding, which can get dangerous. Have you ever found a copy-n-paste bug that exists in hundreds of methods?

      The sort of iterating that for(type t : collection) { } provides really *does* belong in the compiler, since it's what 99.9% of all iterations need to accomplish.

      --

      There aint no pancake so thin it doesn't have two sides.

    9. Re:Agreed.. by dhovis · · Score: 4, Insightful

      Actually, i believe that in Java

      if(x = 5)

      will throw a compiler error because (x = 5) does not resolve to boolean.

      That is something I like about Java, it doesn't allow you to do stupid things like that. There is no reason to do an asignment in an if() statement.

      --

      --
      The internet is the greatest source of biased information in the history of mankind.

    10. Re:Agreed.. by MilesParker · · Score: 1

      Politely disagree; in this case I think if(x==5) is clearly the "best" way.

      These cultural musings are very interesting and its fun to think about different rationales for doing things, but yea, there is a "best" way, or to nuance what I'm saying a bit more, a "preferred" way. And this is the "preferred" way, precisely because it is what most programmer's would expect. Any funny little idiosynchraies you introduce create cognitive dissonance and make the work for the rest of your team that much harder and less fulfilling.

      Paraphrasing Kent Beck IIRC, software syntax is not the place to express your creativity and independence. In particular, agile software development techniques such as Extreme Programming don't leave any place at all for people to pretend that there are not standards, and no such thing as the best way.

      I hope this doesn't come off as rude, but this is a pet peeve of mine, so let me put it in a very concrete way, given the current economic climate. If I was looking to hire someone, and as part of the hiring process asked them to pick the "best" way to write the above, and they answered "if(x == 5)" and you answered what you just said, they would get the job. :-D

    11. Re:Agreed.. by gh · · Score: 1

      The least obfuscated? On a line by itself, sure! When used in an expression, the same doesn't hold.

      Most programmers that understand the difference between pre/post inc/dec operators still tend to answer the following code snippet incorrectly:

      int x = 0;
      int y = 0;

      int z = (--y + x++);

      By no means am I suggesting they should be done away with, but I would not hold them up for display as the one "best" way especially when it would take only an extra two lines of code where there would be no uncertainty as to the intent.

    12. Re:Agreed.. by DunbarTheInept · · Score: 1


      There is no reason to do an asignment in an if() statement.

      I used to see this all the time in C:

      if( fp = fopen(....) )
      {
      }

      Meaning, "open the file, get the file handle, and oh, by the way, only do the following block of stuff if the attempt to do all that actually worked and gave a non-null pointer back."

      I rather liked it. The problem was it couldn't be used consistently in C because too many functions were designed to return zero on success and nonzero on failure, which is the opposite of what you want, and adds confusion to the readability if you try to treat it like a boolean. (I really hated seeing people say: if( !strcmp(...) ) Which has the opposite of the meaning it *looks* like it should have. When using that kind of function (where zero is success) I would never use '!' to negate it, but rather I'd use " == 0" as the check. Granted, it ends up meaning the same thing, but without the chance for extra confusion.

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    13. Re:Agreed.. by MilesParker · · Score: 1

      "I hope this doesn't come off as rude, but this is a pet peeve of mine, so let me put it in a very concrete way, given the current economic climate. If I was looking to hire someone, and as part of the hiring process asked them to pick the "best" way to write the above, and they answered "if(x == 5)" and you answered what you just said, they would get the job. :-D"

      I should say to be clear, all other things being equal. Its most importnat that you are a good coder, as working as part of an XP team can be trained...

    14. Re:Agreed.. by MilesParker · · Score: 1

      Well said -- I just meant that its not as big an issue for me in my day to day coding expereince..but you are absolutly right that your example is cleaner.

    15. Re:Agreed.. by Anonymous Coward · · Score: 0

      It's been ages since I did anything in ML or assembler, so my knowlege is rusty there, but why on earth would there be two seperate operators for increment in a CPU - one for pre and one for post?

      Because it made writing PDP-11 assembly language and the generated binaries more efficient.

      Remember that C was originally "high-level assembly for implementing Unix".

    16. Re:Agreed.. by iabervon · · Score: 1

      The JDK1.5 features seem to be mostly syntactic sugar to make doing things the right (compiler-checked) way easier than doing them the wrong way. A few (autoboxing, e.g.) just make doing things the right way reasonable. I'm not entirely sure that the implicit iterator thing was unreasonable before (it only removes two statements, and it was hard to get them wrong other than typing "iteraotr", unless, perhaps, you accidentally call next a second time on the iterator), so that's the least interesting change.

      On the unboxing issue, there's the annoying situation that you really ought to get a NullPointerException for consistency with the rest of the language, but it would be annoying to have it this way. Personally, I think you should be able to have something like "(m.get(word) : 0) + 1", where you say what value you want for null, and get a NPE if there's a null you didn't provide for (the colon is from ?:, of course).

    17. Re:Agreed.. by dhovis · · Score: 1

      You wouldn't do this in Java anyway. Failure to open the file would generate an exception.

      try{
      myFile = new File(.....)
      }
      catch(FileNotFoundException e){
      ....Error handling code here.....
      }
      catch(FileInUseException e){
      ....Different error handling code here...
      }
      Which I think is a lot easier to understand.
      --

      --
      The internet is the greatest source of biased information in the history of mankind.

    18. Re:Agreed.. by MilesParker · · Score: 1
      if( fp = fopen(....) )
      {
      }
      gackk! :-D
    19. Re:Agreed.. by slagdogg · · Score: 1

      Some prefer the second way because it puts the term which cannot be a valid lvalue on the left side, thus if you make the common typo of "=" instead of "==", you will get a compile error from it, which wold not happen for x = 5.

      You could always make 'x' final, producing the same compilation behavior with the more natural syntax.

      --
      (Score:-1, Wrong)
    20. Re:Agreed.. by oscarcar · · Score: 1

      Assignments are done in if() statements all the time.

      if ((var = myClass.getVariable()) != null) {
      var++;
      }

      Oscar

    21. Re:Agreed.. by Anonymous Coward · · Score: 0

      My ML is lacking as well, but IIRC, some architectures have "load with pre/post increment" instructions.

      So the ASM would be like:

      ++foo
      accumulator = 1
      load foo with increment to accumulator
      push accumulator
      store accumulatore

      or something like foo+=12

      accumulator = 12
      add foo to accumulator

    22. Re:Agreed.. by unborracho · · Score: 1
      Plus, modern IDEs like IntelliJ make it very easy to construct iterators and such
      Yes.. but Eclipse has some EXTREMELY nice features, including but not limited to CVS retrieval/storage, C/C++ Programming extensions, variable/class finders, integrated jar/javadoc creation, and all the features you mentioned intelliJ had you can also find with Eclipse. I would reccomend this over intelliJ anyday for its c/c++ support alone.
      --
      "You had this look that of an angel, it was such a bad disguise" --Dishwalla
    23. Re:Agreed.. by Paradise+Pete · · Score: 1
      You could always make 'x' final

      Tough to use it as an iterator, though.

    24. Re:Agreed.. by fastdecade · · Score: 1

      "x++" is noun-verb, which feels strange to me. "++x" reads as "increment X", while "x++" reads as "x. increment it".

      True, noun-verb is not like English, but if you fnid it strange, I suggest avoiding Object Oriented languages altogether!

      x++ is probably the most object-oriented piece of C syntax around, ie it is semantically equivalent to x.increment().

    25. Re:Agreed.. by mingot · · Score: 1

      ..Thought C# has some nice innovations, one of my big problems with it is that so many of its new 'features' are so much syntactic sugar.

      A few examples, please?

    26. Re:Agreed.. by gheidorn · · Score: 1

      That's a pretty narrow view of the world, my friend.

      Rather you should be asking the potential employee if he/she has a problem with observing your company's coding standards. Then hire the person who will follow whichever way your company uses if(x == 5).

    27. Re:Agreed.. by lscoughlin · · Score: 1

      yes, execpt those are not all equivalent statements.

      X++, x+=1 and x=x+1 are all "roughly" equivalent, but they have different meanings.

      ++x is a different creature all together.

      Try changing all your for loops from stuff like

      for(int i = 0; i someval; i++ ) {

      to

      for(int i = 0; i someval; ++i ) {

      and see what kind of mess it makes all over your room.

      --
      Old truckers never die, they just get a new peterbilt
    28. Re:Agreed.. by oscarcar · · Score: 1

      The code I wrote implies var is an "int" by the "var++" line. It can't be an int and compared to null. The more common scenario is that var is an actual object like a ResultSet. So, I meant something more like this.

      ResultSet rs = null;

      if ((rs = myClass.getResultSet()) != null) {
      while (rs.next()) { //access the resultset
      }
      }

      -Oscar

    29. Re:Agreed.. by axxackall · · Score: 1
      I'm used to as an English speaker

      English spear, uh? Use Cobol then.

      Programming is engineering science and as such requires you to know math, rather than English.

      You don't speak your code, you think it. If you think in abstract concepts - you are good with math and you are a good engineer. But if you think in plain english words - too bad, stay way from programming. Better be a manager or a businessman :)

      --

      Less is more !
    30. Re:Agreed.. by lscoughlin · · Score: 1

      yah, but that order can be important. loops make it the most obvious, if you do

      i = 0;
      while( i do_stuff() to values of i in the set [0, 1, 2 ] where as if you did

      i = 0;
      while( i do_stuff() to values of i in the set [1, 2 ].

      --
      Old truckers never die, they just get a new peterbilt
    31. Re:Agreed.. by lscoughlin · · Score: 1

      wow, i'm brilliant. fucking <'s, mutter.

      comment should be:

      yah, but that order can be important. loops make it the most obvious, if you do

      i = 0;
      while( i < 3 ) {
      do_stuff(i++);
      }

      you do_stuff() to values of i in the set [0, 1, 2 ] where as if you did

      i = 0;
      while( i < 3 ) {
      do_stuff( ++i );
      }

      you only do_stuff() to values of i in the set [1, 2 ].


      --
      Old truckers never die, they just get a new peterbilt
    32. Re:Agreed.. by jeremyp · · Score: 1

      "I came, I saw, I conquered"

      Oh look: noun-verb, noun-verb, noun-verb.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    33. Re:Agreed.. by jeremyp · · Score: 1

      The PDP11 had a direct machine language equivalent to
      *x-- and *++x but not the other way around as long as x was a register variable.

      e.g.

      register int x ;
      y = *++x ;

      looked something like (if x is in r1):

      move +(r1), y

      Apologies if I've got the syntax wrong...

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    34. Re:Agreed.. by kevlar · · Score: 1

      Apply the same analysis with Array initialization between C# and Java. In C# there is one and only one way of declaring an array. In Java there are several.

    35. Re:Agreed.. by Anonymous Coward · · Score: 0

      what if x *isn't* final though?

    36. Re:Agreed.. by zipwow · · Score: 1

      Actually, the bug I hit with iterators the most often is this one:

      Iterator iterator = collection.iterator()
      while(iterator.hasNext()) {
      otherCollection = (Collection)iterator.next();
      otherIterator = otherCollection.iterator()
      while(iterator.hasNext()) {
      Thing realThing = (Thing)otherIterator.next();
      }
      }

      I guess its the same sort of things as calling next twice, but having that iterator variable be anonymous will be helpful.

      Actually, I wonder how this works with the ListIterator, or how removal will work. Hopefully in that case you'll just do it manually and have done, I'm assuming that you won't have some 'magic variable' (*cough*$_*cough) or something.

      The null-to-zero thing is pretty weird though, I agree. I think I'd rather deal with the nulls than have the magic cause me problems.

      -Zipwow

      --
      I don't know which is more depressing, that 2/3 didn't care enough to vote, or that 1/2 of those that did are crazy.
    37. Re:Agreed.. by TummyX · · Score: 1


      I'd say that "++x" is actually the "best" way because it puts things in verb-noun order, which I'm used to as an English speaker. "x++" is noun-verb, which feels strange to me. "++x" reads as "increment X", while "x++" reads as "x. increment it".


      That's a poor reason. Doing it that way makes the noun-verb ordering different from the rest of the language. After all, object.method() is noun-verb is it not?

      You should be used to noun-verb by now.

    38. Re:Agreed.. by jcast · · Score: 1

      Let's take a simple one in C: int x needs to become one larger. You get a few options:
      1. x++;

      2. ++x;

      3. x+=1;

      4. x=x+1;

      All of them are "the right way" of simply incrementing x.

      Incorrect. The one true way to increment x is x++. All others are used only by heretics (the same kind of heretics who put else on the same line as the braces).
      --
      There are reasons why democracy does not work nearly as well as capitalism.
      -- David D. Friedman
    39. Re:Agreed.. by Spud+the+Ninja · · Score: 1

      The second set would be [1, 2, 3].

      --
      You can never put too much water in a nuclear reactor.
    40. Re:Agreed.. by be-fan · · Score: 1

      Smalltalk.

      --
      A deep unwavering belief is a sure sign you're missing something...
    41. Re:Agreed.. by bobbyjack · · Score: 1

      Notice how, in your example, this is subject-verb, subject-verb, subject-verb. In the previous example (x++ vs ++x), the author was talking about object-verb vs verb-object (note 'object' not meaning object in the OO sense!). Here, the argument about verb-object being more 'natural' is correct (at least, to English speakers). Of course, this all assumes that you view the translation as "increment x" as opposed to "x increments itself" which, I think, most of us do ...

    42. Re:Agreed.. by Anonymous Coward · · Score: 0

      Please go and read a C or C++ book.

    43. Re:Agreed.. by po8 · · Score: 1

      x++ is idiomatic because C is zero-based. Allow me to expand on that statement.

      One of the most common uses of the increment operators in C-like languages is in array indexing. Consider for example a simple integer stack:

      int stk[3];
      int sp = 0;

      void push(int s[], int v) { s[sp++] = v; }

      int pop(int s[]) { return s[--sp]; }
      This is the inspiration for post-increment and pre-decrement: if I automagically post-increment and pre-decrement, the array is usually accessed properly.

      Similarly, consider the usual backward-counting while loop:

      int i = 3;
      while(--i >= 0) { stk[i] = 0; }
      (Of course, the forward-counting case cannot be written naturally with pre- or post-increment in this style; hey, no idiom is perfect :-), but if you use an increment operator inside the while body, it should be a post-increment of the last reference to i.)

      One should do what one wants, but following the post-increment pre-decrement idiom may help improve code quality.

      (Excuse the code formatting. Why can't I indent in <ecode>?)

    44. Re:Agreed.. by monique · · Score: 1

      True, but you have to be careful.

      In java, if both a and b are booleans,

      if (a = b) {}

      will compile without a peep.

      Java has no problem with evaluating assignments as conditionals; it simply distinguishes between numerics and booleans.

      (I tested this recently before doing a presentation for my company on java.)

      --
      -monique
    45. Re:Agreed.. by Spy+Hunter · · Score: 1
      Good compilers give you a warning on code like if(x = 5), even in C/C++:

      gcc: warning: suggest parentheses around assignment used as truth value

      That warning has saved me from potentially hours of pointless debugging, on more than one occasion.

      --
      main(c,r){for(r=32;r;) printf(++c>31?c=!r--,"\n":c<r?" ":~c&r?" `":" #");}
    46. Re:Agreed.. by DunbarTheInept · · Score: 1

      ++ predates object-oriented code. It dates back to original K&R C. I was using ++x back when object.method() was a compile-error.

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    47. Re:Agreed.. by DunbarTheInept · · Score: 1

      ...they answered "if(x == 5)" and you answered what you just said, they would get the job.

      Then it would be a job I would not want and the fact that I was rejected would be a good thing in the long run. (Not that the issue of one bit of syntax matters that much, but the fact that my potential boss would be so petty as to hire or fire based on it would be a warning flag to me.)

      The problem with standards is that most proponents don't admit that what they are doing is totally arbitrary. They get this holier-than-thou attitude that there is ONE right way based on what "normal" people would think, and how the other ways are "abnormal". I understand the need to conform to standards, but the more asinine the proponents are about it and the less they recognize the purely made-up arbitrary nature of them, the less willing I am to conform to them. If the standard proponent admits that a particular rule has no real rationale other than they chose to pick one way for consistency, then I'm a lot more willing to work within that rule.

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

  9. Shortcuts by xmutex · · Score: 0, Troll

    Unlike some people, I feel using programming shorthand leads to increased maintenance.

    I hope you never have to look at any PHP; you'll go blind.

    --

    jack's bicycle is music to my ears
  10. So basically C# minus generics by earache · · Score: 3, Insightful

    The metadata, auto-boxing, enhanced iteration looks like catch up with C#'s attributes, foreach, etc.

    Where are true properties though?

    1. Re:So basically C# minus generics by anonymous+loser · · Score: 1

      You really don't want to underestimate the generics. This will make code so much easier to read and understand, as well as make it clear when you are using someone else's library that they expect that ArrayList to be of type Pumpkin, and passing in a few Pumpkins mixed with Legumes is bad.

    2. Re:So basically C# minus generics by Anonymous Coward · · Score: 0

      Not only that, but generics aren't some kind of "bonus" language feature.

      Some sort of generics are pretty much a necessity for working in statically typed programming languages. The fact that Java didn't have them before was a bug, and the workaround was to use widening and narrowing casts.

    3. Re:So basically C# minus generics by devinoni · · Score: 2, Informative

      Generics
      No such thing in C#.

      Enhanced for loop

      foreach (type identifier in expression) statement

      expression needs to implement IEnumerable, or declare a GetEnumerator that returns an IEnumerator

      Autoboxing/unboxing

      int i = 1;
      object o = i; //boxing
      int j = (int) o; //unboxing

      Typesafe enums

      enum Rating {Poor, Average, Okay, Good, Excellent}

      Rating IncrementRating(r)
      {
      if (r == Rating.Excellent) return r;
      else return r + 1;
      }

      Metadata

      // Metadata saying this is a webmethod

      [ WebMethod ]
      public int PerSessionServiceUsage()
    4. Re:So basically C# minus generics by Anonymous Coward · · Score: 1, Informative

      Next version of C# will have generics support. Unlike the Java implementation, it will support generics at level at which not only do you get syntactical sugar / compile-time type safety, you get collection and other classes with improve performance.

      Furthermore, next version will include other nifty features such as lambda-style anonymous methods.

    5. Re:So basically C# minus generics by Anonymous Coward · · Score: 0

      What the hell did you just say?

      Honestly, your reply reads like it was writen by an Eliza bot.

    6. Re:So basically C# minus generics by Mindbridge · · Score: 2, Insightful

      As pointed out in other posts, Metadata is JSR 40, which has been around since 1999 (before .NET). It is not a C# invention.

      In addition, C# properties are pretty badly implemented. Quite often one needs to have a private (protected) 'set' and a public 'get'. This is not something one can do as a property in C#. Also, who had the great idea of making public members and properties look the same? It is okay to allow one or the other in the language, but both?

    7. Re:So basically C# minus generics by Anonymous Coward · · Score: 1, Informative

      No, it reads like it was written by a programmer who understands what lambda expressions are and that the sort of 'generics' proposed for Java are cheap 'under erasure' model.

    8. Re:So basically C# minus generics by devinoni · · Score: 1

      Generics
      Generics are supported as of Visual Studio .NET 2003.

      Enhanced For
      Classes can define their own special iterator as of VS.NET 2003

      class Foo {
      public string foreach() {
      yield "One";
      yield "Two";
      yield "Three";
      }
      }
      When you foreach through a Foo object, you'll get "One", "Two", and then a "Three".
    9. Re:So basically C# minus generics by Anonymous Coward · · Score: 0

      Sorry dude, these are all planned for "Whitbey", the next release of Visual Studio.

  11. ooooh baby by Deadbolt · · Score: 1

    Typesafe enums. That alone makes me quiver with happiness.

    --
    "Honey, it's not working out; I think we should make our relationship open-source."
    1. Re:ooooh baby by Anonymous Coward · · Score: 0

      Ill be happy when we get SML style enums...

      (NONE | SOME of int | DESCRIPTION of String)

      where have all the unions gone?

    2. Re:ooooh baby by slagdogg · · Score: 4, Funny

      Typesafe enums. That alone makes me quiver with happiness.

      You don't get out much, do you?

      --
      (Score:-1, Wrong)
    3. Re:ooooh baby by lokedhs · · Score: 1
      I quiver too, but for a different reason.

      You should avery rarely need typesafe enums, or enums at all actually. Excessive use of enums is a typical code smell that the programmer didn't understand object orientation well enough.

      Usually I have somehting like one enum per 10000 lines of code or so. While I think that the enums in 1.5 will be a great help, I certainly don't think it's a huge amazing feature.

    4. Re:ooooh baby by Anonymous Coward · · Score: 0

      > > Typesafe enums. That alone makes me quiver with happiness.
      >
      > You don't get out much, do you?

      Now that Java is adding enums and generics, a whole class of errors will disappear so I actually have time to get out.

      Wouldn't that make you quiver with happiness (or at least quiver with fear ;=] )?

  12. Write once, Rewrite forever? by HidingMyName · · Score: 1, Troll

    This looks to me like they are changing a language so that existing apps no longer compile which is a bad idea. While I like many features of Java, I try hard to avoid authoring code in a language that has unstable syntax which results in a flux in the semantics. While it is O.K. to extend the language, the grammar has changed and many existing apps are not likely to compile without manual intervention (otherwise the compilers would be smart enough to figure it out). It is exactly this kind of "oh, we will revise the standard" years after the initial offering that hinders wide spread adoption, and opens the doors for the competitors (e.g. .NET).

    1. Re:Write once, Rewrite forever? by customiser · · Score: 5, Informative

      AFAIK they will not be breaking existing code... If anything, they had to go out of their way (e.g. the ugly foreach statement) to ensure backward compatibility. In 1.4, the assert keyword might have caused problems, but now I don't think that's the case.

    2. Re:Write once, Rewrite forever? by jjohnson · · Score: 1

      There's no mention of deprecating any language features. FUD, much?

      --
      Anyone who loves or hates any language, platform, or manufacturer, doesn't know what they're talking about.
    3. Re:Write once, Rewrite forever? by Knight2K · · Score: 2, Insightful

      I sure you have a valid point in general, but I'm not sure if this is a concern with the changes described. The description of the features in the article indicate to me that your concerns were taken into consideration. For instance, they explicitly mention that foreach and in weren't added as keywords to avoid killing programs that may have used these as variable names (kinda lousy variable names if you ask me, but I'm sure it happens).

      Looking at the examples in the article, I didn't see anything that would break the semantics of already existing code... assuming the generics feature uses Object if no other class is used.

      Do you have an example of the proposed semantics breaking some existing code? I would be interested in any examples and I'm sure the JCP would be too. I'm certainly not willing to go along with the JCP blindly if there is a practical, concrete example of where they are going wrong.

      --
      ======
      In X-Windows the client serves YOU!
    4. Re:Write once, Rewrite forever? by Grievance · · Score: 0, Flamebait

      Are you retarded, or astroturfing? did you bother to read the freaking article? (duh, no.)

      Nothing mentioned in this article should break existing Java code. In fact, the author specifically mentions (regarding 'enhanced for loops') that the designers are avoiding introducing new keywords where possible to preserve compatibility with existing code.

    5. Re:Write once, Rewrite forever? by Ageless · · Score: 2, Insightful

      I might have missed something in the article, but as far as I could tell nothing existing breaks. They even mentioned that they worked very hard to make sure that was the case.

      What part of the new syntax would cause old code to break?

    6. Re:Write once, Rewrite forever? by Caoch93 · · Score: 2, Informative

      ...especially since the assert keywork is, on Sun's JDK, only compiled to a bytecode construct if you request it be at compile-time.

    7. Re:Write once, Rewrite forever? by MillionthMonkey · · Score: 2, Interesting

      This looks to me like they are changing a language so that existing apps no longer compile which is a bad idea.

      Huh? Where did you see that?

      It looks like they're making changes so that new apps won't compile on older compilers, not that old apps won't compile on newer compilers.

      They risked a backwards compatibility problem when they introduced that "assert" keyword in 1.4 but there is a compiler switch to turn it off if you have variables with that name. Before that, they haven't messed with the syntax since 1.1, when they added class literals (syntactic sugar) and inner classes (a major change). The new syntax was so bizarre that no older programs were affected. I don't see how the 1.5 changes are any different. Some of them look like a cat walked across someone's keyboard.

      My company is stuck with having to support Java 1.1 because of Mac OS 9. (In fact, according to our demo download stats, the number and percentage of Mac OS 9 users is only going up.) So we use modern compilers when developing (no decent IDE works well with 1.1) but the nightly build script uses 1.1.8.

      Inner classes were an immense change compared to most of this sugary 1.5 stuff (except generics). Work here a few months and you learn about all the bugs in the 1.1.8 compiler with respect to inner classes. There are a number of perfectly legal constructs that get flagged as errors. But I bet the same kind of thing will happen with generics.

    8. Re:Write once, Rewrite forever? by Anonymous Coward · · Score: 0

      Like any good software design, This one hasn't CHANGED, its just been EXTENDED. Java intends to be Closed To Change, Open to Extension. Its one of the most important principles of object oriented design.
      Ok, Ill stop spouting....

    9. Re:Write once, Rewrite forever? by YetAnotherName · · Score: 2, Insightful

      From the article: "... you'll have to get used to providing additional information in declarations. Instead of merely saying:

      List words = new ArrayList();

      You'll have to say:

      List<String> words = new ArrayList<String>();"

      The way he says "you'll have to" suggests that old collection class construction might break. Let's hope that something like new ArrayList<Object> becomes the implicit default if you don't otherwise specify a type.

    10. Re:Write once, Rewrite forever? by Ageless · · Score: 1

      I assumed that the implied default would be the case, but I can understand that the article could be interpreted otherwise. I sure hope not.

    11. Re:Write once, Rewrite forever? by HidingMyName · · Score: 1
      As a matter of fact, this is EXACTLY the case I was worried about. Maybe I should have been clearer about it.

      On a side note, I wrote most of a 10k line app in Java from the 1.1 days, and I need to keep the binaries around since there were some syntax changes (I think the event handling was one of the things that bit me, but I don't have time to research it properly now, so my memory could be faulty there). I recall feeling very disappointed with Sun at the time (although the code was not mission critical).

    12. Re:Write once, Rewrite forever? by AKAImBatman · · Score: 1

      > they explicitly mention that foreach and in
      > weren't added as keywords to avoid killing
      > programs that may have used these as variable
      > names (kinda lousy variable names if you ask me,
      > but I'm sure it happens).

      "in" is actually a big one. How many times have you seen (or written) code like this:

      Socket socket = new Socket("somewhere.com", 80);
      InputStream in = socket.getInputStream();
      OutputStream out = socket.getOutputStream();

    13. Re:Write once, Rewrite forever? by HidingMyName · · Score: 1
      In particular I was referring to the explicit typing requirement of generics for container classes. The article, which says:
      If I had to pick one that might require some adjustment, it would be generics, because you'll have to get used to providing additional information in declarations. Instead of merely saying:

      List words = new ArrayList();

      You'll have to say:

      List words = new ArrayList();

      If they allow default behavior of assuming that the ArrayList contains Object, (as suggested by YetAnotherName then type safety is lost (although I guess the compiler could at least issue warnings in that case). If they strictly enforce it, existing code is unlikely to compile.
    14. Re:Write once, Rewrite forever? by egomaniac · · Score: 1

      Dear God, folks, the generics compiler (JSR-14) has been in beta for ... what, TWO YEARS now? I have been using it in production code for over six months. Go download it and try it. It's stable and works great.

      Nobody on these expert groups is stupid enough to want to break existing programs. Unconverted code works fine, with all of these new language features. Like I said, I'm actually using generics now, and they're great.

      --
      ZFS: because love is never having to say fsck
    15. Re:Write once, Rewrite forever? by delirium28 · · Score: 1
      This looks to me like they are changing a language so that existing apps no longer compile which is a bad idea.

      Where does it say that they will do this? Come on now, if you're going to make such a broad, sweeping statement at least back it up a little.

      For those of you who are scared that this guy might actually be right, I suggest that you look at the JSRs mentioned in the Q&A article. You'll find that backwards compatibility is always at the top of the list. Even Sun isn't crazy enough to avoid backwards compatibility, which is not always true of other orgs, such as Micro$oft.

      --
      Who is John Galt?
    16. Re:Write once, Rewrite forever? by rlowe69 · · Score: 1

      The way he says "you'll have to" suggests that old collection class construction might break.

      I doubt it. He follows what you quoted with this:

      "The upside is that if you try to insert something that's not a string, you find out at compile time and fix the problem."

      So if you declare it the old way, you get an Object-based ArrayList. The new way will give you a String-based ArrayList. That sounds backwards compatible to me.

      --
      ----- rL
  13. Does it have this feature? by BillsPetMonkey · · Score: 0, Troll
    public class Sun extends Profitability
    {
    while (revenue < 0) {
    versionNumber ++;
    }
    }
    --
    "It's not your information. It's information about you" - John Ford, Vice President, Equifax
    1. Re:Does it have this feature? by Anonymous Coward · · Score: 0

      but isnt sun becomming irrelevant in the future of java?

      i do like your code/joke, but how much is sun really important? is the JCP going to take full reigns or how does that all work?

    2. Re:Does it have this feature? by dubbayu_d_40 · · Score: 1

      No, Java still requires method declarations ;-)

    3. Re:Does it have this feature? by BillsPetMonkey · · Score: 1

      I was daft enough to post this troll (I'm surprised no-one else had the balls) and you were daft enough to compile it.

      --
      "It's not your information. It's information about you" - John Ford, Vice President, Equifax
  14. programming shorthand by nother_nix_hacker · · Score: 4, Funny

    I feel using programming shorthand leads to increased maintenance

    My code was hard to write to it should be hard to read. :)

    1. Re:programming shorthand by Usquebaugh · · Score: 2, Insightful

      Code should be written so it can easily be read by a human and incidentally by a machine.

    2. Re:programming shorthand by Anonymous Coward · · Score: 0

      If your post is any sign, the code was probably hard to write because you have a knack for leaving out spelling and punctuation. Compilers aren't as forgiving as your ./ compadres (excluding me).

    3. Re:programming shorthand by Anonymous Coward · · Score: 0

      Watch your language. There are children reading this website.

  15. JAVA by SpanishInquisition · · Score: 1, Troll

    the strongly typed language, that was good in 1996, now is weakly typed, now THAT's good in 2003, can anyone explain this to me?

    --
    Je t'aime Stéphanie
    1. Re:JAVA by Ageless · · Score: 1

      How has Java become weakly typed? Many of the features that are being added are specifically to enforce typing.

    2. Re:JAVA by Anonymous Coward · · Score: 0

      What gives you the idea that it's weakly typed? They've added generics and type-safe enums, which strengthens the type system, and auto-boxing, which basically just adds a handful of implicit coercions. Other than that, there don't look to be any type-system implications at all.

    3. Re:JAVA by Grievance · · Score: 1

      Do tell what in this article transforms Java (*) into a weakly-typed language?

      (* NB: Java is not an acronym.)

    4. Re:JAVA by Anonymous Coward · · Score: 0

      The problem is you have no idea what strongly typed and weakly typed mean. It's easy to find contradictions in the world when you make stuff up.

    5. Re:JAVA by evilpenguin · · Score: 1

      Moreover, it was always strongly typed. Generics simply move type enforcement from run-time to compile time. Also, you dont have to use it. You can still rely on descent from Object and run-time type checking if you want to do so.

      I think these are great changes. That leaves only my desire for operator overloading (or at least a String-like kludge to give operators to the BogDecimal type) and for GPL'ing the VM and SDK as my remaining "Java fantasies."

    6. Re:JAVA by Anonymous Coward · · Score: 0

      JAVA is an acronymn.

      It stands for

      Just
      A
      Visual Basic
      Aper

    7. Re:JAVA by evilpenguin · · Score: 1

      Er, "don't" and "BigDecimal." Sorry for the fat fingers.

    8. Re:JAVA by SpanishInquisition · · Score: 1

      No it's
      Joo Are Very Anal

      --
      Je t'aime Stéphanie
    9. Re:JAVA by Grievance · · Score: 1

      Heh

      sorry, i should have added a smiley 8)

      inadvertently all-capsing names in the software world (e.g. referring to Apple's MAC computers) is one of my pet peeves and sometimes gets the better of me.

      (PS you should see me when i can't restrain myself from correcting grammar...)

  16. Much, much more than syntactic sugar by jameson · · Score: 5, Insightful

    Hi,

    FYI: Generics are _much_ more than mere syntactic sugar (as are enumerators, a weak form of algebraic datatypes, if handled type-correctly).
    These are actually the kinds of things that make program maintenance considerably easier, since they allow more concise specifications of intended semantics to be done. No longer having to typecast (and thus expect run-time exceptions) when using a "vector of FooObjects" gives more power to the type checker, and thus allows a much richer class of programming errors to be detected at compile-time. This is the one major improvement in Java that's been missing since its very inception.

    But note that "generics" or "parametric types" have been present in languages such as Eiffel or Sather for well over a decade, and for much longer in ML. In a way, it's embarrassing that such an essential feature was added this late during development.

    1. Re:Much, much more than syntactic sugar by Anonymous Coward · · Score: 1, Interesting

      Agree.

      It will also make code easier to write in another way:

      Modern java editors (in particular the almost magical Intellij IDEA) provide code completion based on valid types in a given context. The more the editor knows about the types involved, the better this feature will work.

    2. Re:Much, much more than syntactic sugar by FortKnox · · Score: 1

      Exactly... generics give you type specific containers, which is really nice if you need type specific coding (which is important in stuff like financial institute coding).
      The only two alternatives is typed arrays (which only solves 1D solutions, stuff like trees and hashmaps can't be solved this way), or wrapping containers with type specific code (which is just tedious and a pain to maintain, and can be worked around).

      --
      Good quote, too many chars. Seriously, the slashdot 120 char limit sucks!
    3. Re:Much, much more than syntactic sugar by CaseyB · · Score: 1
      Modern java editors (in particular the almost magical Intellij IDEA) provide code completion based on valid types in a given context.

      One of IDEA's more magical features is that it already *does* this, without explicit support from generics. It can sometimes determine how to cast an object out of a collection by figuring out what you put into it! It's that kind of thing that has me looking over my shoulder to find the cameras that IntelliJ are watching me with...

    4. Re:Much, much more than syntactic sugar by TheRealRamone · · Score: 1

      "But note that "generics" or "parametric types" have been present in languages such as Eiffel or Sather for well over a decade, and for much longer in ML."
      Also note that generics have been present in Ada for 2 decades! --TRR
    5. Re:Much, much more than syntactic sugar by lokedhs · · Score: 1
      The really huge advantage that generics will bring us is (and you will have to read the spec to realise this is the case) that we are getting...

      (drum roll)

      Covariant return types!

      All of these suntactic sygar feautres can easily be worked around, but the lack of covariant return types has been a real problem for many people (often without knowing the name of the feature they miss). Especially when trying to do inheritence in EJB's, you really need them.

      For those of you who are interested, what are covariant return types?

      Consider the following code:

      interface Company {
      Collection getEmployees();
      }

      class SomeCompany implements Company {
      private List employees = ...;

      List getEmployees() { // It will fail here without covariant return types
      return employees;
      }
      }
      I suppose you can figure out for yourself now how this can be very useful. :-)
    6. Re:Much, much more than syntactic sugar by Anonymous Coward · · Score: 0

      Covariant return types are a separate issue. You could change one typing rule in the java compiler to allow it...

      It doesn't depend on generics at all.

    7. Re:Much, much more than syntactic sugar by lokedhs · · Score: 1
      Yes it does. You didn't read the Generic specification didn't you?

      In it, it clearly states that covariant return types is a consequence of implementing generics. I suppose I could quote the spec for you, and I guess I will if you still don't believe me. But I'd rather have you trust my word.

  17. Uglification? by oblom · · Score: 4, Insightful

    Is anybody else irked by generics? One of the arguments in C++/Java discussion that I've read was: "Java removes complexity of C++, while remaining OOP". Well, generics remind me of C++ templates, which where a bit hard for me to swallow. Not to mention that attached to variable name doesn't make code any more attractive to look at.

    It appears that Java's way to solve run time errors is to screw the bolts as tight a possible during compile time. Will generics become THE way, or just remain one of the options?

    1. Re:Uglification? by ornil · · Score: 1

      But it looks like you don't have to use generics if you don't want to. Presumably it
      simply defaults to Collection which is
      exactly what we are used to in Java now. You
      can then typecast to the real type if you prefer.

      Read the article, look at examples.

    2. Re:Uglification? by ornil · · Score: 1

      I meant to say that Collection means Collection. Should have used preview :(

    3. Re:Uglification? by ptomblin · · Score: 2, Insightful

      I'm really looking forward to generics. I've got tons of code that casts the results from iterators or collections or maps. I've either got to test like hell and hope that I don't see any ClassCastExceptions and hope the testing was exhaustive, or I've got to do a lot of "instanceof" tests. Since 90% of the time when I use collections/maps I'm putting all of the same type in them, this just irks me.

      But for that other 10% of the time, remember that all classes are children of Object, so I'm betting you can still declare
      List = new ArrayList();

      --
      The next Cmdr Taco duplicate will be ready soon, but subscribers can beat the rush and see it early!
    4. Re:Uglification? by Anonymous Coward · · Score: 1, Insightful

      Not really. The generics take care of the one really irksome problem with Collections, having to recast all your data back to its original type. Its not only a pain, its inefficient. Every cast if chewing up a bit of CPU. It would be a lot better to simply have a List of Strings, instead of a List of Objects that we are going to recast as Strings and hope no one shoved an Integer in by mistake.

      Its an improvement. I'm not sure I like the syntax though, although I can't think of anything better.

      Does anyone know if the generics will allow you to create a collection of primitive values? There have been plenty of times that I would like to have a List of ints but have to settle for a List of Objects that are really Integers in disguise. Woo hoo, I get recast the variable and call a method just to extract my value. That blows. I guess the autoboxing would hide the details, but its still doing the recast and intValue() call in the JVM. I'd rather have a true List of int values.

    5. Re:Uglification? by Anonymous Coward · · Score: 5, Insightful

      No, I'm not irked. Not even a little bit.

      If your only experience of generics is C++, then all you've seen is the *worst* implementation of generics ever done in a language. Template code is almost unreadable. (Have you ever tried debugging one of the STL implementations?)

      Besides, the lack of generic types cripples Java's ability to do static type checking, since your code ends up being full of things like this:

      Foo f = (Foo) vector.elementAt(i);

      where type errors can only be detected at runtime. That not only makes it impossible to detect errors at compile-time, it hurts performance at runtime.

      Check out how generics are handled in Modula-3 for to see a much better way to handle them than C++ templates, or look at ML for something even more groovy (ML uses polymorphic type inference instead of generics, so you don't even have to mention types - the compiler just does the Right Thing).

      Once you've worked with a good generic implementation, you'll never want to stop using them.

      Harry

    6. Re:Uglification? by blamanj · · Score: 1

      Not me. I've been waiting for them ever since Pizza and GJ. The nice thing about the Java version (beyond getting rid of casts, etc.) is that unlike C++, use of generics doesn't bloat your code. The you can have hundreds of ArrayList variants, and they all make use of the one ArrayList class that exists today.

    7. Re:Uglification? by Anonymous Coward · · Score: 0

      Proper use of templates in C++ won't bloat your code, either. It's a simple matter to write a base class that does the work generically (with void* and what not), and then wrap it in template classes whose purpose is to ensure correct type casting. The template code is essentially just casts, and would compile out completely. The only "real" code is that single implementation of the container.

      You can, of course, do it the wrong way, and write a template that duplicates lots of code unnecessarily. But then, as the saying goes, you can write bad code in any language.

    8. Re:Uglification? by Anonymous Coward · · Score: 1, Insightful

      when I make a collection of something, it's always of some type of thing. It's very rare that you only have a bag of 'objects', you have a bag of groceries. etc.

      this is now made explicit, safe, reduces run-time casts so reduces time and errors *and* involves less typing (of the keyboard variety).

      the old way exhibited major suckage.

    9. Re:Uglification? by jameson · · Score: 5, Informative

      Hi,

      Well, generics remind me of C++ templates

      They're not quite the same; C++ templates are essentially glorified preprocessor macros with
      some relatively small checking and a rather baroque
      underlying functional language. Generics are more
      concrete than that.

      Not to mention that attached to variable name doesn't make code any more attractive to look at.

      It would be really neat to have type inference there ;-)

      It appears that Java's way to solve run time errors is to screw the bolts as tight a possible during compile time.

      That's the idea, and that's also what I try to do when writing programs. Why should I have to write half a dozen test suites for some simple program property if the type checker can tell me whether it'll work right?

      Remember: Compilers don't do type checking just to optimise, but also to catch programming errors. And Generics allow you to catch a much more interesting class of these.

      -- Christoph

    10. Re:Uglification? by oblom · · Score: 1
      It would be really neat to have type inference there ;-)

      Yes, it would. Natural Language Processor will be released with JDK 1.6 ;-)

      Of course /. ate the "<String>": Not to mention that <String> attached...

    11. Re:Uglification? by SilentStrike · · Score: 1

      "Why should I have to write half a dozen test suites for some simple program property if the type checker can tell me whether it'll work right?"

      Because typesafe programs still fail. Furthermore, I'd anticipate most errors in even dynamically typed langauges are not type related. Even after a clean compile with the most strict typing rules, are you confident that the code works?

    12. Re:Uglification? by iabervon · · Score: 1

      The new Java generics remove the complexity of C++. The complicated things about C++ templates are the stuff you can do with the type variables and the behaviour with non-pointer types. Java skips both of those.

      In general, it's best to enforce at compile time everything you believe to be true of your code. Of course, you can either just ignore generics if you don't like them or use ArrayList (e.g.), which is equivalent to the old way.

    13. Re:Uglification? by Cederic · · Score: 1


      List objects = new List();

    14. Re:Uglification? by Cederic · · Score: 1

      doh. that'll teach me to use preview

      List objects = new List<Object>();

    15. Re:Uglification? by ptomblin · · Score: 1, Funny

      Damn, me too. That's what I wrote as well.

      --
      The next Cmdr Taco duplicate will be ready soon, but subscribers can beat the rush and see it early!
    16. Re:Uglification? by Anonymous Coward · · Score: 0

      You don't understand C++ templates, in future do not comment on them.

    17. Re:Uglification? by Anonymous Coward · · Score: 0

      Type inference works just fine in languages that use it (ML and Caml dialects, Haskell etc.).

      OO with implicit type widening would make it somewhat more problematic in Java, though...

    18. Re:Uglification? by greenrd · · Score: 1
      It depends on what you mean by "type related". ;-)

      In a language which has both a strong type system and a strong contract system, such as (to blow my own trumpet) the one I'm currently writing (no official name for it yet), the compiler should be able to catch a wide variety of logic bugs thanks to contract checking, which indispensably depends on type checking.

  18. Retro... by dance2die · · Score: 3, Interesting

    These new java features or shortcuts whatever reminds of C++... Is Java going to come with "Pointer" manipulation features later on? Will java become the next C++ and will be extremely tidious to program with? Overall, change is good... :)

    --
    buffering...
    1. Re:Retro... by daveho · · Score: 1

      These new java features or shortcuts whatever reminds of C++... Is Java going to come with "Pointer" manipulation features later on?

      No. Although the parametized types in Java have a superficial resemblance to C++ templates, they compile down to bytecode which is more-or-less identical to what you would get if you just used non-parametized types and lots of casts (i.e., the old way of doing things.)
      I have used Java with generics for almost a year now, and trust me, once you've used them there's no going back. They rule.

      Will java become the next C++ and will be extremely tidious to program with? Overall, change is good... :)

      Java will not be extended in any way that would compromise type safety or backward compatibility. That basically precludes inheriting any real brain damage from C++.
    2. Re:Retro... by Anonymous Coward · · Score: 0

      And the enhanced for construct seems obfuscated. They should almost do something like have a compiler option so that you can use "foreach" and "in" if you want and then slowly phase that in (instead of "for (foo t : bar c)").

      Up to now jave is generally really easy to read and it stays away from symbols to provide logic/functionality (assuming you don't use ? : if statements a lot). There is something to be said for the elegance of using words that reflect what if actually happening. It's not hard to get used to using a : in the for loop, just that foreach loops are so much prettier!

    3. Re:Retro... by jeremyp · · Score: 2, Interesting

      I agree with that. Following the backward compatibility rule blindly can lead to some serious abortions. In this case, they are sacrificing a nice elegant construct for the person who has a variable named "foreach" (unlikely) and the person who has a variable named "in" (their fault for choosing a stupid non descriptive variable name). A "java 1.4" switch would sort that out plus any reasonable search and replace facility.

      If they'd said "i" is now a keyword, that would have been more of a problem.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
  19. Generics vs Enumeration. by Anonymous Coward · · Score: 0

    I feel the opposite. Enumeration types provide for strong type checking at compile time thus catching a lot of subtle bugs.

    Generics worry me. Soon, someone will write something like ATL and we will have to have "Wizards" generating the code like for those poor COM programmers. As I understand it, Generics does not require a change to the byte code. The compiler just does checking and then provides the cast. In Java, all objects derive from Object and are allocated on the heap. Generics really doesn't provide the additional functionality that templates do in C++.

  20. One line summary by Anonymous Coward · · Score: 5, Funny

    Java adds four new syntaxes, Python's for loop, Perl type checking at compile time, something called 'metadata', and C enumerations, all of which impove compile time type checking at the expense of making the source code look and feel like perl.

    1. Re:One line summary by elsilver · · Score: 1
      something called 'metadata'

      Just to complete your list, that should read C#'s metadata.

    2. Re:One line summary by yaphadam097 · · Score: 0

      Actually for those of us who use the open source tool XDoclet metadata is not new, it just wasn't a language feature before. In fact the syntax with the '@' symbol is clearly like XDoclet and Middlegen and the stated purpose is the same - to allow declarative programming without the need for several source files containing interfaces required by the specs, etc.

    3. Re:One line summary by Anonymous Coward · · Score: 0

      .NET's metadata, or rather Visual J++'s, metadata. The ability to declaratively change the function of a class, member or whatever through the use of syntax. Via attributes you force the compiler to perform common tasks.

      Java 1.5:

      import javax.xml.rpc.*;

      public class CoffeeOrder {
      @Remote public Coffee [] getPriceList() { ...
      }
      @Remote public String orderCoffee(String name, int quantity) { ...
      }
      }


      C#:

      using System.Web.WebServices;

      [WebService()]
      public class CoffeeOrder
      {
      [WebMethod()]
      public Coffee[] GetPriceList() { ... }

      [WebMethod()]
      public string OrderCoffee(string name, int quantity) { ... }
      };


      I wonder if Sun will include metadata to bypass JNI, like MS' JDirect.

  21. compilers never make mistakes? by cheezfreek · · Score: 5, Insightful
    As a compiler writer, I found this sentence to be particularly hilarious:

    Because the compiler, unlike the programmer, never makes mistakes, the resulting code is also more likely to be free of bugs.

    That's right, none of us has ever seen bad code generation or an internal compiler error. But, he does have a point. The compiler is less likely to make a mistake than a programmer.

    1. Re:compilers never make mistakes? by amRadioHed · · Score: 1

      So are you saying that when a compiler you write generates bad code or gets an internal error, it's not your fault? ;-)

      --
      We hope your rules and wisdom choke you / Now we are one in everlasting peace
    2. Re:compilers never make mistakes? by cprice · · Score: 1

      Right. The Java Hotspot compiler has no issues, except for the nasty corefiles from things like;

      while (true)
      {
      blah blah
      }

      The hotspot workaround was to run in -client mode or change your code to say;

      boolean done=false
      while (!true)
      {
      blah blah
      }

    3. Re:compilers never make mistakes? by cheezfreek · · Score: 1
      So are you saying that when a compiler you write generates bad code or gets an internal error, it's not your fault? ;-)

      Of course not. Not my fault. Never my fault. I work as part of a team, which means there are always plenty of other people to take the blame. They're kind of like Tibor at the Springfield Nuclear Plant.

    4. Re:compilers never make mistakes? by charlieo88 · · Score: 1

      Bugs that I introduce into the code I can stand. Bugs that are caused by a bug in the compiler, well those are just wrong. Like catching your mom making out with your girlfriend. Not just Wrong, but Jerry Springer Wrong.

    5. Re:compilers never make mistakes? by zenyu · · Score: 1

      Because the compiler, unlike the programmer, never makes mistakes

      Yeah, I was very puzzled by this too. As a compiler _user_ I sometimes think the compiler makes more mistakes than I do. That's not actually true, but I do spend more debugging time on compiler issues than my own bugs. I can see my own bugs by reading the code, compile time "internal compiler error" bugs usually have to solved by rearranging the function order (which from a programmer perspective is just illogical), and the code generation errors are often almost impossible to fix.

    6. Re:compilers never make mistakes? by Kupek · · Score: 1

      See, what you do is define the compiler's behavior to be the correct behavior.

    7. Re:compilers never make mistakes? by cheezfreek · · Score: 1
      See, what you do is define the compiler's behavior to be the correct behavior.

      Sometimes I do wish I could do that. Ah, if only there were no such things as standards...

    8. Re:compilers never make mistakes? by cpeterso · · Score: 1


      I do spend more debugging time on compiler issues than my own bugs.

      what compiler are you using?

    9. Re:compilers never make mistakes? by zenyu · · Score: 1

      VC 6.0, icc & gcc, mostly. VC is the worst of the bunch, I'm hoping to port some of those apps to icc or at least VC 7.0 when I have the time. I've never met a compiler that wasn't buggy though, it's just a matter of how much you stress it. And the bug reporting policies, VC 6.0 is probably so crappy because they've made it so much more difficult to report bugs, back in the day you could call them up on an 1800 number and talk with the developer the next day, now...

    10. Re:compilers never make mistakes? by dracocat · · Score: 1

      Man, I just want to know what kind of compiler you guys are using, and what you are doing to it!

    11. Re:compilers never make mistakes? by Anonymous Coward · · Score: 0

      Hey, it works for Perl!

      (It's not as if, when there's a question, you can go look at the ANSI Perl language spec, now is it? About the best you can do is post to some mailing list and hope to get back a response like, "That seems like a bug to me." It's a language that's defined subjectively! Disclaimer: I actually like Perl a lot though...)

    12. Re:compilers never make mistakes? by theCoder · · Score: 1

      heh, you should go work for Microsoft :)

      (laugh, it's a joke... well, sort of...)

      --
      "Save the whales, feed the hungry, free the mallocs" -- author unknown
    13. Re:compilers never make mistakes? by cheezfreek · · Score: 1
      Man, I just want to know what kind of compiler you guys are using, and what you are doing to it!

      Which compiler is irrelevant, since compilers in general are incredibly complex and therefore at least somewhat buggy. But what am I doing to it? On the order of a million and a half test cases, that's what (some of them take a second or less to compile, others take hours because they're so huge and optimization takes a long time). You find a few bugs that way.

    14. Re:compilers never make mistakes? by cheezfreek · · Score: 1

      What compiler doesn't matter. I think what the poster is getting at is that his own bugs take a certain amount of time, but compiler bugs are much nastier. It's not like you can rule out your own code from being at fault, at least not without going through a lot of debugging (and poring over standards documents to make sure you haven't violated some obscure rule, for that matter).

  22. not just sugar by Anonymous Coward · · Score: 4, Interesting

    I think the new additions are great (except, perhaps, the autoboxing stuff). But I'm missing a fix for that extremely common javabean convention: get/set methods.

    To add a property, say a String called name you have to write:

    /**
    * The name of this object.
    */
    private String name;

    /**
    * The name of this object.
    */
    public String getName() {
    return name;
    }

    /**
    * The name of this object.
    */
    public void setName(String name) {
    this.name = name;
    }

    That's 16 lines of code for one property! This is tedious to write, and more importantly, very hard to read when you have many properties.

    This could easily be reduced to something like:

    /**
    * The name of this object.
    */
    property String name;

    expanded to exactly the same code as above by the compiler. Incredibly useful if you're, say, writing a lot of value objects in a j2ee scenario.

    1. Re:not just sugar by Anonymous Coward · · Score: 0

      Python could come to the rescue here. Define __getitem__ and __setitem__ member functions, and then you can use the object with an index operator.

    2. Re:not just sugar by Anonymous Coward · · Score: 0

      Getter/Setter methods don't always just get and set a simple value. The value of these methods are that you could add other code into them to maintain backwards compatibility in the future. Reducing it to one line makes that difficult.

      Also, if you used one of the newer IDE's, they generate those lines of code for you. You could even make emacs do that. If you love to program in notepad though, quit complaining that you have to type so much. :)

    3. Re:not just sugar by Anonymous Coward · · Score: 0

      That's what your IDE's "implement setter/getter" menu option is for. one click and you have 16 lines of code plus javadoc skeleton for you to fill out too.

    4. Re:not just sugar by Anonymous Coward · · Score: 0

      > Reducing it to one line makes that difficult.

      No, not at all. You just add the needed methods (or revert to the old way of defining javabean properties).

      That way it becomes obvious where the getters/setters actually do anything vs. just return a value.

      > Also, if you used one of the newer IDE's, they generate those lines of code for you.

      Yes. But the IDE doesn't have to read the code. Readability is everything.

    5. Re:not just sugar by Jack+Greenbaum · · Score: 3, Informative
      That's 16 lines of code for one property! This is tedious to write, and more importantly, very hard to read when you have many properties.
      You really need to try a generating/refactoring IDE like Eclipse. I once held to the orthodoxy that if I needed more than emacs then something was broken in the language. I grew up on object systems like CLOS where if you wanted a getter or setter you just asked for it in the definition of a field. So at first C++'s lack of public read-only/private read-write vars annoyed me, and Java's odd package visibility rules made me wince. But now I just declare private and generate my getters/setters, I navigate the file with the outline view, and I get more done per unit time then in any other language/ide pair, including VB.

      -- Jack

    6. Re:not just sugar by tijnbraun · · Score: 1

      Instead of writing a getsetter yourself, you could use a macro. I'm not sure whether I would really would want this "property" syntax thing. It would require less typing, but it would also make it harder to find things in the code. For instance if you would see obj.setId(aID), something like 'grep -r "void setId" *' would return nothing.

    7. Re:not just sugar by Anonymous Coward · · Score: 0

      I ended up solving this problem by writing a simple code generator. It took a .java file for a class that had properties defined, but no getters and setters, and output the same source code plus generated getters and setters. This saved a lot of time and was pretty simple to write.

    8. Re:not just sugar by Anonymous Coward · · Score: 0

      > You really need to try a generating/refactoring IDE like Eclipse.

      I know. Intellij IDEA is, btw., even better imho.

      But they won't read the code. I still have to do that myself...

      This change is mostly about readability.

    9. Re:not just sugar by Anonymous Coward · · Score: 0

      Yes, there are lots of "solutions" to this (automatic code generation in IDEs, XDoclet, etc.).

      IMHO, that just shows that this is a real issue: we don't want to write all that boilerplate code ourselves.

      Code generators are a symptom, not a cure.

    10. Re:not just sugar by Anonymous Coward · · Score: 0

      Macros are, alas, not part of java.

    11. Re:not just sugar by tijnbraun · · Score: 1

      I meant macros a la Emacs macros

    12. Re:not just sugar by RevAaron · · Score: 1

      Don't Java IDEs take care of this for you? This sort of feature (called autoaccessors, methinks) has been around in Smalltalk IDEs for a long time. But then again, it's a lot fewer lines of code to say the same thing in Smalltalk than in Java for this.

      --

      Working toward a usable PDA environment in the spirit of Newton OS: Dynapad
    13. Re:not just sugar by Anonymous Coward · · Score: 0

      This already exists in Java. It's called a field:


      class Blah {
      public String name;
      }

      ...

      Blah blah = new Blah ();
      blah.name = "Hello World!"
      System.out.println(blah.name);


      You just don't get the blah.name("Hello World!") and System.out.println(blah.name());

      Now, the real point of accessors is so that you can (1) make them more complex later down the line (for example, maybe getName()/setName() actually access an SQL DB for some weird reason), and (2) provide appropriate access protection (maybe you can only get, but not set).

      All of that wouldn't be helped by your property suggestion. It might still be a good idea, but as is, it doesn't really solve any problems.

    14. Re:not just sugar by Anonymous Coward · · Score: 0

      Sure, IMHO can generate boilerplate code for you.

      But code generation is almost always a bad solution: it doesn't help readability a bit.

    15. Re:not just sugar by MntlChaos · · Score: 1

      one problem. This (the 16 line) way you can control whether a property is write-only, read-only, etc. Also, it allows you to control the implementation of the write and read methods independently.

    16. Re:not just sugar by easter1916 · · Score: 1

      Oh for Christ's sake. Any decent IDE (Eclipse, for example) will generate accessor / mutator methods for member variables.

    17. Re:not just sugar by Anonymous Coward · · Score: 0

      we all grow up, huh? *sigh* (I am in 100% agreement BTW)

    18. Re:not just sugar by Jack+Greenbaum · · Score: 1
      But they won't read the code. I still have to do that myself...
      I've finally adapted to Eclipse's Outline view for online file navigation at write time. View Definition addresses finding source while online as well. For easing hardcopy navigation I use coding standards for file organization. It surprised me how effective that is when browsing on paper (my preferred "reading" method).

      Personally I like the tradeoff of verbose source files and automated code gen versus hidden magic ala CLOS accessors or unchecked access via publics. Sometimes you have to just ride the wave so it doesn't crush you.

      -- Jack

    19. Re:not just sugar by slagdogg · · Score: 1

      I once held to the orthodoxy that if I needed more than emacs then something was broken in the language.

      I still do ;)

      `jde-gen-get-set' is an alias for `tempo-template-java-get-set-pair', an interactive Lisp function
      -- loaded from "jde-gen"
      (jde-gen-get-set &optional ARG)

      Documentation:
      Insert variable get-set method pair.

      --
      (Score:-1, Wrong)
    20. Re:not just sugar by HisMother · · Score: 1

      Glad to see you read the article before posting. See the discussion of "Metadata" to see how Tiger will address exactly this.

      --
      Cantankerous old coot since 1957.
    21. Re:not just sugar by Anonymous Coward · · Score: 0

      I read the article, I don't think that was in there. Perhaps you are confusing it with another article you've read.

    22. Re:not just sugar by lobsterGun · · Score: 1

      Java is mature enough now that if you were to add a new keyword (espescially one as common as 'property') there would be significant heartache.

      I figure thats why they went with the ':' operator in the new for loop.

    23. Re:not just sugar by Bake · · Score: 1

      Speaking of properties and get/set functionality like the one in C#. What is really the difference between using properties like that and just using public variables?

    24. Re:not just sugar by HisMother · · Score: 1

      Q: Got it. Now could you tell us about the new metadata facility?

      A: It's a bit different from the other features we've discussed. It's also focused on making life easier for the developer, but with the assistance of tools vendors.

      These days, many APIs require a fair amount of boilerplate. For example, when you define a JAX-RPC Web Service you provide both an interface and an implementation class:

      public interface CoffeeOrderIF extends java.rmi.Remote {
      public Coffee [] getPriceList()
      throws java.rmi.RemoteException;
      public String orderCoffee(String name, int quantity)
      throws java.rmi.RemoteException;
      }

      public class CoffeeOrderImpl implements CoffeeOrderIF {
      public Coffee [] getPriceList() { ...
      }
      public String orderCoffee(String name, int quantity) { ...
      }
      }

      This example was copied straight from our Web Services Tutorial.

      With the metadata facility, you don't have to write all of this yourself. You just annotate the code to let a tool know which methods are remotely accessible, and the tool generates the above code. Here's how the source code looks with metadata:

      import javax.xml.rpc.*;

      public class CoffeeOrder {
      @Remote public Coffee [] getPriceList() { ...
      }
      @Remote public String orderCoffee(String name, int quantity) { ...
      }
      }

      All the boilerplate's gone!

      Q: Yes, that's much clearer. But you can't possibly define all of the useful attributes and build all the tools, can you?

      A: No, JSR-175 is just providing the framework that enables others to define attributes and build tools. Other JSRs -- such as JSR-181, which is defining metadata for Web Services -- are defining attributes. We expect lots of activity in this area.

      --
      Cantankerous old coot since 1957.
    25. Re:not just sugar by thebatlab · · Score: 1

      Mainly for control purposes. If you use a variable in your class for various things maybe you don't want a client to be able to change it whenever and to whatever they want. having it in a method gives you control over what happens (if you allow anything to happen at all). Maybe for some reason you want to keep track of how many times a variable was accessed or something like that.

      That's why, though I totally see the point of the previous posters 'property' keyword and why some would want it, it basically amounts to having public variables which defeats the control you get over the access to those variables when you need it.

    26. Re:not just sugar by RevAaron · · Score: 1

      No, it doesn't change readabilility, but who needs to?

      There would be said autogenerated code for accessing the inst vars. You would access them in the same way, whether Java did it in the background for you or if your IDE did it.

      I doubt many people mistype accessors, but having the IDE do it could help reliability as well.

      --

      Working toward a usable PDA environment in the spirit of Newton OS: Dynapad
    27. Re:not just sugar by Admiral+Burrito · · Score: 1
      What is really the difference between using properties like that and just using public variables?

      The whole point of getter/setter methods versus simply making the variable public is to allow other things to happen when the get/set occurs. For example, the return value of the getter method may be generated at call time. Or, maybe you want to fire property change events when the setter method is called (observer pattern, very useful in a model-view-controller structured GUI program (among other things)).

      Even if you aren't doing anything fancy, you should use getter/setter methods right from the start, in case you change your mind later. And it's easier to remember to just always use getFoo/setFoo, rather than trying to remember where you need getFoo/setFoo and where you need foo = . With editor macros its not really any extra work to use get/set, so there's no reason not to use the more flexible mechanism.

    28. Re:not just sugar by ivanandre · · Score: 1

      The problem is that many times the accesor methods do more than just set/get the value of the attribute...

    29. Re:not just sugar by iabervon · · Score: 1

      I think the ideal design would be: /**
      * The name of this object
      */
      private String name;

      public String getName();
      public setName(String name);

      That is, if a method is declared as set* or get*, not declared abstract, and no body is given, the compiler provides the method body to do the obvious thing (and javadoc copies the documentation as appropriate). You should probably be able to drop the return type and maybe the parameter types (although having setName() generate a method with a different signature would be odd). You still get to declare the protection for the methods, though, and any other method attributes you feel like (not that there are any other useful ones right now).

    30. Re:not just sugar by Anonymous Coward · · Score: 0

      I like your concept, but I realy want an additional refinement.

      Sometimes I want properties to be read only, so it would be good to have a qualifier of readonlyproperty .

      Although I'd be quite happy for Sun to user shorter qualifiers such as getset and getonly .

    31. Re:not just sugar by Anonymous Coward · · Score: 0

      but things like generics, autoboxing, and for (a:b) are using a macro-like preprocessor. The reasoning is that's it's okay for them to use a preprocessor, but not okay for stupid people like you and me to do the same.

    32. Re:not just sugar by Anonymous Coward · · Score: 0

      Metadata could facilitate this, at least in one direction:


      public class Person { /* assume @Property metadata automatically creates public accessors */
      @Property private string Name;
      }

      public class App {
      public static void main(String[] args) {
      Person o = new Person();
      o.setName("Ted");
      String s = o.getName();
      }
      }

    33. Re:not just sugar by rnd() · · Score: 1
      Why wouldn't you just type:


      Public String name;

      ??

      --

      Amazing magic tricks

    34. Re:not just sugar by Anonymous Coward · · Score: 0

      At least with these lines of code you know what's going on when you see:
      obj.name = "foo";

      The notion that I'll have to go on guessing what silly obfuscation someone did just because they don't have a decent IDE that generates all of the above from
      private String name;
      and a right-mouse click thereon is maddening! Sheesh!

      If a free IDE like NetBeans gives this to you, then why do you need to hide what's going on? To save 6 characters for each accessor usage? It will gladly do code completion to save you from typing this anyway...

  23. Shorthand programming by Shamashmuddamiq · · Score: 5, Funny
    Yes, I'd agree with that remark about shorthand programming. I thought it was funny when I was teaching classes at UIUC to see stuff like this from the students:

    #define FOREVER for(;;)
    #define BEGIN {
    #define END }
    #define ONE 1
    #define PUSHORT unsigned short *
    #define DONE goto end

    The first thing an amateur programmer does when assigned a new project in C/C++ is to go redefine the language and all the types. I scolded them for these kinds of things, knowing that once they were forced to read other people's code often that they would realize how stupid these kinds of things are. Unfortunately, once I started my career in embedded development, I quickly learned how stupid I must have been to think that people left these behaviors behind in college... (all the above examples are taken from "professional" code that I've seen in the last few weeks)

    --
    ...just my 2 gil.
    1. Re:Shorthand programming by Fnkmaster · · Score: 1
      Why does everybody in C++ land feel the need to roll their own language every time? Why does everything have to be a FLOAT instead of a float? I mean, I understand that in many cases, it's for portability, but it seems like some of these features are completely overused, and absolutely mystical.


      Preprocessors are, I think, way overused. do { ... }while(0) my ass.

    2. Re:Shorthand programming by Anonymous Coward · · Score: 0

      Some of those techniques are actually really nice if you are doing embedded development. I have seen some really nice C code macros that turn C into a quasi-OOP language.

      The ones you listed are pretty silly, though.

    3. Re:Shorthand programming by Anonymous Coward · · Score: 2, Funny

      a while back i did some obfuscation of my code to make it hard to read. i never really shared any of the code so it served no purpose whatsoever. i did things like:

      #define begin }
      #define end {

      but by far my favorite was:

      #define ONION UNION
      #define RINGS REGS

      so I could declare a structure:
      struct ONION RINGS o;

      for doing VESA interrupts.

    4. Re:Shorthand programming by Anonymous Coward · · Score: 0

      Of course the difference is those macros are user defined, not standardized, and not recognized by the compiler or tools. If a forever keyword were added to C++ then there would be no problem using it. The same goes for these new java constructs. Because they will be a part of the standard language they will be no more detrimental to readablity or maintainability than a for loop being used instead of a goto statement. Before you go all hyper on goto statements, really think about what I just said.

    5. Re:Shorthand programming by KrisW · · Score: 2, Insightful

      I guess it doesn't matter if you're the only one reading the code, but I can't see how macros can do anything other than make code harder to read...

      --


      "Think you can take me? Go ahead on. It's your move." --Joe Don Baker in Final Justice
    6. Re:Shorthand programming by DogIsMyCoprocessor · · Score: 1
      Not quite as bad as

      #define ONE 0
      #define ZERO 1

      which allegedly has been seen in the wild.

      --

      "And this is my boy, Sherman. Speak, Sherman." "Hello." "Good boy."

    7. Re:Shorthand programming by lightspawn · · Score: 1
      The best macro ever:
      #define private public
    8. Re:Shorthand programming by ratboy666 · · Score: 2, Insightful

      Redefining the language to better meet the problem is one of the hallmarks of good (artistic) programming. And it has other purposes. To give you one:

      #define NOTHING ;

      ...
      if ((flag & VAL1) || (flag & VAL2)
      NOTHING;
      else
      ...

      I know I can change this to eliminate the empty
      ';', but I choose not to, because I feel that the conditional reads better as a positive statement.

      [I also prefer to have the '<' or '>' in a compound conditional always point the same way:

      (5 <= x) && (x <= 10)

      so the conditional can be read "x between 5 and 10". I am a hacker -- thinking about code is a compulsion for me].

      Now, LINT (splint which I use), complains about the empty ';' as a probable coding mistake... I redefine NOTHING as /*@i@*/; and splint no longer complains ("indent" doesn't do the right thing, so I REALLY use /*=i=*/ which indent can handle, and splint can be trained to). Plus, when I am reading the code I can tell instantly that I meant it that way. FOREVER can be for(;;) or while(1), but it is clear from the read that I mean to iterate, well, forever. Typically, I would use that as the main loop of a thread.

      As to BEGIN and END -- I have coded with C (pre-ansi) on machines whose keyboards didn't have '{' and '}'. I had to construct an include file to define BEGIN and END with a binary editor. But it worked.

      There may be reasons that hackers do this -- don't be immediately dismissive. [#define ONE 1 I have used as well -- in defining manifest constants for numeric types in an object oriented number stack for C++. Ok, it was a constructor: myint one = 1; but I did it to keep only one copy of the number around -- improved efficiency]. The PUSHORT style I agree is USUALLY nonsense. I can see USHORT, but the '*' notation is supported. Of course there may be an attempt to impose an object system underneath, and it may be nice to define PUSHORT as "void*" to quickly highlight all uses of the underlying implementation. So even that has a purpose.

      Ratboy.

      --
      Just another "Cubible(sic) Joe" 2 17 3061
    9. Re:Shorthand programming by Anonymous Coward · · Score: 0

      Well they can make the code more readable for the one person developing the code... and make it easier for them to write. I seem to recall preprocessor somebody had written up that would let you write C/C++ in the same format as you would Python (with no semicolons or brackets on code blocks, using white-space to delimit statements). That could easily make somebody's code more readable for themself. Also, I think somebody wrote a compliment to that preprocessor that would output the code you had written using it as file with "standard" C/C++ formatting or the opposite, so you could write your programs and read other peoples programs in a way that you might be more comfortable, but you can still share with people who write "regular" C/C++.

    10. Re:Shorthand programming by Electrum · · Score: 1

      I guess it doesn't matter if you're the only one reading the code, but I can't see how macros can do anything other than make code harder to read...

      http://www.chiark.greenend.org.uk/~sgtatham/corout ines.html

    11. Re:Shorthand programming by Arandir · · Score: 1

      I can see why they call you "ratboy". Here's a vastly superior way to do you first example: ...
      if ((flag & VAL1) || (flag & VAL2)
      ; /* nothing */
      else ...

      --
      A Government Is a Body of People, Usually Notably Ungoverned
    12. Re:Shorthand programming by Anonymous Coward · · Score: 0

      I prefer...

      if ((flag & VAL1) || (flag & VAL2))
      { // nothing
      }
      else ...

    13. Re:Shorthand programming by Anonymous Coward · · Score: 0

      I've always used macros for portability and to pull literal values out of the code (in C, C++ has a better solution for this)

      The only area where I miss the preprocessor in Java is log/trace/debug. What I would give to have __FILE__ and __LINE__ back... . Even better: __CLASS__ and __METHOD__ would be great. Also, hiding the mess of code that you need to use to (efficiently) deal with debugging in a macro would __GREATLY__ improve readability.

      Unfortunately, since proper log/trace/debug statements are a PITA to write in Java and destroy readability, most folks simply opt to not do it.

    14. Re:Shorthand programming by divec · · Score: 2, Interesting
      As to BEGIN and END -- I have coded with C (pre-ansi) on machines whose keyboards didn't have '{' and '}'. I had to construct an include file to define BEGIN and END with a binary editor. But it worked.


      Interestingly, ISO C defines shorthands for people with crap keyboards. You can type <% instead of { and %> instead of }. Also:


      <: means [
      :> means ]

      %: means #
      %:%: means ##


      You get even more if you include iso646.h. Of course, the old compiler you were using may not have had these :-)
      --

      perl -e 'fork||print for split//,"hahahaha"'

    15. Re:Shorthand programming by JediTrainer · · Score: 1

      #define ONE 0
      #define ZERO 1


      Hey! That's MY code! How dare you publish it without my permission?

      --

      You can accomplish anything you set your mind to. The impossible just takes a little longer.
    16. Re:Shorthand programming by spakka · · Score: 2, Insightful

      I know I can change this to eliminate the empty ';', but I choose not to, because I feel that the conditional reads better as a positive statement.

      At the cost of failing to compile

    17. Re:Shorthand programming by Anonymous Coward · · Score: 0

      Good God.

    18. Re:Shorthand programming by Ed+Avis · · Score: 1

      Absolutely. C++ seems to bring out some prudish, put-clothing-on-the-table-legs attitudes in people who are somehow embarassed to use the naked language.

      Sometimes you see arguments for avoiding the standard int type and defining INT32 (or more likely _MyInt32 or some other monstrosity) on the grounds of portability. Then you can have a header file which defines INT32 appropriately on various platforms. But in fact this will usually have the effect of limiting portability, because you're making your code too dependent on a particular int size. Most code should neither know nor care how long an int is, it should just use the native integer type provided by the compiler.

      C suffers from the same problems to some extent but C++ is worse, probably because there are more language features to 'wrap' and some people feel that simple code is to be disallowed because it is 'not object-oriented enough'. The exact meaning of 'object-oriented' is not specified, but you get the feeling that the more ugly BiCapitalized method names it involves, the more likely it is to be OO. So for example using the built-in boolean type is not OO enough, but a new class with isFalse() and isTrue() methods will be okay. A simple enum { a, b, c } is not allowed: a class with isA(), isB() and isC() methods must be used instead (but a single method to get the value would not be OO enough).

      Stroustrup's book introduces object-oriented programming techniques fairly late on, after templates. Using C++ does not mean you have to treat the language as though it were Java circa JDK1.0.

      --
      -- Ed Avis ed@membled.com
    19. Re:Shorthand programming by Yunzil · · Score: 1

      #define NOTHING ;
      ...
      if ((flag & VAL1) || (flag & VAL2)
      NOTHING;
      else
      ...


      Parse error before 'else'

    20. Re:Shorthand programming by Kupek · · Score: 1

      Redefining the language to better meet the problem is one of the hallmarks of good (artistic) programming.

      Which is not the same as good programming practices in general.

    21. Re:Shorthand programming by blahedo · · Score: 3, Insightful

      Your answer highlights the very reason that C macros are a bad idea. You say:

      #define NOTHING ;
      ...
      if ((flag & VAL1) || (flag & VAL2)
      NOTHING;

      Correct me if I'm wrong, but that's going to put two semicolons after the if---not itself an error, but it's going to block the else from working properly, since the second semicolon is a(n empty) statement after the end of the if clause!

      In general, using macros in this fashion is dangerous and difficult to maintain, because it's not known what exactly is in the content of the macro. If a shortcut is at least part of a language, then a maintainer has some reasonable chance of understanding a piece of code as written without going hunting through header files. (Though of course one of the major complaints against perl is that there are so many shortcuts that are part of the language that nobody knows them all, pretty much reducing us to the previous problem.)

      --
      ``This, too, shall pass.'' ---Eastern proverb
    22. Re:Shorthand programming by Anonymous Coward · · Score: 0

      And I prefer...

      if (!(flag & (VAL1 | VAL2)))
      {
      /* Do something */
      }

    23. Re:Shorthand programming by autopr0n · · Score: 1

      As to BEGIN and END -- I have coded with C (pre-ansi) on machines whose keyboards didn't have '{' and '}'. I had to construct an include file to define BEGIN and END with a binary editor. But it worked.

      You could also haved used '<%' and '%>' rather then going through all that trouble....

      --
      autopr0n is like, down and stuff.
    24. Re:Shorthand programming by SeanAhern · · Score: 1

      He forgot the closing ). Doesn't really affect his argument.

    25. Re:Shorthand programming by Anonymous Coward · · Score: 0


      Most code should neither know nor care how long an int is, it should just use the native integer type provided by the compiler.


      Hmmm... Better not have anything to do with numbers that might wrap a 16 bit int (or even an 8 bit int for that matter) I can see it now. "No one will ever need more than 256 distinct int values"

      Seriously, In languages where there are no Exceptions to tell the code that something interestng happened when you added those two numbers, you had better give some careful thought to the valid range of types or you will be writting some wickedly hard to find bugs.

    26. Re:Shorthand programming by jeremyp · · Score: 1

      The java.util.logging.Logger class is your friend. Only available since 1.4 I'm afraid.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    27. Re:Shorthand programming by ratboy666 · · Score: 1

      You are absolutely right -- I just did this in a hurry: "#define NOTHING /*=i=*/" and

      #define NOTHING /*=i=*/

      if (...)
      NOTHING;
      else {
      ...more code...
      }

      is more like it. Now, there is a contract between the maintainer and the developer. One which I try very hard not to break. Specifically, what the code says it does is what it does. There is no need to "figure it all out" at the same time when analysing. It can be approached in a top-down fashion. A function with the name "create_mutex" is going to create a mutex, and not (say) open a file.

      Beyond that, I promise that there are not tricky bits, unless specifically documented. Sure, macros have problems, but when properly used they can aid in the reading of code. The main problem macros have is they sure make it hard to write code that reads and manipulates code.

      Ratboy

      --
      Just another "Cubible(sic) Joe" 2 17 3061
    28. Re:Shorthand programming by Anonymous Coward · · Score: 0
      ANSI C doesn't define NULL to be zero. I believe the AS/400 might be the most popular platform which has had non-zero values for NULL in some versions of the compiler.

      It's stupid at times but it's actually saved time and money at times to specify that kind of stuff (kind of like $R0 being hardwire to zero on several platforms) Nothing like doing something like a return NULL and expecting to get 0x0 back but it turns out to be something else becuase NULL isn't defined to be 0x0.

    29. Re:Shorthand programming by Ed+Avis · · Score: 1

      Yes I agree you do have to worry about overflow in C and C++. But for many applications it is reasonable to assume a 32 bit int is big enough and you can just stick your fingers in your ears and go 'la, la, la'.

      If people were porting to 16-bit platforms it might make sense to have an INT32 type, although I think I would prefer a compile-time assertion that the maximum integer value is at least a million or whatever high number you feel comfortable with. But it's a bit braindead to insist on INT32 and similar typedefs when you are making a loop counter and the code will run only on modern systems. You should just let the compiler pick the optimum sized int for the current platform.

      --
      -- Ed Avis ed@membled.com
    30. Re:Shorthand programming by DrStrangeLoop · · Score: 1
      this is stupid, of course.
      everyone knows that is is supposed to be
      #define EVER(;;)


      or better yet,
      #define EVER(;

      that way, you get that cute
      forEVER;)

      smiley face ;)

      scnr, strangeloop
    31. Re:Shorthand programming by Anonymous Coward · · Score: 0

      Why not just write it as the following and get rid of the unneeded else clause?

      if (!((flag & VAL1) || (flag & VAL2)))
      /* do whatever you were going to do in your else clause */

      IMO, that's far more readable than what you were doing with the NOTHING #define.

    32. Re:Shorthand programming by Anonymous Coward · · Score: 0
      #define FOREVER for(;;)

      Yes, that is evil. After all, everyone knows the correct way to do that is

      #define EVER (;;)

      followed by

      for EVER { repeated_task(); }
    33. Re:Shorthand programming by Anonymous Coward · · Score: 1, Funny

      or better yet

      #define IS_NOT_IS_TOO_IS_NOT_FINE_HAVE_IT_YOUR_WAY !

      if (IS_NOT_IS_TOO_IS_NOT_FINE_HAVE_IT_YOUR_WAY (flag & VAL1) || (flag & VAL2)

    34. Re:Shorthand programming by Bronster · · Score: 1

      if ((flag & VAL1) || (flag & VAL2)
      NOTHING;
      else


      Here I see a language crying out for perl's 'unless'.

    35. Re:Shorthand programming by Yunzil · · Score: 1

      That's not the problem though. :) Since he define NOTHING as a semicolon, and used it as "NOTHING;", he has two null statements after the 'if'. He needs a set of braces.

    36. Re:Shorthand programming by Anonymous Coward · · Score: 0

      Not all uses of "int" are to count. Two counter-examples: (1) driving hardware registers and (2) exchanging messages with another process. In both cases it's vital to know the exact number of bytes occupied by a certain type.

      The C99 "half-open" types are also useful. You often need to express a concept like "an int that's at least 16 bits; after that, I don't care" even for counters.

      Just plain "int" is rarely useful for anything but a simple loop over tiny data ranges; even then there's a small risk of lack of future-proofing. Even if you use int, you're most likely checking in the back of your mind that the int is really big enough for your purpose. Might as well document that requirement in the code, rather than leaving it in the back of your mind to be forgotten.

    37. Re:Shorthand programming by wkjel · · Score: 1

      The practice of using defined names for native types goes back to the early days of C compliers when the size of int varied from complier to complier. The use of defines was part of the Plum Hall C Stamdards guide.

    38. Re:Shorthand programming by Ed+Avis · · Score: 1

      But the point is, the size of int _should_ vary from compiler to compiler. It's bad practice to write code that requires or assumes a particular int size. Maybe back in the day of 16-bit or 18-bit systems, where there was a real chance of int overflow in many applications, you had to worry about using a type big enough. But when the choice is between 32 bits and 64 bits, best practice is usually to just say 'int' and use the native integer type of the machine.

      --
      -- Ed Avis ed@membled.com
    39. Re:Shorthand programming by Ed+Avis · · Score: 1

      Fair enough, I wasn't really thinking of low-level programming or raw binary message encodings. Although I think that in these cases you would have a header file defining the structures used, and then any low-level 'I require this number of bits' integer types would be confined to that header file.

      I agree with documenting the int size requirements in the code, where there really are requirements. But that is not the same as 'use INT32 for everything instead of int', which is documenting that you require _exactly_ 32 bits when really what you need is something 'big enough'. Instead it would make more sense to use an int, and on a platform where 64-bit ints are the native integer type the compiler will use that. You could have a check in some global header file that 'int' is at least 32 bits wide, I think this is usually adequate and you don't need to stick INT32 in every single place you use an integer.

      I will have a look at the C99 minimum-sized types you mention, they sound like a good answer to the problem.

      --
      -- Ed Avis ed@membled.com
    40. Re:Shorthand programming by wkjel · · Score: 1

      I'd agree that today there is little need to worry about integer size -- my point was about the historical origins of the practice.

      When I first started working on Unix systems 20 years ago, there were over 80 different version of the system and being careful about integer size was a necessary defensive practice. AT that time it was common to migrate several times a year from system to system. On one project I had to write and test on one system and then transfer the source overnight (via uucp!) to a customer's machine running a completely different verson of the OS and complier. All debugging was done at the assembler level using adb - I'm glad that's all a thing of the past.

      Still, there are instances where it is necessary to be aware and clear about primitive datatype size in C and C++, -- for example, when you need to use 64bit floating point for financial math -- but using typedefs and/or classes is much preferred to #defines. Using alternate names for primitive types makes it clear to everyone on a project what use is intended. Such uses should, of course, be well documented in a project's programming standards.

    41. Re:Shorthand programming by WWWWolf · · Score: 1
      Interestingly, ISO C defines shorthands for people with crap keyboards.

      Now I wish Python would do stuff like that that, also. Or at very least I wish Blender folks would fix their damn editor in the Windows port of Blender =)

      But seriously, I think sometimes stuff like this is very cool, even when it looks somewhat, um, inelegant. Uses for constructs like this may surface in unexpected places.

    42. Re:Shorthand programming by J.+Random+Software · · Score: 1

      Assuming int is 32 bits is absurd. We already have an integer type that's at least 32 bits, namely long. And if you want the value of INT_MAX you know where to find it.

    43. Re:Shorthand programming by Ed+Avis · · Score: 1

      I'm not sure whether you are agreeing or disagreeing. My point is that most of the time you shouldn't know or care how many bits are in an int, only that it is enough. On platforms of days gone by this wasn't the case, but now there is no good reason.

      I wouldn't advocate using long instead of int because it may not give such good performance. On some platforms long is 64 bits wide while the compiler may feel that the best general-purpose integer type is only 32 bits. On the other hand, it may be that 64 bit integers are best suited to the platform and so int may be 64 bits wide. You let the compiler decide for you, unless you have a very good reason to insist on a particular representation.

      --
      -- Ed Avis ed@membled.com
    44. Re:Shorthand programming by J.+Random+Software · · Score: 1

      It is best to let the compiler choose the fastest integer type except in special cases, but needing more than the language offers--16 bits--has to be one of those cases. Competent coders use the preprocessor to either include typedefs or refuse to compile if they want INT_MAX > 32767.

    45. Re:Shorthand programming by Ed+Avis · · Score: 1

      Checking INT_MAX (or its C++ equivalent) is the better strategy because you are checking what you really need - a large enough range of values - rather than doing platform-dependent fiddling on the basis of internal representation (number of bits). Also it doesn't turn the code into boilerplate, and doesn't force you to use a typedef like INT32 when what you really want to say is 'let the compiler decide'.

      Although a third option open to a 'competent coder' is to simply say this program requires a platform with large enough ints. Just as it may require a platform with at least 100Kbyte of memory available but you don't check that at compile time.

      --
      -- Ed Avis ed@membled.com
    46. Re:Shorthand programming by Minna+Kirai · · Score: 1

      He means it can be eliminated by inverting the conditional to be "if not A then C" instead of "if A then NOTHING else C", as it is now.

  24. FreeBSD Support by rf0 · · Score: 1

    Don't suppose with this there will be a native FreeBSD port will there rather than having to patch and have 3GB have disk space free to compile it?

    Rus

    1. Re:FreeBSD Support by chefbimbo · · Score: 2, Funny

      It'd be about time Sun ported it to FreeBSD (the ONE thing lacking from it) but as you know, FreeBSD is dying so why bother.

    2. Re:FreeBSD Support by Anonymous Coward · · Score: 0

      uhhh... BSD is dead. Why bother?

    3. Re:FreeBSD Support by Billly+Gates · · Score: 1
      IF you go to usr/ports/lang/jdk and read the files you will see that sun only licenses java for non commercial use.

      For this reason it is not included in the ports. The port can be downloaded from java.sun.com after you agree to an EULA.

      Its similiar to the NVIDIA thing about legality so distro's decide not to include it.

  25. Emacs for Java by Anonymous Coward · · Score: 0

    Check this out at IBM's developerWorks:
    http://www-106.ibm.com/developerw orks/java/library /j-emacs/

    1. Re:Emacs for Java by gray+peter · · Score: 1

      bad url?

      --
      May no camel spit in your yogurt soup.
    2. Re:Emacs for Java by Anonymous Coward · · Score: 0

      Sorry - goto IBM developerworks, Java Technology, Articles & Columns, column name is "Emacs a top notch Java IDE? You bet!" I copied & pasted the URL from the displayed page, but you're right, it doesn't work - again, sorry for the trouble.

  26. Hope it fixes issues with 1.4.x by cprice · · Score: 1, Insightful

    1.4.x is rife with issues; corefiles or memory leaks (StringBuffer ToString anyone?). I sure hope that this is a stability improvement release rather than another round of 'improvements'.

    1. Re:Hope it fixes issues with 1.4.x by boxhead609 · · Score: 1

      StringBuffer.toString() has an issue where a StringBuffer is used to build out a new string. This new StringBuffer is the default 16 byte StringBuffer. When large StringBuffer's are .toString()'d, zillions of StringBuffer's are created in the process because of this ultra small 16 byte issue.

    2. Re:Hope it fixes issues with 1.4.x by Anonymous Coward · · Score: 0

      These are implementation problems, not language problems. Which implementation are you using? Talk to the people who implemented it.

      At least with Java, you have a choice of switching implementations - something you don't get in the .NET world.

    3. Re:Hope it fixes issues with 1.4.x by DogIsMyCoprocessor · · Score: 3, Insightful
      -1, troll

      memory leaks (StringBuffer ToString anyone?).

      Sorry, not a bug. What happened is the JDOM folks (gambling) relied on the internal implementation of StringBuffer and not its public API. That also broke JDOM for 1.2 jvms, which implemented StringBuffer differently. The internal implementation changed in 1.4.1, hosing the JDOM folks. Sun's only mistake was making this change in a minor version instead of a major one.

      --

      "And this is my boy, Sherman. Speak, Sherman." "Hello." "Good boy."

    4. Re:Hope it fixes issues with 1.4.x by _xeno_ · · Score: 1
      I think you're wrong. The public API spec says nothing about the huge memory cost that can be incurred by calling toString() on a StringBuffer. Look at the API spec and tell me where the StringBuffer API says that toString() maintains the original buffer size. In fact, the JDK 1.4.1 documentation says, regarding the StringBuffer.toString() method: "A new String object is allocated and initialized to contain the character sequence currently represented by this string buffer."

      That suggests to me that calling StringBuffer.toString() would allocate a copy of the buffer into the new String. It says nothing about the fact that this new String will silently carry over the internal StringBuffer allocated memory space. But - surprise! - it does.

      The problem that is occurring was basically that a StringBuffer was being used to build various strings. Such a StringBuffer is usually treated as - well, as a buffer. So say the first string was 1024 characters long. The string buffer grows to hold it. (Worst case, a 1023 character buffer having a single character appended would cause a 2050 character buffer. Starting from a new StringBuffer() and building the buffer a character at a time would result in a 1150 character buffer.) The call to StringBuffer.toString() would create a new String that maintains this memory.

      JDOM would then reset the StringBuffer length to 0, on the theory that the StringBuffer already contains the scratch space to deal with incoming data. This assumption is wrong - the StringBuffer allocates a new character array of the size it originally had. So the new 5 character string will wind up in a String object that maintains 1145 useless additional characters. Remembering that a Java character is two bytes, we can see that this can easily add up fast, especially with the way StringBuffers are expanded.

      While assuming that reusing a StringBuffer saves time/memory is an implementation assumption, assuming that the size of StringBuffer and the size of the resulting String should not correlate is not really an implementation assumption - the docs seem to suggest that a brand new String is allocated that contains only the needed characters. (As opposed to a brand new String that contains the entire memory buffer of the StringBuffer.) This is not the case, and instead new String(stringBuffer.toString()) needs to be used to cause the String to only contain the requested characters.

      I would clearly lay the blame on Sun for changing the implementation from what their own API docs dictate.

      --
      You are in a maze of twisty little relative jumps, all alike.
  27. Why I don't like Java by pygeek · · Score: 2, Insightful

    Java is an OK language for teaching programming basics, but it's just too much bondage and discipline for my taste.

    You're forced to do object oriented programming. OK, I can respect that - but Java is not consistent. Everything is not an object, and it's just so damned ugly when you have to wrap an int in an Integer.

    Also, it's statically typed. It's so fucking annoying to have to typecast everything - I know I have a damn String - quit holding my fucking hand!

    Furthermore, Java's text processing abilites suck so bad, I don't even know where to begin.

    Give me Python any day. It can do any job Java can do, and probably better.

    1. Re:Why I don't like Java by Ageless · · Score: 1

      Did you miss the entire article, or what? Every single issue you mentioned up there is addressed in 1.5 and regex was added for your text processing in 1.4.

    2. Re:Why I don't like Java by forsetti · · Score: 4, Interesting

      Also, it's statically typed. It's so .. annoying to have to typecast everything

      Typecasting is a tool -- do you really trust the compiler to recognize exactly what you mean in every scenario, throughout your hundereds of thousands of lines of code? I don't want to have the compiler (or run-time environment, or interpreter, whatever) to "guess" at what I mean -- I want to tell it exactly what I mean.

      <flame> Perhaps this is why huge applications are usually written in languages requiring typecasting, and the "looser" languages are usually relegated to simple task duty.</flame> :)

      --
      10b||~10b -- aah, what a question!
    3. Re:Why I don't like Java by MilesParker · · Score: 2, Insightful
      "Also, it's statically typed. It's so fucking annoying to have to typecast everything - I know I have a damn String - quit holding my fucking hand!"
      Yea, you "know" you have a String...until you don't. Maybe you're superman, but I'm mortal -- and by the way, good practices demand a little humility, and assuming that you are _not_ perfect.

      Java's strong typing has been a huge productivity enhancement for everyone I've worked with. Just knowing that typically when you compile something, its actually going to run without a single error has been a revelation for me.
    4. Re:Why I don't like Java by tim_maroney · · Score: 1

      I agree. Typecasting is just short of "goto" in its awfulness. If you need it more than once in a blue moon then there's something seriously wrong with your software architecture.

    5. Re:Why I don't like Java by pygeek · · Score: 1
      Perhaps this is why huge applications are usually written in languages requiring typecasting, and the "looser" languages are usually relegated to simple task duty. :)

      OK, you have a point. A lot of things are "safer" when you have compile-time type checking.

      But isn't that usually only necessary when a lot of developers, some of who are inexperienced, are working on the same project?

    6. Re:Why I don't like Java by CognitivelyDistorted · · Score: 1

      I love python myself, but it's not the best language for every project. Python progs are 10-20x slower than equivalent C++ progs. Java is only 2-5x slower. Also, in a medium or bigger project, I find type checking to be pretty helpful in catching bugs.

    7. Re:Why I don't like Java by KrisW · · Score: 1

      I absolutely love Python. Yeah sure, everyone always says the same thing about how much slower than C++ it is, but for every program I've written in Python so far (including games), speed has not been even the slightest issue. Plus, if you ever do need the extra speed, it's pretty easy to re-code the bottlenecks in C.

      --


      "Think you can take me? Go ahead on. It's your move." --Joe Don Baker in Final Justice
    8. Re:Why I don't like Java by Malc · · Score: 1

      The inconsistency with the native types has always bugged me too. But I think you're way off about the static typing. Have you ever worked on a big project, or with other people, or on code you wrote over a year ago? Static typing starts becoming imperative as aid for preventing stupid mistakes that cause run time problems.

      Having spent most of my career writing C++ and a little Java and now C#, I get incredibly annoyed with the weakly typed languages I have to use occasionally, such as shell, Java, J and VB script. They're useful if you want to knock up something quickly, but can lead to problems on bigger projects.

    9. Re:Why I don't like Java by forsetti · · Score: 1

      As an example, from a simple optimization point of view -- will a loosely cast language cast "My String" as an efficient static string, hoping that I will never try to change it, or as some sort of dynamic string (StringBuffer), which is inefficiently stored, but flexible for modification? If all of your code is in one file, the compiler can usually figure it out. But if you have multiple files that are compiled separately, and linked at a later stage, the compiler has to choose during compilation, and hope that some action in another module does not make it perform runtime conversions.
      I'd rather tell it EXACTLY what I plan to do with that string -- then I can make it dance the way I want to.

      --
      10b||~10b -- aah, what a question!
    10. Re:Why I don't like Java by HeghmoH · · Score: 1

      Perhaps this is why huge applications are usually written in languages requiring typecasting, and the "looser" languages are usually relegated to simple task duty.

      Yes, because we all know that nobody has ever written large applications in Smalltalk, Lisp, or Objective-C.

      --
      Mod down posts with a "Free Mac Mini/iPod" sig, they're spam!
    11. Re:Why I don't like Java by Jhan · · Score: 1

      Java is not consistent. Everything is not an object, and it's just so damned ugly when you have to wrap an int in an Integer.

      Autoboxing. RTFA.

      Also, it's statically typed. It's so fucking annoying to have to typecast everything - I know I have a damn String - quit holding my fucking hand!

      Generics. RTFA.

      Furthermore, Java's text processing abilites suck so bad, I don't even know where to begin.

      Regexp. RTF last year's A. (Though regexps really could have been implmented in a better way.)

      --

      I choose to remain celibate, like my father and his father before him.

    12. Re:Why I don't like Java by Troll_Kamikaze · · Score: 2, Insightful

      I don't want to have the compiler (or run-time environment, or interpreter, whatever) to "guess" at what I mean -- I want to tell it exactly what I mean.

      Perhaps this is why huge applications are usually written in languages requiring typecasting, and the "looser" languages are usually relegated to simple task duty.

      Dynamically yet strongly typed languages such as Python and Lisp allow you to tell the compiler or interpreter "exactly what you mean" with regard to types, they just don't require you to do so. Where's the beef?

      Bruce Eckel, a C++ and Java expert and the author of the "Thinking In ..." series of books, wrote recently:

      After I had worked with Python for awhile -- a language which can build large, complex systems -- I began noticing that despite an apparent carelessness about type checking, Python programs seemed to work quite well without much effort, and without the kinds of problems you would expect from a language that doesn't have the strong, static type checking that we've all come to "know" is the only correct way of solving the programming problem.

      This became a puzzle to me: if strong static type checking is so important, why are people able to build big, complex Python programs (with much shorter time and effort than the strong static counterparts) without the disaster that I was so sure would ensue?

      This shook my unquestioning acceptance of strong type checking...

    13. Re:Why I don't like Java by Admiral+Burrito · · Score: 1
      Also, it's statically typed. It's so fucking annoying to have to typecast everything - I know I have a damn String - quit holding my fucking hand!

      You may know you have a String, but the junior programmer who just came on may not, and will be trying to read your code. All the typecasting in Java is annoying, but it does improve readability. He'll also be writing his own code, and if he thinks he has a String when he doesn't, the compiler will tell him.

      That is why Java is so successful. It sacrifices convenience for safety, to protect a probject from inexperienced developers. And while you may not be an inexperienced developer, if you spend any amount of time on large projects you will have to work with them. Better that the language does the hand-holding for the juniors, so the senior developers don't have to (as much).

      Sure there is some casting that is clearly redundant, eg. "String name = (String)i.next();". Generics should eliminate those stupid parts.

    14. Re:Why I don't like Java by __past__ · · Score: 2, Insightful
      Try Lisp. Common Lisp compilers usually generate faster code than Java (mostly because they compile to native code), yet you don't have to declare types unless you choose to do so. If you do, the compiler can use the declarations either to check type correctness or to generate optimize code, just as you wish.

      Once you've experienced the freedom and flexibility of Lisp, there's no way back. Unfortunatly, you'll soon realize that this fact sucks hard when you try to program by library-shopping, scince there basically are no third-party libs for CL.

    15. Re:Why I don't like Java by Anonymous Coward · · Score: 0

      Oh I just love it when people invent statistics just to make them look smart. Java 2-5x slower than C++? Doing what? Graphics processing is just about the only thing that is slower than C++ these days. I don't like Python (in fact I hate it) but I'm pretty sure those numbers are completely off too. Python seems to be fast enough for the people that use it.

    16. Re:Why I don't like Java by rjh · · Score: 1

      Also, it's statically typed. It's so fucking annoying to have to typecast everything

      You're confusing strong typing with static typing. Strong typing just means that it's very anal-retentive about type. Static typing means the checks are all done at compile-time.

      It's pretty easy to come up with situations in which the typing is done dynamically (i.e., at run-time). So no, Java is no more a statically typed language than C++ is: both of them allow you to defer type analysis until runtime.

      Java and C++ are strongly typed languages, but they're not clearly either statically typed nor dynamically typed. Some languages (Objective C, Smalltalk) are purely dynamically-typed; some are purely statically-typed; C++ and Java are hybrids.

    17. Re:Why I don't like Java by tunah · · Score: 1
      I'm so sure this is a troll, but...

      and it's just so damned ugly when you have to wrap an int in an Integer.

      RTFA.

      Also, it's statically typed. It's so fucking annoying to have to typecast everything - I know I have a damn String - quit holding my fucking hand!

      RTFA.

      --
      Free Java games for your phone: Tontie, Sokoban
    18. Re:Why I don't like Java by Anonymous Coward · · Score: 0

      I don't like Java either, but depending on the type of program I'm writing, I like to have static typing.

      Try programming in a few languages with static typing but type inference. You don't need to explicitly specify types (except in exceedingly weird situations), but you get compile-time type safety.

      You really shouldn't compare statically and dynamically typed languages. They really are for different purposes. Dynamically typed languages, especially interpreted ones, are much slower (Python is often 100x slower than compiled, statically typed languages, and even semi-interpreted ones like Java).

    19. Re:Why I don't like Java by sbwoodside · · Score: 1

      Also, it's statically typed. It's so .. annoying to have to typecast everything

      Typecasting is a tool -- do you really trust the compiler to recognize exactly what you mean in every scenario, throughout your hundereds of thousands of lines of code? I don't want to have the compiler (or run-time environment, or interpreter, whatever) to "guess" at what I mean -- I want to tell it exactly what I mean.


      Have you even used a dynamically typed language (like Objective-C or Smalltalk ... ) ??? It sounds like the answer is no. Dynamic typing doesn't mean that you lose any ability to have the compiler help you out with the types of your variables. Instead you get the best of both world. With ObjC, you are perfectly free to specify the type of an object variable. If you try to assign it to another type, the compiler will issue a warning but compile anyway. You watch those warnings. If at runtime, the variable turns out to be the right type after all, everything works, if not, you get a runtime error. Maybe a crash, maybe not, depends on what you did.

      So what's the gain? You get to write classes that can operate on any type WITHOUT having to deal with templates or generics. Let's say I have a SortedList class that I want to handle any object. In ObjC all I do is specify that the objects that are put into the SortedList MUST conform to a certain API -- they must have a "compare" method so that I can order them. Aside from that, thanks to dynamic typing and binding, I don't give a hoot what kind of type you give me, because all I'm gonna do is call "compare" on it and if that call works, I'm happy.

      In fact, with dynamic typing, I can even check if the method "compare" is valid FIRST before I try to call it, at runtime, and handle any errors gracefully.

      Don't dis something you don't understand. Dynamic typing rocks.

    20. Re:Why I don't like Java by Jason1729 · · Score: 1

      Typecasting is a tool -- do you really trust the compiler to recognize exactly what you mean in every scenario, throughout your hundereds of thousands of lines of code?

      A technique I frequenly use in C++ is to typecast an object to a string, then pass the string across a communications channel (like TCP/IP), and then typecast it back to an object. You can't do that in a strongly typecast language, so you have to do a lot more work.

      It's a tool that you're forced to use, even for the wrong job. It's like being forced to use a hammer to install screws.

      Jason
      ProfQuotes

  28. ClassCastException by roalt · · Score: 1
    The upside is that if you try to insert something that's not a string, you find out at compile time and fix the problem. Without generics, you discover such a bug when your most important customer calls your VP to tell him that the program on which his business depends just crashed with a ClassCastException.

    Please, please, tell me that there exists a company where the VP knows what a ClassCastException is!

    1. Re:ClassCastException by Anonymous Coward · · Score: 0

      biggest problem there is you can't turn it back on that customer and say, "it can only be attributed to user error" cause' it cant! New best practice:
      Catch unexpected errors at the top level, Throw them back wrapped in a StupidUsersFaultException.

    2. Re:ClassCastException by lokedhs · · Score: 1
      No, but there exists (at least I heard rumours) VP's that can read pretty well.

      ...although the bug report will probably sound something like: "the computer is telling me that my ass is exceptionally classy!"

      Umm... Well... "read pretty well" for appropriate values of "pretty well".

  29. So C# is basically Ada without strong typing? by coyote-san · · Score: 2, Interesting

    It sounds like C# uses a lot of stuff from Ada (and I'm sure countless other languages), but forgot to honor prior work. :-)

    Seriously, the "C# copied from Java/Java copied from C#" argument misses the point. There's a lot of prior work, and finding the right balance between usability and clutter is difficult. As much as I loved writing stuff like "for (value'range) do..." I would rather see a conservative approach to features since it's always easier to add stuff than remove it.

    --
    For every complex problem there is an answer that is clear, simple, and wrong. -- H L Mencken
  30. Some quality stuff - competition is good! by Fnkmaster · · Score: 4, Insightful
    I gotta say, I'm positively impressed. C# and Java are feeding features off of each other. Iterators, enumerators and autoboxing/unboxing - hmm, I think I've seen those before. Java 1.5 starts to look more and more like C#.


    Some of this other stuff has been going on for ages - I'm curious about the metadata/declarative programming features. I've developed complete code generation systems for Java - the number of situations that require reams of very repetitive code in your average large-scale Java app is huge, and much of that can be automated. It would be great to see a consistent, standard system for doing this built in as a language feature rather than having hundreds of home-rolled systems everywhere, but the nature of many problems lends themselves to home-rolling. I can't tell you how many times I've written simple SAX parsers that spew out Java code, and rolled up an ant target to run it on some schema and package up the result. It's not clear from this brief example whether this is only for XML/RPC or whether there's an extensible metadata system that you can build on top of.


    Then again, we should be careful not to roll too much into the language itself. I think generics, autoboxing, and enumerators are fabulous. Iterators I could give less of a shit over. Other stuff is great, but I question whether extending the language is the right mechanism. Much of the power and flexibility of Java comes from its simplicity. And most importantly, the ease of reading other people's code - there's far less stylistic variation because there are only N ways to do a task, rather than N! ways to do it, like in C++ (don't get me wrong, for a lot of tasks, I'd never dream of doing them in Java, like 3D programming). But it takes me about 1/4 to 1/3 the time to assimilate and learn a new Java API or library as it does to learn your average C++ API or library, and that's the appeal of Java.


    Of course, I'll be thanking the gods that I never have to deal with the fugliness of casting and wrapping to move stuff between typed arrays and untyped Lists again.

  31. I agree by rebelcool · · Score: 1
    These new improvements don't do much for improving readability (check out the enhanced for loop).

    They may be useful, but they need to avoid C++ing themselves with hard to read shortcut characters.

    --

    -

  32. Those who don't understand Perl by Anonymous Coward · · Score: 1, Insightful

    . . . are doomed to reinvent it.

    foreach anyone?

    null is zero?

    That said, I've wanted Generics in Perl since the first week of using the language and I can't wait until they are available.

    Disclaimer: I use Java professionally and Perl amateurly and I love them both.

    1. Re:Those who don't understand Perl by Anonymous Coward · · Score: 0

      I agree. The article enumerates several of the things I love about Perl. Perl6 gets parrot and stronger typing, Java gets better support for Collections. Maybe they will merge in Perl7 (Gods version of Perl)

  33. Netbeans by truthsearch · · Score: 2, Informative

    While eclipse is great, Netbeans has more features. I prefer eclipse because it uses a native interface and has refactoring. The most feature-rich IDE I've used for Java, however, is netbeans. If you don't mind a slow user interface it's a great tool to look at.

  34. An Extended Futile Example of Using GJ by AlxBarker · · Score: 1

    By Yours Truly (Shameless Plug): (And GPL/Artistic'd to boot) http://freshmeat.net/projects/gjal/

  35. A better solution than Generics by MarkSwanson · · Score: 2, Informative
    Generics is an auto-casting mechanism that is useful to catch programming errors at compile time instead of run time. Please note 2 things:
    1. the 'cast' still happens at runtime as the compiled bytecode is still the same.
    2. there is a much faster alternative that uses native data types instead of objects (below) and catches errors at compile time.


    As a pro Java developer, I want to use the native 'int' type in order to save memory, have less garbage collection, and perform better. Catching errors at compile time is helpful too. I think it is unreasonable for Sun not to include specializations for native data types. If I want to have an ArrayList of 10,000 ints I should be able to use 'int'.

    The link on this page states up to 10x performance but I've seen it work up to 30x performance - and you can run the code below to see this for yourself.
    NOTE:
    30 = 7272727/236966 where:
    1. 7272727 = 2nd iteration of Int2IntHashMap!
    2. 236966 = 15th iteration of HashMap (Hot spot had 12 more iterations to optimize)

    http://fastutil.dsi.unimi.it/

    package com.wss.utils.test;
    import java.util.*;
    import it.unimi.dsi.fastUtil.*;
    public class TestFastUtil {
    public static void main(String[] args) throws Exception {
    int count = 400000;
    int timerCount = 20;
    long start, end;
    Integer tmp; // Normal HashMap
    HashMap hashMap = new HashMap(count);
    for (int timer=0; timer timerCount; ++timer) {
    start = System.currentTimeMillis();
    for (int i=0; i count; ++i) {
    hashMap.put(new Integer(i), new Integer(i));
    }
    end = System.currentTimeMillis();
    System.out.println("HashMap put(Integer, Integer) count:" + count +
    ", put/s:" + (count / ((float)(end-start) / (float)1000)));

    start = System.currentTimeMillis();
    for (int i=0; i count; ++i) {
    Integer in = new Integer(i);
    tmp = (Integer)hashMap.get(in);
    if (!tmp.equals(in))
    throw new Exception("failed equals()");
    }
    end = System.currentTimeMillis();
    System.out.println("HashMap get(Integer) count:" + count +
    ", get/s:" + (count / ((float)(end-start) / (float)1000)));
    } // FastUtil HashMap Int2Int
    timerCount = 100;
    Int2IntHashMap int2IntHM = new Int2IntHashMap(count);
    int j;
    for (int timer=0; timer timerCount; ++timer) {
    start = System.currentTimeMillis();
    for (int i=0; i count; ++i) {
    int2IntHM.put(i, i);
    }
    end = System.currentTimeMillis();
    System.out.println("Int2Int put(Integer, Integer) count:" + count +
    ", put/s:" + (count / ((float)(end-start) / (float)1000)));

    start = System.currentTimeMillis();
    for (int i=0; i count; ++i) {
    j = int2IntHM.get(i);
    if (i != j)
    throw new Exception("Int2Int failed equals()");
    }
    end = System.currentTimeMillis();
    System.out.println("Int2Int get(Integer) count:" + count +
    ", get/s:" + (count / ((float)(end-start) / (float)1000)));
    }
    }
    }
    --
    Schedule your world with ScheduleWorld.com http://www.ScheduleWorld.com/ (Java Web Startable)
    1. Re:A better solution than Generics by Anonymous Coward · · Score: 0

      Generics are not just an auto-casting mechanism. They are an improvement regardless of whether or how they affect performance.

      The fact that you previously had to cast things when retrieving from a collection was a huge design flaw in Java, because it moves type checking that could be done at compile time to run time.

      From a language-theoretical standpoint, generics are necessary for Java to reasonably be considered a usable type-safe language.

      Similarly, the automatic boxing/unboxing of primitive types is a necessary feature to make the Java type system consistent.

    2. Re:A better solution than Generics by MarkSwanson · · Score: 1

      Generics is auto-casting mechanism and compile-time type checking - nothing else. If you feel otherwise let us all know why.

      Note: I did not say Generics was bad, or that it wasn't an improvement, or that it affected performance.

      I just want to be clear: I mentioned fastutil because I feel in many cases developers would prefer to use it over Generics for these reasons:
      1. It allows you to use native data types in collections.
      2. It provides more algorithms
      3. When used with native data types, it is enormously faster, much more memory efficient, and saves the garbage collector from potentially large amounts of needless work.

      --
      Schedule your world with ScheduleWorld.com http://www.ScheduleWorld.com/ (Java Web Startable)
    3. Re:A better solution than Generics by Anonymous Coward · · Score: 0

      Could always jump to C#. .NET 2.0, which should be out early next year (given Java 1.5 will go beta late this year the timeframes are similar,) will include full generics that support value types, such as int. This was done because generics aren't just there for type-safetly in derived collections but also for performance.

  36. conditional selection by WheatWilton · · Score: 1

    Why can't this new release of Java include selective compilation?! It's incredibly useful in C/C++ to implement common functionality with different platforms and stuff. Yeah, yeah, I should be using inheritance/interfaces/abstract classes to be doing this in Java, but why should the compiled bytecode be bloated with stuff that doesn't need to be compiled in?

    1. Re:conditional selection by MilesParker · · Score: 2, Insightful

      In my mind, this is _exactly_ the kind of thing that should be avoided in Java and that has sown so much confusions and monkey-business in the C++ community. Yea, you _should_ be defining those interfaces and abstract classes. That's why they call it OO. :D

    2. Re:conditional selection by Anonymous Coward · · Score: 0

      I think code in an "if (false)" block is just ignored by the compiler, and in the case of "if (true)" the conditional might just be ignored...you could always write some crazy hacky scripts to insert these conditionals into your code in place of some kind of special token (LINUX/WIN32/MAC, etc.) and compile...but that would be the definition of a Big Ball of Mud.

  37. funny by mirko · · Score: 1

    this is beginning to look like clean Qt/C++ code...
    Especially the iterators, etc.
    Are Sun "inventing" an "interpreted" C++ ?

    --
    Trolling using another account since 2005.
  38. Backing into generics by Animats · · Score: 1
    So now both C++ and Java have generics.

    In both cases, they came late to the language, so they're a bolt-on, not a designed-in feature. C++ before generics was awful. Remember those schemes for generating classes using big preprocessor macros? Unchecked downcasting? Strostrup had a big blind spot there. C++ is still less type-safe than it should be.

    It's a bit wierd for Java to get generics. One of the claimed features of Java was that you didn't need them. Java is supposed to be "polymorphic". But it's too early to judge.

    1. Re:Backing into generics by Anonymous Coward · · Score: 0

      Generics are best implemented in elegant (heavily recursive) functional languages like Scheme or Haskell. Smalltalk has good generics as well. I have yet to see a clean example of parametric polymorphism in a mainstream imperative language. Templates always felt like a giant macro-hack bolt-on in C++ and frankly I don't think it looks much better in Java. In spite of the power it adds, from an aesthetic viewpoint I just find it really distracting.

    2. Re:Backing into generics by Forkenhoppen · · Score: 1

      Java doesn't need them, but man are they nice. It's compile-time checking, which is very useful. Plus it saves time by not requiring you to cast their types coming out of the collections.

      Personally, I think this is wonderful. One of the things that annoyed me to no end whenever I first started using Java was how long of a line you had to type just to do something as simple as pulling a value out of a collection and using it. With this, it's finally at the level I'd like it to be at.

      As for those of you complaining about a lack of templates, they may be speedy, but they go against the object oriented nature of Java. With Java's collections, everything compiles to just one implementation, and can be reused in its byte-code form without your compiler ever having to touch its source. With a template, you have to recompile the entire class for each type you use it with. Imo, Java has taken the more object-oriented approach.

      I know some people think the trade-off in speed isn't worth it, but I disagree; having that byte-code/source one-to-one mapping can be a real blessing.

    3. Re:Backing into generics by lokedhs · · Score: 1
      You're confusing "generics" with "templates" here. Templates are C++ attempt of providing generics which is horribly ugly, and very non-OO. It also leads to huge amounts of code when the templates are instantiated.

      What Java 1.5 generics do, is to provide a way of moving the type check for the downcast to comple time rather than runtime. It's still the exact same object model, and there are no templates.

  39. Enumeration classes by coyote-san · · Score: 2, Informative

    This isn't the forum for a detailed discussion, but I actually prefer enumeration classes now over simple enumerations. The basic idea is to write a class something like:

    final class Color {
    String c;

    private Color (String color) { c = color; }
    String toString() { return c; }

    static final Color RED = new Color("red");
    static final Color BLUE = new Color("blue");
    static final Color GREEN = new Color("green");
    }

    You can then treat this class like a type-safe enumeration. It doesn't have all of the nifty features that you'll see in languages like Ada, but it has the nice property of allowing you to attach whatever information you want to the enumeration class.

    You can also use this approach to create self-initializing classes, e.g., a list of states (including full name, postal abbreviations, shipping zone, etc.) from a database. You can access the enumerated values through a collection class, a "lookup" method, or even reflection.

    --
    For every complex problem there is an answer that is clear, simple, and wrong. -- H L Mencken
    1. Re:Enumeration classes by tetsuji · · Score: 1
      The major problem with this implementation is that you can't use switch statements. At least with the code that I usually find myself working on, switch() is far cleaner to write and read than an endless number of if staements like

      if(c == Color.RED) {
      ...
      }
      else if (c == Color.BLUE) {
      ... }

      ad nauseum. When you have more than 5 or 6 enumerated values, this gets stupidly messy.

    2. Re:Enumeration classes by bluetea · · Score: 1


      This isn't the forum for a detailed discussion, but I actually prefer enumeration classes now over simple enumerations. The basic idea is to write a class something like:

      final class Color {

      [snip]

      static final Color RED = new Color("red");
      static final Color BLUE = new Color("blue");
      static final Color GREEN = new Color("green");
      }


      This idiom works great in some situations, but can be an absolute nightmare in others - see this article for some examples. Real enumerators address some problems that can't be solved using this mechanism.

    3. Re:Enumeration classes by coyote-san · · Score: 1

      The ability to associate extra methods with each element means that you can eliminate many of the situations where you would normally use a switch statement.

      E.g., let's say I want to look up the UPS shipping zone by a state enumeration. I could use:

      switch(state) {
      case 'AL': zone = 1; break;
      case 'AK': zone = 8; break;
      ...

      or I could use a "fat enumerator" (or whatever it would be called) and just use

      state.getZone();

      Obviously this starts to blur the distinction between beans and enumerations, especially if you allow some of these attributes to be modifiable. But in practice I've found that to actually be a benefit, not a problem, since it simplifies the process of adding enumeration values when necessary. I've run into this situation when extending an existing application, and it can be a real pain with classic enumerators.

      --
      For every complex problem there is an answer that is clear, simple, and wrong. -- H L Mencken
    4. Re:Enumeration classes by lokedhs · · Score: 1
      That's when you use HashMap's.

      The trick is to create a HashMap of runnables, keyed on your type safe enum type (yes, you have to implement equals() and hashCode() but that's two-button operation in IDEA), where the value is a Runnable with the code you want to run.

      Calling the code looks something like this:

      Map<Colour,Runnable> actionMap = ...;
      Colour someColour = ...;

      // look! one line of code to call the method, instead of a huge ugly switch/case
      actionMap.get(someColour).run();

      Also note my use of generics to spice things up. :-)

  40. Article didn't mention new concurrency stuff by dood · · Score: 5, Interesting

    One of the coolest new features of JDK 1.5 is the completely reworked concurrency stuff (JSR 166). I just listened to Doug Lea (spec lead) give a talk on this very subject and I'm pretty convince this will rocket Java performance way up for a lot of the collections stuff, concurrent programming, etc.

    Bascially, the goal of JSR 166 is to do for concurrency programming what JDK 1.2 did for data structurs (Collections stuff). The gist is, you'll never need to use "new Thread()" or "synchronized" anymore, but rather you'll execute Runnables, use Locks and Semaphores, etc. Also, queues are *completely* reworked to be ultra scalable.

    JSR 166 is based on Doug's concurrency package:
    http://gee.cs.oswego.edu/dl/classes/EDU/ oswego/cs/ dl/util/concurrent/intro.html

    OH, and there will be classes like AtomicLong which guarantee atomic 'compare and set' options for primitives. :)

    Cheers!

    1. Re:Article didn't mention new concurrency stuff by bricriu · · Score: 2, Funny

      AtomicLong? Born in the heart of a nuclear furnace, endowed with the power of the atom, it's a bird, it's a plane, it's AtomicLong!

      Sounds like a "super" class to me. ;)

      --

      AHHHHHHH! I'm burning with goodness again!
      - Reakk, Sluggy Freelance

    2. Re:Article didn't mention new concurrency stuff by Bluelive · · Score: 1

      Too bad the link is broken :( http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/ dl/util/concurrent/intro.html hmz now that i look better there is a space in your, nevermind me.

    3. Re:Article didn't mention new concurrency stuff by Anonymous Coward · · Score: 1

      OH, and there will be classes like AtomicLong...

      That sounds like a line from my spambox.

    4. Re:Article didn't mention new concurrency stuff by dood · · Score: 1

      Heh, that's not me, that's /.!

      --Bill

    5. Re:Article didn't mention new concurrency stuff by slagdogg · · Score: 2, Funny

      AtomicLong? Born in the heart of a nuclear furnace, endowed with the power of the atom, it's a bird, it's a plane, it's AtomicLong!

      Sounds like a "super" class to me. ;)


      Sounds like a porn star's name to me.

      --
      (Score:-1, Wrong)
    6. Re:Article didn't mention new concurrency stuff by etedronai · · Score: 4, Informative

      I am actually using the initial implementation of this on our current project and it is very nice. Actually have fine grained synchronization control makes it much easier to deal with a lot of thread synchronization problems. It has also helped us greatly reduce deadlock and detect deadlock because locks and waits can time out and report to you that they have timed out rather than just happily returning like Object.wait() does today. All in all this, along with generics, is probably the best new feature that is being added in jdk 1.5

    7. Re:Article didn't mention new concurrency stuff by Paradise+Pete · · Score: 1
      Heh, that's not me, that's /.!

      If you make it a real link Slashdot won't insert the space.

    8. Re:Article didn't mention new concurrency stuff by Anonymous Coward · · Score: 0
      OH, and there will be classes like AtomicLong which guarantee atomic 'compare and set' options for primitives. :)
      Why must I be like that, why must I split the act? Nothin' but the Long in me.
    9. Re:Article didn't mention new concurrency stuff by Anonymous Coward · · Score: 0
      Without memory ordering or barriers on the new atomics, they're about as useless as volatile currently is. I think that stuff is in JSR 133 but it should have been moved to JSR 166.


      ~karma

    10. Re:Article didn't mention new concurrency stuff by dr2chase · · Score: 1

      Is JSR 166 really in 1.5? Neither the happy-talk article nor JSR 201 (draft proposals for 1.5) imply this.

    11. Re:Article didn't mention new concurrency stuff by jonabbey · · Score: 1

      Yeah, it's really silly that Java has not yet had a standard set of concurrency control classes built on top of the monitor construct. I'm sure tons of Java programmers have rolled their own to get more deadlock-safe control over concurrency.

    12. Re:Article didn't mention new concurrency stuff by fantastic · · Score: 1

      That article didn't talk about half the things in 1.5, which is JSR 176

  41. Generic Java by henni16 · · Score: 2, Informative

    Interested in Generics?
    A Compiler for generic Java has been available for years:
    You can check out Pizza/GJ here or here

  42. Properties by truthsearch · · Score: 1

    I think "true" properties are a big mistake for a language. I'd much rather have the explicit "get" in front of the property's name to make it a method than the possible ambiguity of using only the property name to mean two things. Also I think the way of writing properties in C# is very ugly. But at the same time I couldn't think of a much better way to do it. All together I'd rather have functions.

    1. Re:Properties by TummyX · · Score: 1

      Although, it could be argued that since noone uses public fields (except for static final fields) that syntax for accessing fields is never used, so it might be better to move get/set to use that syntax.

    2. Re:Properties by kruntiform · · Score: 1

      I hate getSomething() methods. Yuck. They lack declarativeness. Which reads better, banana.getColor() or banana.color()? The latter naturally; you don't say "what it the get color of that banana" after all. And while we are at it, let's lose the brackets: banana.color. (Presumably that's what they mean by properties. I didn't bother to read the article.) Most people don't realize it yet, but declarative programming is the way of the future.

    3. Re:Properties by arkanes · · Score: 1

      I agree - properties are a cool idea, but the more I use them the more I find that I prefer the explicitness of a function call.

    4. Re:Properties by spitzak · · Score: 1
      Just done C++ but the main advantage I see here is that you can make read-only properties with Java (apparently you can't in C#). For a lot of my code this would make things much easier to read as it would eliminate a lot of "()" from the expressions.

      Oddly enough, I don't see so much need to assign to properties. Almost always in my code their values are set as a side effect of some other method, or it is much more convienent to set a bunch of them at once. For instance though box->x, box->y, box->width and box->height are useful properties, it is often more useful to set them with box->set(x,y,w,h) than with four assignment statements, and only with that type of assignment could some invariant like "w*h must be greater than 10" can be enforced.

      A thing I would like to see are static properties (just like static methods), and some kind of "unchanging" property for optimization, where you mark the fact that the property will not change value no matter what methods you do to the operator, or that it will not change value as long as const methods only are used. In my box example this would allow box->width to be implemented as box->right-box->left, yet the compiler would be smart enough not to do this subtraction 100 times if the calling function asked for the width 100 times.

    5. Re:Properties by sproketboy · · Score: 1

      I don't agree. Properties can hide performance deficits in code.

      Example (agnostic language)

      for j = 1 to prism.Colors
      -- do whatever
      next

      In this example referencing the 'Colors' property is really calling a hidden getColors() method. What if getColors() is doing something that could be time consuming like getting the value from an XML document or from a socket connection or from counting rows from a large rowset? In these cases it would not be obvious why where the performance deficit was.

      If, on the other hand you see:

      for j = 1 to prism.getColors()
      -- do whatever
      next

      You are reminded that 'get' means 'go do something and then return a value'.

      When one of my programmers writes something like the above example, I can spot this easily and give him a good slap on the wrist. ;)

      This should obviously be written as:

      n = prism.getColors()

      for j = 1 to n
      -- do whatever
      next

      But it's much obvious when using an explicit getter.

      My 2 cents anyway.

  43. Re: Generics are much more than typed containers by JamMasterJGorilla · · Score: 1

    > But note that "generics" or "parametric types Generics are much more than typed containers, I'll have to read more on the Java implementation. The most useful part of generics is of course generic algorithms. Hopefully java generics are more than the hijacked "Design Patterns" they gave us with JavaBeans - a Java "Design Pattern" is to name a getter as "get" and a setter as "set".

  44. My feelings on java and sun by zymano · · Score: 0
    1. Re:My feelings on java and sun by Glock27 · · Score: 1
      are answered here.

      If you're basing your opinion regarding Java on 2001 information, you're missing the boat.

      Java has its weak points, but it has many more strong ones.

      --
      Galileo: "The Earth revolves around the Sun!"
      Score: -1 100% Flamebait
    2. Re:My feelings on java and sun by zymano · · Score: 1
      I use java all the time at yahoo finance.

      Java has uses but not all the ones sun is claiming.

      What I have a problem with is academia and commercial companies choosing java because of the claims of Sun which were false.

      Dont you think there are better alternatives like

      1.python
      2.eiffel
      3.ruby
      4. euphoria. ok not oop but could be good for applications in webbrowser(speed)

    3. Re:My feelings on java and sun by Glock27 · · Score: 1
      I use java all the time at yahoo finance.

      OK...

      Java has uses but not all the ones sun is claiming.

      Example?

      What I have a problem with is academia and commercial companies choosing java because of the claims of Sun which were false.

      I'm not too sure what you're talking about here...Java was probably not quite ready for prime time when it was originally hyped - many companies have been guilty of similar things.

      Dont you think there are better alternatives like

      1.python
      2.eiffel
      3.ruby
      4. euphoria. ok not oop but could be good for applications in webbrowser(speed)

      I don't necessarily view those as "better" alternatives, though you can use at least Python (and I think Ruby) with the JVM.

      One area that's important to me is speed, which has always been touted as one of Java's strong points. It was overhyped at first, but Java performance is now quite strong, and gcj is looking very promising in that regard.

      Java is largely living up to it's original promise...it's just taking a bit of time to get there. ;-)

      --
      Galileo: "The Earth revolves around the Sun!"
      Score: -1 100% Flamebait
  45. How this compares to C++ by lkaos · · Score: 4, Informative

    Generics
    The new Java generics are really weak compared to C++ template support. This is probably partially due to difficult in compiler support and also complexity (templates are without a doubt the most complex feature of C++). I was disappointed though in Java generics mainly due to lack of any kind of specialization support and also about the strange paradigm used for Iterators (instead of an iterator being class defined with a consistant interface, it's an external class that just behaves that must wrap a behavior around the class).

    Enhanced for loop
    This is for_each() in C++. Now, with for_each, you have to use function objects which is arguable as to whether it's more readable. Fortunately, Boost has developed a boost::lambda class that allows for code to be used as the third parameter. This is _really_ neat.

    Autoboxing/unboxing
    I presume this means that primatives can't be used in generics.. That's kind of sad. This isn't a problem in C++.

    Typesafe enums
    This would be a nice linguistic pattern to have in C++. As it stands, the equivalent would be:

    struct Coin { enum { penny, nickel, dime, quarter }; };

    Static import
    This can be achieved via using in C++. Of course, Java doesn't even really have a namespace paradigm so it's not really a fair comparision.

    Metadata
    This is.. well.. strange. I didn't see the syntax for doing something like this. If it is just keyword/code replacing, then an #include directive would work just as well.

    --
    int func(int a);
    func((b += 3, b));
    1. Re:How this compares to C++ by not+Mr.T · · Score: 1

      My guess is that the Metadata he's talking about is Sun absorbing the xdoclet project into the base language.

    2. Re:How this compares to C++ by TummyX · · Score: 5, Informative

      Metadata
      This is.. well.. strange. I didn't see the syntax for doing something like this. If it is just keyword/code replacing, then an #include directive would work just as well.


      IMO, metadata is the coolest thing. It's a feature of C# which has had little recognition despite its coolness.

      In both Java and C# you can use reflection to find out information about a class (class name, method names, etc). Attributes/metadata allow you to attach information to just about every element of a class/struct so that it can be queried dynamically using the reflection apis.

      Imagine them as JavaDoc tags that aren't discarded at compile time but are instead compiled into a class's meta data. They'll do for source code what XML did for HTML -- give more meaning to the code.

      Here's an example of using attributes/metadata to simplify XML serialization:
      [XmlRoot("cat")]
      public class Cat
      {
      [XmlAttribute("id")]
      public string Name;

      [XmlElement("color")]
      public string Color;

      public Cat()
      {
      }

      public Cat(string name, string color)
      {
      this.Name = name;
      this.Color = color;
      }

      public static void Main()
      {
      Cat cat = new Cat("felix", "yellow");

      XmlSerializer serializer = new XmlSerialzer(typeof(Cat));

      serializer.Serialize(cat, Console.Out);
      }
      }

      The code yields the following output:

      <cat id="felix">
      <color>yellow</color>
      </cat>
      The C# XmlSerializer class dynamically generates the IL that will do the serialization so it is *very fast*. It knows how to map the field names to element/attribute names by inspecting the attributes.

      Some other obvious uses include object/relational mapping (no need for external XML mapping files) and XMLRPC (just mark a method as Remotable!) etc. You can imagine infinite other uses for attributes/metadata.

      I'm not sure how it works in Java but in C#, attributes are simply classes (usually with a name ending in 'Attribute'). You can define your own custom attributes and your own classes that work with them. It's very cool.
    3. Re:How this compares to C++ by slagdogg · · Score: 2, Informative

      This would be a nice linguistic pattern to have in C++. As it stands, the equivalent would be:

      struct Coin { enum { penny, nickel, dime, quarter }; };


      Not equivalent, the Java version also supports writing as a String ... so the below statement produces the string "coin: PENNY" which is very, very handy.

      System.out.println("coin: " + Coin.PENNY);

      --
      (Score:-1, Wrong)
    4. Re:How this compares to C++ by Anonymous Coward · · Score: 0

      It appears the "metadata" in Java 2 v. 1.5 isn't at all the same as that in .NET.

      The author uses the following example.

      The old way you'd have to do this:
      public interface CoffeeOrderIF extends java.rmi.Remote {
      public Coffee [] getPriceList()
      throws java.rmi.RemoteException;
      public String orderCoffee(String name, int quantity)
      throws java.rmi.RemoteException;
      }

      public class CoffeeOrderImpl implements CoffeeOrderIF {
      public Coffee [] getPriceList() { ...
      }
      public String orderCoffee(String name, int quantity) { ...
      }
      }

      But the new way is shorter:
      public class CoffeeOrder {
      @Remote public Coffee [] getPriceList() { ...
      }
      @Remote public String orderCoffee(String name, int quantity) { ...
      }
      }

      Perhaps it's just a lame example, but it looks to me like it's a fancy macro. Given the @Remote attribute, a method declaration is automagically transformed into a web service. This can be done in C/C++ with a #define, though Java's is probably much safer.

      I guess the plus side is you have to type less, but the downside is you have less control over how your interface is declared. Where does CoffeeOrderIF get declared, for example? Tough cookies if CoffeeOrderIF has a parent interface. No @Remote for you!

      This sytax sugar is nicish, but lets face it, not a lot or time is spent actually keying in code compared to designing dataflow, schemas, policies, user roles, etc. Sure, I'll use the for_each et. al features, but the generics and the typesafe enums are the golden additions. They let you write _better_ code, not just key it in faster.

    5. Re:How this compares to C++ by TummyX · · Score: 1

      Perhaps it's just a lame example, but it looks to me like it's a fancy macro. Given the @Remote attribute, a method declaration is automagically transformed into a web service. This can be done in C/C++ with a #define, though Java's is probably much safer.

      Um. The code doesn't turn the class into a webservice anyway -- it looks like it makes it an RMI accessible object. And it's not just a fancy macro. You can reflect on the @remote tag at runtime. Just like you will be able to reflect on a @webservice tag at runtime and then generate the appropriate bindings to make the method a webservice.

      Attributes/metadata is not something you can do with macros!


      I guess the plus side is you have to type less, but the downside is you have less control over how your interface is declared. Where does CoffeeOrderIF get declared, for example? Tough cookies if CoffeeOrderIF has a parent interface. No @Remote for you!


      Huh? Not sure what you mean. Attributes don't remove any power.


      This sytax sugar is nicish, but lets face it, not a lot or time is spent actually keying in code compared to designing dataflow, schemas, policies, user roles, etc. Sure, I'll use the for_each et. al features, but the generics and the typesafe enums are the golden additions. They let you write _better_ code, not just key it in faster.


      Attributes (which is what we're talking about here) is not syntactic sugar. It, like I've said before, will do for source code what XML did for HTML. Attributes allow meta programming and is important for implementing AOP.

    6. Re:How this compares to C++ by Anonymous Coward · · Score: 0

      templates are without a doubt the most complex feature of C++

      --I completely agree, especially when you consider that most compilers don't follow the standard with them, it makes it all even more confusing

    7. Re:How this compares to C++ by SuperKendall · · Score: 1

      Generics: It might seem weaker than C++ templates. But it's a totally different beast - and for my money, generics in Java as proposed will help create a lot of readable code whereas I have seen the nightmare that templates can, and almost always do, make of code. In short, Generics are templates that are usable and useful, and wont give you wallpaper when there's an error with them.

      Enum: Didn't you read the code samples? I've used the same kind of enum classes in Java for years now (as the improvement for 1.5 is just a syntax that helps make easier to write what you can do already). In your example I fail to see how you could attach a monetary value and (to extend the example) metallic composition and object to obtain a current exchange rate, all of which you can do in enums - not to mention they are serializable.

      I'm not quite sure what you mean by not having a namespace paradigm... You could have an enum called "fred" in two different packages if you like.

      As for metadata, others have spoken but I'll note that it's a really handy thing to be able to annotate code such that you can programmatically glean more meaning from code than you would otherwise be able to.

      --
      "There is more worth loving than we have strength to love." - Brian Jay Stanley
  46. Problems with less verbose accessors by MilesParker · · Score: 4, Insightful

    AC, I agree that the current approach is a PITA. I would also be very happy to see a more terse way to express properties. But what you are doing in your example, is throwing the baby out w/ the bathwater.

    Note that you now don't have anyway to specify access and protection! I had given a little thought to better ways to handle this, and even had an interesting brief email exchange w/ a C# engineer about it. For the protection aspects you could do something like [this is just a quick idea I cam up with:]

    property access String name;

    where access is one of {read, write, readwrite}

    But note taht right away you have a problem -- no way to assign protection levels to the various access, which is really a cross-product. What happens for example if you want the getter to be public, but the setter to be private?

    Also, note that you would also need semantics to handle overriding the property accessors. You could just say that the property access defines an equivalent to the getter and setter methods, but that can get weird and confusing very quickly. Think about the situation where you have an interface defining getters and setters and then you implement it by just providing the one-line property definition. That would not be very transperent TSTL.

    All this is just to say that it is a noble goal, but not as trivial as it sounds at first glance. IMO, the C# "solution" is particularly ugly, and qualifies strongly for the "syntactic sugar" label.

    FInally, as in my other note, good IDEs like IntelliJ provide very convenient ways to auto-generate these things. I care much less about this issue now that I am not having to type all this stuff out by hand!

    1. Re:Problems with less verbose accessors by Anonymous Coward · · Score: 0

      > But note taht right away you have a problem -- no way to assign protection levels to the various access, which is really a cross-product. What happens for example if you want the getter to be public, but the setter to be private?

      You just return to the old way (explicit coding of getters/setters). It will still work. No need to add complex semantics for this.

    2. Re:Problems with less verbose accessors by MilesParker · · Score: 1

      Right, but then you a confusing and basically arbitrary line between different appraches. Just think, "How confusing is it going to be to try explaining this to a new Java programmer."

      "Let's see, if both my accessors are the same I can use this form; otherwise I have to use that form."

      Again, I'm not saying these problems aren't surmountable -- personally I would _love_ to see a better answer. I'm just saying that there are a lot of subtleties.

    3. Re:Problems with less verbose accessors by Pentagram · · Score: 1

      Inally, as in my other note, good IDEs like IntelliJ provide very convenient ways to auto-generate these things

      Still jams up the source code though.

    4. Re:Problems with less verbose accessors by licketyspit · · Score: 0

      I think what the initial poster was trying to get at was a private property. At least that's what I expected. The javabeans spec forces all properties to be private with public get/set functions. You don't really need get/set functions for default or public access. You can just specify myObject.proerty = value. It would be nice if there a syntax that would auto create get and set functions for private properties.

    5. Re:Problems with less verbose accessors by MilesParker · · Score: 1

      true..better code-folding tools would help here..

  47. Boilerplate code... by Scrooge919 · · Score: 1

    If I understand the article correctly, this would be possible using the new metadata features, so then a "tool" could generate the getters & setters.

    That said, having it built into the language directly, so you didn't have to rely on a "tool" to generate them would be certainly be more convenient. Maybe they're holding back features so they have something for the 2.0 version of the language... ;)

  48. I agree with the author by Anonymous Coward · · Score: 1, Interesting

    I think a number of the 'improvements' for 1.5 are nothing more than syntaxic sugar that are pushing Java in a bad direction. One or two these enhancements does offer some lesser compile time checking which is a good thing, but for the most part they seem to be an attempt to let the programmer type fewer characters and letting the compiler 'generate' the code.

    Why is that bad you might ask? I mean who wouldn't want to do more in fewer keystrokes. Well there are a few major problems that I see:

    1. There is a much greater ability to get into the "Perl factor" where there are 16 million ways to do the same thing. While having so many ways to get the same thing done is great if you are one or two folks working on a project, its terrible if you are 20-30 developers working on the same project. So these 'improvements' seem to push Java away from being a good Enterprise level language.

    2. While none of the changes specifically target this, its movement away from being a systems language where the programmer is very close to the underlying action that the computer is doing. One of Javas greatest strengths is its ability to get deep into the bits (like C), and while this is not going away this seems to be where alot of the thinking is.

    3. These 'improvements' will be all that some newer programmers learn. I think this will lead to a much greater number of java programmers who don't really understand whats going on and we will have a lot of confusion out there.

    All of this because some people wanted to save a few keystrokes.

  49. Crap! by panda · · Score: 1

    JDK 1.5 is coming out soon, and I still haven't really gotten to play enough with the new stuff in 1.4!

    --
    Just be sure to wear the gold uniform when you beam down -- you know what happens when you wear the red one.
  50. Hell yeah by Anonymous Coward · · Score: 0

    Unlike some people, I feel using programming shorthand leads to increased maintenance.

    AMEN! Look what shortcuts do to PERL!
    Java is normally very readable, even by people who are not familiar with the details.
    I can't think of any gains afforded by shorthand syntaxes, projects are not usually billed in keystrokes.
    I do like iterators if they mean less nested for(...) loops, but you can't always convince people to use them.

  51. Where is operator overloading? by AaronW · · Score: 1

    I would *love* to see operator overloading. It would actually make Java much more useful for scientific tasks which involve things like vectors, matricies, or complex numbers. I'm also sure it would also be helpful in other areas.

    -Aaron

    --
    This post is encrypted twice with ROT-13. Documenting or attempting to crack this encryption is illegal.
    1. Re:Where is operator overloading? by Anonymous Coward · · Score: 1, Informative

      I used to wonder why Java doesn't haver operator overloading. But it just occurred to me that overloading doesn't actually do anything except make misleading code. Think about it... what can an operator do that a normal method can't? Some would argue that operators make the code more readable, which they do. But they also obscure the difference between compiler reserved words and programmer defined words. Which is as dumb as being able to redefine "while". OTOH, in Lisp you can redefine +, even for integers.

    2. Re:Where is operator overloading? by avalys · · Score: 2, Interesting

      Aside from the opportunities for abuse of operator overloading, I don't think it's really that important in Java since it was never intended as a language for anything heavy on calculation (being interpreted and all).

      --
      This space intentionally left blank.
    3. Re:Where is operator overloading? by Glock27 · · Score: 2, Informative
      I would *love* to see operator overloading. It would actually make Java much more useful for scientific tasks which involve things like vectors, matricies, or complex numbers. I'm also sure it would also be helpful in other areas.

      There was a preprocessor named jpp floating around a few years ago that supported operator overloading for Java. It seems to have vanished off the net in the meantime, though I'm sure I have a copy somewhere. True operator overloading is supposed to be added to Java at some point, IIRC.

      In the meantime, perhaps we should write a new preprocessor, the "Operator Overloading Preprocessor System" or OOPS. jpp seemed like a good idea (it offered several features beyond operator overloading). Java coupled with a good preprocessor is a fine idea. ;-)

      --
      Galileo: "The Earth revolves around the Sun!"
      Score: -1 100% Flamebait
    4. Re:Where is operator overloading? by Anonymous Coward · · Score: 0
      Opportunities for abuse aside, whether or not Java was intended for numeric computing is irrellevant; people are using it that way. There are even books already by O'Reilly and Prentice Hall (can't remember the titles offhand... but I've seen them at the computer bookstore near my place) that have been published that specifically address numerical computing in Java.


      As for the issue of the possibility of abuse, do you not find it interesting that this is the same argument that the RIAA is using against unregulated filesharing technologies?


      I will not argue that operator overloading capability puts more responsibility on the programmer's shoulders, but that's inevitable when adding any new and powerful feature. Sun can either continue hold our hands while we walk around their house, or eventually programmers will simply walk out of the door without Sun's help at all when Java no longer suits them.

    5. Re:Where is operator overloading? by Anonymous Coward · · Score: 0
      Operator overloading only obfuscates code when programmers use the predefined operators in a context that conceptually differs from the operator's normal view. Regrettably, Stroustrup started it all with the > operators being used in the iostream library for input and output as opposed to their formerly accepted "shift" interpretation.


      Nevertheless, the potential for a technology to be abused does not alone justify a cause for avoiding it. Well used overloaded operators are *EXTREMELY* readable, and actually ends up being much easier to maintain and debug the code that employs them sensibly than code that only uses methods for the equivalent operation.


      In code that manipulates matrices, tell me which of the following is easier to understand:


      e=a.add(b.times(c.minus(d)))

      e=a+b*(c-d)


      The problem with the former notation is that it forces the reader to think of a,b,c,and d in terms defined by the computer language rather than in terms defined by the domain of the problem (not to mention introducing the hassle of counting parentheses). It should not matter to the reader of the code that these variables are implemented as objects, all that should matter to him or her is that they are entities that can be manipulated by the standard rules of algebra. Thus, the second version is more readable even to someone who may not understand programming, but may be familiar with the problem that the program is attempting to solve, and can help troubleshoot problems with it on that basis.


      Further, it cannot be said that numerical computing is an exception and not the rule. Numeric computing, while it may not form the bulk of most programs, often finds its way into almost every programming project in one form or another. If this code is expressed in notations that people familiar with the domain of the problem (and not just fluent in the programming language) understand, then one has made radical progress to increasing the maintainability of their entire code base.


      I wish with all of my heart that it were in some way technologically possible to stop programmers from abusing operator overloading and I've even come up with some ideas of my own that might help to minimize it. My ideas wouldn't stop it though... in particular, the mechanisms I've thought of wouldn't stop programmers from writing code that does something counter to how the code reads (in much the same way as nothing stops a programmer from naming a variable as 'int pickle' when the code has nothing to do with pickles). Of course, I'm not a designer at Sun, so it doesn't really matter, and I can wish all I want, but it won't make a difference.

    6. Re:Where is operator overloading? by Anonymous Coward · · Score: 0

      Heretic!!!!

      Operator overloading is only useful for making the code incomprehensible.

    7. Re:Where is operator overloading? by Ed+Avis · · Score: 1

      Operator overloading isn't useful only for numeric computation (defining classes for complex numbers, vectors, matrices, bigints and so on), although it certainly is handy for that. It also has a use for container classes, to give them a syntax that is conciser and closer to that for built-in arrays. 'm["red"] = 5;' is IMHO a lot more readable than 'm.set("red", 5)'.

      What's particularly annoying about Java is that if operator overloading is so unnecessary, why do they themselves use it for the String class? If overloading the + operator was good enough for the writers of the standard library, why isn't it good enough to use in writing your own library?

      --
      -- Ed Avis ed@membled.com
  52. Netbeans IDE! by fforw · · Score: 1
    I prefer Netbeans over Eclipse which was mentioned earlier because :
    • It offers features I can not find in Eclipse
    • it's more mature
    • it's easily extendable. (some parts of the development cycle of the company I work for are already implemented as netbeans-extensions)
    some downsides are:
    • you have to get used to it.
    • it uses Swing instead of SWT. (with execution and startup speed really improving in the last releases.)
    and it's open source...
    --
    while (!asleep()) sheep++
  53. compiled java? by dipierro · · Score: 2, Interesting

    When it comes down to it, once the code is compiled, it's the same.

    If you're compiling, shouldn't you use a language which wasn't designed to be interpreted?

    1. Re:compiled java? by Anonymous Coward · · Score: 0

      If you're posting, shouldn't you post on a subject you know something about?

      The statement above is talking about compiling to bytecode.

    2. Re:compiled java? by dipierro · · Score: 1

      I know.

  54. IDE features in the compiler by Anonymous Coward · · Score: 0

    Generics aside, most of 1.5 are interesting ideas that have value, but they should probably NOT be built into the language.

    If you consider that most of the features in 1.5 are essentially macros to generate code, it seems like Sun is trying to bind IDE features into the JDK itself. This strikes me as a BAD idea for a language, and should be somewhat personnal choice (e.g. let each programmer make they're own macros instead of tying them to the language).

  55. Personal comment by Anonymous Coward · · Score: 1, Interesting

    Well having to use java day in day out and mostly loving it, here is a personal comment.

    The generics and the autoboxing are heaven sent from a language standpoint. The other stuff mostly is syntatic sugar and the static imports I really don't know if that is a good extension to keep the code readable. But the biggest gripes with java are not the language but two other things:

    a) long loading times caused by the class loader class verifier mechanism
    b) huge memory footprint thanks to mem hungry hotspot optimizations

    What I really couldn't find is if those two issues will be adressed or postponed again.

    Btw. if you like java but think that swing is slow in X check out the latest blackdown release, it is amazing what the blackdown guys did to swing. Also check out the 1.4 JDK for the mac, no difference to a native mac app speedwise.

  56. Re:Java 1.5! by Anonymous Coward · · Score: 0

    OK, Java is shit, but Java is where the money is. If you choose not to work with Java, it limits your career.

    This is totally fine with me though. More money for me!

    oh, fuck france.

  57. What Bjarne Stroustrup has to say about Java by Q+Who · · Score: 5, Informative

    This is what he said about Java and the likes.

    Also here.

    1. Re:What Bjarne Stroustrup has to say about Java by crazyphilman · · Score: 1

      I like Mr. Stroustrup quite a bit; isn't it cool how he can never be baited into saying anything seriously negative about anyone? He's totally honorable, throughout his FAQ. The most he said (and really, who could find fault with it?) was that he wasn't a fan of proprietary languages, and he felt that as far as Java and C# go, they're both proprietary and tie you into one platform. He seems like a very reasonable, very nice man.

      He made some pretty good points, too. Maybe I'll dust off my copy of Swan's C++ tonight, review a little... Hmm...

      --
      Farewell! It's been a fine buncha years!
    2. Re:What Bjarne Stroustrup has to say about Java by Anonymous Coward · · Score: 0

      Love what he says about C. He thinks it should not be used at all, apparently.

      I guess he forgot to tell that to all the embedded programmers, device drivers, and OS that are based on C and only C.

      C++ is powerful, but like a swiss army knife, it does some things pretty poorly.

    3. Re:What Bjarne Stroustrup has to say about Java by rjh · · Score: 1

      I have yet to see any instance where C could be used, but C++ couldn't. Let me repeat that: I have yet to see any instance where C could be used, but C++ couldn't.

      People keep on forgetting two very important things about C++. The first is, it has support for virtually all of ISO C90. The second is, one of the big maxims in C++ is you don't pay for what you don't use. If you write C90 code and compile it in C++, you don't incur any penalties for objects, for templates, for iostreams...

      Take a look at Stroustrup's recommended books for learning C++. One of the first books listed is the K&R C book. According to Stroustrup, every program in K&R C is a well-written C++ program.

      So no, there's actually very little out there which is based on C and only C. There are probably lots of embedded systems for which C89 compilers are the only ones available, but that's purely a limitation of economics (not enough money to spend on developing a C++ environment), not an inherent limitation of C++.

    4. Re:What Bjarne Stroustrup has to say about Java by firewrought · · Score: 1
      I have yet to see any instance where C could be used, but C++ couldn't.

      Your statement is technically correct, not just because C++ is a near-superset of C, but also because both are Turing-complete and have equivalent low-level access to the underlying hardware (thanks to the assembly-code embedding, the raw memory-handling semantics, and the macro preprocessor).

      In other words, your statement is trivially true. Pragmatically speaking, the (relative) simplicity of C makes it a better language in many real-world situations. For instances, you blame the shortage of C++ compliers for embedded devices on economics and not on the "inherent limitations of C++". But it's exactly the intrinsic complexity of C++ that limits the number of compilers that can be made for them. By contrast, how many different Lisp/Scheme interpreters are there? The intrinsic simplicity of Lisp means that you can write a basic interpreter in just a few hours. (Of course, being simpler-to-write-an-interpreter-for doesn't mean simpler-to-think-in, so Lisp mainly attracts academians.)

      Another example: as you mentioned, in C++ you don't pay for what you don't use. But you do pay for what others use. That is, your code has to interact with other people's code and take into account the specific language features they use. Thus, you end up using parts of the language you didn't want to have to deal with.

      This has even wider implications if you're a project manager: you may want to limit your programmers to C so that you can:

      1. easily develop bindings from other languages (since every damn language ever made has a proven, straightforward, well-documented way of interfacing with C).
      2. easily rely on design techniques that require writing code-parsing/manipulation/generation tools (which are easier to write when targeting simpler syntax and semantics).
      3. easily find cheaper/better labor (since the set of C expertise is a superset of C++ expertise [the corollary of C++ being a superset of C]).
      4. easily ensure that your libraries/APIs are usable by a wider audience.
      5. easily support a wider variety of build environments

      I'm not saying that C is always better than C++... I'm just pointing out that C's simplicity affords it tangible advantages that you won't get using C++, especially in a multi-developer environment where one programmer's design choices will impact the productivity of his peers. Neither am I saying that C is simpler than C++ in all respects. It's simpler syntactically and semantically, but at a behavioral level, C++ is going to let you create more intuitive high-level API representations of many problem domains (e.g., like scene graphs and simulations).
      --
      -1, Too Many Layers Of Abstraction
    5. Re:What Bjarne Stroustrup has to say about Java by rjh · · Score: 1

      On the contrary: it's not trivially true at all. If C++ was incapable of generating code with C's speed and resource footprint, then even if you programmed in the C-like subset of C++, you'd be unable to use C++ compilers in the C space. Just because a language is Turing-complete doesn't mean it can be used in all situations in place of another Turing-complete language.

      But it's exactly the intrinsic complexity of C++ that limits the number of compilers that can be made for them.

      You haven't seen C++ for the embedded space, have you? You're assuming that "embedded C++" necessarily means "full access to the huge spread of modern C++98 facilities". It doesn't. There are very few full ANSI/ISO C++98 environments for the embedded space, because it makes no economic sense to invest that much money producing a compiler where a large number of the features (STL, templates, exceptions, RTTI) not only will never be used, but literally cannot be used due to memory/time requirements. This is not the same thing as saying there are very few C++ environments for the embedded space; the Embedded C++ Technical Committee is rapidly approaching a standard and many manufacturers are promising to support it as soon as the standard is published.

      And who's committing to C++ in the embedded space? A bunch of nobodies, like NEC, Toshiba, Hitachi, Mitsubishi, Red Hat, and Dinkumware. (Dinkumware is PJ Plauger's company, and is an extremely well-respected C++ outfit.) All have committed to using C++ in the embedded space.

      (I think Red Hat's interest in Embedded C++ stems from their lack of success with iTRON, but don't quote me on that...)

      Please, please, please, learn about C++ in the embedded space before you go about talking about how C++ in the embedded space is a foolish idea, or how C++ cannot be used profitably in the embedded space, or how it's the inherent complexity of C++ which will forever bar it from the embedded space.

      (Of course, being simpler-to-write-an-interpreter-for doesn't mean simpler-to-think-in, so Lisp mainly attracts academians.)

      LISP is a far simpler language, conceptually speaking, than C++ or even C. My copy of K&R has 272 pages. McCarthy's original LISP specification has 12. Scheme is even more terse. ANSI Common LISP has a larger spec, but all but about 100 pages deal with the semantics of CLOS.

  58. Only 19.99! by Anonymous Coward · · Score: 0

    Now how much would you expect to pay for templates, enum and bizarre @ keywords? With the new Java 1.5, you can have all this for three easy payments of $19.95!

    Anyone else think that the article read like a Saturday morning info-mercial?

  59. Thought Police by Anonymous Coward · · Score: 1, Funny

    Don't you mean /.?

  60. Moderators . You show bias ! People read all the by zymano · · Score: 0, Troll
    messages and not the filtered board.

    There are some good points that have been deleted by the moderators.

    All the messages about java being about profit for sun have been DELETED(not using modded down term) .

    All the messages about java language being too wordy,slow, or even people griping about certain syntax of the language has been deleted.

    Take the FILTERS off for all JAVA news submittions.

    I am guessing here that the MODERators are JAVA programmers.

    You do not need to mod down a submitted message to Troll if it has actual substance to it.

    pathetic.

  61. They've missed one very common idiom by Westley · · Score: 1

    This is one of the nicer things about C#. How often in Java do we see code such as:

    BufferedReader br = null;
    try
    {
    br = new BufferedReader (...);
    // Do some stuff...
    }
    finally
    {
    if (br != null)
    {
    try
    {
    br.close();
    }
    catch (IOException e)
    {
    // Never been sure what to put here...
    // just logging?
    }
    }
    }

    The equivalent of this in C# is:

    using (BufferedStream bs = new BufferedStream (...))
    {
    // Do stuff
    }

    Basically it's the same thing (can't remember what happens to exceptions during Dispose, admittedly).

    Much easier to get right. Means having a common interface for "I've finished with this object", but that's not too hard...

    I'm hoping to put together a proper RFE for this at some stage.

    1. Re:They've missed one very common idiom by lysander · · Score: 1
      Why not just put the bs.close(); right after the // Do some stuff and lose the finally block altogether? Unless you're trying to distinguish between an IOE in failing to open the file vs. one later when trying to close it after doing some stuff.

      Rarely have I felt the need to use a finally block...

      --
      GET YOUR WEAPONS READY! --DR.LIGHT
    2. Re:They've missed one very common idiom by Mindbridge · · Score: 1

      Just to say that I second this with both hands.

  62. Static Import by SimplexO · · Score: 1
    From the Article:
    What will the new static import facility offer developers?

    It lets the programmer avoid prefixing static members with class names. People really want this, so much that they implement so-called constant interfaces.

    This is a very bad idea: interfaces are for defining types, not providing constants. The fact that [your] class uses [certain] constants is just an implementation detail, but it "leaks" into the public API of [your] class. Not only does this confuse the clients of this class, but it creates a long-term commitment. Even if you re-implement [your] class so that it doesn't need these constants, you still have to implement the interfaces, as clients of [your] class can now depend on the fact that it implements [those constants].

    The static import facility offers a clean alternative. It lets the programmer avoid qualifying static member names without subtyping. It's analogous to the package import facility, except that it imports static members from a class, rather than classes from a package. Here's how it looks:

    import static org.iso.Physics.*;

    Note that this works whether Physics is an interface or a class. If it just defines constants, it should definitely be a class rather than an interface.
    I think this is wonderful, and will probably be overlooked. But I know lots of guys who use implements ClassConstants, which is just messy. This way we can just import our own constants packaged up for modularity, without letting clients know, while looking good understandable at the same time.

    I know I just ate a big pile of PR, but these changes seem good from a developer's perspective. Once 1.5 goes final, I'll probably re-compile using some of these new features.
  63. Re: Generics are much more than typed containers by jameson · · Score: 1
    Hi,

    Yes, Generics can be used for much more than this, particularly in combination with anonymous classes (which are Java's way for handling higher-order functions). Again, a lot of examples for this can be found in existing languages, e.g. we can now have something equivalent to the 'map' function found in functional languages. Here's a Haskell definition of map:


    map :: (a -> a) -> [a] -> [a]
    map f [] = []
    map f x::l = f(x)::l


    I don't know the precise Java syntax for Generics, so I'll make one up for a Java equivalent:


    public interface F[A]
    {
    public A f(A v);
    }

    static Container[A] map(F[A] fn, Container[A] c)
    {
    Iterator[A] i = c.getIterator();

    while (i.hasNext()) {
    i.performUpdate(fn.f(i.get()));
    i.next();
    } /* OK, these aren't standard iterators, but
    ** it's been a while since I last did Java
    */
    }



    Granted, it's not quite the same, particularly since it supposedly works on all containers (with the right kind of iterators) and performs a destructive update, but you get the idea-- you can do powerful stuff and still get your types right.

    -- Christoph
  64. Does anyone know more about static imports? by Anonymous Coward · · Score: 0

    Does it import all static members and static methods or just constants (static final's)?

  65. Enumerators in Python. by Anonymous Coward · · Score: 0
    Before enumerators:
    file = open("filename")
    line = file.readline()
    while line != None :
    print(line)
    line = file.readline()
    After enumerators:
    file = open("filename")
    for line in file :
    print(line)
    Really - what's the problem? The second code block is far more maintainable and less error-prone (assuming I didn't make any typos). In short: enumerators rock. The only problem is if you're working on a team with a few who aren't 100% comfortable with enumerators - the use of them (or not) should be consistent throughout the project.
    1. Re:Enumerators in Python. by czth · · Score: 1

      Well geez, it wouldn't be a problem in the first place if Python wasn't all fascistic in not allowing:

      while line = file.readline(): print line

      czth

    2. Re:Enumerators in Python. by Anonymous Coward · · Score: 0

      I believe this is an example of an iterator, not an enumerator. Now file() is a builtin constructor and is prefered over open(). This also means that the use of file as a variable name is discouraged because it shadows the builtin. Parens around the argument to print are not idiomatic in Python.

      f = file("filename")
      for line in f:
      print line

  66. I disagree - x++ vs ++x by Pentagram · · Score: 3, Insightful

    x++ is the standard way of writing the statement, used by most coders in preference to ++x (in my experience anyway.) The fact that there is such a convention is reason enough to use it IMHO; if I see ++x in a piece of code, it's a warning that something unusual is going on.

    As for your equality test examples, putting assignments in if statements in Java gives you a compile error. Also, it's quite rare to ever put a specific number in an if statement, and if you do it's likeley to be 0.

    1. Re:I disagree - x++ vs ++x by Coward+the+Anonymous · · Score: 1

      It's not just a different way of doing the same thing, they do different things.
      ++x is pre-increment while x++ is post-increment.

      Psuedo-code Example 1:
      x = 0
      PRINT ++x
      will print out 1.

      Psuedo-code Example 2:
      x = 0
      PRINT x++
      will print out 0.

      --
      -- Jason
    2. Re:I disagree - x++ vs ++x by dsplat · · Score: 1

      x++ is the standard way of writing the statement, used by most coders in preference to ++x (in my experience anyway.) The fact that there is such a convention is reason enough to use it IMHO; if I see ++x in a piece of code, it's a warning that something unusual is going on.

      When used with native data types, x++ is at worst only marginally less efficient than ++x. Unfortunately, when dealing with operator overloading (my experience draws heavily on C++ here) you can run into some efficiency problems. Because you should, assuming that you mimic the behavior of postfix ++ on native types, return the value of the object before the increment, you have to make a copy. You have the overhead of executing the copy-constructor. You may be adding significant overhead that you don't need.

      It has also been my experience that the single most common use of ++ and -- is in loops that iterate over something. The variable in question may be an int used as an array index, a pointer into an array or an interator that is actually an object. It is this final case where the overhead really shows. Generating the same code from x++ and ++x when the value of the expression is not used is a fairly common optimization for POD types, I think. I wouldn't expect it to be done for objects as a general rule.

      --
      The net will not be what we demand, but what we make it. Build it well.
    3. Re:I disagree - x++ vs ++x by BigJimSlade · · Score: 1
      x++ is the standard way of writing the statement, used by most coders in preference to ++x (in my experience anyway.)

      To anyone that hasn't taken an intro CompSci class, x++ and ++x do two entirely different things in Java, C, etc.

      Ok, not entirely. Using the ++ before the variable increments it before doing anything else with it, where as ++ after the variable increments it after doing anything else with it.

      Sample code time:
      int x=2;
      a=x++;
      // At this point, a==2 and x==3

      x=2;
      a=++x;
      // At this point, a==3 and x==3
      Yes, when using as an iterator counter:
      for(x=0; x<20; x++)
      it doesn't matter if it is before or after the variable. It does make a difference when assigning the value to another variable though.
    4. Re:I disagree - x++ vs ++x by kisrael · · Score: 1

      You're right, though as a developer I've never really "trusted" x++ vs ++x ; usually, I'd just write

      x=0
      PRINT x
      x++

      or

      x=0
      x++
      PRINT x

      explicitly, using ++ as an instantly readable incrementor rather than capitalizing on its "in place increment" functionality.

      --
      SO YOU'RE GOING TO DIE: The Comic for Dealing with Death
    5. Re:I disagree - x++ vs ++x by Pentagram · · Score: 1

      Really? I didn't know that. Oh no, wait, I did know that, along with anyone who's ever spent more than 10 minutes coding in a modern programming language. It was my whole point - if you see ++foo in a program, you can usually assume that there's a good reason that the author wanted to pre-increment so you have to be careful changing anything.

    6. Re:I disagree - x++ vs ++x by mypalmike · · Score: 1

      In C++, when using STL, the preferred way to increment iterators is ++x. This is because it is more efficient than x++. Why? Postincrement must evaluate to the state of x before the incement, which requires additional effort ove preincrement, which evaluates to the state of x after the increment.

      While x++ has historically been the preferred apporach, ++x is becoming the preferred approach, largely because of STL. I work at a large game developer, and I'm seeing this more and more, including some people who want to make it part of our coding standard.

      --
      There are 0x40000000 types of people: those who understand 32-bit IEEE 754 floating point, and those who don't.
    7. Re:I disagree - x++ vs ++x by Anonymous Coward · · Score: 0

      Well, at least in C it doesn't make a difference to use pre or post-increment in a for statement. But when it comes to C++ and operator overloading, you have to be careful.

    8. Re:I disagree - x++ vs ++x by Pentagram · · Score: 1

      The article we are discussing is about Java, so your point about operator overloading is irrelevent. A plain ++x / x++ on its own will compile to the same bytecode.

      I'm not sure I follow your argument about loops - I don't at least see any reason why for (int i = 0; i would be any slower than (int i = 0; i foo; ++i) . Unless you're still talking about C++.

    9. Re:I disagree - x++ vs ++x by Pentagram · · Score: 1

      Damn /., stripping out my angle brackets! first for loop should have i++, second should have ++i

    10. Re:I disagree - x++ vs ++x by Pentagram · · Score: 1

      Yes, I know this! Thanks for pointing out the obvious - I assumed that the world and its dog already knew this. This is why I think people should adhere to convention, not use whichever one they feel like.

      for(x=0; x<20; x++)

      I hope you've never used this line in an actual program.

    11. Re:I disagree - x++ vs ++x by blahedo · · Score: 1

      I see ++foo all the time, without any special meaning. In fact, I've conditioned myself never to write foo++ unless I need to. For one thing, there's the performance issue if foo is an object---no need to keep a copy with ++foo. But more importantly, the semantics of ++foo are much more in keeping with other expressions in the language. If I write
      dfoo = ++foo * 2;
      then it works the same as if I'd written
      dfoo = (foo += 1) * 2;
      or
      dfoo = (foo = foo + 1) * 2;
      ---not that either of those is any better, but in all of them, there is a sense of "do everything for this operator, reduce it to a value, then plug into the surrounding context". By contrast, for
      dfoo = foo++ * 2;
      you can't rewrite the "foo++" as anything else while preserving semantics, without spreading it over multiple statements.

      So I take issue with your comment that programmers do, or even should, use the postfix form by default. Not that it really matters; well-written code ends up using this operator so very rarely that it doesn't end up mattering very often. :)

      --
      ``This, too, shall pass.'' ---Eastern proverb
    12. Re:I disagree - x++ vs ++x by jeremyp · · Score: 1

      Funny that, to me as a fairly ancient C coder, ++x looks right and x-- looks right. Why? because in the days when I learnt C, the PDP11 was still a fairly common machine and it has a preincrement indirect mode and a postdecrement indirect mode but not the other way around thus you could save precious cycles using ++x and x--. I realise that now it really doesn't matter.

      Having said that, if you're implementing (say) a stack it does matter because if you use

      *x-- = someValue

      to push items on the stack, you must use

      someValue = *++x

      to get things off.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    13. Re:I disagree - x++ vs ++x by dsplat · · Score: 1

      The article we are discussing is about Java, so your point about operator overloading is irrelevent.

      Earlier in this thread someone stated that x++ is supposed to be less efficient than ++x. I was detailed the reason why that is true in the case of objects in the presence of operator overloading. I also pointed out why it can be particularly detrimental because it is commonly used for incrementing interators in loops. Presumably, you are looping over a sizeable amount of data at least some of the time. That's the reason I brought up loops.

      You are correct that in Java or C, with a decent optimizer, you should get the same instructions. In the absense of a good optimizer, the extra overhead is very small at worst. You would store the value prior to the increment and return that. Your optimizer can spot that the temporary that is generated for that is never used and remove it. The two versions look like this:

      ++x;
      x = x+1;

      x++;
      tmp = x;
      x = x+1;
      return tmp;

      The whole problem arises when the original value must be returned by the expression in a context where it is too difficult for the optimizer to make that temporary go away.

      Part of my point was to illustrate why it makes only a slight difference, if at all, in C and Java because our discussion here is about Java. IMHO, operator overloading is a good thing, but it should not be overused. When the analogy to the behavior of plain old data is a good one, it enhances readability. I've seen operator+=() used for a function that appends an object to a collection. The fact that list += obj; is not equivalent to list = list + obj; is a strong argument against overloading either the + or += operator for a container.

      --
      The net will not be what we demand, but what we make it. Build it well.
    14. Re:I disagree - x++ vs ++x by Pentagram · · Score: 1

      For one thing, there's the performance issue if foo is an object---no need to keep a copy with ++foo

      In Java, the domain of the story, this is not an issue of course.

      So I take issue with your comment that programmers do, or even should, use the postfix form by default

      I think having a default is useful because when you see the special case you immediately know that it's acting differently, that the code is dependent on increment/decrement order, and that there is probably a good reason why it was written that way.

      I think the default is postfix form, but I don't know how I can support that - google doesn't seem to like ++i (!) You sound like a primarily C++ programmer (not ++C you notice :) where I expect prefix notation is more prevalent than other languages because of the performance difference.

    15. Re:I disagree - x++ vs ++x by Pieroxy · · Score: 1
      putting assignments in if statements in Java gives you a compile error

      That is not true, you can put any assigmnent (actually any expression, the assignment being one of these) in a if. As long as it resoves into a boolean.

      For example, the following code is valid:
      boolean a,b,c;
      ...
      if (b=(a?true:c)) {
      ...
      }
    16. Re:I disagree - x++ vs ++x by Cato · · Score: 1

      I'm afraid your memory is not right - the PDP-11 had post-increment and post-decrement only, see http://www.wikipedia.org/wiki/PDP-11 to confirm this. C's post-increment/decrement operators, used for something like *p++ = *q++, were designed to be easily mapped onto the PDP-11 (i.e. one instruction in this case).

      For everyone else: PDP-11's are still used for industrial control, were a key Unix platform, and gave rise to the instruction sets of the VAX, 6809 (ish) and 68000.

    17. Re:I disagree - x++ vs ++x by Anonymous Coward · · Score: 0

      I stand corrected. That does, to my surprise, actually work (though you don't of course need the ternary operator.) Can't think of a situation offhand when using that would be a good idea though. Perhaps a compile error would actually be a good idea considering the potential for bugs.

    18. Re:I disagree - x++ vs ++x by J.+Random+Software · · Score: 1

      But the syntax was copied from C. If the argument is that you write "i++" in Java because that's what you write in C, the counterargument is that you should have been writing "++i" in C whenever you didn't actually need the previous value. C++ just increases the cost of the incorrect style.

    19. Re: Re:I disagree - x++ vs ++x by Pieroxy · · Score: 1

      Well, you see, Java syntax is based off of C syntax (at least for most of it) and the only difference in this case is that there is a boolean type in Java. So if(foo="bar") is not valid since it's a String.

      If you remove an operator (here assignmnt) from the list of valid operators in boolean expression (I think you would like that also for while, for ....), the question is then where to stop? Why banning this one and not another one ?

    20. Re:I disagree - x++ vs ++x by DunbarTheInept · · Score: 1

      There's times when convention is wrong to me. And this is one. I see no reason to do "x++' unless there was some reason the person wanted to return the preincremented value, so that's the version that makes me stop and think about it, while you have the opposite reaction. Besides, I avoid '++' side-effects like the plague, so I'm usually using it on a line by itself (or as the last clause of a for(...) header), where you don't really care when the value is returned since you're just throwing the return value away anyway. And in the case where you are just throwing the return value away, it makes no sense to bother remembering what it used to be before the increment occurred.

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    21. Re:I disagree - x++ vs ++x by DunbarTheInept · · Score: 1


      I think having a default is useful because when you see the special case you immediately know that it's acting differently, that the code is dependent on increment/decrement order, and that there is probably a good reason why it was written that way.

      That's not true though. The code could be just as dependant on increment order when it's written postfix as when it's written prefix. If you train yourself to only bother thinking about it when you see it one way and not the other, you are asking for trouble. You should be paying attention to it BOTH ways. In fact, I would argue that the cases where postfix is really needed are more unusual than the cases where prefix is really needed. The idea is very strange of the return value from an operation NOT being the result of the operation but instead the result before the operation was done.
      That's not the way anything else in the language works. Imagine if you had a concatenation string function called concat(x,y) that tacks y on to the end of x. It would be very odd for that to return x as it looked before concatenation.

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    22. Re:I disagree - x++ vs ++x by Anonymous Coward · · Score: 0

      OTOH one popular (even iostreams uses it sometimes) C++ style does properties that way: the "int foo() const" method returns the current value, while the "int foo(int)" method changes the value and returns the previous value. This is handy if you're going to update the value but restore it later, and the optimizer should take care of cases where you ignore the previous value (anything too complex to inline probably shouldn't be regarded as a property).

  67. When will Java be 'frozen'? by MarkWatson · · Score: 3, Interesting
    I have complained here before on this issue:

    One of things that makes older more mature languages like Common Lisp (and perhaps Smalltalk) nice to work with is a feeling of both having really solid implementations and not breaking legacy code.

    I like the idea of boxing and generics, but, these changes will affect old code (probably?) and the platform in general.

    My vote would be to freeze the Java language (perhaps after 1.5) and concentrate on the following:

    • memory footprint
    • runtime efficiency

    I would not like to see Java become a language designer's playground.

    Because of great infrastructure software like servelt/JSP containers, (perhaps EJBs :-), XML utilities, solid web services support, etc. Java is a great platform.

    Leave it alone (the sooner the better) except for improvements in the implementation.

    -Mark

    1. Re:When will Java be 'frozen'? by _fuzz_ · · Score: 5, Insightful

      My vote would be to freeze the Java language (perhaps after 1.5) and concentrate on the following:

      * memory footprint
      * runtime efficiency ...

      Leave it alone (the sooner the better) except for improvements in the implementation.


      This is a good idea. However, my vote is to concentrate on Java3. Screw backwards compatibility going forward and fix the standard library. Throw out the crap that has come along from JDK 1.0-1.1 and make the platform consistent. Why do we have both Enumerations and Iterators? Why are constants mostly UPPERCASE but sometimes lowercase (see java.awt.Color)? What about Thread.stop()?

      This cruft is never going to go away until Sun releases a version of Java that isn't backwards compatible. Perl and Python do it. Java should too. It makes for a much cleaner language for new projects. Old projects may get stuck on a Java2 platform until the owners invest the time to convert them, but that's the way things go. It's time to clean out the cobwebs in Java and make better use of the new features.

      Once all the old crap is gone, then it will be time to freeze the language and standard library.

      --
      47% of all statistics are made up on the spot.
    2. Re:When will Java be 'frozen'? by Kupek · · Score: 1

      One of things that makes older more mature languages like Common Lisp (and perhaps Smalltalk) nice to work with is a feeling of both having really solid implementations and not breaking legacy code.

      There's a causal relationship there. Java is a relatively new language. It's going to take a while before they stop making changes to it.

    3. Re:When will Java be 'frozen'? by Anonymous Coward · · Score: 0

      > One of things that makes older more mature languages like Common Lisp (and perhaps Smalltalk) nice to work with is a feeling of both having really solid implementations and not breaking legacy code.

      So comment when Java is 20+ years old. Those other languages also didn't have language freezes during their first 10 years of development - no useful language does.

      > I like the idea of boxing and generics, but, these changes will affect old code (probably?) and the platform in general.

      If you'd read the article you'd already know. Answer: No, due to deliberate design choices in the new features.

    4. Re:When will Java be 'frozen'? by crazyphilman · · Score: 1

      I agree completely. I only just recently got J2SDK 1.4 on my linux boxen at home, installed all the documentation and such, and got ready to start having some fun, and they're coming out with the next version already. It's overwhelming. Every five minutes, there's a new version, with an associated runtime and plugin you've got to be aware of.

      I'm going nuts anyway, because at work I have to maintain all this old VB6 code, and we're switching to .Net so I have to become solid in VB.Net as well, and I have to maintain ASP and ASP.Net, and at home I'm using Linux, Java and C++. My head's going to explode; I can't take any more. I wish I could just become a sysadmin, escape all these damn languages and spend all day yelling at programmers for breaking stuff.

      --
      Farewell! It's been a fine buncha years!
    5. Re:When will Java be 'frozen'? by cant_get_a_good_nick · · Score: 2, Insightful

      When will C be frozen?

      C99 changed a lot of things, and added things that may cause some breakage for old projects. Just like you can tell your compiler to compile pre-C99, you use a different jsdk. C is > 30 years old and still has to evolve. Java is much younger and has more places where it needs to mature.

    6. Re:When will Java be 'frozen'? by Anonymous Coward · · Score: 0

      When will you freeze your code? I think that languages should always evolve to allow easy implementation of new design philosophies.

      If you want Java frozen, then why not free the Linux Kernel. No more features. Now let's make it more efficient, right? After all, it bites that hardware drivers are broken by new Kernels...

      I'd rather use a language that supports *current* design practices rather than write hacks:

      OO in C:

      #define CLASS_A \
      int a_member;

      typedef struct {
      CLASS_A
      } class_a;

      #define CLASS_B \
      CLASS_A \
      int b_member;

      typedef struct {
      CLASS_B
      } class_b;

      THERE! Now C supports inheritance... sort of... So there is no need for C++, right?

      -- Jon

    7. Re:When will Java be 'frozen'? by MarkWatson · · Score: 1
      I agree with you - one point that I had not considered is that it is easy to have multiple JDK/JRE instances on a server - keep 1.3 around for legacy systems.

      -Mark

    8. Re:When will Java be 'frozen'? by Mister+Proper · · Score: 1
      You want to break millions of lines of code just because you're bothered seeing deprecated classes and methods in the JavaDocs? Are you insane???

      Modify the JavaDoc generator to filter them out if you care that much but leave my legacy alone, will you?

      As for uppercase/lowercase confusion in java.awt.Color, I believe the rationale for this is that the colors are assigned in the constructor, and not in the assignments (i.e. after the constructor is run). It's a freaking stupid reason (IF I remember this correctly), I'll grant you that. I say add Color.BLUE next to Color.blue and put a deprecated tag on the latter.

      But I'll say it again: don't break that much code just because you're bothered by aesthetics.

    9. Re:When will Java be 'frozen'? by iabervon · · Score: 1

      None of these changes will affect an old program compiled with a new compiler (unless it didn't compile before...), nor old class files run against a new library. They've been very careful this time to avoid breaking legacy code. (Unlike in 1.4, where they added a keyword, which broke everybody's testing code, but not the actual programs)

    10. Re:When will Java be 'frozen'? by _fuzz_ · · Score: 1

      You want to break millions of lines of code just because you're bothered seeing deprecated classes and methods in the JavaDocs? Are you insane???

      It's more than just deprecated things. But since we're on the subject...

      It's more than compiler warnings or javadocs. It's not just aesthetics. Things are deprecated for a reason. Usually it's because there are serious problems, like with Thread.stop(). Sometimes it's because there's a better way to do it. Sometimes it's just to make things more consistent, like with Color constants (which are fixed in 1.4).

      Modify the JavaDoc generator to filter them out if you care that much but leave my legacy alone, will you?

      Who's going to force you to upgrade? You could keep using JDKs up to 1.5 which is backwards compatible to JDK 1.0.

      --
      47% of all statistics are made up on the spot.
    11. Re:When will Java be 'frozen'? by Mister+Proper · · Score: 1
      It's more than compiler warnings or javadocs. It's not just aesthetics. Things are deprecated for a reason. Usually it's because there are serious problems, like with Thread.stop(). Sometimes it's because there's a better way to do it. Sometimes it's just to make things more consistent, like with Color constants (which are fixed in 1.4).
      Fine. Then don't use Thread.stop(). Who cares that such code still exists? Like I said, if you remove it from the JavaDocs you won't even notice that it's still there. You'll be backwards compatible though. (i.e. it really is aesthetics for all practicle purposes.)

      Who's going to force you to upgrade? You could keep using JDKs up to 1.5 which is backwards compatible to JDK 1.0.

      Well, you couldn't upgrade if you'd want to keep using old libraries. Also, if after a while this Java 3 edition had many more feautures than 2 (1.4), you could only use them if you upgraded your entire codebase. An utter waste of time for some projects (if it's not broken, don't fix it).

      I realise getting rid of cruft can be satisfying to the perfectionist (a treat often found in programmers), but @deprecated is doing that just fine already. Willingly breaking code for the reasons you outlined is madness.

  68. programming shorthand by exp(pi*sqrt(163)) · · Score: 1
    I feel using programming shorthand leads to increased maintenance
    That's why I never use functions calls. They obfuscate the code because they hide what's being done in another function somewhere else. So I always replace any function call in any code I see with a hand-inlined copy of the body of the function. That way everyone can see clearly exactly what's going on. Shorthand? Who needs it?
    --
    Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
  69. what if... by moojin · · Score: 1

    sun has been rumored as a target for acquisition. what if microsoft buys sun? what would become of java?

    what if ibm buys sun? java would thrive, but i do have some concerns. when connecting a java client to a websphere ejb, the client jvm must be the same version (from ibm) as the webpshere jvm (from ibm).

    just some ramblings...

    andrew

    --
    Why did I lurk so long before registering for a Slashdot account? I could have had a Slashdot ID of less than 100000.
    1. Re:what if... by pmz · · Score: 3, Insightful

      what if microsoft buys sun?

      What happens when matter meets anti-matter?

      1) Microsoft wouldn't have a clue how to manage Sun. Sun is a hardware-engineering firm with a different corporate culture than Microsoft.

      2) Most of Sun's employees would either quit or sight tight until they can quit.

      3) Sun's customers would leave for IBM or HP; they would not eat MS' dog food.

      4) The Justice Dept. would actually do something for once, because J2EE is the only big competitor to .NET, and Solaris is the biggest commercial competitor to Windows Server.

      what if ibm buys sun?

      Bye bye, UltraSPARC. This would probably alientate lots of Sun customers.

      Java would cease being as open as it is. The JCP would close down.

    2. Re:what if... by crazyphilman · · Score: 1

      pmz said:
      ">> what if ibm buys sun?"

      "Java would cease being as open as it is. The JCP would close down."

      I don't know about that; you have to weigh IBM's innate corporate-ness and desire to control all with their equally powerful desire to see Microsoft suffer. It's possible that IBM would completely open up Java to the free software community just to piss Bill Gates off. Another possibility is, they might do this because they want to keep using Java internally, and it might be more convenient for them to be the influential rich uncle instead of the actual mother/father. Yet another possibility is, they might see Java as a platform they can open up the way they did PC hardware, a platform on which they can sell all their server software. If the platform takes off even more than it already is, they can sell more software.

      IBM won't necessarily live up to the worst stereotypes of corporations. It's entirely possible that they'll work hard to preserve goodwill in the developer's community (at least, towards IBM, Java, and other non-microsoft vendors). What do you think?

      --
      Farewell! It's been a fine buncha years!
    3. Re:what if... by pmz · · Score: 1

      What do you think?

      I agree that IBM opening up Java to spite Microsoft is plausible. It depends on which half of IBM's psyche makes the decision. Linux on IBM mainframes is a good example of the unexpected happening; however, the mainframes themselves are gool ol' IBM.

    4. Re:what if... by crazyphilman · · Score: 1

      Yeah, but I don't mind that so much; IBM hardware is probably pretty good. I like their laptops (although I keep seeing them referred to as "stinkpads" for some reason). I wonder which way they're going to go? I hope they're the ones to buy Sun if it gets sold... If anyone else does it, the company will be wrecked. At least with IBM it has a chance.

      If worse comes to worst, and Microsoft buys and buries Sun, killing off Java, well... At least we can fall back on C++. That's a completely open spec, with free, open-source compilers and IDEs available. It'll end up being okay, I think.

      (knock on wood).

      --
      Farewell! It's been a fine buncha years!
    5. Re:what if... by Anonymous Coward · · Score: 0

      Bye bye, UltraSPARC. This would probably alientate lots of Sun customers.

      Yes, most probably.

      Java would cease being as open as it is

      No, IBM would submit Java to a standards comitté.

      The JCP would close down

      I have no knowledge of this, however, as openess has become a focus point for IBM (it's one of the cornerstones of IBM's On Demand (TM) initiative) I hardly think IBM would clamp down on it. Perhaps extending it even further though.

    6. Re:what if... by thedarkstorm · · Score: 1

      I don't think MS would ever buy Sun. The Gov't wouldn't allow that to happen. And even if they got bought out (did I say that?), since Sun is sooooo Global; Europe would definately not all that.

      IBM picking up Java would be a wonderful thing. IBM is one of the most active of vendors, and has a great app server. I don't know what your doing, but I've been able to get non IBM clients to connect to WAS.

      --
      ... hey ... I had a .sig, bu then MicroSo$$ embraced it...
    7. Re:what if... by pmz · · Score: 1

      (although I keep seeing them referred to as "stinkpads" for some reason)

      Their laptops have a good reputation (I have an old Pentium 75 one still going strong). "Stinkpad" is probably a pet name assigned by people who have had chance bad experiences. It's sort of like "Slowaris," even though Solaris' performance is very acceptable.

      I hope they're the ones to buy Sun if it gets sold...

      Another option would be Fujitsu, who sell arguably better servers than Sun and have an investment in SPARC v9 and Solaris. Fujitsu also tends to dominate several benchmark categories, in spite of their low clockrate CPUs. They could absorb Sun's peripheral and chip engineering and Sun's relationships with TI. That wouldn't be too bad, unless Fujitsu's management style is so different that it puts of people in the U.S.

    8. Re:what if... by crazyphilman · · Score: 1

      Now, that's a pretty interesting idea. Fujitsu is a pretty cool company. I'm a little nervous about it myself, for the reason that I hate to see all U.S. businesses getting sold to foreign concerns -- I would think that would be a strategic error on our part. However, it's still interesting. They make pretty sexy laptops, if I remember; someone in my office got a recent model of their lifebook, and it was really, really neat.

      --
      Farewell! It's been a fine buncha years!
  70. This is a sad day for me. by Henry+Stern · · Score: 2, Interesting

    I've been using Java for most of my projects for years because it didn't let you get away with many of the confusing things that you can do with a preprocessor. I may sound like a big geek for this, but I was actually weeping while I read the article. JDK 1.4 broke the ice with the assert keyword and now everything bad about C++ is going to pollute Java.

    To the many cooks who spoiled the broth: "Thanks a lot, assholes."

    1. Re:This is a sad day for me. by easter1916 · · Score: 1

      Henry, Henry... weeping over a programming language? You need to get out more!

    2. Re:This is a sad day for me. by CharlesEGrant · · Score: 2, Interesting

      Hmm. I could understand your reaction if they were adding operator overloading, but assert seems pretty benign. Can you give an example of a confusing use of assert?

    3. Re:This is a sad day for me. by Anonymous Coward · · Score: 0

      I want to see what happens when this dude gets Runtime Exceptions

    4. Re:This is a sad day for me. by rowanxmas · · Score: 1

      I am excited about not having to cast and make stupid class specific collections.

  71. Hypocrites by melted · · Score: 1

    When C# came out, all the features you're singing praises today to were called "syntactic sugar" by this very community. Now they come out in Java and it turns out it's such a huge innovation that nobody can live without it. Next thing you know you'll be praising true properties and delegates. :0)

    1. Re:Hypocrites by easter1916 · · Score: 1

      I'm a J2EE developer and I have to agree with the parent... most of this stuff is just fluff.

  72. Test Driven Development by stand · · Score: 1

    Java is still strongly typed, but weak typing is good now in large part because of test driven development. Unit tests that you design yourself and run as part of the build process enforce your constraints much more effectively than strong typing does.

    For more, read Tim Bray's piece on this.

    --
    Four fifths of all our troubles in this life would disappear if we would just sit down and keep still. -C. Coolidge
  73. thanks. Stroustrup is right about java business by zymano · · Score: 1

    it's all a con. It's about sun $$$. And nothing great about it anyways.

  74. Great! by Anonymous Coward · · Score: 0

    This is great, with generics and so forth, Java is beginnig to be a REALLY sweet language! From the looks of it, Java 1.6 will be called "C++" :)

  75. I think these are all great... by axlrosen · · Score: 3, Insightful

    ... but man do I hate the enhanced for-loop syntax. At some point you have to give up perfect backwards-compatibility for readability. One or two new keywords would do a world of good.

    for (TimerTask task : c)
    task.cancel();

    becomes

    foreach (TimerTask task in c)
    task.cancel();

    1. Re:I think these are all great... by Anonymous Coward · · Score: 0

      comment, comment, comment.... I sent a commetn exactly to that effect to the email address listed on the JSR.

    2. Re:I think these are all great... by Anonymous Coward · · Score: 0

      I really agree with you on this point. The foreach-statement is just way more beautiful.

    3. Re:I think these are all great... by sohp · · Score: 3, Informative

      Sun has been burned once when they introduced the assert keyword and broke thousands of programs that use the JUnit testing framework. The bustage occured because JUnit already used the keyword as an identifier, for the assert() methods. A token can't be an identifier, so everyone's tests broke with 1.4 I applaud Sun from learning from that fiasco and avoiding a repeat.

    4. Re:I think these are all great... by Doppler00 · · Score: 2, Funny

      They can't make the syntax easy to read. If they did, then it would be called Python.

    5. Re:I think these are all great... by Anonymous Coward · · Score: 0

      Agreed. But the reason they CAN'T do that is because if anyone ever used "in" as a variable name, their code would be broken. And the ONE thing Sun doesn't want to do is have a bunch of people going, "'Write once, run anywhere. Forever. huh? That's CRAP!'"

    6. Re:I think these are all great... by Anonymous Coward · · Score: 0

      I think the problem is clearly System.in. But I say, screw it. More people used assert (JUnit and everyone using it) than people using System.in.

    7. Re:I think these are all great... by malachid69 · · Score: 1
      I think it is more likely that it would break things like:


      BufferedReader in = new BufferedReader(...)


      'in' and 'out' are used by MANY programmers for the names of their i/o readers/streams.


      Malachi

      --
      http://www.google.com/profiles/malachid
  76. Convergent evolution by Julian+Morrison · · Score: 1

    All computer languages undergoing rapid user-driven evolution are doomed to either converge on perl or python. Looks like java is heading pythonwards.

  77. Obsfucated.. by MilesParker · · Score: 1

    Oh, totally agree. I was assuming a single line, or in a for statement for example. In that context it is the best way, but in another..

  78. really lame by andy1307 · · Score: 1
    The upside is that if you try to insert something that's not a string, you find out at compile time and fix the problem. Without generics, you discover such a bug when your most important customer calls your VP to tell him that the program on which his business depends just crashed with a ClassCastException.

    Is this really the number one problem for most projects? ClassCastExceptions in production code?

  79. JCP strikes again by Wesley+Felter · · Score: 4, Informative

    Thanks a lot Sun for posting absolutely no information about the progress of this JSR. At least Doug Lea has posted a little information.

    1. Re:JCP strikes again by lokedhs · · Score: 1

      Absolutely no information? What do you call this then? http://www.jcp.org/en/jsr/detail?id=166

  80. How did this get modded +1, Insightful? by Anonymous Coward · · Score: 0

    Anyone?

    Jesus fucking Christ.

  81. Excellent IDE by Rudy+Rodarte · · Score: 1

    If you want a lightweight IDE, look at JCreator. There is a free version here!

  82. Agree by Anonymous Coward · · Score: 0

    They are ugly and of little use. Java has a different object model than C++ so Generics are not as useful as in C++. They do provide for compile time checking when adding objects to a collection class. However, I use collection classes extensively and have NEVER put the wrong kind of object in one. Even if I had, it would be caught by the run time checking the first time I tested the program.

  83. pre/post increment is a bad example by Kunta+Kinte · · Score: 1

    pre-increment is usually slightly faster than post increment. I can't rememenber the details, I'm sorry, but it's something about not making an internal copy of the variable be incrementing. This can be material if you're trying to get every bit of performance out of a piece of code.

    Which raises the point. I've noticed that quite a bit of "equal choices" in programming aren't really equivalent. There are cases where a "for" or a "while" loop can be used, but really one choice is much, much better in terms of performance. But the result is the same.

    --
    Based on upvotes, Ageism is the only "-ism" Slashdotters care about and think isn't SJW
    1. Re:pre/post increment is a bad example by Anonymous Coward · · Score: 0

      The main reason pre/post-increment is a bad example is that the semantics are different.

      x = 10
      y = 10

      a = x++
      y = ++y

      We now have a set to 10 and y set to 11, while both x and y are 11.

      The above poster correctly pointed out that pre-increment is generally faster. This is because for post-increment two copies of the variable are needed: that which is incremented and that which is returned. While this difference can be trivial for the likes of integers, for more complex types (e.g. some iterators) the difference in efficiency can be significant, and if you're using C/C++ efficiency is probably pretty important.

    2. Re:pre/post increment is a bad example by neden · · Score: 0

      pre-increment is usually slightly faster than post increment. I can't rememenber the details, I'm sorry, but it's something about not making an internal copy of the variable be incrementing. This can be material if you're trying to get every bit of performance out of a piece of code.

      In C, pre- and post-increment doesn't make a difference. Likewise, when using plain integral types in C++ (int, etc), it still doesn't make a difference. Where is does make a difference is when you get into operator overloading in C++.

      Pre-increment increments the object and then evaluates to the new value. Post-increment increments the object and then evaluates to the *OLD* value of the object.

      Overloading the pre-increment value is pretty easy - do the operation and return the updated 'this' (by reference).

      However, overloading the post-increment requires you to make a *copy* of the original object before incrementing it, so that you can return the original value, not the new one. Thus the body of the post-increment function would look something like:

      type orig = *this;
      ++(*this);
      return orig;

      Thus, using the post-increment will lead to a copy-constructor being invoked. Since it doesn't hurt to use one form or the other if all you are doing is incrementing and nothing else, a lot of C++ programmers just use

      ++i;

      in preference to

      i++;

      Of course, if the operators and constructors are all inlined functions and the optimizer is good, hopefully all of the extra code generated to make a copy of the un-needed copy of the object will be removed, anyway. But why take the chance?

      K.

    3. Re:pre/post increment is a bad example by Anonymous Coward · · Score: 0

      The above poster correctly pointed out that pre-increment is generally faster

      Not in Java. Don't talk about things you don't know about.

    4. Re:pre/post increment is a bad example by yaphadam097 · · Score: 0

      When compiled pre-increment takes one less instruction that post-increment. This is true in pretty much any language, the reason having to do with the fact that in post increment we have to care about the value before the increment as well as the value after, where as in pre-increment we can discard the value before the increment.

      Depending on how the compiler is implemented this really might not matter at all, but it is a good habit to prefer pre-increment. Plus, since good programming style in any language wants you to avoid side-effects pre or post increment should be semantically equivalent in your code. i.e.
      this: ++c;
      is slightly better than this: c++;
      but if we never do this crap: a = ++b - c--;
      then we don't have to worry about it.

    5. Re:pre/post increment is a bad example by DunbarTheInept · · Score: 1
      I would argue that if your compiler does something different with
      for( ; condition ; )
      than it does for
      while( condition )
      that it is broken. The rule is that for( ; condition ; ) literally means: start a loop, do nothing before the loop starts, check condition at the bottom of the loop, do nothing at the bottom of each loop.

      If your compiler is inserting some kind of code for those "do nothing" parts, I would call that broken.
      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    6. Re:pre/post increment is a bad example by Anonymous Coward · · Score: 0

      Clearly any optimizer ought to reduce both to a conditional branch, but I could imagine a debug build might include extra stack-unwinding code after "for" (since it does introduce an extra variable scope and extent).

  84. read this salon article by zymano · · Score: 0, Redundant

    i agree with both of you. read this article.

  85. Like C++? by triskaidekaphile · · Score: 1

    Generics were not in the first release.

    The language continued to change for well over a decade before being standardized by ANSI.

    If Java had been done "right", it would not have been done at all.

    --
    @HbFyo0$k8 tH!$
  86. Not convinced by SerpentMage · · Score: 1

    I am not convinced about generics. Generics with a test bed being C++ created nothing but nightmares.

    Before generics it was possible to take a C++ program and integrate it with another C++ library without much hassle. Sort of like how it is with C these days. Integration is not that difficult.

    Java integration is an absolute piece of cake. There are no issues whatsoever. But I fear generics is going to complicate this situation immensly.

    What I get concerned about templates is not the List type templates. Those are ok. Actually pretty nice solution. What concerns me is when we start the following List > > >. This is where C++ integration falls flat on its face. And I fear the same will happen to Java.

    Additionally what I always liked about Java is that it was simple to get things done. Generics adds a complication that most programmers do have problems with.

    Having said all that I am curious to see how it all plays out. But there is one BS statement:

    Without generics, you discover such a bug when your most important customer calls your VP to tell him that the program on which his business depends just crashed with a ClassCastException.

    Yeah right and these "crash the business" bugs will disappear? Oh yeah, and let me show you my porfolio of land in Florida!

    --

    "You can't make a race horse of a pig"
    "No," said Samuel, "but you can make very fast pig"
  87. Maintenance by ruriruri · · Score: 2, Interesting
    Unlike some people, I feel using programming shorthand leads to increased maintenance.

    Do you like seeing "public void setX()...public int getX().." a hundred thousand times to implicitly declare a bound property? Or would you rather see "published int x;" (to steal a line from C#) and be able to refer to x by field name rather than accessor method? I think simplifying code like this is a good idea. However, there is a dilemma created herein, as the example below will illustrate!

    Thought Experiment #1
    Assumption: Maintenance cost is directly correlated with program size.
    Therefore: The more terse the language grammar, the easier programs written in the language are to maintain.
    Thus: Perl.

    At that moment, the programmer was enlightened.

  88. OOPS... by SerpentMage · · Score: 1

    I added a whole bunch of brackets and the browser is cutting them out....

    Here is where I get concerned with brackets

    List[ Container[ Container[ String, Object[Long] ] ] ]

    That is complicated

    --

    "You can't make a race horse of a pig"
    "No," said Samuel, "but you can make very fast pig"
    1. Re:OOPS... by jcast · · Score: 1

      List[ Container[ Container[ String, Object[Long] ] ] ]

      That is complicated

      Yeah. Why do you need a four-dimensional container?

      Oh well, to each his own, I guess. In any case, it's still clearer than anything I've seen spelling it out in non-generic notation.
      --
      There are reasons why democracy does not work nearly as well as capitalism.
      -- David D. Friedman
  89. Enum/Maintenance? by Anonymous Coward · · Score: 0

    > Unlike some people, I feel using programming
    > shorthand leads to increased maintenance.

    How does changing from int to enum increase maintenance? Either way, you've got to look up the values in the class where they're defined.

    I've learned shorthand can be nice if used in a sane manner. C/C++ macros can be utilized for saving a lot of typing. The C/C++ goto construct can be a really nice way to clean up within a function/method call. I find shorter/cleaner code to be easier to maintain.

  90. "synchronized" vs. locks & semaphores by jlusk4 · · Score: 2, Interesting

    The gist is, you'll never need to use ... "synchronized" anymore, but rather you'll execute Runnables, use Locks and Semaphores, etc.


    I'm not sure how locks and semaphores are a step forward from monitors, which is what "synchronized" represents.

    Are you claiming "synchronized" is inefficient? Did you see the developerWorks article?

    Are you claiming that such a high-level structure as a monitor is unnecesary for real programmers, who know what they're doing and will never screw up using synchronization primitives?

    John.
    1. Re:"synchronized" vs. locks & semaphores by TummyX · · Score: 1

      Funny thing is the concurrency package uses monitors to implement the semantics of the locks, semaphores etc.

      Once it's in the API I'm sure Sun will integrate native support into the VM.

  91. Programming Myth by mrpotato · · Score: 2

    " I feel using programming shorthand leads to increased maintenance."

    False.

    Shorter code and more powerful idioms makes a program *easier* to debug.

    Too much code makes the purpose lost in the noise. Consider:

    foreach (@array) {foo $_};

    and

    my $i;
    for ($i = 0; $i < $#array; $i++)
    {
    foo $array[$i];
    }

    (I use Perl here since it is well known and I can show the 2 idioms, but really Perl isn't the clearest language of all). One form is much clearer and reveal much more eloquently what is the intent of the code.

    Of course, this doesn't mean that shorter code "at all cost" is easier to debug, it means that "less code" is better.

    Oh, and also it pisses me off when management tells me I need to use only certains idioms in case someone comes over my code and don't understand it. I hate to have to program like the next maintainer will be clueless and ignorant.

    --

    cheers
    1. Re:Programming Myth by Anonymous Coward · · Score: 0

      Bah. I think you meant:

      foo $_ for @array;

    2. Re:Programming Myth by Anonymous Coward · · Score: 0

      but really Perl isn't the clearest language of all

      Understatement of the week.

  92. Real Programmers Don't Use Pascal by dsplat · · Score: 1

    My code was hard to write to it should be hard to read. :)

    "Real Programmers don't need comments-- the code is obvious."

    -- Real Programmers Don't Use Pascal

    --
    The net will not be what we demand, but what we make it. Build it well.
  93. Automatic boxing/unboxing by autopr0n · · Score: 2, Interesting

    It's interesting the problem they were having with unboxing. Right now a null pointer would return a int value of zero, rather then throwing an error.

    Actually, I think that's a bad idea, since you wouldn't be able to tell a zero you put in a collection with one that you didn't. Personally I'd like to see this as an option, somewhere. perhaps as a parameter to Integer, so you could do Integer<0> or Integer<null> to chose the behavior of the class. The problem there is that it's not obvious what a parameter to integer would do. Although I suppose you could use an if statement.

    Personally, I wished they would have thought up a more interesting way to do generics then the C++ model. I wonder if this is going to give us the full range and power of C++ templates in java.

    --
    autopr0n is like, down and stuff.
  94. When are people going to learn... by Anonymous Coward · · Score: 0, Funny

    ....that C++ is perfect and using other languages is useless.
    C++ does it all, does it faster and although may be harder to learn, allows the programmer to make the choices. I've always beleived that if learning a high leval language like C++ is too complicated for you, you have no business working on anything even remoatly serious. I have always felt like I am being held back with most other languages, including Java, but with C++ I have felt like I can do anything. I have choice over pointers, generics, classes, friend fuctions....I guess I love the fact C++ allows you to break all the rules...which can lead to clever tricks....it's beautiful. Lower leval languages, as well as .asm have always been easier for me to grasp I guess....no hiding things, what you put in is what you get out. Smalltalk is cute though. :)

    1. Re:When are people going to learn... by Anonymous Coward · · Score: 0

      Flamebait, fine but it's true.

  95. foreach by RichiP · · Score: 1

    Why was the for operator enhanced instead of introducing a new keyword (such as "foreach") which would lessen the confusion, build on the understanding that most programmers who've seen other languages have, and make much more sense in general?

    1. Re:foreach by sohp · · Score: 2, Insightful

      I guess you didn't RTFA. Introducing a new keyword breaks programs that happen to use that as an identifier. They broke JUnit when they introduced the assert keyword, and having been burned once, learned something.

  96. Can someone please tell me why anyone uses Java? by Chromodromic · · Score: 0, Interesting

    "Generics"? Castrated templates.

    Enhanced "for" loop? Syntactic sugar. Oh and for God's sake, don't use new keywords. It'll be destabilizing.

    The "split type system" in Java has always compromised Java's status as a true OOP platform. Seriously, this is supposed to be exciting? Java is how many years old and they've finally made it oh-so-easier to convert between primitive and class types? Aren't there enough conversions in a strongly typed language?

    Typesafe Enum pattern, Constant Interface antipattern ... Whenever I see this corporate programming designspeak crap I thank God that Apache wasn't written in Java.

    Metadata programming. Now Java will have code that emits code before the compiler emits code. Well, there goes Java having no pre-processor. But in true Java fashion, it looks like this "framework" will be much, much harder to use than a pre-processor, so that's good.

    Bottom line, Java is Byzantine, slow, bloated, and now playing catch-up. Want to avoid all this verbose, camel-cased code? Go C++. Yes, you'll have to learn how to write secure code, and yes, you'll have to use pointers, which are supposedly EXTREMELY DANGEROUS, and yes you'll have to learn about how your computer works a little more to be an expert. Of course, Java requires none of these things.

    If you must go with some absolutely proprietary platform, then go C#. At least it's standardized. Oh, oh, Sun was going to do that with Java but then, you know, didn't.

    --
    Chr0m0Dr0m!C
  97. programming shorthand. by hatrisc · · Score: 1
    I feel using programming shorthand leads to increased maintenance
    like typedefs. ugh, i hate tracing through header file after header file to find what those typedefs really are.
    --
    I write code.
  98. ML doesn't have generics by Chuck+Messenger · · Score: 1

    But note that "generics" or "parametric types" have been present in languages such as Eiffel or Sather for well over a decade, and for much longer in ML.


    ML (at least) has parametric types, but not generics.
    1. Re:ML doesn't have generics by Anonymous Coward · · Score: 0

      Where parametrized functions aren't sufficient, functors can be used.

      I'm not sure how long ago they were introduced, though.

  99. The Six-Million-Dollar Sweetener by SEWilco · · Score: 2, Funny
    Some of the enhancements to me are purely sugar

    I often also enhance myself with sugar.

  100. Just from pesonal experience.. by LogicHoleFlaw · · Score: 5, Insightful

    You know, I've just got to say this.

    Each and every point on this list of additions to the languages addresses problems that I have personally run into in my use of Java at work. These things will make the writing and maintenance of java projects small and large much, much easier.

    Generics: Thank you God, yes! Having to explicitly cast objects out of Containers is tedious and error-prone.

    Iterators/Enhanced 'for': Make iteration much easier to read and understand.

    Autoboxing/Unboxing: This helps alleviate the enormous kludge that is the Object/primitive dichotomy. Casting to and from wrapper types just to pass ints, etc. around really sucks.

    static import: Not having to fully specify tedious class names to access static members is a big boon for making stuff digestible and easy to read.

    Metadata: Writing boilerplate sucks the big one. How many hours have I lost writing boilerplate? Way too many. Having language support for generating code from the metadata cuts my implementation times way down.

    I could sit here and argue with folks about the 'new Java' versus C++ or C# or Smalltalk or whatever endlessly. But man, these things sure make Java a whole lot more pleasant to use.

    --
    -- Flaw
    1. Re:Just from pesonal experience.. by Enonu · · Score: 1

      IMHO, static import is really going to confuse the hell out of maintainers.

      static import package.*;

      Where was the int BOB_DOBBS declared again, an what is it really equal to? Go have fun looking through every class in that package.

      Yep, not good :(

    2. Re:Just from pesonal experience.. by ChannelX · · Score: 1
      Generics: Thank you God, yes! Having to explicitly cast objects out of Containers is tedious and error-prone.

      Please explain why you think this is so. I know many people who *arent* looking forward to generics and don't really care about them (myself included). I still don't understand how in most situations that casting objects out of Containers is tedious and error-prone. How often are you putting objects in collections that you don't know what they are? Yes there are certain situations where generics are handy. I just dont see the hype tho.

      --
      My blog: http://jkratz.dyndns.org/~jason/blog/
    3. Re:Just from pesonal experience.. by Alex+Blume · · Score: 1

      The major benefit, besides the shorter easier to read code (i.e. no casting), is that the compiler can now check to ensure you don't ever put the wrong type of objects into a collection.

      A whole class of bugs that you would only see at runtime can now be caught at compile time.

    4. Re:Just from pesonal experience.. by ChannelX · · Score: 1

      Yes. A whole class of bugs that I have yet to have seen ;) Thats why I don't get the hype. The code reading part I can understand. I don't design classes for others to use (ie: like a class library of some kind) so I can see that it might be helpful to some folks but I just cant see how generics are gonna do a lot for people error-wise. If you dont know what you're putting in a collection and then pulling stuff out well....just very weird ;)

      --
      My blog: http://jkratz.dyndns.org/~jason/blog/
    5. Re:Just from pesonal experience.. by iggymanz · · Score: 1

      well, in a huge project with dozens of developers coming and going, and hundreds of classes this kind of thing will help alot...especially since a bad cast is a show-stopper in production (code runs fine for developer and QA and first 3 months of production, then wham!)

  101. It seems to me... by CptChipJew · · Score: 1

    That Java is lacking a few things I'd expect from such a popular language.

    Now, I'm not the most experienced programmer in the world, but I've found that unlike other languages (especially C++), lots of different common tasks don't have standard methods for doing things. This suprises me primarily because the JDK is chock full of built-in-abstact-data-type goodness (I'll never write another Linked List again =D ).

    In C++, where you have cin, with Java, there are a number of different setups that produce the same behavior. However, most of these seem non-trivial when compared to the simplicity that libaries like C++'s iostream provide.

    So I feel adding common shorthand tasks is a good thing. If you know what you're doing with things like enumerators, you aren't going to cause much damage.

    --
    Vonal Declosion
  102. kawa by b17bmbr · · Score: 1

    bought my macromedia, and shitcanned. it was a good ide for windows. eclipse is great, but a litle heavy. for overall use, try jedit

    --
    My problem? I was perfectly gruntled, until some numbnuts came by and dissed me.
  103. Warning: COMPLETELY OFF TOPIC by ratboy666 · · Score: 1

    The name "ratboy" stems from a contest. We were having a patio party whose theme was "worst songs of the 70s and 80s". Each had to get up to sing. My contribution (almost the winner) was "Ben". Since then, I have been known as ratboy.

    Ratboy.

    PS. And I stick by my original source... and I really wish I had a friend like Ben.

    --
    Just another "Cubible(sic) Joe" 2 17 3061
  104. Re:Emacs for Java - fixed URL by mughi · · Score: 1

    The URL just had a space in it. Just try it as an actual link:

    http://www-106.ibm.com/developerworks/java/library /j-emacs/

    (For some reason, /. seems to want to stick that space in there, but not on the actual hyperlink)

  105. Eclipse is yer only man by jdesbonnet · · Score: 1

    I was a text editor/command line person until I encountered Eclipse 2 and I've never looked back since. http://www.eclipse.org/

    Only (small) drawback is that the UI is just a tad sluggish. But if you have a 1GHz+ machine you're unlikely to notice.

    And if you are a webapp developer the Tomcat plugin really makes life easy.

  106. Bug in example?? by TheFairElf · · Score: 1

    This method :

    void cancelAll(Collection c) {
    for (Iterator i = c.iterator(); i.hasNext(); ) {
    TimerTask tt = (TimerTask) i.next();
    tt.cancel();
    }
    }

    can be replaced with

    void cancelAll(Collection c) {
    for (Object o : c)
    ((TimerTask)o).close();
    }

    using the enhanced for statement. So cancel() changes to close()?

    1. Re:Bug in example?? by Anonymous Coward · · Score: 0

      that's what he was talking about. it's a nice little feature that will save people having to look up the documentation because they will now be able to use similarly named methods and the compiler will know exactly what they mean.

  107. Error checking with IFs. UGH by autopr0n · · Score: 1

    One thing I remember about win32 programming back in the day, was the insanely nested if statements (for example, in example programs) You had like all these blocks of code like

    if(doOneThing(lpfSomething){ if(doAnotherThing(lpfSomething){ if....

    And so on, it was just a huge amount of wasted code, and if you added error handling for each condition made it huge.

    Exceptions are so much nicer...

    --
    autopr0n is like, down and stuff.
  108. This is sad... by pchown · · Score: 2

    It makes me really sad to read this. Java is a long way behind the state of the art for expressive power. These changes are welcome but Sun are presenting them as though they are innovative. Three lines to remove the four character strings from a collection? Look at it in Python:

    filter (lambda x: len(x) != 4, list)

    If you object that Java is doing type checking, and Python isn't, look at it in Haskell:

    filter (\x -> (length x) /= 4) list

    Time to move on I think...

  109. Programmers don't even document type of collection by tungwaiyip · · Score: 1

    Generics should have come much sooner.

    Today, without the language support, I ask every programmer to minimally add a comment to document the data type used in the collection, like

    HashMap myTable; // username(String) => UserRecord

    Still many people fail to do just that. I have to trace the typecast and the usage of the collection to discover what are they putting in the collection. :(

    The proposal seems to keep Java collection's light -weight design. It simply provides some compile time checking and implicit typecasting. It avoids the complexity of C++'s template. I remember I have spent a lot time debugging the compilation. An error message would spend multiple lines with long and unreadable class names decompose of a template instances...

  110. Bjarne Stroustrup should be lynched by melted · · Score: 2, Insightful

    For the gaping holes and pitfalls he has created in C++. Everyone who has read books from Effective C++ and Exceptional C++ series knows this. In Java or C# you've got to try to shoot yourself in the foot, in C++ this comes by default, you don't even have to do anything. Some insanely simple situations shoot you in the foot so bad, it's not even funny. Not that C++ doesn't have its uses, but its usage should be limited and punished for. Thanks to Bjarne's "excellent" design, devs punish themselves every time they use the language for something non-trivial.

    1. Re:Bjarne Stroustrup should be lynched by Anonymous Coward · · Score: 0

      Doing anything non-trivial in Java usually involves multiple trips to Google to figure out why the #$%#$ (NS/MSFT) VM does weird crap...decompile some of the JDK to see WHY it's behaving the way it is...

    2. Re:Bjarne Stroustrup should be lynched by Anonymous Coward · · Score: 0

      man, you must really suck at Java programming then...

  111. pizzacompiler by cyco/mico · · Score: 2, Informative
    I found java always underachieving, the rt environment ("virtual machine") and especially the language. the compiler was, well, ok.

    my favorite language (extension) for the vm has always been pizza. It gives you said generics, but also

    • first-class functions and
    • algebraic types (think functional pattern matching)
    all three compatible with the original jvm 1.0 specification.

    But to be honest: this seems to be a real great step for java. programmer with a certain need for aesthetics (and self regard) can now really use this language...

  112. What Alan Kay has to say about C++ by BitwizeGHC · · Score: 1

    "I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." --Alan Kay :)

    I don't mind C++ (or Java) that much but spend enough time on the Squeak ML and you get an idea just how much the other OO languages have been playing "catch-up" to Smalltalk, from a power standpoint.

    --
    N4st0r, trixx0r h0bb1tz0rz! Th3y st0l3 0ur pr3c10uzz!
    1. Re:What Alan Kay has to say about C++ by rjh · · Score: 1

      Fortunately, Bjarne Stroustrup has never--not once, not ever--claimed C++ is an object-oriented programming language. He says OO is one of the programming styles C++ supports... but that's not the same thing as saying C++ is an object-oriented language. (Long-time C++ programmers generally think the idea of C++ as an object-oriented language is silly: it has primitive data types and explicitly supports procedural programming. How can it be an OO language?)

      Java isn't OO, either. Primitive data types. :)

    2. Re:What Alan Kay has to say about C++ by ChannelX · · Score: 1

      Modern Smalltalks also use primitives under the hood for performance reasons. The use of primitives doesn't make a language not OO.

      --
      My blog: http://jkratz.dyndns.org/~jason/blog/
    3. Re:What Alan Kay has to say about C++ by J.+Random+Software · · Score: 1

      Unlike Java's (needlessly crippled) "primitive types", SmallInteger is a genuine class. Instances happen to be implemented more efficiently with no boxing, but they still support an extensible set of messages and can be intermingled transparently with other (boxed) objects. Lisp fixnums act like this too--the trick is to reserve a few tag bits to tell you whether a value is a pointer to the most general representation of class instances, or an unboxed integer (or character, boolean, cons...).

  113. Microsoft Visual J++ by Anonymous Coward · · Score: 0

    Visual J++ is a great way to make Java programs

  114. Re:Error checking with IFs. UGH by oscarcar · · Score: 1

    Don't get me wrong, I wouldn't do win32 programming unless I had no food to eat. And even then... my food wouldn't taste as good.

    But...

    Exception Handling doesn't get rid of logic statements, it just does for exceptions. And these come at the expense of a lot of overhead.

    I agree Exception Handling in java is nice, but this is all done by Objects. Objects are removing the spaghetti code. But it is VERY nice that java has them all done for you. And you can use objects when coding for win32, even if you would have to write some of your own.

    Plus, to be fair, coding an XWindow program is no joy.

    Oscar

  115. The essence of this: by Julian+Morrison · · Score: 1

    A program should express WHAT you are doing, rather than require you to faff about detailing HOW you want it done, unless you actually want to.

    A programming language should make this easy with syntactic sugar.

    Humans read programs.

    Computers read machinecode binaries.

  116. Yeah, but... by Burpmaster · · Score: 5, Funny
    I'd say that "++x" is actually the "best" way because it puts things in verb-noun order, which I'm used to as an English speaker.
    In Soviet Russia, x++!
  117. Needed feature by quantaman · · Score: 2, Interesting

    They need to include an option to not include bounds checking in arrays. Right now Java is becoming very popular in physics because it's easy to use and portable across systems. I know a lot of people in physics who program in Java and I've worked the past two summers as a summer student writing code for physicists. The biggest complaint both they and I have in the bounds checking it does. It's a great option for debugging, testing, and for running most applications. But when you are running a large program the overhead of bounds checks in arrays can be prohibative. Ideally I would like either a runtime or compiler option where you can specify to run it without bounds checks. Obviously this wouldn't be a good idea for a great many apps but it would be extremely useful when running an array heavy application that takes hours or days to complete.

    --
    I stole this Sig
    1. Re:Needed feature by Thorgal · · Score: 2, Insightful

      Hotspot optimizes bound checks away. What would be more useful for scientists are:

      a) true arrays,
      b) FPU-using trigonometrical ops

      --
      "Man in the Moon and other weird things" - wfmh.org.pl/thorgal/Moon/
    2. Re:Needed feature by GrayArea · · Score: 1

      There are VM's that can optimize away bound checks. Sun 1.4.1 Server VM does this, as well as latest IBM VM.

      --
      "The deluded are always filled with absolutes. The rest of us have to live with ambiguity." - Aristoi, Walter Jon Willia
  118. Re:you fags by Anonymous Coward · · Score: 0

    nearly approaching the homosexuality or you and your post.
    -1 Offtopic

  119. XDoclet by Julian+Morrison · · Score: 1, Informative

    Sounds to me like they just slurped in XDoclet, just like they slurped in Log4J in the 1.4 release.

    1. Re:XDoclet by TummyX · · Score: 1

      It's a bit different. Log4J was a class library that could just be absorbed into the Java API. To fully implement C#-like custom metadata you need to change the reflection APIs *and* the compiler.

    2. Re:XDoclet by yaphadam097 · · Score: 0

      That is part of what is great about open source. What greater compliment than to have your code stolen by the owners of the language?

  120. Uh, read the article by autopr0n · · Score: 3, Informative

    This is exactly what the new Java enums do. You just get to type a lot less and you can use them in case statements.

    --
    autopr0n is like, down and stuff.
  121. Bah humbug... by Troll_Kamikaze · · Score: 1

    One of the examples discussed in the article compares the following pre-generics code to the generic code:

    /* Remove the four-letter words from the specified
    * collection, which must contain only strings.
    */
    static void expurgate(Collection c) {
    for (Iterator i = c.iterator(); i.hasNext(); ) {
    String s = (String) i.next();
    if(s.length() == 4)
    i.remove();
    }
    }

    Here's how the same method looks with generics:

    static void expurgate(Collection<String> c) {
    for (Iterator<String> i = c.iterator(); i.hasNext(); )
    if (i.next().length() == 4)
    i.remove();
    }

    Here's the same method written in Python:

    def expurgate(col):
    return [ s for s in col if len(s) != 4 ]

    Now tell me, which of the three is the most consise and readable expression of the idea?

  122. Sig by Anonymous Coward · · Score: 2, Funny

    Arguably the most terrifying sig I've ever seen.

  123. I mod this thread a 5. read it ! by zymano · · Score: 1
    good points guys.

    Let me add that people are being forced to use this language like slaves.

    Academia and corporations are slaves to propoganda by sun.

  124. What about making the language useful by samwhite_y · · Score: 5, Insightful

    In the old days when people talked about Linux, there was an expression "What about the big pink elephant in the middle of room" and it was referencing the fact that Linux did not support truetype fonts and font aliasing. Now some of that has been fixed, but Java still has its big pink elephant. Here are some of the things that people don't talk about.

    The memory foot print for loading Java is 20meg + and growing. I am part of a team that has been developing a complex Java application for the last few years and we have created about a 3meg library (and it probably does at least as much as the more popularily used Java classes). I have looked at some of the source code for the core Java libraries and it is clear that a good rewrite could reduce this footprint by a factor of 2 to 4. Currently, C# loads with a footprint of 2 meg to 4 meg. Most other scripting languages usually have engines that are about the same size. To put it simply, the base core Java libaries are unjustifiably large. Maybe if Java were truly open source this could be addressed, but of course Sun doesn't even believe in submitting Java to a standards board.

    You cannot load the Java VM once and run multiple processes (note "processes", not "threads") from the same Java VM memory footprint. I hear that such a thing is becoming possible for C# on Linux. You would have to build all the core Java classes into a "DLL" or ("so" on Linux), but that shouldn't be so difficult.

    You still cannot do basic OS operations in Java without writing your own JNI library. The one that stands out is the inability to get the ID for the current running process. The "nio" package has corrected some of these issues, but the "nio" package should be the "io" package instead of having two separate packages (similar to AWT vs. Swing).

    Window focus handling is still terrible. Ever have two frame windows up, have a modal dialog pop up on one frame while you were looking at the other? The frame window without the popop modal dialog becomes unresponsive and the other frame cannot be reached by tabbing through the windows. Only if you are lucky and that window is still visible on your desktop can you successfully reach it. Also, if a user clicks on a button that generates a modal dialog, the frame is only locked out from user input once the dialog manifests. This creates the infamous "double" clicking problem.

    Java's package management is still primitive. If you want to do anything more subtle then using the classpath to load in custom libraries, you have to write your own class loader. Having an auxillary file specifying parameterizable rules for class loading would be nice. It would also be nice if you could ask a running Java process what packages it had loaded (and metadata about them such as location and version). Compare this to C# (or the way some of the web server oriented scripting languages work).

    Some of the basic core library functions have some major weaknesses. For example, the Hashtable should be written as a native object when using String lookup keys and also allow you to dictate the algorithm for creating hashes (ex: use first 8 characters, last 8, or middle 8). There should also be a non thread safe version as well as a thread safe version. The lack of such a natively implemented primitive object is one of the big reasons why some less cleverly implemented scripting languages (such as python) can beat Java in performance on many web applications. In general, the core collection classes should be implemented in pure optimized (down to the actual chosen assembly code) native code.

    Many of the utility libraries are broken in fundamental ways. Send back a badly formed response to the HTTP library and you go into an infinite loop when it falls into its keep-alive/retry logic. Date parsing is still behind what is available in the C standard library. Locale specifications do not allow you to independently specify date formats, language, floating point format, currency format, and time zone. You get o

    1. Re:What about making the language useful by Anonymous Coward · · Score: 0
      Java's package management is still primitive. If you want to do anything more subtle then using the classpath to load in custom libraries, you have to write your own class loader.

      I'll have to disagree on this one. Classloaders aren't perfect by any means, and force programmers to do things in a different way. The whole idea of having multiple versions of libraries in the same memory and application domain to me is a bad idea and increases the likelihood of security issues. If I write a library v 1.0, but a major security bug is discovered, some one could argue load both. Well that seems fine, except that loading both libraries could cause unpredictable behavior and could allow an attacker to force the application to use the older version. Take a different example, if the classloader allows for multiple version of a library, which has the same name, it could cause instability. So instead, Sun chose to make classloader work in such a way that you have to write custom classloaders. Is this hard. Damn right it's hard, but it should be hard.

      Screwing around with classloader isn't something a typical programmer should do and should be done by those with the experience and skill to implement it correctly. Not everything should be easy, because making it easy could very easily produce the DLL version nightmare windows currently deals with now. Every thing is a trade off right. It's really about choosing which problems and limitation you're going to live with.

    2. Re:What about making the language useful by SashaM · · Score: 1

      The memory foot print for loading Java is 20meg + and growing.

      Huh?

      public class HelloWorld{

      __public static void main(String [] args){
      ____System.out.println("Hello World!");
      ____Object lock = new Object();
      ____synchronized(lock){
      ______try{
      __ ______lock.wait();
      ______} catch (InterruptedException e){}
      ____}
      __}

      }

      $ jikes HelloWorld.java

      $ java -version
      java version "1.4.1_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
      Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)

      $ cmd /C ver
      Microsoft Windows 2000 [Version 5.00.2195]
      (C) Copyright 1985-2000 Microsoft Corp.

      $ java HelloWorld

      The task manager shows 4700KB memory usage and 8408KB VM size.

      Now, I agree that this is way more than "Hello World!" should take, but it's a far way to 20MB.

    3. Re:What about making the language useful by greenrd · · Score: 1
      You make some good minor points (check out the high-voted RFEs and bugs in the bug parade for me), but some quibbles:

      Currently, C# loads with a footprint of 2 meg to 4 meg.

      I would not see that as a fair comparison, since MS can bundle the API into their core operating system DLLs - and Mono doesn't even have a MS-compatible API yet.

      You cannot load the Java VM once and run multiple processes (note "processes", not "threads") from the same Java VM memory footprint

      You can on Mac OS X, thanks to Apple. I've heard that they're considering rolling this feature back in to the Sun version.

      You still cannot do basic OS operations in Java without writing your own JNI library.

      Yes you can - multiple solutions exist. JavaUNIX, for example. There's one that's more cross platform, as well.

      and also allow you to dictate the algorithm for creating hashes (ex: use first 8 characters, last 8, or middle 8)

      What's wrong with creating your own MyString and MyStringHashMap classes?

      There should also be a non thread safe version as well as a thread safe version.

      Use HashMap, which has been around since JDK 1.2!

      In general, the core collection classes should be implemented in pure optimized (down to the actual chosen assembly code) native code.

      Have you done actual profiling to prove this is the cause of the slowness? I'm not convinced that this is a big issue - it could be just a case of programmers using the wrong tool for the job. For example, just because a hashtable is O(1) doesn't mean we can be sloppy about it and use hashtables where arrays would be better suited.

      The character encoding (UTF8, SJIS, etc.) conversion libraries do not let you control how conversion failure is handled. It doesn't let you find out where the failure occurred or how the bad byte sequences should be handled. In general, error reporting on conversions and parsing is light weight and will not let you pinpoint the source of the error.

      That sounds like a niche market. It's perfectly possible to write your own code for that, and for performance, only call it when you need to generate an error message.

      And of course, everybody's favorite. Swing runs like a bloated dog (the Eclipse project proves that it did not have to be this way).

      Actually, Swing is better now. On my Linux machine, Blackdown JDK 1.4.1 appears to be more efficient than Qt! Qt apps can cause an mp3 player to break up through excessive X server usage when scrolling, but Java apps no longer do (although they used to in a prior version). But I agree, it still has some way to go.

      Swing and SWT had different design goals. SWT sounds like it was like an "AWT++", focusing on native widgets. But Swing is not inherently slow by design, it just has a lot of crud (*cough*Taligent?*cough*) inside the implementation.

    4. Re:What about making the language useful by samwhite_y · · Score: 1

      So the fact that almost all real world Java applications (including Sun's) use shell scripts to launch their Java applications just so they can get around the limitations of the classpath is not sufficient proof of the problem. Ten applications share a common library. You want to upgrade the library but the name of the jar file has changed or you do not want to move or delete the existing library. In the best possible scenario, you would like to suggest to these 10 applications where they should go for the latest and greatest version of library API, but allow them to fall back to an older version. It is a real pain to have to write complicated shell scripts or custom classloaders to do this and once I use shell scripts or a custom classloader, there will be no textbook out there to explain to others what crazy things I did.

      An example would be some XML library APIs (Xerxes?) that have incompatibilities with some of the shipping Java SDK libraries depending on which version of the Java SDK you are using. It would be nice to have a parameter that could test for version before deciding which XML library you would load.

    5. Re:What about making the language useful by samwhite_y · · Score: 1

      I must admit this was smaller than I suspected. I am basing my claims on the simple configuration dialogs that I have written that in spite of their simplicity can take a long time to start (2 seconds is way too long for a trivial app like this) and seem to take up an inordinate amount of memory.

      Then somebody at a convention demoed a sophisticated user interface application on Linux using C# that used a tree control and tabbed dialogs. It came up immediately and took only a couple megabytes of memory.

      It is also possible that Sun has improved this a bit in 1.4.1_02 using the client optimized launch. I have not checked the numbers recently.

    6. Re:What about making the language useful by SashaM · · Score: 1

      You have to keep in mind that Microsoft can "cheat" a lot of times by preloading DLLs when Windows starts and sharing the loaded libraries between applications. The task manager is very often misleading about the actual memory usage of application.

      Hopefully Sun will implement this feature request, at which point you will be able to make an apples to apples comparison.

    7. Re:What about making the language useful by samwhite_y · · Score: 1

      The demo I saw was of an open source port of C# to Linux. I do not think that there was a cheat. It is weird in a way that there is now an active open source development in progress for C# but not of Java.

      However, C# does cheat in the sense that it does not use cross platform GUI libraries, it uses the native window APIs of whatever OS it is working on. In that respect, it has a fundamentally different mission than Java.

    8. Re:What about making the language useful by Minna+Kirai · · Score: 1

      What's wrong with creating your own MyString and MyStringHashMap classes?

      It's impossible to create a Java class which acts like the native String class, since the language doesn't support operator overloading for the critical concatenator "+".

  125. Where are shared jar files/JVMs? by Anonymous Coward · · Score: 3, Interesting

    When will Java support shared jar files that work like shared objects or DLLs in operation systems?
    IMHO this is one the main shortcommings of Java. Every jar file is loaded into every process causing a huge memory footprint and long startup times.

    When playing around with some java shells, that only load classes once and simulate processes as threads, I saw simple swing applications load in 0.1 secs and other significant speed ups.

    I was hoping for it in 1.4.x and now it seems it won't even make it into 1.5. I realize that it will be hard to implement this in a platform transparent way.

  126. wont happen by zymano · · Score: 1
    Marc . if they wanted that , they would have already have done it. Java is not for browser apps or executable apps anymore.

    Sun wants control of servers for their own profit. It's that simple. Why can't anyone see this?

  127. Question regarding enhanced for ... by AlxBarker · · Score: 1

    Collection c; ... for (String s : c)

    What if I have a data structure that is logically iterable yet not a Collection nor an array? How would I use for in say, a Vector or Matrix class of my own design? What if I wanted that for loop to iterate over the elements of a Matrix in some nonstandard denumerable manner?

    It would seem more logical to me for Java to simply apply allow blocks as used in Smalltalk.

    URL : Enhanced for discussion on JCP site

    URL : About Smalltalk Blocks

    1. Re:Question regarding enhanced for ... by GrayArea · · Score: 1

      There is a new Iterable interface you would implement that consists of a single method returning an iterator. Collections types and the built-in Array class implement this interface.

      --
      "The deluded are always filled with absolutes. The rest of us have to live with ambiguity." - Aristoi, Walter Jon Willia
  128. It's ALL syntactic sugar by cbogart · · Score: 1

    What language feature isn't syntactic sugar? High level computer languages are all shorthands for machine language. It's all about making it easier to read and write. It's bizarre to criticize Jdk1.5 for adding one ounce of sugar to what's already a ton of sugar. These are all features that I thought were absurdly verbose when I first learned Java, so I'm pleased to see the changes.

  129. missing "fix" by alder · · Score: 1
    Properties are supposed to provide controlled access to whatever they represent. Hence true property needs get/set methods. The syntax may be different, more terse (C#), but a property still has to be manipulated through methods.

    The example above simply does not reflect the fact of controlled access, and one can make it more "convenient" by rewriting as:

    /**
    * The name of this object.
    */
    public String name;
  130. mod that up funny!!! Re:ClassCastException by Anonymous Coward · · Score: 0

    ha!haha!
    seriously. That's the funniest comment I've seen on this. A VP who knows what a ClassCastException is! Haahahahha! That's RICH!!
    hahaha!

  131. No enumerators?? by Billly+Gates · · Score: 1
    No Enumerators??

    Dam. I can not imagine work without them.

    I suppose I could work without them but I disagree with the story that it would make difficult code to read.

    If I am writing a turtle graphics program for my cs101 class which is easier to read....

    write = penup;
    direction = verticalup;

    or

    write = 0;
    direction = 0;

    The first is obviously clearer. The second would confuse the person debugging it because he/she would have no idea what 0 represents.

    I am planning to learn java after c++ is done and I could not wait for the cleaner language. However I am shocked that enumerators were not in. Pointers are a dual edged sword and can be nasty stuff so I see why sun got rid of them.

    I use pointers where they are appropriate but I only use them when appropriate. They can be quite dangerous.

    1. Re:No enumerators?? by Jord · · Score: 1
      In your example you would normally use constants in Java. If I wrote that it would read:

      write = PENUP;
      direction = VERTICALUP;

      with the global static variables looking like:

      public static final int PENUP = 0;
      public static final int VERTICALUP = 0;

      Then instead of referring to 0 you can refer to the constants instead and makes for very readable code.

    2. Re:No enumerators?? by Billly+Gates · · Score: 1
      True but your way I would also have to type.....

      public static final int PENUP =0;
      public static final inst PENDOWN=1;
      public static final int VERTICALUP=0;
      public static final int HORIZONTALUP=1;
      public static final int VERTICALDOWN=2;
      public static final int HORIZONTALDOWN=3;
      public static final int VERTICALDOWN=4;

      If I write a calender app, enumerators are also usefull. I do not think anyone would want to write 12 constants to represent each month.

      Your way is clever in making code easier to read if you can not use enumerators.

    3. Re:No enumerators?? by Jord · · Score: 1
      The example of a Calendar does not work because there are constants for each day of the week and month in the year in the standard API.

      But I understand your point and apparently so does Sun :)

    4. Re:No enumerators?? by Anonymous Coward · · Score: 0

      I use pointers where they are appropriate but I only use them when appropriate. They can be quite dangerous

      Pointers are only dangerous if you don't know what you are doing.

    5. Re:No enumerators?? by Anonymous Coward · · Score: 0
      "Pointers are only dangerous if you don't know what you are doing"

      Which accounts for %90 of all programmers.

      Working by yourself and with groups is different. References and arrays can acomplish most of what pointers can do "safely".

    6. Re:No enumerators?? by J.+Random+Software · · Score: 1

      Liveness is a global property. Pointers are dangerous unless you know what everyone is doing--or might ever do.

      Now that generational copying collectors are often faster than malloc/free, dangling pointers are an entire class of errors that it's stupid to still tolerate.

  132. we can thank Microsoft for this by g4dget · · Score: 2, Interesting
    Sun is finally rolling this out because of competition from Microsoft and C#. Until C# looked real, Java had mostly stagnated.

    Unfortunately, this doesn't quite make Java competitive with C# yet. Major missing features are:

    • JVM support for generics. Lack of JVM support makes generics not type-safe across compilation units, and it also makes them less efficient. The result is that the current generics implementation for Java is a stop-gap measure that isn't a good long-term solution. C#/CLR doesn't have generics yet, but Microsoft is planning on CLR changes to support them.
    • Lack of value classes. Value classes are essential for scientific programming, and automatic optimization cannot infer them reliably.
    • Lack of operator overloading. Again, that's essential for scientific programming. Some people worry that they lead to unmaintainable code. Of course, andy feature can be abused, but that's really a problem with overloading, not operator overloading.

    Also, Sun's patents on core Java technologies and the lack of a well-defined, open Java standard are still serious problems. The fact that Swing is de-facto part of the Java standard but that Swing is as ill-defined as the Windows API is another problem because it makes it hard to create open source implementations of Java.

    1. Re:we can thank Microsoft for this by TheAwfulTruth · · Score: 1

      That and the fact that the Sun JVM is still the slowest, buggiest environment on the planet.

      I'm sitting here trying to use Object Domain and on a p4-2.4 gig machine it's like running a drawing program in 1997 on a p-200. The screen updates are one a second and it frequently fails to redraw itself at all.

      Contrast to a C# program I am running at the same time that is as instantaneous as you can imagine, like any other C or C++ windows program.

      Frankly I care a lot less about a program that BARELY functions on multiple platforms than I do about having the same program perform flawlessly on ONE platform.

      This is the exact same thing I have experienced with every sizable JAVA application I have ever used of the last several years. Why bother? Use a cross platform C or C++ tool kit. Hell TCL/TK programs linked to C or C++ backends behave much better! (Still ugly though)

      Even the smallest company (like where I work) can write 90% of their code cross platform in C/C++ and use a platform specific front end and OS io API for the last 10%. Result? Native looking apps that run at full speed without need for special environments or the pulling out of the users short hairs (once a second).

      --
      Contrary to popular belief, coding is not all free blow-jobs and beer. Those things cost MONEY!
    2. Re:we can thank Microsoft for this by Anonymous Coward · · Score: 0

      please back this up with real data. I've been running benchmarks on reflection and memory intensive applications the last several months and in all cases, jdk1.4 is 30-50% faster than .NET 1.0.

    3. Re:we can thank Microsoft for this by Anonymous Coward · · Score: 0
      The problem isn't with Sun's JIT or garbage collector--Sun has done a great job optimizing those. That's why they are doing really well in benchmarks and why Java is quite usable for server applications.

      The problem is with everything else: memory footprint, collection API, initial class loading, lack of support for value classes, inefficient and bloated UI library, array semantics, etc.

      As GNU gcj and SWT show, one can do a much better job than Sun has, but one can't do better and stay compatible with the entire Java2 platform. Some parts of the platform just need to be junked.

    4. Re:we can thank Microsoft for this by Billly+Gates · · Score: 1
      If you read the review you will see support for generics.

      Value classes are still not there and I agree with the notion that operator overloading is evil and wish it was never invented.

      Its only purpose is to produce very bad code and create debugging nightmares. You can cast values to different data types when necessary. It beats using overloaded operators depending on value type because it can be confusing to other people looking at your code through a debugger. This is not the early 80's anymore where ram is a premium. Operator overloading was added when c++ programes were measured in kb's.

    5. Re:we can thank Microsoft for this by g4dget · · Score: 1
      If you read the review you will see support for generics.

      You are saying that Sun is extending the JVM to support generics in 1.5? Ummm--where exactly does it say that?

      Value classes are still not there and I agree with the notion that operator overloading is evil and wish it was never invented. Its only purpose is to produce very bad code and create debugging nightmares. You can cast values to different data types when necessary. It beats using overloaded operators depending on value type because it can be confusing to other people looking at your code through a debugger. This is not the early 80's anymore where ram is a premium. Operator overloading was added when c++ programes were measured in kb's.

      The applications we write barely fit into several Gigabytes of memory and they involve complicated mathematical formulas.

      Basically, your attitude is typical, and it's ignorant: "I don't need it, so it must be useless". Fine, but as a result, Java is simply unsuitable for an increasing range of applications. And the fact that Java's C++ interface is so inefficient and cumbersome means that Java doesn't have an easy workaround either.

      C# looks like a pretty general purpose, modern programming language, but Java clearly is not because it is not a good language for scientific and numerical computing, and because it does not interface well with existing C/C++ code.

    6. Re:we can thank Microsoft for this by Anonymous Coward · · Score: 0

      "You are saying that Sun is extending the JVM to support generics in 1.5? Ummm--where exactly does it say that?"

      From the link...

      Q.)Do you want to give us a simple take-home message for each of the six areas of improvement?

      A.) I'll give it a whirl...

      * Generics - Provides compile-time type safety for collections and eliminates the drudgery of casting.

      * Enhanced for loop - Eliminates the drudgery and error-proneness of iterators.

      * Autoboxing/unboxing - Eliminates the drudgery of manual conversion between primitive types (such as int) and wrapper types (such as Integer).

      * Typesafe enums - Provides all the well-known benefits of the Typesafe Enum pattern (Effective Java, Item 21) without the verbosity and the error-proneness.

      * Static import - Lets you avoid qualifying static members with class names, without the shortcomings of the Constant Interface antipattern (Effective Java, Item 17).

      * Metadata - Lets you avoid writing boilerplate code, by enabling tools to generate it from annotations in the source code. This leads to a "declarative" programming style where the programmer says what should be done and tools emit the code to do it.

      " C# looks like a pretty general purpose, modern programming language, but Java clearly is not because it is not a good language for scientific and numerical computing, and because it does not interface well with existing C/C++ code"

      Scientific and numerical computing is not general purpose. Fortran, ADA, and Modula-2 are used for these specialized market. I would not want to use C# or Java for writing any of these applications. C++/C is ok for this use. In your market you need absolute controll over your app and java certainly does not allow this.

      Java is ok for general purpose computing. The vm is getting better but still sucks! Just load netbeans if you do not believe me. I like C#'s approach to compiling to CLR .net interface that can integrate more with the os and apps written in other languages. Also you can compile native .exe's with Java lacks for general programming.

      Java can not do integrate. I can not write a com+ application in it. Thats for sure.

      Sun is so scared of it turning into c++ that it can not have it compiled to native executables. I find this dumb since it was the lack of libraries is what killed it since a proprietary market for these came by. Microsoft also saw it as a way to force developers to use Windows.

      Proprietary libraries can easily be added to java as well. I guess sun was worried that third party libarary makers would only target Windows if java ever became natively executable.

      A .net like framework that would be natively compiled on each java client would be perfect and would speed it up.

    7. Re:we can thank Microsoft for this by g4dget · · Score: 1
      From the link...

      You didn't understand the question. Yes, Sun has added generics to the language and compiler. But without changes to the JVM, Java generics are not type-safe across compilation boundaries.

      Scientific and numerical computing is not general purpose.

      No, and server-side computing, desktop application development, graphics, or any other specific application isn't "general purpose computing" either. What makes a language "general purpose" is that it has acceptable support for all those application areas, even if it doesn't excel at any of them.

      In your market you need absolute controll over your app and java certainly does not allow this.

      It is folly to think of numerical computing as being a separate "market". Do you want E-mail filtering? Do you want text-based retrieval? Do you want to browse images? Do you want to mine databases for patterns? Do you want to analyze business data? Do you want to edit video? Do you want nicely laid out text? Do you want great looking outline fonts? Do you want good process scheduling? Do you want good intrusion detection? Do you want smart opponents in games? Good, modern implementations of all of those have strong numerical components, in addition to requiring good UIs and other facilities. Java makes it a lot of unnecessary work right now to do a decent job at implementing their numerical components.

  133. More overloading evil... by Gorimek · · Score: 2, Insightful
    The same goes for preprocessing. Consider things like '#define + -'...

    An other awful consequence of operator overloading is that code like this
    if (x != null && x.foo()) ...
    is unsafe, since the && may be overloaded.

    (The above may not be valid C++ syntax. I left C++ for Java many years ago and I'm never going back!)
    1. Re:More overloading evil... by Anonymous Coward · · Score: 0

      > The above may not be valid C++ syntax.

      Can anything be? After all, C++ is more or less a superset of C

    2. Re:More overloading evil... by jcast · · Score: 1

      An other awful consequence of operator overloading is that code like this

      if (x != null && x.foo()) ...

      is unsafe, since the && may be overloaded.

      Which is why Haskell and ML allow you to make operators like && non-strict (i.e., short-cutting). Of course, OO is basically designed on the premise of taking functional language features and using them without understanding, so it'll be a while before Java or C++ gets features like this.
      --
      There are reasons why democracy does not work nearly as well as capitalism.
      -- David D. Friedman
    3. Re:More overloading evil... by bmckeever · · Score: 1
      > (The above may not be valid C++ syntax. I left C++ for Java many years ago and I'm never going back!)

      Well, it's hard to judge the validity of the syntax without variable declarations, but I will try anyway:

      Since the point of your post is that && can be overloaded, and if it is, it loses its shortcut semantics, I assume that x is of type T*. So let's replace x.foo() with x->foo(), and voila! No problem. No operator overloads are called, and the && shortcuts the way it needs to.

      I think you were reaching for an example like:

      A a();B b();

      C c = a() && b();

      Assuming an appropriate user-define operator&&(), the problem here is that both a() and b() are evaluated, no matter what. But I wouldn't call it an "awful consequence". Did you ever see a problem that resulted from this particular operator overload semantics, or is this imagined FUD?

      --
      Your favorite .sig sucks
    4. Re:More overloading evil... by Gorimek · · Score: 2, Interesting

      My example in the general form is the fairly common "pattern"

      if (fooIsSafeToDo() && foo())...

      This is guaranteed to work in C and Java, and to 99.9% in C++. So as a C++ developer you're forced to either always write

      if (fooIsSafeToDo()) {
      if (foo())...


      or to keep writing code that will almost always work. That is, if you're even aware of the issue, which I'm sure most programmers are not.

      If I understand your point, this can't happen in the common case where 'fooIsSafeToDo' is a null check, which is good, but doesn't really change the principle. And no, I haven't seen this one bite anyone, but I've seen plenty of other really obscure C++ traps wreak havoc.

      Here's an other pet peeve, while I'm whining. Why is this unsafe C++ code?

      getResource(); // memory, file, whatever
      foo();
      releaseResource();


      because foo() may throw an exception, so this is a resource leak.

    5. Re:More overloading evil... by bmckeever · · Score: 1

      My example in the general form is the fairly common "pattern"

      if (fooIsSafeToDo() && foo())...


      Yes, but do you understand what has to happen for this to not work the way you'd expect? One or the other of these has to return an object of class type that participates in an overloaded operator && with the other return type! Sure it's possible, but I think you're concerned about things that never happen. In addition, someone whom you trust to some extent (because you're using their code) intentionally overloaded this operator. I'm not saying that there aren't pitfalls in C++, but this doesn't keep me up at night.

      Here's an other pet peeve, while I'm whining. Why is this unsafe C++ code?

      getResource(); // memory, file, whatever
      foo();
      releaseResource();

      because foo() may throw an exception, so this is a resource leak.

      Yes, but this isn't any better in Java, so what's your point? There are well known ways of handling this situation (C++: variables with automatic scope, google for RAII; Java: finally). I call it a wash (maybe advantage C++ since RAII is more flexible than finally). And the answer to this is not GC and finalize: if you are relying on GC to free non-memory resources, then you have a bug waiting to manifest itself. Java GC is a one-trick pony - it knows how to destroy Objects to free memory for other Objects. If the lifetimes of your Objects control other resources (file descriptors, threads, sockets, etc), you have to rely on GC running even when there is not memory pressure.

      --
      Your favorite .sig sucks
    6. Re:More overloading evil... by Anonymous Coward · · Score: 0
      class A
      {
      public:
      A() {getResource();}
      ~A() {releaseResource();}
      };

      int f()
      {
      A a;
      g();
      }
      If g throws, the a's deconstructor is called. a's deconstructor is also called when g is finished executing.
    7. Re:More overloading evil... by greenrd · · Score: 1
      Which is why Haskell and ML allow you to make operators like && non-strict (i.e., short-cutting).

      I'm confused. && is shortcutting in Java, C++ and (by implication) C. The alleged problem here is that someone could redefine && to give it unexpected semantics.

      it'll be a while before Java or C++ gets features like this.

      What are you talking about? C++ already has non-strict && and operator overloading. Java only has the former, which some consider saner.

    8. Re:More overloading evil... by J.+Random+Software · · Score: 1

      Any overload of operator && is strict (though the builtin is not), because they didn't provide any way for a user-defined function to request evaluation of a non-strict argument. You can emulate this yourself with expression-tree classes but it's a lot of work.

    9. Re:More overloading evil... by greenrd · · Score: 1
      Ah yes, I see the point. The problems caused by neglecting to include a lazy keyword in the language... ;)

    10. Re:More overloading evil... by angel'o'sphere · · Score: 1

      LOL, smart C++ expert.

      x != null returns an int, or in newer c++ compilers a boolean.

      Please overload me the appropriated && operation.

      If you know what foo is, you know if && is overloaded. Because it can only be overlaoded when foo returns neither an int nor an boolean.
      In both cases you very likely want to have the overloaded && operator.

      angel'o'sphere

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  134. Short Cuts Make Long Debugs??? by jefu · · Score: 1
    For the most part I tend to like shortcuts in code - it reduces code size and complexity and usually increases readability.

    But it is true that its possible to build syntactic shortcuts that do unexpected things. I think that operator overloading has the potential to do this in C++ - not so much because of the kind of example given as because of some of C++'s added, um, features.

    In particular reference parameters tend to give me problems (but I should say up front that I'm nowhere near smart enough to use C++). The fact that "x=y+z" might do odd conversions (such as given in the parent article) is annoying enough, but the fact that because of operator overloading and reference parameters all of x, y, z might get changed and in odd ways, just makes me cringe.

    Of course, there are good reasons why someone might want to do that - or at least there is a someone out there who will think that the reasons are good. But its all too much for me.

    I haven't looked carefully into the boxing/unboxing mechanisms described so I don't know if they might be abused in similar ways. (Crossing fingers for luck.)

  135. Iterators by jefu · · Score: 1
    Iterators as described are still a bit on the feeble side for my taste.

    Sather iterators had it right - incredibly powerful and able to leap tall buildings in a single bounds-check.

    I'll bet that use of Sather iterators reduced my code size by half.

    Someday someone will reinvent them, graft them poorly on to some other language and people will find out what they've been missing. Sigh.

    But then Sather also had a great program-by-contract feature, very very nice support for generics and FABU!(tm) support for operator overloading in a way that I could understand.

  136. Aaah... by Anonymous Coward · · Score: 0

    You're a perl programmer, aren't you?

  137. Re: Generics are much more than typed containers by Frizzle+Fry · · Score: 1
    map :: (a -> a) -> [a] -> [a]
    map f [] = []
    map f x::l = f(x)::l

    Are you sure you don't want to recursively map f onto the tail of your list?
    --
    I'd rather be lucky than good.
  138. if( xxx ) versus if( xxx ) by Baki · · Score: 3, Insightful

    I always get the creeps when I see if( xxx ).
    It is as if "if" is a function putting the parentheses like that.

    foo( xxx ) is a function call
    if ( xxx ) is a statement which gets a block in parentheses.

    I couldn't resist. I have to fight this good fight every day against some of my colleages.

    1. Re:if( xxx ) versus if( xxx ) by RedWizzard · · Score: 1

      Personally I prefer no space after the "if". My reasoning is the having the space makes it look as though the parentheses should be optional, but of course they're not.

    2. Re:if( xxx ) versus if( xxx ) by Fubari · · Score: 1

      "the good fight" ?
      You actually expend energy about where to put a space character. Why?
      1) in Java, "if" is a reserved word so you'll never confuse it with a method (and neither will the compiler).
      2) your colleagues May be writing lots of short methods like so:
      ia();
      ib();
      ic();
      id();
      ie();

      In this situation, while I can see that if() would be confusing, there are Other Things you should be trying to ''educate'' your colleagues about.

    3. Re:if( xxx ) versus if( xxx ) by DunbarTheInept · · Score: 1

      That's only if you view "put parentheses next to name" as an indicator of "this is a function". I don't. You only see it that way because that's the convention you are used to seeing. The convention I'm used to seeing is "put parentheses next to name" means "these parentheses are a required part of the syntax for this thing - hence they are directly attached to it." I think that makes more sense.
      so, for example, if you choose to put parenthesis around the expression of a return statement, they don't go next to the return. They are not part of the syntax of return. They are part of the syntax of the expression, in that case:

      return (foo);

      means: return thingy; where in this case thingy is "(foo)".

      Whereas:

      while( foo )
      means: while( thingy ), where thingy is "foo".

      To me, this:
      while ( foo )
      would read as: while thingy, where thingy is "( foo )", which is of course not really what's happening.

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

    4. Re:if( xxx ) versus if( xxx ) by Anonymous Coward · · Score: 0

      I feel it's important to distinguish functions from special syntax (especially for environments that don't highlight keywords) and I'm accustomed to whitespace keeping me from briefly misinterpreting the parens as an argument list. I'm also big fan of Perl's "X if Y" variant.

  139. Another Broken JDK? by the-dude-man · · Score: 1

    I hope this isnt yet another broken jdk....jdk 1.3.1 wasnt the best thing in the world..it was pretty slow..the implementations sucked....but there was no Real broken stuff in it.

    JDK 1.4.x is very broken...for example...if you make more than 10,000 rand calls...you will actually push the main thread out of sync with the garbage collection thread...and alot of your variables will dissapear. I've actually had this problem...and the problem of the VM just outright seg-ving on me all the time.

    Also, list iterators are broken with the checkConcurencey method of iterator, parts of the JDK 1.4.x wont even compile...even with all the .so files in their proper places....and literllay hundreds of other errors i have stubmeled across.

    This has lead me to have to completley re-implement anything from the jdk on my own in production code. Its just to unstable for me to use it in anything that goes into production. Not to mention its as slow as dog shit...and if you eve read the implementation of the jdk....your left going What the fuck? the implementations are very poor in desgin and code...its no wonder they fail.

    Hopefully they will fix this in jdk 1.5..at least bring themselves back to were they were with jdk 1.3...i have to say after working with jdk 1.4.1 and several of the betas.....you really start to understand were the concept of Euogenitcs comes from.

    All of this has lead be to use the Blackdown JVM..and JDK...they actually work...still quite slow...but double the speed of sun's VM...and the JDK dosnt break. Howeever, since there is no windows version of Blackdown VM, it really can mainstream...so were left with Sun's pice of shit. Hopefully, with JDK 1.5, I can at least use a JDK that will at least work.

  140. try { ... } finally { ... } by Admiral+Burrito · · Score: 1
    Why not just put the bs.close(); right after the // Do some stuff and lose the finally block altogether?

    Because if an exception is thrown, you still want the file to be closed.

    If you don't find finally useful, you are probably not a defensive coder. Cleanup code (such as calling close()) belongs in a finally block. That way it is sure to be executed, no matter what happens in the try block (barring horrible death of the JVM, power failure, etc). Even if the try block throws an OutOfMemoryError or some other thing you would have no reason to catch, the cleanup code will be called.

    If you don't explicitly call close(), the file will still be closed when the garbage collector invokes the destructor, but who knows when that will happen. On some systems with broken filesystem concepts (eg. win32) having an open file will prevent other cleanup operations like delete from working.

    Finally is also useful if you simply want to return (or throw) within the try block. Instead of having to duplicate your cleanup code at every point where you return, or do contortions with a "retval" variable and force program flow to pass to the cleanup code before returning, just place the cleanup code in the finally block and place your return statements wherever they naturally belong in the try block. The finally block is guaranteed be invoked as execution leaves the try block, no matter how you leave the try block.

    1. Re:try { ... } finally { ... } by Westley · · Score: 1

      Absolutely. And it's not just with files, either. Network connections, importantly *database* connections, anything that's likely to have an open resource. Then there's the kind of resource which holds a lock while you've got it open - fail to close one of those, and you'll end up in deadlock.

      The effect of try/finally is a wonderful thing - and the C# "using" statement makes it delightfully simple for the most common cases.

  141. Sather by RedWizzard · · Score: 1

    Sather's a great language, once you get use to all the SHOUTING. Pity it never caught on. I was hoping Java would pick up the implied get/set methods (i.e. x = 5 calls x.set(5)) as C# did, but I guess it's too late now.

  142. sir, i think you are looking for by dollargonzo · · Score: 1

    alloca(). it allocates on the stack. in fact it is exactly what int a[1000] compiles to. it is equivalent to doing: int * a = alloca( 1000 * sizeof(int));

    --
    BSD is for people who love UNIX. Linux is for those who hate Microsoft.
    1. Re:sir, i think you are looking for by J.+Random+Software · · Score: 1

      "In C" doesn't mean alloca() will exist, even if it happens to be in your implementation. And a compiler could produce better code for a known set of objects (at fixed offsets in a traditional stack frame) than for accessing one of an unknown number of randomly-sized allocations.

  143. The top thing that should be fixed by 21mhz · · Score: 1

    Strings and chars. Let's admit it, 16-bit character was a trap. This path abandoned compactness of ASCII strings while stopping short of real "universal characters".

    I say, make character values 32-bit wide, but store String internals in UTF-8. This will make charAt less efficient method than it is now, but everyone using charAt to access complete charaters now produces broken code from the i18n standpoint.

    --
    My exception safety is -fno-exceptions.
  144. Danger of generics by Trinition · · Score: 1

    One of the things that worries me about generics is how they could be abused, or at least lead one to think things are good enough. Consider a HashMap. Because of boxing, it's really a HashMap. If you've ever looked at HashMap's code, you know it calls .hashCode() on the key objects (Integers in this case), as well as .equals(). However, if you just broke down and wrote an IntHashMap, you could iuse the int value itself as the hashcode, and use == instead of .equals(). Of course, this would no longer adhere perfectly to the Map interface which of old, but with generics, that's supposed to be a thing of the past.

    Don't get me wrong, there are also benefits to generics. A lot of people forget that casting in Java is not a compile-time operation alone. It is performed at runtime and actual instructions are executed to verify the types can be casted. By using generics in collections, for example, you eliminate the need to do runtime casting, and thus eliminate the associated overhead.

  145. Redefining the language is essential. by rjh · · Score: 2, Insightful

    Any language which cannot be redefined is, much like any programmer who says languages must not be redefined, fundamentally wrong. If you can't rewrite your language on the fly, then what good is it? :)

    Signed,

    A Very Happy LISP Programmer.
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    No, really. Redefining the language is one of those things which sounds like a bad idea, up until the time you learn functional languages. Once you grok functional languages, redefining the language becomes second nature to you: for any given serious programming task, you modify the language into a special-purpose language meant specifically for solving your problem. For instance, I wrote a crypto library in LISP recently, and I needed to do a lot of addition modulo 2**32. In any other language, I'd have to write a function to do the additions... in LISP, I just wrote a macro.

    Redefining the language is an astonishingly powerful technique, and once you grok it, the idea of a language forbidding you the ability to redefine itself seems like an Apocalyptically Bad Idea.

    1. Re:Redefining the language is essential. by Shamashmuddamiq · · Score: 1
      I too have done my share of LISP programming (I was doing AI for a year in grad school), and I understand how macros can be useful. However, I see them used unwisely more often than not. As an embedded programmer porting code everyday between every combination of 4 architectures and 3 operating systems, I tend to make use of good macros probably more than most other programmers. But when I see stupid stuff like the ones I mentioned above, it's like speaking in english and replacing every instance of "the" with "DEFINITE ARTICLE". It makes things ambiguous and hard to understand, and there's generally no reason to do it.

      In any other language, I'd have to write a function to do the additions...

      Really? You can't do stuff like that in C or C++? I'd beg to differ. Better yet, you can use an inline function and get the best of both worlds.

      I don't think anyone has trouble "grokking" the idea of language redefinitions. I think you might be confusing programming languages with what many programmers generally refer to as APIs. I know, there's a thin gray line, but making FOREVER a macro to replace for(;;) is not the same thing as defining a macro to do addition modulo m.

      --
      ...just my 2 gil.
    2. Re:Redefining the language is essential. by rjh · · Score: 1

      Really? You can't do stuff like that in C or C++? I'd beg to differ.

      Let me rephrase: in virtually any other language, I would need to write a function to do the additions. People who write functions in C-style macros are Evil. Re: inlining, that's only possible with C++; C89 doesn't support inlining.

      And even then, there's no guarantee that the macros would make the code more comprehensible. For instance, try the following macro on for size:

      PLUS_MOD32(a, PLUS_MOD32(b, PLUS_MOD32(c, PLUS_MOD32(d)))); [*]

      C-style macros don't accept varargs, so if you want to do multiple modulo additions you've got to resort to that baroque syntax. In LISP, you just do something like the following:

      (+mod32 a b c d)

      ... and +mod32 follows the same rules of associativity, grouping, etc., which the conventional LISP #'+ does. This is a Very Big Win: it permits you an astonishing amount of linguistic flexibility which can be applied towards making your code easy to understand.

      Programs are, first and foremost, written for human beings. That they are compilable is just a fortunate happenstance. C-style macros are not Evil because they are inefficient; they are Evil because they sacrifice the first task of a program (to communicate its idea to whatever poor schmuck is stuck maintaining your code in six months) on the altar of the second, less important, task (efficiency), and completely disregard everything else (i.e., safety).
      .
      .
      .
      .
      .
      [*] Or, on IA32 platforms, you could just do a + b + c + d, since the C operator is really a modulo-addition operator. But grant me my example for sake of pedagogy.

  146. Re:Retro... (rebuttal) Please Mod Up by RoboProg · · Score: 1

    always see something when I DON'T have moderator points. Blah!

    --
    Yow! I'm supposed to have a plan?
  147. Java already has conditional selection, mostly by Anonymous Coward · · Score: 0

    Java already has this capability. Java just does it in a different phase than C and C++ do. Java does it at the semantic analysis phase of compilation, whereas the C preprocessor does it before compilation even starts. In other words, in C and C++, you muck around with the source before it's compiled, but in Java, everything is parsed and then before code is generated, the compiler checks for certain sections of code that can never be reached and removes them.

    To be more concrete, if you write this:

    static final boolean USEFLOATINGPOINT = true;

    if (USEFLOATINGPOINT)
    {
    return (x / 2.5 > 91.7 ? a : b);
    }
    else
    {
    return (x * 5 / 2 > 91 ? a : b);
    }

    then a Java compiler should actually only emit code for the "then" part of the "if" statement. Actually, I think it's optional to do this optimization, but since Java compilers already must do pretty extensive analysis to see whether sections of code are reachable, I'd guess that most compilers do it.

    By the way, I don't normally format my code with blank lines inside the "then" and "else" blocks like that, but the only way I know to get the blocks to be indented given Slashdot's limited HTML subset is to use <blockquote>...

    1. Re:Java already has conditional selection, mostly by EthSoma · · Score: 1

      There's a caveat to doing this though: if the constant is defined in another class/interface the class that uses it must extend/implement it to be compiled conditionally. The new static import feature of Java 1.5 ought to fix this :)

      --
      It is truely written: a man has five times as many fingers as ears, but only twice as many ears as noses.
  148. C# steals these ideas from Java by SuperKendall · · Score: 2, Informative

    All of these proposials have been around forever, I was attending talks on pretty much the same Generics syntax at JavaOne two or three years ago... and I've been using the same kind of enum classes since Java 1.1.

    C# didn't add generics at the start as they were waiting for Java to solidify how to do them.

    Also, Java has a bit more of a wait for new features since Java goes through a real standards body instead of just being defined by what Microsoft wants. And of course lots of real production code that can break if you get things wrong.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  149. Collections are availiable in non-thread safe form by SuperKendall · · Score: 1

    You can use HashMap, or if you want a synchronized version wrap an instance with a Collections.synchronizedMap() call. Currently, I find collections to be about the most well-thought out part of Java and really nice to use - even better after Generics are added (which I've been waiting years for).

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  150. I pity the software engineer... by gafter · · Score: 2, Funny

    who has to implement the new javac.

    Uh, ... wait, that would be me.

  151. Book chapter is available online by j7953 · · Score: 1
    I don't use ints for my enumerations anymore after reading Josh Bloch's Effective Java. The type-safe enum pattern he recommends is fantastic.

    I second that. For those interested, the pattern is described in chapter 5 of the book, "Replacing C Constructs," which is available as a free sample chapter.

    The book is great, I highly recommend that you read it (the whole book, not just the sample chapters).

    --
    Sig (appended to the end of comments I post, 54 chars)
  152. Unboxing by takotech · · Score: 1

    Not sure I agree. As I read it, unboxing concerns itself with primitives and their Java wrappers(int, char, boolean, etc.). In that context, it seems apropriate to transform null wrappers to the primitive defaults.

  153. Re:Shorthand programming something even worse by Anonymous Coward · · Score: 0

    How about this bit of brain damage, culled from actual source code:

    #define const

    I.e., Me too dumb/lazy engineer to call or cast properly.

  154. You non-functional invertebrates! by Anonymous Coward · · Score: 0

    map { cancel; } @timerTask;

  155. SWT: Cross-platform Java GUIs by rlowe69 · · Score: 1

    but I really do use Java's platform independence all the time, and for non-GUI applications I think it works beautifully. The key here is the 'non-GUI' ...

    For cross-platform GUI applications, try IBM's SWT and JFace. Eclipse uses SWT for its GUI and it works well for me on Windows XP, Mac OS X and Red Hat Linux 8.

    --
    ----- rL
  156. I agree by Anonymous Coward · · Score: 0

    Sort out the IO library (and that bloody calendar), and why can't we have a compiler switch to compile into native code :~^( Would that be so bad? Just one little switch?

  157. Re:Error checking with IFs. UGH by Zenki · · Score: 1

    Actually, what you can do is:

    HRESULT Result = SUCCESS;

    if (SUCCEEDED(Result))
    {
    Result = DoPart1();
    }

    if (SUCCEEDED(Result))
    {
    Result = DoPart2();
    } ...
    return Result;

    You're trading horizontal space for vertical space though. But then again, it's easier for me to keep my eyes fixed and to scroll the page up/down with the mouse than to scan left and right wildly.

  158. Hm. Some better examples: by jtheory · · Score: 1

    Make sure you understand the diff between i++ and ++i, though -- they don't behave quite the same.

    i++ and ++i both increment i, but they evaluate differently.
    int i = 1;
    int x = i++;

    Here i is 2, and x is 1; putting the ++ after the i means "increment i after evaluating".

    int i = 1;
    int x = ++i;

    Here i is 2, and x is also 2; "increment i before evaluating".

    For the next one, I want to point out that you are NOT helping anything by using 5==x instead of x==5.

    If you screw up and type
    if( x = 5 )
    you WILL get a compiler error because Java is stricter than C/C++ and only accepts booleans for a boolean test (not "any non-zero integer", etc. etc.).

    But I have a related case where putting the things you're comparing "backwards" makes code simpler, if you can handle the confusing ordering.

    String CONSTANT = "hello";
    String s = null;

    if( s.equals(CONSTANT) ) return 1;

    This will throw a NullPointerException because you're calling a method on s.
    If you used
    if( CONSTANT.equals(s) ) return 1; ...it wouldn't. And since what you really want to know is whether s equals the constant or not, this is simpler... but I'm torn about the readability thing. I usu tend to either comment stuff like this to make sure the reader understands the trick, or I just suck it up and write
    if (s != null && s.equals(CONSTANT) ) return 1;

    It's like that ternary thing
    String s = (boolValue) ? value1 : value2; ...it's convenient, but I can't use it because it sucks to read, and it's kind of obscure so plenty of programmers won't understand it.

    --
    There are only 10 types of people: those who understand decimal, those who don't, and, uh, 8 other types I forget.
  159. Mod -1; wrong by jtheory · · Score: 1

    This is irrelevant. You'll get the compiler error either way.

    (x = 5) doesn't evaluate to a boolean value any more than (5 = x) does. The compiler will choke on it because it needs a boolean for the "if" test.

    You people are thinking of C/C++.... Very understandable error, but a good illustration of one of the small improvement Java made -- you're trying to fix a problem that isn't there.

    --
    There are only 10 types of people: those who understand decimal, those who don't, and, uh, 8 other types I forget.
    1. Re:Mod -1; wrong by DunbarTheInept · · Score: 1

      You're assuming we see it as a problem.
      I *like* the fact that booleans aren't artificially crippled version of an int in C and are instead just ints like they *really* are underneath. What I don't like is that the library of system routines aren't consistent with the meaning of booleans. (Most functions on man page 2 return zero for success, while most functions in stdlib return zero for failure, rendering this neat feature rather useless in practice because you always have to remember which way around the function you are using does it, and it might be the opposite of the handy boolean interpetation.)

      --

      Don't label something "offtopic" unless you know the topic well enough to tell what's on topic.

  160. JDK 1.0.2 code STILL SUPPORTED by jtheory · · Score: 1

    Yeah, troll, but I'll bite, because I have a nifty example of how careful Sun has been NOT to break backwards-compatibility.

    It boggles the mind, but some fairly complex applets I wrote in 1996, using JDK 1.0.2 and the pre-1.1 event model still compile and run just fine in JSDK 1.4.

    I'm assuming this will be the same in 1.5, but it's madness, I tell you. Madness!

    The Java 1.0 event model was trickle-down -- no listeners. You had to subclass components and override methods to get events. It was horrible... but it's still fully supported (though not recommended, I'm sure).

    Yes, when I ran the compilation, I got deprecation warnings out the wazoo... but it worked!

    --
    There are only 10 types of people: those who understand decimal, those who don't, and, uh, 8 other types I forget.
  161. Agreed, with caveat by jtheory · · Score: 1

    I fully agree with your main point, but I want to comment on this:

    it pisses me off when management tells me I need to use only certains idioms in case someone comes over my code and don't understand it. I hate to have to program like the next maintainer will be clueless and ignorant.

    One of the dangers of throwing in more (and more) special language features to reduce extra code is that some of them aren't going to be nearly as powerful as others. Honestly, there are (alas) programmers out there who use obscure language features simply "because it's there", to remind themselves of their cleverness. Check it out! I saved one line of code and possibly one millisecond out of a 900 millisecond operation (what do you mean, I can't go lead the new project in the Bahamas because I'm "needed here"!?).

    These latest updates seem to be mostly addressing very real needs of developers, and will give us enough value to make it worth increasing the complexity of the syntax... but these updates bear *very* close watching. We should avoid adding features that will only be used very rarely... because they will affect maintainability when they are used.

    It would be interesting to build a tool that would analyse my Java code and pop out a list of "rules" that any reader of my code would need to know to understand what I'm doing -- e.g.:
    * the defaults of uninitialized instance variables
    * evaluation of i++ vs. ++i
    * path of execution of break when loops are unlabelled
    * path of execution with return inside try/finally
    * path of execution when throwing exception within catch block, with finally clause
    * differences b/w && and & as boolean "and" (not bit-shifting).

    There are lots of niggling little rules that no one knows when they first start, and while they should learn them, if I can easily avoid depending on them, I should. As more language constructs are added into the language, we're increasing the entrance barrier. Maybe with a sufficient benefit, but we should be aware of the cost.

    --
    There are only 10 types of people: those who understand decimal, those who don't, and, uh, 8 other types I forget.
  162. J++ is dead. Long live J++. by hwaite · · Score: 1

    Seems like a troll but J++ is a pretty good editor. After a few registry tweaks, the IDE runs JRE1.4 and has no proprietary junk. Wouldn't recommend starting out anew with this app but if you've already invested any time in learning Visual Studio it can be convenient to work in a familiar environment.

  163. Oh yeah? by iamacat · · Score: 1

    switch (numBeerBottles) {
    case 0:
    goto safeway;
    case 1:
    this.drink(1);
    default:
    this.drink(1)+buddy.drink(1);
    }

    Please kindly present your proper OO design.

  164. You can only use Generics in 1.5 VMs by Anonymous Coward · · Score: 1, Informative

    If you use Generics, your code will only run in 1.5 VMs. This was a marketing decision. Prototype versions of the Java compiler could previously use Generics and produce code for older virtual machines like the 1.1 VM.

    Sun made this decision by itself without listening to its users and even censored its discussion. You can read about in the Generics message board:

    http://forum.java.sun.com/thread.jsp?forum=316&thr ead=389987&tstart=0&trange=15

    http://forum.java.sun.com/thread.jsp?forum=316&thr ead=321534&tstart=30&trange=15

  165. Apple has it by Anonymous Coward · · Score: 0

    Search for "Less memory, faster start"

    http://www.apple.com/java/

  166. Wrong! by gidds · · Score: 1
    ANSI C doesn't define NULL to be zero.
    ANSI C does define NULL to be exactly zero. K&R 2nd ed, section 5.4, p.102:
    Pointers and integers are not interchangeable. Zero is the sole exception: the constant zero may be assigned to a pointer, and a pointer may be compared with the constant zero. The symbolic constant NULL is often used in place of zero, as a mnemonic to indicate more clearly that this is a special value for a pointer. NULL is defined in <stdio.h>.
    Just above, it says that:
    C guarantees that zero is never a valid address for data

    As far as the C language is concerned, the null pointer is always zero; zero is a special value which tells the compiler that you mean a null pointer. The compiler may map that to any bit pattern it likes to match the underlying machine architecture, but that's completely transparent to the programmer.

    That's why NULL is defined to be plain 0. Always. Not even (void *) 0, as many think, though that wouldn't do any harm. Plain zero is all that's needed. You could use plain zeroes all through your code, and it'd still be completely portable, though less readable. In fact, we all rely on it being zero every time we test for a null pointer with the ! operator!

    --

    Ceterum censeo subscriptionem esse delendam.

    1. Re:Wrong! by J.+Random+Software · · Score: 1
      I thought that's one of the differences between C and C++. A C compiler can get away with
      #define NULL ((void *) 0)
      but a C++ compiler cannot, because the implicit conversion from (void *) to any other pointer type has been removed.

      And it's important to note that only a zero value that's a compile-time constant has this meaning. Casting a zero-valued int to a pointer at runtime summons nasal demons (though many recent platforms have a clean enough architecture that a word-sized zero really is a null pointer).

  167. Barf by DrivesMyApe · · Score: 1

    What's wrong with bad coding blowing up at runtime? Java's dichotomy between objects and primitive types is a defining characteristic, there's no need to cover its nakedness. From my C++ experience, genericity equals CRAPPY PERFORMANCE in time and space. Any thoughts about that? Enums are cool, but given the cosmetic nature of the other changes (Avon calling), I am skeptical. I read "Effective Java" and it contains one of my pet peeves. To paraphrase: "Don't waste your time trying to write better versions of library methods. The library programmers are way ahead of you and more competent in the first place. Just wait until they fix the current version." Fallacious and insulting. Perfection is not when nothing more can be added, but when nothing more can be taken away.

    1. Re:Barf by J.+Random+Software · · Score: 1
      What's wrong with bad coding blowing up at runtime?

      If you can easily prove that it can't, is there any reason to run the risk?

      From my C++ experience, genericity equals crappy performance in time and space.

      Time? How can a compiler produce worse code given more information about the arguments? Space is the usual tradeoff. If you want inline wrappers that just cast and use one real implementation, you can do that too.

  168. Operator overloading and scientific programming by jbanana · · Score: 1

    I always thought that operator overloading was evil, but I may be wrong. I'm not at familiar with scientific programming, so could you say why operator overloading is essential?

  169. Re:Error checking with IFs. UGH by deanj · · Score: 1

    What you really want to do here is check the negated values of things, and act on those. Instead of code crawling across the page to the right, you can handle the != parts right there on the spot, and exit the routine...then you can do the next "if".

    Doesn't always work, but when it doesn't it's probably time to do multiple function/method calls anyway.

    Plus, it makes the code one helluva lot more readable.

  170. TCL/TK/C vs Java portable app by Latent+Heat · · Score: 1
    For an example of the TCK/TK/C approach to a portable app look at WaveSurfer as an example of a scientific/graphics program that computes digital sound spectrograms. For the Java approach, look at Raven (I don't have anything to do with either of these programs -- I picked them as examples of portable software using the approaches mentioned by the parent software that are very heavily 2-D graphics oriented).

    While WaveSurfer doesn't have the snap of a native Windows app doing the same thing, it is OK, but I found Raven (Java/Swing) to be a bit clunky.

  171. Re:Error checking with IFs. UGH by Anonymous Coward · · Score: 0

    I'd much rather see the useful code all together than intermingled with the boilerplate error-handling code (which I don't care about if I want to understand the intended semantics). When I can't use exceptions, I prefer a macro that checks for errors and jumps to the error handling block buried at the end of the function. If you give it a nice subtle (short and lower case) name like must() you pretty much stop noticing it's there.