Slashdot Mirror


Java Urban Performance Legends

An anonymous reader writes "Programmers agonize over whether to allocate on the stack or on the heap. Some people think garbage collection will never be as efficient as direct memory management, and others feel it is easier to clean up a mess in one big batch than to pick up individual pieces of dust throughout the day. This article pokes some holes in the oft-repeated performance myth of slow allocation in JVMs."

846 comments

  1. Re:Duh Stack wins whats to agonize over? by nighty5 · · Score: 1

    And yes I haven't read the article because its slashdotted

    Web site seems fine to me.....

  2. Slashdot IBM? by totallygeek · · Score: 1
    And yes I haven't read the article because its slashdotted
    Web site seems fine to me.....


    Yeah, I do not think that IBM's websites could get Slashdotted. Article looked fine to me too, and loaded in a second or two.

  3. Nonsense by hedge_death_shootout · · Score: 5, Funny

    These java urban performance legends are rubbish - java is highly performant in a rural or urban setting.

    1. Re:Nonsense by justsomebody · · Score: 2, Funny

      And it is no urban legend needed to tell me that Coffe wakes me up much faster than C++.

      --
      Signature Pro version 1.13.2-3 release 83.5 beta3try7 after-breakfast edition
    2. Re:Nonsense by object88 · · Score: 1

      I'm glad to know that I'm not the only one who read the article headline like that.

    3. Re:Nonsense by MHobbit · · Score: 1

      This has been proven especially with the "Starbucks" factor.

      --
      Debugging? Klingons do not debug. Bugs are good for building character in the user.
  4. Not too bad by zegebbers · · Score: 0

    but the main thing that frustrates me is the difficulty in storing primitives in sets or as keys for maps. I realise that there are libraries available such as pcj, but it's still annoying :)

    1. Re:Not too bad by GuyWithLag · · Score: 1

      Automatic boxing and unboxing exists in Java 1.5

    2. Re:Not too bad by LDoggg_ · · Score: 1

      This was fixed as of Java 1.5

      Look for autoboxing / unboxing :
      article

      --

      "If they have both, tell them we use Linux. And if they have that, tell them the computers are down." -Dave Chapelle
    3. Re:Not too bad by Swamii · · Score: 2

      No, it's not really fixed. It's just syntax candy that lets the developer see strongly typed primitives, even though in the underlying JVM, you'll notice that it's still just a list of boxed Objects, thus losing performance and memory benefits with the inducing of boxing and unboxing of each element in the list. Contrast this with the .NET or Mono runtimes, where the runtime actually creates code for storing primitive types, thus gaining a performance and memory benefit.

      --
      Tech, life, family, faith: Give me a visit
    4. Re:Not too bad by LDoggg_ · · Score: 1

      Interseting.
      Do the .net & mono implementations do this for all collection type objects?

      Seems strange that you could add a primitive to a vector without some kind of wrapper. I could see that if you were only doing that for a single type of primitive, but what happens when you add a complex object to the list that only had primitives? Does the structure stay effecient?

      The java version may indeed just be syntactical sugar, but I haven't seen any benchmarks from a reliable source that compares it to .net or mono.

      --

      "If they have both, tell them we use Linux. And if they have that, tell them the computers are down." -Dave Chapelle
    5. Re:Not too bad by Swamii · · Score: 1

      That's one big difference between Java and .NET/Mono. Java has no concept of primitive value types; everything's a wrapper that gets allocated on the heap (and thus, requires an eventual garbage collection).

      In .NET/Mono, we have value types called structs that are allocated on the stack and do not require heap allocation or garbage collection. These lightweight types are quite nice performance wise. Games and other high performance software rely heavily on structs to alleviate garbage collections and keep the heap tidy.

      what happens when you add a complex object to the list that only had primitives?

      To do this, you would need a non-strongly typed list that can store any type. For .NET/Mono developers, this is the System.Collections.ArrayList. When you put a primitive in an ArrayList, it is boxed into a reference type just as it is in the Java implementation. But with generics, ArrayList is almost useless; we now use System.Collections.Generic.List<int> to store a list of 32-bit integers, strongly typed and efficient. It's really a rare case when you need to add value types (structs) and reference types (classes) together in the same collection. In fact, in my company's 500,000+ lines of code C# application, I can say for a fact that we do not use any such collections; everything's strongly typed.

      In any case, I suggest you have a look at this article, which details exactly how Java and C# generics work, what their differences are, and how they differ from C++ templates.

      --
      Tech, life, family, faith: Give me a visit
  5. Robomaid by Doc+Ruby · · Score: 5, Interesting

    How much time have I spent with Electric Fence and valgrind finding memory leaks in my C programs? In Java, the auto garbage collection is as good as Perl's, without that tricky "unreadable code" problem ;). And I can always tune garbage collection performance by forcing a garbage collect when I know my app's got the time, like outside of a loop or before creating more objects in storage.

    --

    --
    make install -not war

    1. Re:Robomaid by Some+Random+Username · · Score: 3, Insightful

      If you spend alot of time using stuff like valgrind and searching for memory leaks, then you are doing something very wrong. Its really not hard to just free the memory you allocate. The fact that people can write entire operating systems in C without having these problems indicates that the problems are with people, not C.

    2. Re:Robomaid by Doc+Ruby · · Score: 5, Insightful

      Of course, that's why I program everything in machine language. Memory allocation in hex opcodes worked for me in 1981, it still works in 2005. Programming languages don't leak memory, programmers leak memory.

      In seriousness, look at the bugzillas and changelogs of any programming project. Memory leaks abound. So the reality is that memory de/allocation programming eats quite a lot of productivity, and impedes many otherwise ready releases. Of course we can de/allocate memory properly in C. And we can compute with scientific calculators. When we've got something better, we use it.

      --

      --
      make install -not war

    3. Re:Robomaid by Anonymous Coward · · Score: 1, Informative

      You've clearly never worked a medium to large project in c (c++ is easier because you can make much more use of the stack). You forget sometimes, sometimes you don't know (other people's libraries) and most of the time you mess it up while debugging logic issues and totally forget to fix it cause your happy the logic part is working.

      That said. I usually spend about 2% of my time, tops, looking for memory leaks. I spend like 15% of my time checking for memory violations though... But most of that time is waiting for a slow machine to run valgrind (if you think java feels slow).

      I think the slow part of Java is actually Swing, something about that toolkit used to seem slow (Java 2), like slower than gtk+.
      I've found that Java is about as quick as c for heavy processor intensive calculations (like calculating prime numbers); which is impressive since python was 30 times slower. My trouble with Java is its lack of easy connectivity with a more basic language; all the best languages have done that (c allows assembly).
      But yea, Java is pretty stinkin' awesome these days.. And he's right, every c program knows that malloc is slow and its speed unpredictable. If you do a big malloc after tons of small frees, you'll be waiting for it to run the whole list and condense it!

    4. Re:Robomaid by gr84b8 · · Score: 0

      1) Java still has memory leaks, its just manifested in a different way
      2) Troubleshooting garbage collection problems can be harder than troubleshooting traditional c memory problems
      3) You should almost never manually GC - especially just because you think you your app's got the time. First of all, the garbage collector knows more about when it has time than you do. Second of all, this type of assumption (i.e. that your code is the only thread in the JVM) is never a good idea. Third of all, every jvm has different properties to the garbage collection, so embedding assumptions about these properties in your code can be non-portable.
      4) PERL can be more readable than java, in some ways, since it allows shorthand for non business logic operations. Some java code is so littered with overhead that it is impossible to sort through the uninteresting operations to find the business logic. Understood that this shorthand is more apt to being abused, but ugly code is always hard to read.

    5. Re:Robomaid by AArmadillo · · Score: 3, Insightful
      The company I work for does development in mostly C/C++, and we haven't had a memory leak bug issued in 3.7 years according to our database. If memory leaks are your biggest problem, you probably aren't making effective use of smart pointers and structured allocation/deallocation.

      Also, let us not forget that java has memory leaks too and in my opinion they are much less obvious than C++ memory leaks.

    6. Re:Robomaid by hedge_death_shootout · · Score: 1

      If you spend alot of time using stuff like valgrind and searching for memory leaks, then you are doing something very wrong.

      Yep, you're programming in a language that requires manual memory management and lets you do 'dangerous pointer shit' in everyday coding.

      While human beings can do it (cf: industrial revolution era machinery with no safety features), but it's not advisable if you can avoid it.
      Thankyou, Moore's law.

    7. Re:Robomaid by Doc+Ruby · · Score: 1

      Anyone can write bad code. The sensible programmer uses tools to reduce the chances of those missteps. Testing, analysis and revision on those results, is the key to finetuned apps. Automated GC is a kind of CASE, using javac and the JVM to generate the GC code. Which means a smart programmer can find tuning opportunities in test results. So perhaps the real difference, apart from finding smart programmers (as usual), is better profiling and revision tools. I believe Java has the edge over Perl there, in quality if not quantity. But perhaps C is still king of the runtime analysis hill.

      --

      --
      make install -not war

    8. Re:Robomaid by carlislematthew · · Score: 1
      I have to agree and disagree. It is true that a GOOD programmer can code easily without leaking memory. But it is also true that most programmers are not good! Look around - most are adequate at best. As a percentage, there are very few really good programmers out there - I would guess under 10%. Therefore, any tool that helps the adequate programmer fuck things up less is a good thing in most instances as it will save a ton of time/money.

      Obviously, there are some applications (OS/real-time/audio/video) that require more deterministic outcomes and not some "silly" garbage collection or VM hanging around.

      In summary, pick the right tool for the job and understand the limitations of those doing the work.

    9. Re:Robomaid by Doc+Ruby · · Score: 2, Interesting

      I didn't say memory leaks are my biggest problem. The insufficiency of voice recognition and dataflow programming tools are my biggest problems :). But I still get memory leaks. And it still costs me more to hire programmers who don't generate memory leaks than to use their less-qualified peers and a JVM. If we programmed dataflow graphs, we'd spot redundant objects more easily. And voice recognition would let us drop them, without paying programmers to act as that middleware. A man can dream...

      --

      --
      make install -not war

    10. Re:Robomaid by Anonymous Coward · · Score: 2, Informative

      Actually, Java implementations are allowed to ignore System.gc() calls. It's just a suggestion to the runtime.

    11. Re:Robomaid by Mr.+Shiny+And+New · · Score: 5, Insightful

      You're right, Java does have memory leaks, in a sense, but these same problems can arise in any language. You could have a cache implemented in C/C++ that is never properly emptied, so over time it fills up. Or you could have a request log where, due to a bug, requests are not always removed from the log after they are processed. Sure, you might have included code to free the objects in the cache or log when you are done with them, but the programming error is that you forgot to remove the item. This is not a language issue, this is just a programming mistake.

      At least in Java you only need to worry about one problem: removing items from caches, logs, queues, etc when you are done with them; in C++ you have to also worry about de-allocating that object, which requires strict planning since the object must not be referred to anywhere else when you de-allocate it. In general you can't prove that the object isn't still referred-to by someone who had it before it was put into the cache/log/whatever; instead you need to establish rules and write documents to make sure everyone knows what the lifecycle of an object should be.

      As for your company not having a memory bug logged in 3.7 years, that's great, but without knowing what kind of applications you write, or how they're used, it's hard to say if that's significant. Some programs, like, say, grep, or mv or ls or any one-time-use utilities may be rife with memory leaks, but who cares? When the program terminates the memory is freed, and the user will likely not notice the leak. But even if your apps are long-running network services or whatever, I bet the time spent by developers preventing memory leaks is significant, even if that time is completely spread out throughout the development cycle instead of in large, easy-to-spot chunks running Valgrind or some other profiler.

    12. Re:Robomaid by Q2Serpent · · Score: 2, Insightful

      If you are hiring programmers who can't understand simple memory allocation and deallocation, you are more likely to run into a maintenance nightmare.

      Good programmers know how to write structured code that's easy to maintain, and a side effect of this is that memory allocation becomes second nature (like most other "problem": buffer overruns, memory leaks, etc). When you write good code, these problems rarely exist. The code structure sees to it.

      Just because Java tries to save you from one issue doesn't mean you can throw programmers with fewer skills at it and get the same result. Quality will suffer, because there are sill plenty of mistakes to be made in Java, and they all cost your bottom line just as much.

    13. Re:Robomaid by Anonymous Coward · · Score: 0

      in C++ you have to also worry about de-allocating that object, which requires strict planning since the object must not be referred to anywhere else when you de-allocate it. In general you can't prove that the object isn't still referred-to by someone who had it before it was put into the cache/log/whatever; instead you need to establish rules and write documents to make sure everyone knows what the lifecycle of an object should be.

      Clearly you're not a C++ programmer. Java gives you a full toolbox and that's what you use. C++ gives you a handful of tools and the ability to make more. (except now, many fine tools have been written that you can also just pick up and use)

      The proper thing to do in C++ is not to manually manage memory. The proper thing to do is to use tools that manage memory for you. Scoped pointers and ref counting work surprisingly well, and if that's not good enough there's always garbage collection. And these techniques work just as well for any resources you need to manage.

      Of course, this is not to say that there's anything particularly wrong with Java's approach. But C++ is not just "fancy C," even if there are people that use it that way.

    14. Re:Robomaid by someone1234 · · Score: 2, Interesting

      Let's see the Java OS then :)

      --
      Patents Drive Free Software as Hurricanes Drive Construction Industry
    15. Re:Robomaid by Doc+Ruby · · Score: 3, Insightful

      Please forward me the resumes of these programmers, which include "Skills" like "I never write memory leaks". And whose "Certifications" include "Good Programmer", not those other resumes which say "Bad Programmer".

      The fact is that Java programs include more intelligence about programming from the compiler and the JVM. So programmers are more productive than with C. Which means that the same programmer budget can produce more product, or a lower budget can produce the same product. With distributed teams, outsourcing, OSS integration projects, those considerations are crucial to project success. Sure, quality projects also require good design and management. But Java eliminates some quality problems right out of the box. That can't be dismissed merely by saying "hire good programmers, not bad". Because it's a continuum, with a sliding scale of costs that isn't always proportional to productivity.

      --

      --
      make install -not war

    16. Re:Robomaid by Doc+Ruby · · Score: 1

      Let's see the OS with 0.0 memory leaks, then.

      --

      --
      make install -not war

    17. Re:Robomaid by Midnight+Thunder · · Score: 1

      That's where in Java, things like WeakHashMaps come in useful.

      --
      Jumpstart the tartan drive.
    18. Re:Robomaid by dorkygeek · · Score: 1
      The fact that people can write entire operating systems in C without having these problems indicates that the problems are with people, not C.

      A quick search on google for "memory leak" reveals about 900 messages on lkml.org. On microsoft.com, about 13'000 pages were found. To me, this does not look like a non-issue...

      --
      Windows is like decaf - it tastes like the real thing, but it won't get you through the day.
    19. Re:Robomaid by ezzzD55J · · Score: 0, Redundant
      Let's see the OS with 0.0 memory leaks, then.

      Let's see an OS written in java, then.

    20. Re:Robomaid by stesch · · Score: 1

      By the way: If you don't want unreadable Perl code, then don't write unreadable Perl.

    21. Re:Robomaid by Doc+Ruby · · Score: 2, Funny

      BZZT: Circular reference - you lose. Should've used javac.

      --

      --
      make install -not war

    22. Re:Robomaid by dubl-u · · Score: 1

      The fact is that Java programs include more intelligence about programming from the compiler and the JVM. Which means that the same programmer budget can produce more product, or a lower budget can produce the same product.

      Yes! And I don't think that means you should hire less competent programmers. All the Java programmers I want to work with are perfectly capable of working in other languages. The difference with Java is that we can spend our obsessive powers and more of our intellectual energy on things that matter.

      Not that Java is perfect or anything; I have a lot of issues with it. But computers keep getting faster, while people stay about the same. Anything that can be cheaply and effectively automated should be, and for most projects I see, memory allocation is now firmly in that category.

    23. Re:Robomaid by Mnemia · · Score: 1

      Garbage collection can be implemented in such a way that it still gives deterministic guarantees about latency. Incremental GC alone does not necessarily achieve this by itself, but it is indeed possible if your real-time application is designed properly with GC in mind. Basically, you need to have enough "extra" memory to make sure that the garbage collection can stay ahead of your realtime application without requiring too much time for the realtime deadlines to be met.

      This isn't necessarily easy to do, but realtime programming in general isn't easy. But I think it's not true to say that garbage collected languages will never be useful for realtime applications.

    24. Re:Robomaid by carlislematthew · · Score: 1

      When java is controlling the anti-lock braking system on my car, I will stop driving. :)

    25. Re:Robomaid by David's+Boy+Toy · · Score: 2, Insightful

      Java should really be compared to the STL in C++, not to C, or a bastardized C/C++ coding mix. Ideally new/delete/malloc/free should only be used in small pieces of low level code and fully encapsulated in an object.

      Much of Java code can be converted almost line for line to C++. Unlike Java, the STL can create containers of any type, including built in types, operating on them very efficiently.

      const size_t size = 500000000;
      std:vector<int> X(size);
      for(unsigned i = 0; i < size; i++)
      X[i] = random();

      std::sort(X.begin(), X.end());

      Compare the performance of this sort() operation to its Java equivalent. Compare the space used. Notice that at no point did we worry about having to allocate/free memory, its taken care of by the vector template. To be nice we presized the vector, but we didn't need to, we could have used X.push_back(random()) with some additional overhead from automatic resizing. Something like this matters alot in high performance application, a good example would be transforms of large sets of vectors in 3d games.

      Java is just another religion like LISP used to be, the CS purists are always chasing the holy grail of coding purity without regards to programming realities, yet Java is hardly even pure, its already got more evolutionary cruft than C++ and its around 1/3rd the age of the original C which has been evolved into C++.

      Rarely do I see real world Java code perform with any degree of efficiency, even when compared to Perl, let alone C++. A Java appserver is much larger and uses much more CPU time than a similarly complex one written in perl.

    26. Re:Robomaid by thoth · · Score: 1

      I'm with you Doc Ruby, garbage collection is great. Yeah, I understand memory allocation/deallocation too, and know the techniques C++ gives you to minimize resource leaks. But the fact is, for the cost/benefit, garbage collection is great.

      But you are arguing with the entrenched opinion that garbage collection is for wimps. Just look at the responses to your posts in this thread. Some people are so anti-garbage collection it is astounding. They'll either argue GC has horrible performance characteristics or the relying on GC means you are a weak programmer. Or, they happen to be working on embedded code and can't pay the GC cost. Whatever man, I say there are too many other things to occupy my mind with that memory bookkeeping. I'll do it if I have to, but GC is great.

    27. Re:Robomaid by tsotha · · Score: 1

      Yes, well, you and I never put memory leaks in our code. Of course. Unfortunately, in any large commercial project you'll still spend much of your time chasing down memory leaks that other people have put there. Not everyone can be the programming gods that you and I are.

    28. Re:Robomaid by Baki · · Score: 1

      Just compare C++ Corba to Java Corba. In C++ Corba, a big issue with any API is, who owns the pointer? If you're not very precise, you risk not freeing memory or freeing it twice. In Java the issue doesn't exist.

      As soon as you start with multiple processes passing objects/memory around, this is an extra complication easily leading to errors.

    29. Re:Robomaid by Jonner · · Score: 1

      Apparently, Google is not your friends: JavaOS.

    30. Re:Robomaid by MenTaLguY · · Score: 1

      Perl's (mostly) reference-counted garbage collection isn't actually that good. Though it's servicable, reference cycles will cause memory leaks for the lifetime of a thread.

      --

      DNA just wants to be free...
    31. Re:Robomaid by NoOneInParticular · · Score: 1
      For this kind of stuff, shared memory, a sane C++ developer uses a shared_ptr. A simple reference counted pointer scheme that will take care of deallocation. It's trivial to write your own, or just use boost.

      Modern C++ simply doesn't use raw pointers. One uses the memory management scheme that is most suitable for that part of the code, but hardly ever use 'delete' anymore.

    32. Re:Robomaid by Anonymous Coward · · Score: 0
      Some programs, like, say, grep, or mv or ls or any one-time-use utilities may be rife with memory leaks, but who cares
      Actually, ls does have a memory leak (or at least the version that came with some old oldish distribution of Debian). It doesn't dealloc a bunch of memory, but it terminates so soon that it's actually faster to let the kernel dealloc the whole process than dealloc before exiting.
    33. Re:Robomaid by NoOneInParticular · · Score: 1

      I think he prefers jikes, written in C for speed.

    34. Re:Robomaid by Billly+Gates · · Score: 1

      How rude and insulting?

      I do not consider myself a professional programmer, but have written code and scripts before and have seen memory leaks first hand from commercial applications. MS Office, Windows, Mozilla, and a few other aplications.

      How do you know some release candidates did not have leaks in these unix os's? Also object oriented programming makes it easier to have leaks. You just cited C operating systems using functions to do a variety of tasks.

      Memory leaks happen in large applications. Its a fact and skill is involved with controlling them, but still no one is perfect in a complex application being developed.

      Please don't insult anyone over this as I am sure your code is not perfect either.

    35. Re:Robomaid by Some+Random+Username · · Score: 1

      I am sure its not a problem for these unix systems because I am on the cvs changes mailing list and I see how rarely a "fix a memory leak" or even similar problems like "fix a fd leak" happen.

      And I am not insulting anyone. I didn't say anyone was perfect, or that memory leaks never happen. I said that they are a very minor and rare problem, and if its such an issue to someone that they are not productive in C, then that person is not competant.

    36. Re:Robomaid by radtea · · Score: 4, Informative

      And I can always tune garbage collection performance by forcing a garbage collect when I know my app's got the time, like outside of a loop or before creating more objects in storage.

      No, you can't. At most you can give the JVM a hint that it would be nice to collect garbage now. The JVM is free to ignore that hint, and many JVMs will do just that.

      --
      Blasphemy is a human right. Blasphemophobia kills.
    37. Re:Robomaid by halleluja · · Score: 4, Funny
      The fact is that Java programs include more intelligence about programming from the compiler and the JVM.
      It is particularly sad the Visual PnP-generation of today cannot identify the merits of GOTO's and self-modifying code.

      I have never had any memory leaks, just by including the following code snippet:

      /* Distributed under GPL */
      #include <stdlib.h>

      static void* repo = malloc(100000000);

      int main(int argc, char** argv)
      {
      /* do stuff, just increment & cast *repo when I need to utilize free memory. */
      free(repo);
      }
    38. Re:Robomaid by PyroGx1133 · · Score: 1

      Most definitely, http://www.jnode.org/

    39. Re:Robomaid by Q2Serpent · · Score: 2, Insightful

      Productivity may be slightly hindered by the language (how easy is it to encapsulate functionality into easy-to-use packages), but I argue that it is dominated much more by the easy-to-use packages that are used.

      Java certainly helps here, but good libraries can be written in many languages. In fact, most libraries are written in C so that they can be used from many languages. A library written in C plus a small wrapper for the language-du-jour is a library usable from many languages. If you have good developers on your team, libraries will be written and re-used, and productivity will be high.

      Productivity comes from writing solid libraries so that you don't have to duplicate effort. Productivity comes from understanding how technologies work before you use them, so that you can avoid bug fixes, re-architecting the product, etc.

      My point is that a majority of productivity doesn't come from the language, and neither does a majority of the bug-avoidance. Java may help you in a few small ways, but if you are telling me that you'd rather have people with fewer skills just because you think Java will make up for it, you're mistaken.

    40. Re:Robomaid by Anonymous Coward · · Score: 0

      Perl doesn't have garbage collection; it has reference counting.

      Sorry to be so pedantic, but the wounds of a week's debugging are still fresh ;)

    41. Re:Robomaid by Mr.+Shiny+And+New · · Score: 1

      Exactly, unless you need more complex behaviour.

    42. Re:Robomaid by bani · · Score: 1

      actually I have looked at the bugzillas and changelogs of hundreds of projects, and memory leaks are the single least common bug ever. far more common (by orders of magnitude) are off-by-one errors. java won't save you there. other far more common bugs than memory leaks are logical bugs and high level design flaws, which would have occured regardless if the project was written in c, c++, java, or any other language.

    43. Re:Robomaid by Anonymous Coward · · Score: 0

      Clearly you're not a C++ programmer. Java gives you a full toolbox and that's what you use. C++ gives you a handful of tools and the ability to make more. (except now, many fine tools have been written that you can also just pick up and use)

      Clearly you're not a Java programmer. What makes you think that Java doesn't allow you to make more tools too, in addition to the many it provides by default?

    44. Re:Robomaid by Jeremi · · Score: 1
      If you're not very precise, you risk not freeing memory or freeing it twice. In Java the issue doesn't exist


      Use shared/ref-counting pointers and the issue doesn't exist in C++, either. So the real difference is that in Java everyone is forced to handle the problem in the "standard" way provided by the JVM, whereas in C++ the implementation is left to the programmer. Whether that's good or bad depends on what problems you are trying to solve.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    45. Re:Robomaid by Jeremi · · Score: 1
      memory leaks are the single least common bug ever.


      Probably that is not because they are rare, but rather because they are harder to detect and report. It's very difficult to tell when a program has a (small) memory leak vs. when it is just using up a bit more memory than it would normally use. For many programs, you would have to exercise them for weeks or months on end before the abnormal memory usage grew large enough to be obviously wrong.


      far more common (by orders of magnitude) are off-by-one errors. java won't save you there


      Well, actually, Java will give you a nice ArrayBoundsException when you try to iterate one past the end of an array. C/C++, on the other hand, will silently return undefined data or corrupt memory in that case, leading to very "interesting", non-obvious symptoms. So while Java might not "save you" from off-by-one errors, it certainly does make them easier to find and fix.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    46. Re:Robomaid by jsight · · Score: 1

      actually I have looked at the bugzillas and changelogs of hundreds of projects, and memory leaks are the single least common bug ever. far more common (by orders of magnitude) are off-by-one errors. java won't save you there. other far more common bugs than memory leaks are logical bugs and high level design flaws, which would have occured regardless if the project was written in c, c++, java, or any other language.


      Yes, but have you ever seen how much time those bugs take to fix? I suspect that time consumption is roughly in this order:


      1.    
      2. Design Flaws & Logic Bugs - Toughest to fix

      3.    
      4. Memory Bugs - Almost as bad

      5.    
      6. Off-by-ones - Super-easy


      Add to that the fact that 99.9% of users probably don't even know what a "memory leak" would be (much less the how to get enough details to report one), and you can see why looking at a few bugzillas is misleading.

      GC is a big deal.
    47. Re:Robomaid by shmlco · · Score: 1
      Okay, this should have been in the article on software quality, as one of the DUMBEST things a developer can do to ensure a bug-free program.

      Great idea. Let's hog a hundred megabytes of system memory, whether we need it or not, and start allocation into our own private heap. Let's also assume that our program is never kept running for long enough such that we overwrite the end of our buffer.

      This HAS to be a joke, right?

      --
      Any sect, cult, or religion will legislate its creed into law if it acquires the political power to do so.
    48. Re:Robomaid by Doc+Ruby · · Score: 1

      I'm a language bias rorschach blot :).

      --

      --
      make install -not war

    49. Re:Robomaid by Pseudonym · · Score: 1
      The fact that people can write entire operating systems in C without having these problems indicates that the problems are with people, not C.

      Quick exercise for the interested:

      Go to your Linux source tree. Take a look in fs/pipe.c. Go to the function do_pipe. Take a look.

      Yes, it's possible to clean up after yourself by writing code like this. But then, you'd have to be prepared to write and maintain code that looks like this. In Java, you wouldn't have to. You could let the GC take care of it, and your code would be much cleaner.

      Now in an operating system kernel, there's a good argument here in favour of writing this awful code: The kernel's entire job is to manage resources well, so it's very important that resources are freed as soon as possible. In most user-space programs (there are some exceptions), there is less of a requirement to release most kinds of resources as soon as they become free, so you can batch them up and free them together instead, and reap the performance gains.

      Believe it or not, it can make a huge difference. On a piece of high-performance, resource-intensive C++ code at work, we discovered that freeing a piece of memory was much more expensive than allocating it. The reason is that you can allocate memory from any arena, but freeing it requires that you return it to the arena that it came from. Decent multi-threaded allocators usually assign memory arenas to threads, so when allocating, a thread generally has an arena to itself. But freeing memory requires obtaining that thread's arena, which introduces lock contention. We fixed the problem with a judicious combination of using memory pooling, structure reuse and deferred deletion. If we had been using a GC-friendly language, a concurrent GC running at low priority would also have fixed the performance problem, at the cost of being more uncertain when resources would have been reclaimed. (For the particular application, the uncertainty was not an option, but most applications are not like that.)

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    50. Re:Robomaid by Doc+Ruby · · Score: 1

      There's all kinds of GC criteria to like or not. I like when programmers don't have to write any code to deal with memory, unless we want to. So Perl is good, and Java, while C/C++ are not so good. I'm not as hung up on whether the GC is fast, or memory efficient, but that matters as a secondary criteria, so I like Java better than Perl. FWIW, I rarely run Perl code in persistent processes - just CGI and tools that die quickly, taking memory leaks with them. Programmer time is more expensive than CPU time, so I optimize that.

      --

      --
      make install -not war

    51. Re:Robomaid by Doc+Ruby · · Score: 1

      Moderation -1
          100% Redundant

      Finally, a mod that's "Funny", but no way to metamod it that way.

      --

      --
      make install -not war

    52. Re:Robomaid by Doc+Ruby · · Score: 0, Troll

      Let's take it in the other direction: why not have machine language, or assembly programmers, who would therefore be quite skilled (high barrier to entry)? Because their time is better spent doing things the compiler can do. C is mostly a glorified macro assembler language, relying on GCC to do the hard work. And Java is another step in that scale. Different people's organizations will find their balance in their own place. Generally, Java means programmers, even if they're really good, don't have to spend *any* time dealing with memory bookkeeping. So they're more productive. Now, some programs deal with problems closely modeled by memory bookkeeping, so they are worth writing in C (eg. pointer arithmetic). But generally business problems are better modeled in messaging schemas among objects than simple structures. If you're programming hardware solutions, C is probably better. But if you've got to choose between spending time designing/implementing memory de/allocation or message passing, Java is probably better. So you don't need programmers with memory de/allocation skills. They might have other skills, or just fewer skills, because the messaging has been designed by the architect or designer. And therefore the budget can afford a better architect/designer, which is usually more productive money spent.

      --

      --
      make install -not war

    53. Re:Robomaid by Doc+Ruby · · Score: 1

      Sure, but I want the JVM to overrule that GC request, when it knows it's not time to GC, given runtime conditions. Sounds like the best of both worlds.

      --

      --
      make install -not war

    54. Re:Robomaid by Doc+Ruby · · Score: 1

      Moderation +4
          60% Insightful
          20% Troll
          10% Overrated

      Who are these anonymous clowns with their "Troll" mods? Probably just as bad programmers as they are moderators.

      --

      --
      make install -not war

    55. Re:Robomaid by Q2Serpent · · Score: 1

      Please don't confuse being skilled with assembly and being a skilled programmer. A skilled programmer will make the best of whatever language he or she is given. If they are using assembly, and they see areas where they can be more efficient, they will create new libraries and languages, and the best of them will be re-used for many years.

      I'm not trying to single out Java here; sometimes, I think Java is the right tool for the job. My point is to single out this flawed logic of yours:

      it still costs me more to hire programmers who don't generate memory leaks than to use their less-qualified peers and a JVM

      My point is this: "programmers who don't generate memory leaks" are generally programmers who are skilled at programming in general. They understand computers and how they work; they understand programming languages and how to use them to get the job done. They understand how to encapsulate things, how to separate concerns, how to keep cohesiveness to a minimum, and how to get the most from their tools.

      If you would rather have someone without these skills, just because you think Java protects you from the poor programming they will produce, then you're mistaken. The mistakes these unskilled programmers make span way beyond memory management, and if you think that memory management is some special case that is different from maintaining database connections, open files, or any other resource, you're wrong. These "cheaper" programmers will be more expensive in the long run.

      Programming skills are important, and no language can protect you from those who don't have them. Don't single out memory management as the cause of your problems. Poor developers are the cause, and hiring cheaper developers who don't understand this stuff just because you think Java will protect them just perpetuates the problem.

    56. Re:Robomaid by bani · · Score: 1

      memory *leaks* are rare because applications very rarely malloc. most data is temporary local variables off the stack, automatically destroyed when the function is exited.

      gcc4 has -fbounds-checking and -fmudflap which work very well to catch bounds errors. while they might have been harder to find and fix years ago, they are now trivial and java no longer has the upper hand.

    57. Re:Robomaid by ebbe11 · · Score: 1
      The fact that people can write entire operating systems in C without having these problems indicates that the problems are with people, not C.

      The solution to that problem is to remove people from the process. Now, if we could get the program to de-allocate memory automatically.

      Oh, wait...

      --

      My opinion? See above.
    58. Re:Robomaid by Anonymous Coward · · Score: 0

      The fact is that Java programs include more intelligence about programming from the compiler and the JVM.

      Wow! Compilers and VMs as intelligence providers!. Great, now even stupid sentences will be intelligently translated into non sensical binaries!.

    59. Re:Robomaid by Doc+Ruby · · Score: 1

      And you're confusing the skill of memory allocation with some "safe zone" of being a "skilled programmer". That's just one skill. The skill of OOP is largely unrelated to memory management. And OOD/OOP is much more important to the programming I generate, business programming, than are "machine level" skills. Give me the programmer who's more skilled in the human considerations of programming, like the business modeled by the program, or the people who'll use and maintain their programming. I can replace the memory management skills with the Java compiler and JVM, but those other skills have to be replaced by other people, like me. I'll take the assist from the computer wherever I can get it, and I can't get it replacing my design and management skills yet. When I can, I'll move even further up the chain.

      --

      --
      make install -not war

    60. Re:Robomaid by Doc+Ruby · · Score: 1

      Sorry, does not compute.

      --

      --
      make install -not war

    61. Re:Robomaid by Anonymous Coward · · Score: 0

      Sorry, does not compute.

      Sorry, does not compile. :)

    62. Re:Robomaid by aled · · Score: 1

      CVS is an OLD project. I guess the code base is mature and sees little big changes and major restructuring. It's hardly a representative project. If would be more fair to look on projects like Linux Kernel, GNOME, KDE, Subversion, BSD, OpenOffice.

      --

      "I think this line is mostly filler"
    63. Re:Robomaid by aled · · Score: 1

      You know STL isn't the holy grail of programming, as much as C++ programmers like it to be. In fact there many other languages with a collections library, and is just an usefull part of the library. But not every problem can be expressed as operations on collections. BTW, Java can create collections of any type without casting since version 1.5.
      A Java appserver may use more memory than a Perl implementations, but I would like to know:
      -is the functionality/feature set equivalent? Most Java appservers include distributed transactions, database connection pooling, messages queues, web applications abstractions, corba, etc.
      -what about speed?
      -development time?
      -easy of recruiting programmers?

      --

      "I think this line is mostly filler"
    64. Re:Robomaid by Jeremi · · Score: 1
      memory *leaks* are rare because applications very rarely malloc. most data is temporary local variables off the stack, automatically destroyed when the function is exited


      And if they aren't rare, how would you know? That was my point. A leaky application that allocates 3MB on startup, leaks 1KB an hour, but never gets run for more than 5 days at a time, will probably never get fixed, because it's likely nobody will ever notice there is a problem.


      As for your claim that applications 'rarely' use malloc(), that is not my experience. It may be true for some apps where the maximum size of the dataset is known at compile time, but for many (most?) non-toy apps, dynamic memory allocation is used quite regularly. Polymorphism (one of C++'s key features) is rather limited without it.


      gcc4 has -fbounds-checking and -fmudflap which work very well to catch bounds errors. while they might have been harder to find and fix years ago, they are now trivial and java no longer has the upper hand


      That's great, but gcc4 is not the same thing as C++.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    65. Re:Robomaid by bani · · Score: 1
      And if they aren't rare, how would you know? That was my point. A leaky application that allocates 3MB on startup, leaks 1KB an hour, but never gets run for more than 5 days at a time, will probably never get fixed, because it's likely nobody will ever notice there is a problem.

      Developers use things like dmalloc and mpatrol to tell, if they don't wrap allocations themselves (which is trivial to do). It's not like these are unsolvable C/C++ problems that can only be solved by porting to java.

      That's great, but gcc4 is not the same thing as C++.

      Sure it is.
      $ cat test.cpp
      int main( void ) {
              int xyz[30];
       
              xyz[31] = 0;
      }
      $ g++ -v
      Using built-in specs.
      Target: x86_64-redhat-linux
      Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2 .0/jre --host=x86_64-redhat-linux
      Thread model: posix
      gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)
      $ g++ -fmudflap -lmudflap -o test test.cpp
      $ ldd test
              libmudflap.so.0 => /usr/lib64/libmudflap.so.0 (0x00002aaaaaadc000)
              libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003d87d00000)
              libm.so.6 => /lib64/libm.so.6 (0x0000003d85900000)
              libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003d87b00000)
              libc.so.6 => /lib64/libc.so.6 (0x0000003d85600000)
              libdl.so.2 => /lib64/libdl.so.2 (0x0000003d85b00000)
      /lib64/ld-linux-x86-64.so.2 (0x0000003d85400000)
      $ ./test
      *******
      mudflap violation 1 (check/write): time=1128968399.682800 ptr=0x7ffffff384f0 size=128
      pc=0x2aaaaaae4add location=`test.c:4 (main)'
      /usr/lib64/libmudflap.so.0(__mf_check+0x18) [0x2aaaaaae4add]
      ./test(main+0xbd) [0x400a65]
      /lib64/libc.so.6(__libc_start_main+0xef) [0x3d8561c3cf]
      Nearby object 1: checked region begins 0B into and ends 8B after
      mudflap object 0x602ae0: name=`test.c:2 (main) int xyz [30]'
      bounds=[0x7ffffff384f0,0x7ffffff38567] size=120 area=stack check=0r/3w liveness=3
      alloc time=1128968399.682787 pc=0x2aaaaaae541e
      number of nearby objects: 1
      microsoft and intel's compilers have similar features.

      these tools exist, these are easily solvable problems. it's not like this is the exclusive domain of java.

      now if they'll solve the java problem of eclipse and azureus wanting 100's of mb's of ram just to start up... :-/
    66. Re:Robomaid by Q2Serpent · · Score: 1

      Wrong, wrong, wrong! This is my last post on this topic, because I'm sick of repeating myself.

      Memory management is not some "machine level" skill. It's basic resource management. It is the same as handling any other resource: open files, database connections, ANYTHING. If you read my last post, you would have understood this. I'm not talking about implementing a memory manager, I'm talking about simply acquiring a resource and freeing it up again the right place. This is basic programming, and anyone who can't structure their code to handle resources will cause problems. If they can't handle memory management, then I argue that they can't handle ANY resource management, and Java or no Java, resource management is important. No JVM or language will replace knowing how to manage resources. Sorry.

    67. Re:Robomaid by aled · · Score: 1

      "Reference counting is nearly always very much slower than other garbage collection techniques, because of the need to update reference counts whenever a reference is changed, rather than only following references during garbage collection. Reference counting also requires some space in each object. Simple reference counting also fails to reclaim the memory used by data structures that have cycles (such as doubly linked lists), although this is ameliorated somewhat by judicious use of weak pointers."
      from http://en.wikipedia.org/wiki/Garbage_collection_(c omputer_science)

      --

      "I think this line is mostly filler"
    68. Re:Robomaid by Anonymous Coward · · Score: 0

      Ah yes, the old "Java programmers are unskilled" argument!

    69. Re:Robomaid by Nevyn · · Score: 1
      And if they aren't rare, how would you know? That was my point. A leaky application that allocates 3MB on startup, leaks 1KB an hour, but never gets run for more than 5 days at a time, will probably never get fixed, because it's likely nobody will ever notice there is a problem.

      Nice circular argument. a) leaks are a huge problem. b) I never see them. a) but that's why they are a problem.

      IMO if nobody ever notices there is a problem, there isn't a problem. Also the application that leaks the most on the desktop is written in Python, which has reference counting and garbage collection.

      As for your claim that applications 'rarely' use malloc(), that is not my experience.

      RAII requires allocating from the stack, and a _lot_ of C++ uses that design pattern. malloc() is much more used in C (which I prefer) ... but I still almost never see memory leak problems (and, yes, my code counts the memory and complains at exit if I've leaked something).

      --
      ustr: Managed string API with ave. 44% overhead over strdup(), for 0-20B
    70. Re:Robomaid by Jeremi · · Score: 1
      Nice circular argument. a) leaks are a huge problem. b) I never see them. a) but that's why they are a problem.


      I'll see your "circular argument" and raise you a "straw man". I never argued the above. What I said was that just because people don't detect leaks, doesn't mean they don't exist. Whether they constitute a "huge problem" or not is in the eye of the beholder, and not something I addressed.


      IMO if nobody ever notices there is a problem, there isn't a problem.


      I sure hope you don't work for NASA or a nuclear power plant or anyplace else where software correctness is important. A bug that you can't easily detect is still a bug, and under the right conditions it can bite people, even if you choose to ignore it. In many ways it's worse than an obvious bug, because it's less likely to be caught during the testing cycle, and thus more likely to eventually bite someone.


      but I still almost never see memory leak problems (and, yes, my code counts the memory and complains at exit if I've leaked something)


      The problem is that not every C/C++ programmer is as conscientious as you are. (neither is every Java programmer; but then, they don't need to be)

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    71. Re:Robomaid by Nevyn · · Score: 1
      I sure hope you don't work for NASA or a nuclear power plant or anyplace else where software correctness is important

      There is a big difference between "important", which is what I'd describe the status of quality of a significant amount of software as, and "kills people if you fail". The later is often developed very differently, and with much more expense than any other typ0e of software ... NASA's JPL does lots of things that's just not affordable to do elsewhere.

      A bug that you can't easily detect is still a bug, and under the right conditions it can bite people

      I agree, but a memory leak if it is there at all usually happens slowly ... so if you see it, it's not hard to fix ... and if you don't (because, say, the application doesn't get run for long enough for it to matter) who cares.

      The problem is that not every C/C++ programmer is as conscientious as you are. (neither is every Java programmer; but then, they don't need to be)

      They don't need to care "some" of the time, often when you need to release resources you need to do other things ... if you've layed out your code well, doing both isn't hard ... if not then doing either can be hard. Yes, having destructors/dispose helps some ... but even then it can't save them if they don't unlink the objects from the heap properly (and sometimes doesn't save them anyway, when using a limited number of resources, like DB connections).

      Basically writting code well, is always the best defence :). I just don't see leak protection helping "the others" much ... although, I'd probably agree that memory protection can help everyone quite a bit, and helps "the others" a lot. But even then, I see those problems only very rarley even in C.

      --
      ustr: Managed string API with ave. 44% overhead over strdup(), for 0-20B
    72. Re:Robomaid by pthisis · · Score: 1

      And it still costs me more to hire programmers who don't generate memory leaks than to use their less-qualified peers and a JVM

      Okay, I'm a big proponent of high-level languages (my current project is about 200,000 lines of Python, with maybe 500 lines of C mixed in). But I can't agree with that; in my experience, you'll save money by hiring fewer skilled programmers--the kind for whom on C/C++ projects, memory leaks would be a fairly rare problem that didn't represent a large portion of debugging time. If your programmers are sloppy enough that it'd be a major issue, they're also sloppy enough that real logic bugs are going to explode to the point where time spent debugging easily outweighs the cost-per-hour savings that you're getting.

      Obviously it's not 100% true; it's possible to find good, careful entry-level programmers, and you take them whenever you find them. But overall, getting good programmers should be a cost savings.

      But yes, even with good programmers you don't want them to spend more effort than required. Limit the use of low-level constructs to where it's required (those few hundred lines of C that we do have are certainly performance-critical). Sometimes that means using hybrid systems (a mix of high- and lower level languages). Sometimes it means using garbage-collected memory allocation in low-level languages. Sometimes it means using low-level libraries from high-level languages. Mostly, it means picking the right tool for the job.

      --
      rage, rage against the dying of the light
    73. Re:Robomaid by pthisis · · Score: 1

      And if they aren't rare, how would you know? That was my point. A leaky application that allocates 3MB on startup, leaks 1KB an hour, but never gets run for more than 5 days at a time, will probably never get fixed, because it's likely nobody will ever notice there is a problem.

      OTOH, if they're never noticed then they really aren't a problem, are they?

      I could have a program that runs frequently and exits, without ever bothering to free memory (relying on the OS to do so)--for my application, that could be fine but the startup cost of the available JVM could kill me even though it's more correct wrt memory usage.

      You could have a long-running application, where using a good GC (in C or in Java) is paramount.

      Pick the right tool for the job.

      That's great, but gcc4 is not the same thing as C++

      And there are conforming JVMs out there with memory leaks. Indeed, the language never specifies if memory will ever be freed. That's not an argument against using Java, though.

      For a lot of projects (the vast majority, in fact) I can rely on being able to pick my development toolchain in order to use the tools that let me get the job done the best.

      --
      rage, rage against the dying of the light
    74. Re:Robomaid by pthisis · · Score: 1

      Unfortunately, in any large commercial project you'll still spend much of your time chasing down memory leaks that other people have put there.

      In practice for me, this is simply untrue even in bare C without bounds checking or garbage collection (though there's usually little reason not to use those features in most projects, even in C). Time spent chasing memory violations and leaks is trivial compared to time spent chasing bugs in programming and business logic.

      I still stick with higher-level languages for the vast majority of my code, but the reasons aren't greatly related to memory safety--using Python saves me a few percent on debugging time there, but huge amounts of time on development and debugging of real problems vs. Java, C or other lower-level languages.

      --
      rage, rage against the dying of the light
    75. Re:Robomaid by tsotha · · Score: 1
      I'm curious as to the particulars of your project. How many people are working on it? How long has it been around? Does your company employ short-term contractors? Every C/C++ project I've been involved with has been around at least ten years, with more than 100 people working on it over time (not all at once).

      In every case the program would core-dump seemingly at random. Each time I cajoled my boss into getting a copy of Purify and then spent the next three months flushing out all the memory leaks and buffer overruns, and to everyone's amazement the program became stable.

      The problem was in every new release some bozo would put more in. I myself was originally a big advocate of C, but I've come to the conclusion the average programmer is simply too stupid to avoid 1)memory leaks, 2) buffer overruns, and 3) my personal favorite - passing references to stack variables back to the calling frame.

    76. Re:Robomaid by NoOneInParticular · · Score: 1
      That's all true, and well known, but only points to the fact that you are not supposed to use reference counting everywhere. You use it for simple shared memory, not for non-shared stuff. Unlike Java, you are not forced to use one particular mode of memory management and stick with it. One uses refcounting for 'shared memory' only, and local memory (i.e., simple scoped memory) for other purposes. When that shared memory involves cycles that cannot be factored out, you might throw in a garbage collector for that piece of the code. This doesn't happen often however, as many cycles can be resolved by using a combination of shared_ptr and weak_ptr. The latter points to the same mem as a shared_ptr, but doesn't do reference counting. Who owns what can be simply found by looking at the type.

      But just a question for GC lovers (in Java). Have you ever worked with some library/other person's code, gotten and object (say an int[]) back and asked yourselves: can I safely change these values or would the whole system fall over? GC does not solve memory ownership, it only gets rid of garbage. Memory sharing is difficult (as it breaks encapsulation), and need to be treated as such. In my experience, most Java programs have horrible encapsulation, simply because most code give references to their private parts out freely ;)

    77. Re:Robomaid by aled · · Score: 1

      In my experience in C sharing memory would most likely make the "whole system fall over" because of overwriting the memory or free'ing twice the same block. C++ is more o less the same, though you can manage it better there is usually third parties libraries one cannot control. In Java you just cannot overwrite shared memory or release twice an object, accidentally or otherwise. All access are throught references. You can share an object and use it wrongly (example: account.substract(n) from two places) , but its a different problem at a different abstraction level.
      I personally like not to worry about pointers when I'm not doing low level work.

      --

      "I think this line is mostly filler"
    78. Re:Robomaid by pthisis · · Score: 1

      I'm curious as to the particulars of your project. How many people are working on it? How long has it been around? Does your company employ short-term contractors?

      The current project isn't really a C project, it's about 300,000 lines of Python (with an equivalent amount of template code) and maybe 500 lines of C; we have 5 full-time developers and 1 part-time (maybe 10 or so people have worked on it at some point). About a third of the code is machine-generated via tools we've written; half the remainder is generic library code used by many client implementations, and the other half is specific to client needs. I've been on it for a year, the project has been around for 4 years.

      The previous project was about 50,000 lines of C, 15,000 lines of C++, and 30,000 lines of Java. Because of institutional inefficiency, it had as many as 15 people work on it at peak (maybe 20-25 total over the life of the project) for about 6 months. Normal staff over the project lifespan was 3 C developers, 4 Java developers, and 2 C++ developers.

      It's still in production (large network server servicing millions of requests daily--it's over the 1 billion served mark in its lifetime). No short-term contractors were used. It's in static production now, with a few weeks of development each year if new features are needed--it's been in production for about 6 years (active development for the first couple), with a year of development lead-in before that.

      It's essentially 7-8 seperate back-end processes (C, one C++ component) interfaced by a desktop UI for data entry and system management (Java), a reporting front-end (server-side Java web interface) and a number of logging and summarizing processes (C mainly, one small Perl component).

      I myself was originally a big advocate of C, but I've come to the conclusion the average programmer is simply too stupid to avoid 1)memory leaks, 2) buffer overruns, and 3) my personal favorite - passing references to stack variables back to the calling frame

      In my experience, such programmers are also bad at avoiding business and programming logic errors. You're far better off going with fewer skilled programmers. Not only will the bug rate decrease, but the productivity will be higher--and although the cost per programmer will be higher, the total amount spent on programmers will be lower for more work done.

      Essentially, if memory leaks and buffer overruns represent a significant amount of debugging time for your staff then you're going to be woefully underproductive no matter what language you choose.

      That said, shaving a few percent off is worth it, and higher level languages can give you much more dramatic productivity gains in other arenas (depending on the task).

      --
      rage, rage against the dying of the light
    79. Re:Robomaid by Jeremi · · Score: 1
      I agree, but a memory leak if it is there at all usually happens slowly ... so if you see it, it's not hard to fix ... and if you don't (because, say, the application doesn't get run for long enough for it to matter) who cares.


      What you get by not caring is computer systems that have to be restarted every week or two -- not coincidentally, the state of many computer systems today. The situation is tolerable (since users often don't demand better) but not very desirable IMHO. I certainly wouldn't accept that level of reliability in, say, my alarm clock!

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    80. Re:Robomaid by NoOneInParticular · · Score: 1
      I personally like not to worry about pointers when I'm not doing low level work.

      Honestly, in my C++ work, I don't like to worry about pointers either. To wit, two weeks ago I was doing some quick and dirty work and suddenly had to call delete on a simple array. I really had to think about what the syntax for that was again, as I hadn't used that for years. And for Java not having pointers, seen any NullPointerExceptions lately? At least my C++ references cannot be NULL (they can be invalid though ;)

    81. Re:Robomaid by aled · · Score: 1

      And for Java not having pointers, seen any NullPointerExceptions lately? At least my C++ references cannot be NULL (they can be invalid though ;)

      Well, I seen LOTS of NullPointerExceptions, thank you very much :-) Really, this usually isn't as bad as it sounds because I can diagnose the problem more easily (in most cases) than an equivalent C++ program. The name isn't very good (NullReferenceException would be better maybe?) but the meaning is the same. Alas, I'm having one such problem that produces NullPointerExceptions because of missing parameters in http request and can't find what causes the problem. I know the NPE are the consecuences and not the cause and can catch them. This is a very weird case, almost in every other situation NPE were more easily spotted.

      --

      "I think this line is mostly filler"
    82. Re:Robomaid by NoOneInParticular · · Score: 1

      Ah, those lovely Java references: combining the strengths of pointers (being NULL) with the strengths of references (no pointer arithmetic). In any case, good luck with your hunt. At times I also wished that Java had a way of specifying that an object is not supposed to be null in a function signature, that would help a lot. But until that happens we're stuck at specifying it in the Javadoc...

    83. Re:Robomaid by Agret · · Score: 1

      of course it's a joke. Why do you think its on +5 funny. Your one of those people who analyse a joke too seriously =P

      --
      Have you metaroderated recently?
    84. Re:Robomaid by Anonymous Coward · · Score: 0

      .. it's likely nobody will ever notice there is a problem. ..

      Look at it this way: If nobody will ever notice there is a problem, then there is no problem. This is a little bit similar to the 'don't optimise prematurely' rule. If it doesn't look like a problem (in the real world), then don't waste time fixing it, because it ain't broke.

  6. Java Urban Performance Legend #1 by GillBates0 · · Score: 5, Funny

    JVM memory allocation isn't "SLOW". It's just pleasantly unhurried.

    --
    An Indian-American Hindu committed to non-violent thought/speech/action alarmed by the global explosion of radical Islam
    1. Re:Java Urban Performance Legend #1 by Anonymous Coward · · Score: 0
      Ever use Limewire. That thing runs the JVM. It's the fastest client I ever used!!

    2. Re:Java Urban Performance Legend #1 by rjshields · · Score: 1

      Somebody didn't RTFA.

      --
      In this world nothing is certain but death, taxes and flawed car analogies.
    3. Re:Java Urban Performance Legend #1 by McCarrum · · Score: 1

      Slashdot Rule #61

      Never let the article get in the way of Funny Karma.

    4. Re:Java Urban Performance Legend #1 by WhiplashII · · Score: 1

      Slashdot Rule #62

      There is no Funny Karma.

      --
      while (sig==sig) sig=!sig;
  7. Coral cache by Baron+Eekman · · Score: 0, Redundant

    Here or use the Firefox extension.

    1. Re:Coral cache by Anonymous Coward · · Score: 0

      Do you honestly think that www.ibm.com is likely to get Slashdotted?

    2. Re:Coral cache by gaj · · Score: 1
      Do you seriously think IBM can't handle a slashdotting?

      <sigh>

      Karma whoring is so twentieth-centry.

  8. They're good.. now.. by onion2k · · Score: 5, Insightful

    JVMs are surprisingly good at figuring out things that we used to assume only the developer could know.

    Yes they are. Now. 10 years ago when Java applets were being embedded in webpages (to show rippling water below a logo :) ) they weren't. The performance of the language has greatly improved while the perception of language has remained the roughly same (at least amoung the general coding community).

    Just goes to show that even if you have a great technical product you'll still need the marketdriods. Unfortunately.

    1. Re:They're good.. now.. by Anonymous Coward · · Score: 0

      Just goes to show that even if you have a great technical product you'll still need the marketdriods.

      Or, better: forget about the "great technical product" part of the equation, just stick with the marketroids. It definitely worked for Java.

    2. Re:They're good.. now.. by eraserewind · · Score: 1

      Is it any faster on the computers we were using 10 years ago? Or is it just riding the performance wave like everything else?

    3. Re:They're good.. now.. by Mr.+Shiny+And+New · · Score: 3, Informative

      In some aspects, yes, it is much faster. For example, I can tell the difference between Java 1.4 and Java 5 (1.5) on the same hardware. My company's website was upgraded to Java 5 and performance increased significantly, mainly due to garbage-collection improvements. So I'd say that the same holds for the older JVMs. However, there may be other things added to the JVMs that make them less suitable for older hardware. I know that class libraries and app frameworks have gotten bigger as time goes on, so that would definately impact things in terms of memory usage.

    4. Re:They're good.. now.. by Anonymous Coward · · Score: 1, Insightful
      The performance of the language has greatly improved while the perception of language has remained the roughly same
      You can see the same effect with C vs. C++. There's still a lot of C++ performance myths going around that are based on first-generation C++ compilers from the early 90s, and even though empirical evidence contradicts them, C++ still has a reputation for being slower than C.
    5. Re:They're good.. now.. by Orycterope · · Score: 0

      >Just goes to show that even if you have a great technical product you'll still need the marketdriods. Unfortunately. Java is slow. I don't care what part of the JVM sucks, it just sucks. Even marketdroids wouldn't be able to do anything about it. The current JVM being faster than what was available 5 years ago doesn't make it a great technical product. It still sucks, just a little bit less than it used to.

      --
      Just because your voice reaches halfway around the world doesn't mean you are wiser than when it reached only to the end
    6. Re:They're good.. now.. by DrXym · · Score: 1, Insightful
      In my experience Java is fast enough for most server side operations and just as fast as the highly touted CLR / C#. The problem with Java is that Swing performance truly is wretched for writing UIs, but with SWT it's quite acceptable for most tasks.

      The problem aside from Swing of using Java for UI work is the tools are wretched. Even something like the VE extension for Eclipse can't overcome the sheer bloody awfulness of trying to develop visual applications in the Java language.

    7. Re:They're good.. now.. by Anonymous Coward · · Score: 0
      "I can tell the difference between Java 1.4 and Java 5 (1.5)"

      I know it's off topic, but it still gets me every time when I see that 1.4 --> 5 upgrade. I wish normal people could get away with that:

      Guy at bar: I'd like a drink, here's my ID.
      Bartender: This thing says you're 17.
      Guy at bar: Nah, I decided I didn't like that versioning scheme, so I'm 21.3 now.

    8. Re:They're good.. now.. by qbwiz · · Score: 1

      This isn't the first time they did that. I believe they actually have two concurrent versioning schemes: the core language (1->2->5) and the JDK/whatever (1.0->1.1->1.2->1.3->1.4->1.5). It's a useful concept, having these two different schemes, but the problem is that no one generally distinguishes between them.

      --
      Ewige Blumenkraft.
    9. Re:They're good.. now.. by M.+Baranczak · · Score: 1

      The problem aside from Swing of using Java for UI work is the tools are wretched.

      The GUI editor in NetBeans is pretty nice. Of course, it doesn't fix any of the inherent problems of Swing, but it just might make you forget them for a little while.

    10. Re:They're good.. now.. by killjoe · · Score: 0

      The neat thing about Java is that you don't need to code in swing. There are lots of options including swt and wxwindows. There are java bindings for every gui toolkit.

      --
      evil is as evil does
    11. Re:They're good.. now.. by Taladar · · Score: 1

      If you can even notice a difference in performance for effects/UI of your web page something is wrong with using Java for that task. UIs should be totally responsive even on the "older hardware" of today by now.

    12. Re:They're good.. now.. by Mr.+Shiny+And+New · · Score: 1

      I notice a difference in performance because the web site I work for has high volume and we keep track of stuff like CPU usage over time. CPU usage has dropped because garbage collection has significantly improved. The website itself is snappy and responsive but that's because there's lots of hardware behind it; we have multiple servers to provide both speed and redundancy. But we can demonstrate that each server is working more efficiently with Java 5 than it was with Java 1.4.

    13. Re:They're good.. now.. by ConceptJunkie · · Score: 1

      Maybe performance isn't the problem. Maybe the problem is that most Java programs look like Java programs, i.e., crappy. Java's strength seems to be on the back-end, not for UI work. My sole experience with Java UI programming was nightmarish, but that was 5 years ago. I found myself digging into library source just to try to do something that took a few minutes to set up with MFC.

      --
      You are in a maze of twisty little passages, all alike.
    14. Re:They're good.. now.. by a11 · · Score: 0

      It's a sun thing - Ex: SunOS (2.8, 2.9, ...) == Solaris (8, 9, ...).

    15. Re:They're good.. now.. by Decaff · · Score: 1

      The performance of the language has greatly improved while the perception of language has remained the roughly same (at least amoung the general coding community).

      This is something that puzzles me. I would have thought that coders in general would feel the need to keep their skills and IT knowledge up to date. However, I still find attitudes which were based on an evaluation of Java 5 or more years ago predominate. In an industry where things change so dramatically over a period of a few years, I find this strange.

    16. Re:They're good.. now.. by bani · · Score: 1

      too bad jvms are still resource-hungry monsters. i'm quite tired of java apps taking >100mb of real memory and >500mb of virtual.

      it's notable that these days, good java gui applications are the exception, not the rule, when it comes to java. applications like eclipse are highly unusual -- not the norm. most of java's penetration is behind the scene these days with web server backends, where interactive performance doesn't matter that much.

    17. Re:They're good.. now.. by TekPolitik · · Score: 1
      CPU usage has dropped because garbage collection has significantly improved.

      Be careful about looking at CPU usage in isolation - depending on the application, lower CPU usage may be bad rather than good. Where an application is performing CPU intensive tasks, low CPU usage usually means the application is stuck waiting for hardware for too long.

      It is a common newbie programmer mistake to think "application's running slow, let's see how much we can speed it up by doing X" where X involves using more memory to reduce the instructions required to perform the task. But then you may well end up making more use of swap space (assuming a mass-deployed app you cannot assume everybody will just add more memory), slowing the app down.

      On the other hand, sometimes the answer to speeding things up may be to use more memory up to the point just before you would expect swap space to start being used, even without looking at what instructions are being executed.

      The tradeoff at this level is something that does need to be done by the programmer based on knowledge of what the application is doing and where the real bottlenecks are.

      In TFA, the garbage collection strategies are very wasteful of memory. Java developers seem to like to say "memory is cheap", but it is not free, and a sufficiently hungry use will eventually run into a barrier in terms of price, available address space or hardware limitations. Where an application performs best by using a lot of memory all at once, it may well be that those approaches will result in lower performance rather than higher.

      The upshot - you still have to choose your tools based on whether they are appropriate to the task at hand. And while I have not seen many C++ developers who will claim that C++ is the right tool for every job, it seems many Java developers like to claim Java is the right tool for every job.

      (Now watch the Java bigots mod me down)

    18. Re:They're good.. now.. by Joe+Tie. · · Score: 1

      I hate to say it, but that's just human nature no matter what the field. Humans in general aren't very good at revising opinions on rather large or abstract concepts. Past a certain age it becomes even more difficult to do so. There's been enough time since java came onto the scene for the then kids to pass into early middle-age, with the even stronger resistance to change that comes with it.

      --
      Everything will be taken away from you.
    19. Re:They're good.. now.. by EvlG · · Score: 1

      Not sure what caused this, but my experiments earlier with .Net 2.0 beta 2 on VS.Net 2005 Beta 2 were awful. The GUI performance was much much much slower than anything I considered acceptable. It was like using Java 5 years ago on a P2.

      I hope the final release solves that, but man, from that experience, it seemed like the CLR had a long long way to go.

    20. Re:They're good.. now.. by Vintermann · · Score: 1

      I too see a difference between 1.5 and 1.4: With 1.4, when starting netbeans, my laptop fan spins up a step. With 1.5, it doesn't.

      --
      xkcd is not in the sudoers file. This incident will be reported.
    21. Re:They're good.. now.. by ultranova · · Score: 1

      The neat thing about Java is that you don't need to code in swing. There are lots of options including swt and wxwindows. There are java bindings for every gui toolkit.

      Unfortunately, if you use such a toolkit, the user needs to have it and the Java bindings installed as well. Everyone has Swing (since it comes with the Java runtime), but not everyone has SWT or wxWindows. Every piece of software the user has to install is a strike against your program.

      Of course, if this is acceptable, you could simply use the OpenGL bindings and go the Blender route by making an UI that's equally unintuitive and incomprehensible to everyone, be they Mac, Windows, KDE or Gnome users ;).

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    22. Re:They're good.. now.. by DrXym · · Score: 1
      How is that not true of any other language or platform in existence? The problem with those other choices you mention is that they introduce platform dependencies, rendering Java non-cross platform and essentially eliminating any reason to use it all. If Swing were an acceptable speed this would not be an issue, but performance is really, really poor.

      I know there all kinds of rationale for cross-platform UIs, but Sun really, really need to fix Swing or deprecate it for SWT or something else. The thing is a frigging albatross when developing desktop Java apps.

    23. Re:They're good.. now.. by DrXym · · Score: 1
      I haven't tried .NET 2.0, but one of the few good things you can say about VS .NET 2003/2002 is that it is incredibly easy and fast to knock together a form. Trying to do the same for Java can be an exercise in frustration. On the downside, .NET doesn't have (until 2.0) layout models, so resizing must be coded manually and there are probably issues with theme engines / cross platform too.

      Even after 5 years of Java development, I haven't seen a visual designer which I would describe as any better than tolerable. Currently I'm using VE in Eclipse. For the most part it works okay but sometimes it just destroys your form making it essential to maintain backups. On top of that, I don't like that when you you switch from one layout model to another that it royally screws up the constraints it uses.

    24. Re:They're good.. now.. by Mr.+Shiny+And+New · · Score: 1

      Well, CPU usage isn't the only metric we've used to measure performance, however our experiment is pretty simple: we have our application deployed on a production web-server, under normal load. We measure CPU usage and keep track of GC logs (this is a JVM feature). Then we switch to Java 1.5 and run the app again. The app is doing the same work but has lower CPU usage. Memory usage is pretty constant for both scenarios; the JVM is configured to GC whenever its various memory zones reach a certain percentage of used memory. We've also experimented with alternate GC algorithms that ship with the JVM. Experience has shown that our site's performance drops when the CPU load on the server reaches a certain level; the new JVM keeps the CPU load down for a larger percentage of the time.

      You're right in saying that it's possible our app is waiting for hardware, or something, proportinatly more of the time now that we have Java 1.5, but that's because there's a database involved, it's a separate task to optimize that, and a separate discussion. In truth though, our servers are actually under-utilized now that we are running Java 1.5 because our database is back to being the biggest bottleneck; previously due to poor memory usage, bad GC, and leaks in the application server, the java servers were the bottleneck so we added more of them. Since we've profiled the app, fixed the application server, and switched to Java 1.5, that particular bottleneck is cleared.

    25. Re:They're good.. now.. by CoughDropAddict · · Score: 1

      Just goes to show that even if you have a great technical product you'll still need the marketdriods.

      No, if you've got a great technical product, you need a great technical demo to show it off.

      What does Java have to show itself off on the desktop? Eclipse. Eclipse has a bunch of nice features, but its performance is a joke.

      If Java is so fast, where are the popular Java desktop applications that feel snappy? Java advocates brag about the JIT, but the cost of a JIT is running the compiler at runtime. Java is perceived as being slow largely because it is so slow to start up, and largely because it takes up so much memory, which leads to lots of swapping.

    26. Re:They're good.. now.. by fcgreg · · Score: 1

      If Java is so fast, where are the popular Java desktop applications that feel snappy?

      *beep* *beep* *beep* Breaking News Alert:
      "This just in: ... Benchmarks have been redesigned with ground-breaking new criteria: The 'Snappy-ness factor'. Details at 11:00 ..."



      Java is perceived as being slow largely because it is so slow to start up, and largely because it takes up so much memory, which leads to lots of swapping.

      The above statement is so generalized that it isn't worth debating. How long must we endure these specious, unfounded, tired, old statements?

      The techno-groundhog just stuck his head out of his hole, and the results aren't good. I'm afraid we're in for another stretch of winter mired in blindness. It must be all the snow...

      --
      Greg T.
    27. Re:They're good.. now.. by CoughDropAddict · · Score: 1
      *beep* *beep* *beep* Breaking News Alert:
      "This just in: ... Benchmarks have been redesigned with ground-breaking new criteria: The 'Snappy-ness factor'. Details at 11:00 ..."


      Umm, it's called latency. You can define that as "the amount of time I wait for Java to notice that I pushed a button in Swing and actually do something about it."

      Java is perceived as being slow largely because it is so slow to start up, and largely because it takes up so much memory, which leads to lots of swapping.

      The above statement is so generalized that it isn't worth debating. How long must we endure these specious, unfounded, tired, old statements?

      Are you really in such denial that you can't even acknowledge that there is truth to these facts?

      $ time ./hello
      Hello, world!

      real 0m0.041s
      user 0m0.001s
      sys 0m0.007s
      $ time ruby hello.rb
      Hello, world!

      real 0m0.064s
      user 0m0.011s
      sys 0m0.010s
      $ time java Hello
      Hello, world!

      real 0m0.590s
      user 0m0.225s
      sys 0m0.137s

      That's the sound of your favorite language getting spanked by an interpreted language. The Ruby wasn't even byte-code compiled -- it loaded the interpreter, parsed the source file, executed the entire program, then went to go get a cup of coffee waiting for your pre-compiled class file to reach line 1 of public static void main().

      Maybe you think this is some constant overhead that isn't significant in large programs. That's why I brought up the Eclipse example. Its startup time is a joke.

      Do you know what a JIT is? It's a compiler that runs at runtime. "Java runs so fast because of JIT" is one side of the coin, "Java starts slow as shit because it loads and runs the compiler at runtime" is the other.

      Respectable Java programmers at least acknowledge that the price they pay for the platform-independence of the JVM is increased memory usage and startup time. Idiots like you aren't even aware the tradeoff exists.
    28. Re:They're good.. now.. by fcgreg · · Score: 1
      Boy oh boy... we're already to the name-calling stage, are we? I'll maintain my demeanor and not drop to your level. Furthermore, since you finally attempt to quantify some of your previous statements, I can finally address something real.

      (CoughDropAddict) Java is perceived as being slow largely because it is so slow to start up, and largely because it takes up so much memory, which leads to lots of swapping.

      (FCGreg) The above statement is so generalized that it isn't worth debating. How long must we endure these specious, unfounded, tired, old statements?

      (CoughDropAddict) Are you really in such denial that you can't even acknowledge that there is truth to these facts?

      --

      "FACTS" you say? Until this recent post, you hadn't provided any evidence to support your statement AT ALL. Furthermore, your statements were entirely subjective. I'll address:

      • "[Java] takes up so much memory": How much is "so much", hmmm? I find that just a LITTLE BIT hard to quantify in literal terms. What is our comparison matrix? If you're going to bash Java with tired arguments, please at least do us the favor of spending some time backing them up in the first place. Then I could have responded to some substance right from the start, instead of drawing it out from you like I did (which was the entire point of my original post). Moving on...
      • "... which leads to a lot of swapping": Swapping??? What in the world does swapping have to do with Java itself? I could edit large images in GIMP and cause "swapping", but that would HARDLY be cause to say that C/C++ is bloated and causes "lots of swapping". See my point?

        Swapping is ENTIRELY a function of the operating system, dependent on many factors, such as oh, let's see, the available amount of RAM on the machine.

        Java, like any other language, is capable of writing programs that are very large and consume much memory. However, it is perfectly normal to write Java programs that do NOT consume substantial amounts of RAM compared to similar programs in other languages. Again, my point is that we can't even discuss this properly without being able to quantify it adequately.
      • "[Java] is so slow to start up": Again, my point is that "slow" is subjective. Compared to what? C/C++? Again, we have to quantify this. I readily admit that a well-designed, well-written C/C++ application will usually begin user-level program execution faster than it's cold-started, stand-alone Java counterpart (i.e., when no VM is already running, starting from "cold"). In such an instance there is no bytecode interpretation to do from the now-native C/C++, no virtual machine to start, no classloader to initialize, etc. However, I see this more as a consequence of the user-space environment than Java itself. In other words, if the VM was already initialized this comparison falls apart (J2EE, for example) -- it generally only holds true for Java desktop applications in the default environment configuration.

        To recap, had you said "Java desktop applications are usually slow to start in their own, newly instantiated JVM", I would have dismissed the subjective "slow" and just granted you the point for the sake of discussion.

      Moving on to the rest of your post today...

      (CoughDropAddict) That's the sound of your favorite language getting spanked by an interpreted language. The Ruby wasn't even byte-code compiled -- it loaded the interpreter, parsed the source file, executed the entire program, then went to go get a cup of coffee waiting for your pre-compiled class file to reach line 1 of public static void main().

      Please point out in my original post where I indicated that a HelloWorld in Ruby would execute more

      --
      Greg T.
    29. Re:They're good.. now.. by CoughDropAddict · · Score: 1

      Boy oh boy... we're already to the name-calling stage, are we?

      Sorry, but you can't pretend to be on the high ground. The only reason I had so much fun ripping into you is because your post was so condescending. There's nothing more amusing that someone who is condescending and wrong, and I have no moral qualms with mocking such behavior.

      I'm not really interested in going line-by-line on waffling like "OK, maybe you're right that Java starts up slowly when you actually load the JVM" or "I never said the Java doesn't take more memory." You think my statements are too general? That's because they're the general experience I've had every single time I've ever used Java.

      You Java people keep saying "Java's way better now! Anyone who says different is stuck in the past!" Java is no more compelling than it was 5 years ago. It's still a reasonable choice on the server where you have long-running processes on beefy boxes (this is pretty clearly the main use case that the standard JVM was optimized for). It's still not particularly useful for desktop applications.

    30. Re:They're good.. now.. by fcgreg · · Score: 1
      (CoughDropAddict) Sorry, but you can't pretend to be on the high ground. The only reason I had so much fun ripping into you is because your post was so condescending. ... and I have no moral qualms with mocking such behavior.

      Mock all you want. It is your right in an environment of free speech. It's really fine with me, as your own words do a much better job of illustrating the quality of your character than mine will probably do.

      My post didn't call you any names, and only made light of the fact that you were using tired statements against Java while giving no supporting evidence. Just because you realize you're in a bad light now, don't pretend I'm in the same hole with you.


      (CoughDropAddict) I'm not really interested in going line-by-line ...

      It's OK. I didn't think you would. I've poked some serious holes in your original, generalized statements. I've also spent considerable time addressing your concerns outlined in your follow-up post. Now that things have started to fall apart for you, I guess it's time to go now.


      (CoughDropAddict) ...on waffling like "OK, maybe you're right that Java starts up slowly when you actually load the JVM"

      Sorry, but I'm not going to let you get away with that. I never said that statement, and it's wrong for you to quote it (especially with quotes) as you have.

      To address your underlying point: - For starters, there was NO waffling. I did NOT intone that such a "maybe" ever existed. It is absolutely for-certain that if you're loading an entire virtual machine instead of a natively compiled application there WILL BE initial overhead and increased startup time if the JVM is not already running. Please, if you're going to attempt to argue with me, at least put some forth some solid effort -- it only takes me one or two clicks to see EXACTLY what I did and did not say.


      (CoughDropAddict) ... or "I never said the Java doesn't take more memory."

      And it is true. I had not said, nor did I say in my subsequent posts, that Java doesn't require increased memory usage over a natively compiled, comparable, well-designed, and well-written application. I outlined this in-depth... if you want me to do it again please point out your specific point of confusion.


      (CoughDropAddict) You Java people keep saying "Java's way better now! Anyone who says different is stuck in the past!" Java is no more compelling than it was 5 years ago.

      At least you got this correct. I think that any reasonable, well-informed person would agree that Java is much better today than 5 years ago. I also agree that anyone that doesn't realize this MUST be stuck in the past, as one cannot do an objective comparison of Java now and Java 5 years ago and NOT come up with that conclusion.

      Good day to you.

      --
      Greg T.
    31. Re:They're good.. now.. by CoughDropAddict · · Score: 1

      Mock all you want.

      Thanks, I'm having fun!

      My post didn't call you any names, and only made light of the fact that you were using tired statements against Java while giving no supporting evidence.

      I love the assumption here: that there's some threshold of decency whereby calling you an "idiot" is in a whole different league than more minor insults like "*beep* *beep* *beep* Breaking News Alert."

      It's OK. I didn't think you would. I've poked some serious holes in your original, generalized statements.

      What are you talking about? You've granted almost all of my original statements. That's why line-by-line would have been so boring. Let's take a trip down memory lane.

      (me) Java is perceived as being slow largely because it is so slow to start up...

      (you) I readily admit that a well-designed, well-written C/C++ application will usually begin user-level program execution faster than it's cold-started, stand-alone Java counterpart (i.e., when no VM is already running, starting from "cold").

      So we agree that Java is slow to start up -- when no VM is already running (and I have never encountered a situation where a new program joins a running VM -- it's just not common use).

      Oh, and all those qualifiers ("well-designed", well-written", "usually") is the waffling I'm talking about. Only in a diabolical example will Java beat C or C++ to user code for comparable applications. It's not like it's some special case.

      (me) ...and largely because it takes up so much memory

      (you) I never said that Java didn't require increased memory usage.

      So we agree that Java takes up more memory. Your rebuttal was "How much is "so much", hmmm?" The answer is "enough to be a problem, in my experience."

      So we couldn't agree about swapping. I would modify that statement a bit anyway. I would surmise that the disk churn associated with Java is a combination of loading the JVM, performing JIT compilation, and sometimes swapping. Who knows exactly, I haven't studied it in depth. I know what I need to know: the disk churn exists, and it makes Java inferior to other solutions for desktop applications.

      That's why I brought up the "technology demo" concept. If Java is as awesome as you think it is, some Java fan should write a reasonable Java desktop application that doesn't have disk churn or suck-ass latency. Your arguments about Java ring hollow when Eclipse, the shining star of the Java universe, reinforces nearly all the "specious, unfounded, tired, old statements" you complain about. Its one credit is that is finally uses native widgets instead of Swing.

      At least you got this correct. I think that any reasonable, well-informed person would agree that Java is much better today than 5 years ago. I also agree that anyone that doesn't realize this MUST be stuck in the past, as one cannot do an objective comparison of Java now and Java 5 years ago and NOT come up with that conclusion.

      Weren't you just complaining about unsubstantiated statements? It's ok, I don't expect you to be consistent. (ooh, I'm not calling you names, am I on the high ground now too?)

    32. Re:They're good.. now.. by fcgreg · · Score: 1

      By all means, please continue posting rebuttals that entirely ignore the majority of my points made -- in particular the ones that hurt your argument the most.

      Much of what you just posted doesn't even bear proper context to the discussion. It's like you're just making stuff up as you go at this point. Example:

      (CoughDropAddict): What are you talking about? You've granted almost all of my original statements. That's why line-by-line would have been so boring. Let's take a trip down memory lane.

      You then proceed to discuss two of the minor points I made in about 10. And then you only cover about 10% of those minor points. Then you ignore the rest. Is this supposed to be convincing?


      (CoughDropAddict): I love the assumption here: that there's some threshold of decency whereby calling you an "idiot" is in a whole different league than more minor insults like "*beep* *beep* *beep* Breaking News Alert."

      Boy, thanks. I don't think I need to even respond to that one. LOL


      (CoughDropAddict): So we couldn't agree about swapping. ...

      Couldn't agree? Your swapping statement didn't even apply to Java itself, and made the specious assumption that all Java apps "lead[s] to lots of swapping". Many folks these days have enough RAM to never swap out memory AT ALL , regardless of what desktop applications they run.

      (CoughDropAddict): I would modify that statement a bit anyway.

      I should hope you would!


      (CoughDropAddict): You Java people keep saying "Java's way better now! Anyone who says different is stuck in the past!" Java is no more compelling than it was 5 years ago.
      (FCGreg): At least you got this correct. I think that any reasonable, well-informed person would agree that Java is much better today than 5 years ago. I also agree that anyone that doesn't realize this MUST be stuck in the past, as one cannot do an objective comparison of Java now and Java 5 years ago and NOT come up with that conclusion.
      (CoughDropAddict): Weren't you just complaining about unsubstantiated statements? It's ok, I don't expect you to be consistent.

      Huh? I'm not even sure what you're talking about in the last comment. My comments about "unsubstantiated statements" had nothing to do with what you quoted AT ALL. It wasn't even related. And then you (of all people) say it's inconsistent somehow? Inconsistent with what?

      OK, I think it's clear to anyone still following this where we both stand. Since that's all I can expect at this point, I think my work here is done.

      --
      Greg T.
  9. BULLONEY!! by Anonymous Coward · · Score: 3, Insightful

    These articles keep popping up flatly stating that Java's slowness is a myth. But, no matter how many times you say it is a myth and how hard you try to create a new perception, the FACT is that people's real-world experience, no matter how anecdotal, consistently demonstrates that Java is MASSIVELY slow than similar apps in C or C++.

    Java is slower. Don't even get me started on C#.

    1. Re:BULLONEY!! by Anonymous Coward · · Score: 0

      Very true. I'm also tired of hearing this "it's a myth" and hearing my java friends drone on about how uneducated in java I am. Fact is, every Java program I've run has been slower than any non-java app (that I run). Sure, it has improved a lot, but the slowness isn't a myth.

      The first step is to admit you have a problem.

    2. Re:BULLONEY!! by HeaththeGreat · · Score: 4, Interesting

      What Java apps are you talking about?

      There aren't many professional-grade Java Desktop apps out there, and those that _are_ out there are generally built for maintainability, not speed (Eclipse, Netbeans). I built a Java web client that blew the pants off its older C++ version. The reason Java apps are generally slower is because the Java culture is about maintainence over performance.

    3. Re:BULLONEY!! by Anonymous Coward · · Score: 0

      Are there any large Open Source java programs that are built for speed?

      Why can't Java programs be built for speed and maintainability like every major C++ app I use?

      I honestly have nothing against Java, and I have used it many times - I just don't think you can deny the fact that its slow - which is OK.

    4. Re:BULLONEY!! by pla · · Score: 5, Interesting

      Don't even get me started on C#.

      I should hope not! Any form of benchmarking of Microsoft's .Net violates the EULA. And we wouldn't want that!

      So when Microsoft declares their interpreted inverse-polyglotic language as "faster" than compiled pure C, just accept it. Best for everyone that way.


      the FACT is that people's real-world experience, no matter how anecdotal, consistently demonstrates that Java is MASSIVELY slow than similar apps in C or C++.

      Well, the linked article contained a number of what I will graciously call "assumptions" (rather than "outright lies") about allocation patterns in C/C++ that simply don't hold true in most cases.

      For example, the parent mentions the old "stack or heap" question... Which no serious C coder would ask. Use the heap only when something won't fit on the stack. Why? The stack comes for "free" in C. If you need to store something too large, you need the heap. But then, you can allocate it once, and don't even consider freeing it until you finish with it (generational garbage collection? Survival time? Gimme a break - It survives until I tell it to go away!). As for recursion... You can blow the stack that way, but a good programmer will either flatten the recursion, or cap its depth.


      And the article dares to justify its "assuptions" by comparing Java against a language interpreter such as Perl. Not exactly a fair comparison - Yes, Perl counts as "real-world", but in an interpreter, you can't know ahead of time anything about your memory requirements. At best, you can cap them and dump the interpreted program if it gets too greedy. Now, some might point out that Java gets interpreted as well - And I'll readily admit that, for doing so, it does a damn fine job with its garbage collection. But if you want to compare Java to Perl, then do so. Don't try to sneak in a comparison to C with a layer of indirection.


      One last point - The article mentions that you no longer need to use object pooling. SURE you no longer need it - Java does it implicitly at startup. You can avoid all but a single malloc/free pair in C as well, if you just steal half the system's memory in main(). Sometimes that even counts as a good choice - I've used it myself, with the important caveat that I've done so when appropriate. Not always. I don't have malloc() as the second and free() as the second-to-last statements in every program I write. And that most definitely shows in the minimal memory footprints attainable between the two languages... Try writing a Java program that eats less than 32k.

    5. Re:BULLONEY!! by msormune · · Score: 1

      No, you are still not getting the picture. The question is not whether Java is slower or faster than native C. The question is: Is it so slow that it actually matters? I guess you think you can justify your case by saying Java is "MASSIVELY slow". But if allocation of memory and deallocation is 10 times slower in Java than in C, does it still matter?

    6. Re:BULLONEY!! by LarsWestergren · · Score: 3, Informative

      The stack comes for "free" in C. If you need to store something too large, you need the heap. But then, you can allocate it once, and don't even consider freeing it until you finish with it

      Or NOT consider freeing it when you forget about it... as the case may be.

      Try writing a Java program that eats less than 32k.

      No problem at all.

      --

      Being bitter is drinking poison and hoping someone else will die

    7. Re:BULLONEY!! by Anonymous Coward · · Score: 0
      TFA refers to memory allocation/deallocation performance, not overall performance.

      Summary: certainly Java is slower than C. But it's not because it uses garbage colletion.

    8. Re:BULLONEY!! by Anonymous Coward · · Score: 0


      Yes, let's compare apples and oranges and mark it informative.

      Dipshit.

    9. Re:BULLONEY!! by pla · · Score: 4, Insightful

      Or NOT consider freeing it when you forget about it...

      Programming takes some level of skill.

      If you "forget" to increment a pointer, it won't have advanced the next time you use it. If you forget to open a file, assuming your program doesn't crash, anything you write to it goes to the bit bucket.

      If you forget a wife' birthday, you'll have a pissed-off wife.



      "Try writing a Java program that eats less than 32k."
      No problem at all.

      Uh-huh... Now do the same thing without needing a special, stripped-down, nearly featureless JRE. I don't need a special build of GCC to satisfy the condition, why did we shift from apples to oranges to make it possible in the Java world?



      And most of these points end up exatly there - Apples and oranges. Java can do better than a few worst-case scenarios in C. Java can fit in a sane amount of memory with special builds. Java can outperform C by-way-of Perl. All nice claims, but self delusion doesn't make for better programmers.

    10. Re:BULLONEY!! by Ray+Alloc · · Score: 1, Interesting

      Well, as my own "real life experience" is concerned, programming in Java is a lot simpler, faster and less prone to bugs than programming in C++.
      In addition, I bear witness that Java applications are faster than C++ applications.
      I still use C (NOT C++) for simple, host system-level tasks, though, as it is a good system-level language (heck, *nix are C-based, after all)
      In short : I concur with the submitter.

    11. Re:BULLONEY!! by gaj · · Score: 5, Insightful

      It's not really apples to oranges to use a smaller profile JRE for creating smaller profile programs. The JRE includes libraries and features such as threading and such. Let's see you build a C program that uses pthreads and one or two major libraries and still have your memory use come in under 32K. Remember, apples to apples, right?

    12. Re:BULLONEY!! by Anonymous Coward · · Score: 0

      Not to be nitpicky, but the link only rates the KVM as performant down to 128K of memory. Not 32K.

    13. Re:BULLONEY!! by earthbound+kid · · Score: 4, Insightful

      Programming takes some level of skill.

      If you "forget" to increment a pointer, it won't have advanced the next time you use it. If you forget to open a file, assuming your program doesn't crash, anything you write to it goes to the bit bucket.

      If you forget a wife' birthday, you'll have a pissed-off wife.

      I'm not about to forget my girlfriend's birthday, because my computer warns me about it three days ahead of time. Similarly, why should we risk forgetting to deallocate stuff from the heap, when we can have the computer do it itself? Yes, programming takes some skill. But we shouldn't start programming using only our thumbs while dangling over a pit of lava, just to up the skill factor needlessly. If we're going to do something more difficult, we need to get a benefit for it. The benefit of not using a garbage collecting language is that your code will probably be slightly faster than the equivalent code in a GC language. But, is that slight performance increase worth the pain in the ass of doing it the manly way? In most cases, not really. But hey, judge for yourself: find the best language for your particular job and forget the rest.
    14. Re:BULLONEY!! by m50d · · Score: 1
      There aren't many professional-grade Java Desktop apps out there, and those that _are_ out there are generally built for maintainability, not speed (Eclipse, Netbeans). I built a Java web client that blew the pants off its older C++ version. The reason Java apps are generally slower is because the Java culture is about maintainence over performance.

      The python culture is about readability and maintainability over performance, and python programs still perform far better than Java ones. Specific example: eric3, which is closer to a full-fledged IDE in terms of features, starts far faster and is far more responsive than jedit. Java is just horribly slow.

      --
      I am trolling
    15. Re:BULLONEY!! by LarsWestergren · · Score: 1

      >>Or NOT consider freeing it when you forget about it...

      >Programming takes some level of skill.


      Yes yes, you are a big man. Go fix those memory leaks that have been with us in Mozilla for years if you think it is so damn easy. No really, I mean it. I would be grateful.

      --

      Being bitter is drinking poison and hoping someone else will die

    16. Re:BULLONEY!! by Q2Serpent · · Score: 1

      You can have both!

      In fact, I argue that when you take the time to write maintainable C or C++ code (which isn't much more time that throwing crap together), you AUTOMATICALLY get to a point where memory allocation becomes second nature.

      With a well-structured program with separate modules and a functional API, allocation and deallocation just fit right in. There's rarely a case where you forget to clean up memory, just like with proper structure, you rarely forget to close a file. It's the same problem, and it has the same solution, but in C/C++, I get performance and a lower memory footprint out of it too.

      Maintainable code and performance are not mutually exclusive.

    17. Re:BULLONEY!! by Skye16 · · Score: 1

      It's only a pain in the ass until you get used to it. Like typing.

    18. Re:BULLONEY!! by ninejaguar · · Score: 1
      Uh-huh... Now do the same thing without needing a special, stripped-down, nearly featureless JRE. I don't need a special build of GCC to satisfy the condition, why did we shift from apples to oranges to make it possible in the Java world?

      Because, Java has had a special purpose since its inception - to be cross-platform without code changes. The Java Runtime Environment is something like an Operating System - more accurately, an Operating Environment that can run on multiple Operating Systems. Or, it can be an Operating System on its own if implemented that way.

      C is executed by the Operating System. Java is executed by the JRE - Operating Environment. GCC is a compiler. JRE is a byte-code interpreter. Now who's talking apples and oranges?

      A more accurate comparison would be running a C program under an Operating System (mostly written in C) and a Java programming running under an Operating System/Environment (mostly written in C or in Java). I wouldn't know the purpose for it... but, it would've been apples to apples. GCC != JRE.

      The next stipulation you'll demand is that Java should operate without hardware.

      = 9J =

    19. Re:BULLONEY!! by KarmaMB84 · · Score: 1

      Maybe your C++ code was ass?

    20. Re:BULLONEY!! by sjasja · · Score: 2, Insightful

      > And the article dares to justify its "assuptions" by
      > comparing Java against a language interpreter such as Perl.

      Err... what? The article mentions Perl once, as an example of a C application.

      The article says if you run that particular application you'll find that it spends 20-30% of its time in malloc() and free(). The points being that allocation speed matters in real applications, and that malloc+free is pretty slow.

      > Try writing a Java program that eats less than 32k.

      Lots of cell phone games manage to do this.

    21. Re:BULLONEY!! by innot · · Score: 1

      There aren't many professional-grade Java Desktop apps out there, and those that _are_ out there are generally built for maintainability, not speed (Eclipse, Netbeans).

      There might not be many desktop apps out yet, but I have seen at least one very impressive - and fast application that really shows what Java can do these days.

      It is an (inhouse) application developed by the DWD (Deutscher Wetterdienst = German Weather Service) to visualize raw weather data. It can project all past and current met-data as well as the output of their forecast models onto any map with color gradients or all other kinds of visual representations meterologist like.

      The demonstration was on a normal laptop (with lots of RAM of course) and it took maybe 1-5 seconds to generate a map (e.g. current European temperature gradiants with high level wind vectors or a combined North Atlantic temperature / humidity forecast chart at 10.000ft altitude - all with a few clicks and generated in seconds).
      The only thing not real-life about this demonstration was that all databases were stored locally on the laptop as it did not have a network connection.

      This shows that Java also has a future for handling large amounts of data at great speed like data mining and visualisation applications.

      --
      X IMPRIMITE "SALVE TERRA!"
      XX ITE AD X
    22. Re:BULLONEY!! by hobo+sapiens · · Score: 1

      Man, isn't that the truth?!?

      I read the article and was amused that it focused on how much work (i.e. system processes) memory allocation required in C and Java. Maybe Java doesn't have to work as hard to allocate memory. Looking solely at memory allocation is not a true indicator. Maybe it is a problem with the people developing Java apps. Maybe development methodologies are at fault. In the end it doesn't matter. People hate slow apps and nobody cares why an app is slow. And Java apps are slower. That certainly has been my experience. And not just my experience, but that of most people, else the article would have never been written. How come every Java application I have ever used (even the fabulous jEdit) is considerably slower?

      Don't even get me started on how you can always tell a Java app by it's clunky look and feel!

      Having said all of that, I have been hearing a lot about Python these days. I wonder how long it will be until we start seeing Python apps where Java apps formerly were? It could happen!

      --
      blah blah blah
    23. Re:BULLONEY!! by Matt+Perry · · Score: 1
      And the article dares to justify its "assuptions" by comparing Java against a language interpreter such as Perl.
      Actually, perl compiles the program into bytecode and then executes just like Java does. So I would call it a fair comparison.
      --
      Slashdot: Failed Car Analogies. Amateur Lawyering. Anecdote Battles.
    24. Re:BULLONEY!! by Xyrus · · Score: 1

      "Try writing a Java program that eats less than 32k."
      "No problem at all. (link)"

      Hmmmm......

      First, lets compare apples to apples. J2ME was not designed to write programs for PCs. That's what Java is for. J2ME was written for embedded/limited systems.

      That being said, you still can't write a Java program that uses less than 32 KB. And that info comes straight from your link.

      #Reduced VM Size - the K virtual machine is currently only 50-80 K of object code in its standard #configuration, depending on target platform and compilation options.

      Alright, you already have 50-80K gone. There goes that 32KB limit.

      # Reduced Memory utilization - In addition to the K virtual machine's small object size, it requires #only a few tens of kilobytes of dynamic memory to run effectively. Because of the reduced VM size and #memory utilization, even with total memory available of only 128K the K virtual machine enables useful #Java technology-based applications to run on a device.

      I gather from this, you'll need about 128KB of memory.

      And you haven't written a single line of code yet.

      Plus, it seems you need to have at least a semi-powerful CPU to run the thing (25MHz 16-bit is the example from the link).

      Now as a comparison, I've written apps and even whole games in 32KB or less on PCs and limited systems. The original gameboy, for example, had a 1.05MHz processor 4KB dedicated RAM (with another 7 banks of switchable 4KB blocks). The processor was a stripped down Z80 CPU.

      Java has it's place, along with J2ME. But it's not in writing tight fast code when system resources are limited or in situations where every cycle of performance matters.

      Remember, with Java you still have the overhead of a virtual machine. And that counts towards program and resource size (sometimes, significantly).

      ~X~

      --
      ~X~
    25. Re:BULLONEY!! by Chagrin · · Score: 1

      The K Virtual Machine doc you linked to states that the minimum is 50K for the interpreter.

      --

      I/O Error G-17: Aborting Installation

    26. Re:BULLONEY!! by dubl-u · · Score: 1

      Try writing a Java program that eats less than 32k.

      Why would that ever matter? Other than when doing embedded work, I can't remember the last time that that 32k mattered to me. I just bought some RAM yesterday, and 32k of that RAM cost me about 0.4 cents.

      My current computer has 250,000 times the RAM my first computer did 25 years ago. My allowance that week was $10; if my salary had scaled similarly I'd be making $130 million a year, more than most Fortune 500 CEOs. That's no excuse for needless waste, but I can't take my money or my RAM with me, so I might as well enjoy it while I'm here.

    27. Re:BULLONEY!! by aaronl · · Score: 1

      No cell phone games written in Java do this. I can quite confidently state this, as Sun says it will take more than that just for the JRE. See any number of other comments around this post. Go read teh J2ME docs.

      malloc and free can be pretty slow if you do it wrong. You can also write your program so that it isn't a performance issue. The same thing can be pretty slow in any language. No surprise that poor coding skills equal poor applications. You can also cherry-pick your apps to give you the numbers you want. PERL and GhostScript are interpreters; it is no surprise that they spend a lot of time doing memory management.

      They could've also mentioned Java as a C application, but they didn't, because that would've defeated that point. Just because one app doesn't run well doesn't mean that all C apps will do the same.

    28. Re:BULLONEY!! by Anonymous Coward · · Score: 0

      It's only a pain in the ass until you get used to it. Like typing.

      Or anal sex.

    29. Re:BULLONEY!! by Lost+Found · · Score: 0, Troll

      When the fuck did you assholes show up in my industry? You're the reason I have to wait *seconds* when I click links on many major websites (read: J2EE websites). We live in the age of cable modems and fiber to the fucking curb... I shouldn't be surfing at dialup speeds whenever I happen across one of these 'miracles of modern engineering'. "Slight" performance increase for doing it the manly way? Bullshit! Bullshit, bullshit, bullshit!

      Who the fuck is raising this generation to think that mediocrity is totally a-Okay, and that you shouldn't have to know anything about a computer to use (let alone program) it?

    30. Re:BULLONEY!! by Bloater · · Score: 1

      > Go fix those memory leaks that have been with us in Mozilla for years if you think it is so damn easy. No really, I mean it. I would be grateful.

      But mozilla doesn't leak any memory, when it exits it will garbage collect everything in one go. This is the same philosophy that java takes: let unused memory pile up and be wasted (ie leak) then reclaim it sometime later.

      GC is a memory leak. refcounting is the only non-leaky way to automatically free unused memory, and refcounting is really, really *hard* to do right without GC.

      C++ is the future.

    31. Re:BULLONEY!! by Anonymous Coward · · Score: 0

      You're stupid. The article is about memory allocation speed, not about overall application speed. Also, Python can never be as fast as Java because of its object model, etc.

    32. Re:BULLONEY!! by ctzan · · Score: 1

      No. That is utter nonsense. Perl doesn't use any bytecode at call. Perl executes scripts simply by 'walking' the syntax tree its yacc parser has built. Just like (n)awk or gawk (and unlike mawk).

    33. Re:BULLONEY!! by matfud · · Score: 2, Interesting

      And when resources get really tight C is no longer an appropriate language to use. Many microcontrollers have less then 128 bytes of ram to work in. Often the program has to be stored in less then 256 bytes of ROM. C does not cut it in those environments. Welcome to our assembler overlords. C also has to be cut down to run on these low end devices. floating point divisions, 32 bit mulitplications, 16 bit additions...well they are not supported. The J2ME IS cut down. However it does specify a basic set of operations you must implement on the chip (or emulate in a layer in software)

      "Remember, with Java you still have the overhead of a virtual machine. And that counts towards program and resource size (sometimes, significantly)."

      The processors I'm playiung with at the moment run java byte code natively. You would have to have a virtual machine to run C on them. Rememeber, C is only efficient in some situations because the bytecode (machine code) it produces maps directly to the platform it is running on. Java and other "interpreted" langauges are designed to run on a machine that you may not have, so generally they are run on an interpreter. That does not mean that a machine to run the code directly does not exist.

    34. Re:BULLONEY!! by Baki · · Score: 1

      Have you actually done benchmarks? I have, and in many cases the difference varies between -5% (i.e. java a bit faster than C++) and +30%, mostly C++ is about 10% faster than Java.

      So whie Java may be slower, it is not at all a order of magnitude slower, in most real world circumstances you won't notice the difference.

      By the way, I also benchmarked C# (1 year ago, it may have changed) and found C# to be somewhat slower than Java, again about 10% slower, in most cases. I have tried some basic algorithms and other CPU bound stuff, also allocating objects, manipulating strings, using in-memory "I/O" (memory buffers) etc. There may be differences in some of the standard libraries and/or GUI libraries (such as Swing/AWT which up to release of Java5 was not too fast, but in Java5 it has dramatically improved), but intrinsically Java really is in the same league as C++.

    35. Re:BULLONEY!! by gbjbaanb · · Score: 1

      The demonstration was on a normal laptop (with lots of RAM of course)

      I thought the article was about memory allocation and dealocation speeds in Java. Chuck so much RAM at the problem that it never needs to deallocate is hardly a good example of how Java is a fast language.

    36. Re:BULLONEY!! by Baki · · Score: 1

      that is not true. Python is much slower than Java, you must be comparing python to Java from 1999. As a performance and benchmark freak, I always benchmark any language I use. For example, Python is provable slower than Perl, except for some of the built-in (very good) API's which are very rich in Python. But doing basic non-API using stuff in python, such as the Sieve of Eratosthenes algorithm or other CPU intensive stuff, python is really a scripting language. Perl does some byte-compilation but also is an order of magnitute slower than truely compiled languages such as Java, C++ and C# (Java and C# being just-in-time compiled, which is about as good as compiled in advanced with todays technology, and theoretically could even outperform).

      The latter three are about 10% within each others range, most benchmarks I have done indicate C++ is fastest, Java about 0-30% slower, and C# about 10% slower than Java (C# tests done 1 year ago).
      All tests are library/API neutral, i.e. I did not test the speed of some C++ GUI toolkit such as Qt versus a Java GUI toolkit such as AWT/Swing, but only tested pure language features and "core" stuff.

      Claiming that python, clearly an order of magnitude slower than compiled languages, is faster than Java is an absolute joke and proves that you have never done or read some serious benchmarks.

    37. Re:BULLONEY!! by LnxAddct · · Score: 1

      I'm a huge python fan, but what you stated is blatantly false. Python is around 700 times slower than java, on a good day. Perl is around 95 times slower than java. For any gui related work though you'd never know it, the "responsivess" of an application depends on the gui toolkit. In java , just don't use swing if you want an app that feels fast. Use SWT or GTK, its quite simple. Gui applications do things in discrete steps, so a python app can feel as fast as a java app because nothing is usually happening for more than a few milliseconds. Implementing any heavy performance servers or just about anything else that requires heavy duty calculations (like 100 million calculations per second) you just can't do in python. I use python all the time, but don't be naive and look past its limitations. It may also be worth noting that the fastest database on the market right now is written in java (I'm sure others will argue, and there are many variables to take into account, but from a raw performance view in general use it almost always beats out the competition)
      Regards,
      Steve

    38. Re:BULLONEY!! by Anonymous Coward · · Score: 0

      You are a fucking idiot. J2EE apps are certainly slow, but ONLY THE FIRST TIME A PERSON CLICKS THE LINK, which is when your view components get compiled. After that, no compiling happens, and everything is nice and fast. Apparently you are the most unlucky bastard in the world, always being the first person to visit a site after it gets started...

      By the way, I am a J2EE developer on a rather large government project, and the only performance issues we have are with some of our legacy Cold Fusion shit.

      Take your preconvienced notions from the first 5 years of Java, and shove them up your willfully ignorant ass.

    39. Re:BULLONEY!! by Anonymous Coward · · Score: 0

      The reason Java apps are generally slower is because the Java culture is about maintainence over performance.

      Why don't you switch to functional languages? Object orientation generally falls right out of the typing system and they're often faster than Java while being more powerful.

    40. Re:BULLONEY!! by wft_rtfa · · Score: 1

      Don't forget that Java is also about ease of use. If I'm writting a light desktop app that will be used by lots and lots of people, I might go with C/C++ for performance reasons.
      But, I my boss tells me he needs a program that reads some data from a database and creates some file output or some everyday programming task, I'm not going to waste my time using C/C++ when Java or C# will work just fine.

      --
      :-] :0 :-> :-| :->
    41. Re:BULLONEY!! by jma05 · · Score: 2, Insightful

      No! Python (or Ruby or Perl) programs run FASTER than Java programs. That's despite pure Python being much slower than pure Java. Don't focus too much on benchmarks. They don't give a big picture. Python IDEs ARE MORE RESPONSIVE than Java IDEs. Take a look yourself.

      That's because much of the cycles in a Python app are spent in optimized native code rather than in Python's byte code.

      All Python GUI apps are faster because they are wrappers around fast C/C++ toolkits rather than pure byte code like Swing. If someone were to reimplement Swing in Python without using an external toolkit, it will no doubt be slow. But that is not the culture in Python. Same goes for most programming in Python. In fact, almost as a rule, anything where performance matters for Python apps, you have a C extension.

      There is an advantage to Java's approach. Pack everything into a jar and it will run anywhere. With Python, I will have into seperately ensure that wxPython, numarray etc are installed for each platform since they are native extensions. However I never had a problem with that since they are available for both the platforms I use (windows and Linux) easily. If you use an exotic platform, you will have compile for it.

      So while your code in Python will be portable, the dependencies are not always automatically. But I am happy with this trade off.

    42. Re:BULLONEY!! by 91degrees · · Score: 1

      But, no matter how many times you say it is a myth and how hard you try to create a new perception, the FACT is that people's real-world experience, no matter how anecdotal, consistently demonstrates that Java is MASSIVELY slow than similar apps in C or C++.

      I wonder if this could be because the faster coders write in C++. On average, C++ programmers are more experienced and a lot more likely to have written performance critical code. Some of the code I see from younger programmers is terrible in terms of efficiency. We have searches of stl vectors when a map would work so much better, no reuse of searched for values, and passing large structures as parameters when a const reference would work.

    43. Re:BULLONEY!! by Baki · · Score: 1

      So you take the responsiveness of an IDE as a measure for a language? That is nonsense.
      Indeed, Pythons GUI toolkit is implemented natively, and the default Java GUI toolkit is not. However, there are also native language bindings for Java GUI toolkits, and SWT is a hybrid solution.

      You are claiming that Python as glue + C as language to do the heavy work is faster than Java, and in that sense: yes. So in fact you're not comparing Java to Python, but Java to C. As I mentioned, Java is on average 0-30% slower than C++ (and C might be a bit more efficient these days, not much, than C++). However, surely there is not a significant (order of magnitude) difference between Java and C(++). Anyone who claims otherwise does not have up to date information and has probably last tried/benchmarked Java several years ago.

      I am a C++ and Java software engineer, working on very large projects for banking applications. We run Java (amongst others) on an MVS (IBM) mainframe, amongst others. As you might know, IBM mainframes are not bought, but paid per used CPU cycle! So we know damn well how efficient Java is. PL/1 is more efficient (it is also more efficient than C) but the difference is NOT significant. In complex programs Java often wins, because of its structure it is easier for programmers to keep track and create correct and efficient solutions. It is the same old story as assembly in theory being more efficient than C, but often resulting in less efficient solutions because for all but small applications it is very hard for a human to come to a good solution.

      Nowadays, all new software in our industry is written in Java (at least in the banking industry in europe), because it is the most economic thing for several reasons, a.o. a good trade off in run-time performance and ease of programming and safety.

    44. Re:BULLONEY!! by Xyrus · · Score: 1

      "And when resources get really tight C is no longer an appropriate language to use."

      Indeed.

      "C also has to be cut down to run on these low end devices. floating point divisions, 32 bit mulitplications, 16 bit additions...well they are not supported."

      That's misleading at best.

      That has nothing to do with the language, and everything to do with the compiler and linker for the platform. In the end, you wind up with native CPU instructions. If the processor supports flops, then the compiler/linker will use flops. If the processor does not, then it will use whatever algorithm to replace the flop code with. That's the whole purpose of cross compilers such as gcc. It takes C code and compiles it for a given platform. If the platform doesn't support certain operations then those operations are replaced at compile time with whatever the platform needs to approximate/implement said feature.

      "The J2ME IS cut down. However it does specify a basic set of operations you must implement on the chip (or emulate in a layer in software)"

      I'm well aware of the fact that J2ME is cut down. I've written several games in J2ME. But you seem to be a little confused. J2ME has a bytcode spec, and several chip manufacturers follow the spec for J2ME microcontrollers but that is not native execution. The translation from bytcode to CPU instructions happens in hardware, which is fast to be sure but still is not native CPU code.

      "The processors I'm playing with at the moment run java byte code natively."

      No they don't. They have a "hardware JVM" for lack of a better term. The CPU is not running bytecode. None of the processor families I found doing a quick search have a J2ME bytcode based instruction set. Underneath, they are still running ARM, Fujitsu, etc. chips, which use their normal CPU instructions to execute.

      "You would have to have a virtual machine to run C on them."

      At first, I thought you were merely confused. Now it appears you don't know what you are talking about. C is compiled. Period. If you have a processor with instruction set A and you have a C compiler for that processor, after the program is compiled you have binary code consisting of instruction set A operands. C is not interpereted. C is not JIT. After compilation, you have a raw binary executable which will run on that processor.

      "Rememeber, C is only efficient in some situations because the bytecode (machine code) it produces maps directly to the platform it is running on."

      C is always "mapped" to the machine's native instruction set.

      Let's see if I can clear this up for you.

      Java, when compiled, produces bytecode. You know this. When you want to run a java program, you must have a JVM. You know this as well. The JVM takes the bytecode and translates this into the machines native CPU instructions. That translation happens at run-time. I think you know this. On PCs, the JVM is software, so the translation all happens in software.

      C, when compiled, produces native machine CPU instructions. That's it. There is no translation at run-time. There is no virtual machine. There is no bytecode. A compiled C program is a native executable.

      Bytecode and machine code are two different things.

      Bytecode allows for one to have portable compiled programs. For instance, you can take a compiled java program, bring it onto a machine of completely different architecture, and have it run as long as there is a JVM installed on that machine.

      If you try to take a C executable and bring it onto a machine of completely different architecture, it won't run at all. The only way to get the program to run is to take the original source, recompile it on the new machine, and then run the program.

      J2ME microcontrollers take the JVM one step further by taking a set of java bytecode instructions and embedding the translation to machine code in hardware. This results in a much faster JVM performance than the slower software JVMs found on general purpose computers. But there is still

      --
      ~X~
    45. Re:BULLONEY!! by Anonymous Coward · · Score: 0

      did you even read the article? on the whole, garbage collectors are faster than manual allocation / deallocation. the major disadvantage to garbage collection is its unpredictability, which becomes crucial in real-time applications.

    46. Re:BULLONEY!! by maraist · · Score: 1

      Even w/ a heavily loaded, highly generalized (multiple layers of generic filtering w/ database accessees, XSLT transforms) system I easily achieve 30 100 pages / second on a modern single core machine. And guess what, it's trivial to have a J2EE app cluster to a dozen or more machines; thereby almost linearly scaling. W/ the performance scaling you also get fail-over (assuming your DB and firewall don't die).

      It is very hard to write enterprise level applications in C or even perl/PHP that can cluster across multiple machines. There are enterprise-level concurrency considerations that are non trivial to solve, but are standard practice in J2EE environments... Yes there are enterprise libraries in perl and C, but most perl and C programmers don't know about them (I'm only aware of a few; and most of the time I keep my C/Perl apps stateless and non-transactional).

      So, now in comparison, your multi-second page load somehow seems out of sync w/ my 1/30th second page load.

      --
      -Michael
    47. Re:BULLONEY!! by maraist · · Score: 1

      ONLY THE FIRST TIME A PERSON CLICKS THE LINK
      Hehe.. You mean you don't have ant/maven pre-compile your JSP's? Or don't have servlets load-on-startup?

      Prior to convinient precompilation scripts I'd use a jython recorded script to hit all of my web pages in succession after each servlet restart.

      Granted, it takes me something like 10 seconds on a quad-processor to get tomcat up and running w/ spring, hibernate, etc. But the cool thing is that w/ clustering, I can firewall off one worker-node while I'm upgrading it; leaving another node running the old version. Course that only works if there are backwardly compatible DB changes (e.g. adding a new nullable column).

      --
      -Michael
    48. Re:BULLONEY!! by Lost+Found · · Score: 1

      If what you say is true, then you could probably make millions training the rest of the world how to write fast Java portals, because so far I've only heard of them - I've never actually seen one.

      By contrast, I have seen (on the far opposite end - Java disasters) an enterprise application that would have made the most rabid Java programmers cream their pants in terms of the sheer "architecture" to it all... yet, its only problem was that it took around *90 seconds* to answer a fucking query.

    49. Re:BULLONEY!! by Trejkaz · · Score: 1

      As a long-time fan of IntelliJ IDEA, I have to say that your claims are complete bullshit. IDEA is at least as responsive (and not to mention more featureful) as Visual Studio, and certainly as responsive as an IDE written in a scripting language.

      --
      Karma: It's all a bunch of tree-huggin' hippy crap!
    50. Re:BULLONEY!! by Anonymous Coward · · Score: 0

      you could probably make millions training the rest of the world how to write fast Java portals, because so far I've only heard of them - I've never actually seen one.

      Ever been to amazon.com?

    51. Re:BULLONEY!! by maraist · · Score: 1

      GC is a memory leak. refcounting is the only non-leaky way to automatically free unused memory, and refcounting is really, really *hard* to do right without GC.

      I'm slightly confused.. You sound like you know what you're talking about, but I feel this statement can be misleading to the uninformed.. ref-counting does NOT resolve memory leaks at all.. In fact it has a horrible memory leak built into it's design.. Namely self-referencing.

      a = new A
      b = new B
      a.child = b
      b.parent = a
      a = null
      b = null

      You'll never reclaim neither a nor b.

      Linked lists, trees, XML representations, etc. None of these are efficiently handled in Perl.. You have to perform explicit object destruction in perl (i.e. setting all refs to undef) which takes a LOT of overhead (you not have an interpreted garbage collector).

      So the problem w/ ref-counting is two fold:

      1'st as in the above, you suddenly have to be VERY conscious of the data structures you use, and more importantly inadvertant circular references.. Perl gets around this by making HEAVY use of symbolic references (those which don't affect the ref-counts). But this is very error prone.

      2'nd the mere process of assinging "a = c" in a behind-the-scenes ref-counting scheme can take over a second to complete. Why? Because if "a" was the only pointer to a deep tree of data nodes, then you have to physically perform a gc desctructor on each instance... BUT, you can't do them in a batch, because you don't yet know that the child nodes are about to be freed.. You have several round trips into the garbage collector.

      Compare issue 2 w/ a copying collector.. "a=c" will never cause a GC.. Depending on the GC implementation, it may still trigger a cleanup, but it will only be to get a stale reference of "b" from "a" to now point to null. Moreoever once you've orphaned the entire tree of nodes originated from "a" you perform zero work in "freeing" them.. You get free's for free (except when you explicitly delcare a finalizer; and even that can be completely ignored by the JVM).

      The main problem w/ copying GCs are that periodically you'll have to touch every allocation in your heap. This is very cache unfriendly, and very swapped-memory destructive.. It's painful to watch two competing JVM's that have each taxed more than 50% of system memory bring the machine to a state of uselessness (thanks to competing garbage collection).

      Alternatively incremental "train" mark-and-sweep collectors have to do almost as much work to free up objects as ref-counting (though they don't do it at the reference assignment; they do it at the malloc stage). Though mark-and-sweep can optimize the process by potentially using aggregated bit vectors instead of dispersed bits on each object scattered throughout the heap. Don't know which SUN's low-latency collector uses.

      --
      -Michael
    52. Re:BULLONEY!! by matfud · · Score: 1

      >That has nothing to do with the language, and everything to do with the compiler and linker for the platform. In the end, you wind
      >up with native CPU instructions. If the processor supports flops, then the compiler/linker will use flops. If the processor does
      >not, then it will use whatever algorithm to replace the flop code with. That's the whole purpose of cross compilers such as gcc. It
      >takes C code and compiles it for a given platform. If the platform doesn't support certain operations then those operations are
      >replaced at compile time with whatever the platform needs to approximate/implement said feature."

      What? you mean Gcc starts emulating instructions that if implimented in hardware would give you far greater performance? (before you say it. Yes it does. it is EMULATING behaviour that does not exist natively.)

      >I'm well aware of the fact that J2ME is cut down. I've written several games in J2ME. But you seem to be a little confused. J2ME
      >has a bytcode spec, and several chip manufacturers follow the spec for J2ME microcontrollers but that is not native execution. The
      >translation from bytcode to CPU instructions happens in hardware, which is fast to be sure but still is not native CPU code."

      In most mobile devices I have used they have NO native support for the execution of bytecode. It is all emulated. What I was attempting to suggest is that J2ME specifies the minimum requirements for the developer to use. Whether those requirements are met by emulation on an 8 bit microcontroller or have corresponsing 32 bit instructons on a strongarm. The 8 bit micro has top provide a development environment that supports 32 bit math whether emulated or not.

      >"The processors I'm playing with at the moment run java byte code natively."

      >>No they don't. They have a "hardware JVM" for lack of a better term. The CPU is not running bytecode. None of the processor
      >>families I found doing a quick search have a J2ME bytcode based instruction set. Underneath, they are still running ARM, Fujitsu,
      >>etc. chips, which use their normal CPU instructions to execute."

      Umm, Yes they do. For example I am currently playing around with JOP http://www.jopdesign.com/ This is a processor whose native instruction set is java byte code. Unless C can compile code to JBC then it would have to run in an emulation layer on this processor (I have yet to see a c compiler that can produce java byte code. It Could be done I just have not seen it yet)

      >Bytecode and machine code are two different things.

      No they are not. Bytecode is machine code for a "java virtual machine". It is called a Virtual Machine because hardware implementations did not exist when java bytecode was developed therefore they were all interpreted. Processors that handle bytecode natively do exist.

      C and java require a "virtual machine" in the same way. However Java targets one architecutre (java byte code) and C targets many (any instruction set that can be targeted by your compiler).

      Jop, Cjip, aJ-100, are all processors that run bytecode natively. Even sun produced one back in 95 (cant remeber the name but it was a hacked up sparc)

      matfud

    53. Re:BULLONEY!! by hobo+sapiens · · Score: 1

      You are what's wrong with slashdot and what's wrong with the world in general. Is "you're stupid" the best you can do? Really. No intelligent debate or anything.

      The article was all about application speed, if only one specific factor relating to application speed. What's the point of discussing memory allocation speed if it doesn't contribute to overall application speed? Wouldn't that be a somewhat irrelevant thing to discuss if it were *just* about memory allocation speed? Yeah. Use your real ID, you tard.

      --
      blah blah blah
    54. Re:BULLONEY!! by hobuddy · · Score: 1

      You're correct that (non-graphical) pure Java code is much faster than pure Python code, although Java typically uses 2-5x as much memory.

      But you say that, "Python is provable slower than Perl... [for] the Sieve of Eratosthenes algorithm". I don't think you could have picked a worse example to support your claim; in the Shootout's Sieve test, Python is friggin' four times faster than Perl .

      Circa 2000, it was true that Perl was significantly faster than Python, but not anymore. While the Perl interpreter stagnated due to the Perl 6 fiasco, the Python interpreter has closed the gap, and then some. Except for regular expression-heavy code and I/O-heavy code (which are Perl's specialty), Python is now faster across the board. Check the shootout if you don't believe me.

      Don't get me wrong. I'm not claiming that Python is a speed demon (in fact, it has serious performance problems). But Perl is not faster anymore.

      --
      Erlang.org: wow
    55. Re:BULLONEY!! by maraist · · Score: 1

      No cell phone games written in Java do this. I can quite confidently state this, as Sun says it will take more than that just for the JRE. See any number of other comments around this post. Go read teh J2ME docs.

      Except that J2ME is already loaded in many/most cell phones / PDAs. The space a game takes up is only as large as the game library and it's associate heap.. And most cell phone libraries make HEAVY use of cell-phone specific libraries. Most of your graphics, event handling, and persistance are mere function calls away. Thus, if all you are writing is a checkbook program.. You're talking about maybe 5 files compressed in a zip-format (and unzipped temporarily to convert it into whatever native format the cell phone hardware uses. Everything else is already accounted for in the cell phone's OS (which may or may not be Java itself).

      What you guys aren't understanding about Java is that it doesn't work the same way as c programs.. The closest comparison you could make would be CORBA, DCOM or RPC based applications where you don't deal w/ directly loading the libraries for code. Even if you're invoking a constructor directly in Java, you have no garuntee that it's even executing in your local memory model (thanks to aspect-oriented code an runtime bytecode enhansers). The actual Java could could have been swapped out and replaced w/ a JNI native "C" function call by the cell phone manufacturer. This is only possible because the only linkage between java classes are the symbolic names. W/in the same running JVM you can have segregated namespaces (by way of class-loaders), so you could have java.lang.String have 5 different implementations all in the same executing memory frame. This is how tomcat and jboss work. Each application context has a separate class-loader, so you can have different versions of the same named libraries kept seperately.. Thus you can have 10 different applications all running under the same executable, each w/ completely different sets of library dependencies. As the system administrator, you can choose to move common libraries together so you don't redundantly load libraries into memory (but you have to be sure that there is only one version needed by applications).

      This is somewhat similar to .so libraries in UNIX or .dll in windows. But the point is that the amount of memory consumed by a "c" application and the amount consumed by a java applications are not directly related. Ignoring the fact that JVM's themselves use .so libraries to operate, java is really designed to be a monolithic operating system.

      So no, JVM's don't work well below 32KB of RAM or ROM. But neither does windows or even Linux for that matter. But memory is cheap. What's the excuse for not having 16Meg of RAM available to an embedded device anymore? I'm sure there are reason's, but it certainly isn't money.

      --
      -Michael
    56. Re:BULLONEY!! by adrianmonk · · Score: 1

      Well, the linked article contained a number of what I will graciously call "assumptions" (rather than "outright lies") about allocation patterns in C/C++ that simply don't hold true in most cases.

      For example, the parent mentions the old "stack or heap" question... Which no serious C coder would ask. Use the heap only when something won't fit on the stack. Why? The stack comes for "free" in C. If you need to store something too large, you need the heap.

      This is all well and good until you start trying to have good programming practices like, say, encapsulation. In order to use an object, you have to know details about its implementation, namely its size, which is something you shouldn't have to know.

      Let me give a real-world example. Recently, I was coding a class that does a GUI version of the Periodic Table. For various reasons, it made a lot of sense in my case to create some lookup tables when the object is created, so that I know the exact geometry of every one of the elements. Subtle details determined whether these tables could be constants (and thus global constant data and not part of the individual instances) or needed to be part of the object itself. An implementation that used some other method than lookup tables would've made the object much smaller, because I had several screen coordinates and other values for each element. In fact, the difference could be an order of magnitude or more.

      So, imagine that I need to use this Periodic Table object. Should I put it on the stack? In this particular case, on this platform (whose apps by default have a 4K stack size), it needs to go in the dynamic heap. So, the client code needs to know the rough size of the object, so it needs to know about its implementation.

      Now, what would've happened if I had started with a class that had a small footprint, and the client code put it on the stack, but then I go back later and realize I can get a huge performance increase by making the object much larger? If I go through with it, I have to do one of two things: either change all the client code everywhere, or let client code risk blowing the stack.

      You can see, then, how the stack vs. heap compromise really is an issue in C++ code. If development time means nothing, then by all means, optimize your code (and all the libraries it calls and so on) so that you maximize your stack usage without going over. But if you'd like a language that gives you good performance without making the programmer make that determination, then a language where the implementation chooses for you is probably better than a language where the programmer has to choose in most cases.

      But then, you can allocate it once, and don't even consider freeing it until you finish with it (generational garbage collection? Survival time? Gimme a break - It survives until I tell it to go away!).

      You've totally missed the point here. In either language, it survives until no longer needed. The difference is just that in Java, the generational allocator takes advantage of the fact that some pieces of allocated memory are not needed for very long and uses that fact to improve performance of the allocator.

      The reason this is possible is that a fair amount of the work required of the allocator and deallocator involves dealing with different sized allocations and deallocations. When you want a piece of size N, the allocator has to somehow go through its free list and choose the best piece to give you, because the free list contains all different sizes. When you free a piece, the deallocator has to go through and determine if there are adjacent free pieces that can be combined with that piece to form a larger piece. There are algorithms and data structures to do this, but it still requires work.

      Meanwhile, a generational allocator takes a different approach. It picks a region of memory and then just starts allocating at the beginning and moving

    57. Re:BULLONEY!! by maraist · · Score: 1

      Perl doesn't use any bytecode at call. Perl executes scripts simply by 'walking' the syntax tree its yacc parser has built. Just like (n)awk or gawk (and unlike mawk).

      I've looked at both the JVM environment and the perl environment internals, and I have to dissagree.

      Java compiles to a stack-machine 1 byte op-code interlaced w/ 0 or more bytes of opt-code arguments. The op codes refer implictly or explicitly to an external set of local-variables or to an evaluation stack in an interesting combination of load-store and stack execution, utilizing some of the more interesting aspects of RISC.

      Perl compiles down to an AST-tree, where each node has a custom set of associated data-structures; generated directly from the compilation.

      Perl makes an attempt to run through the AST tree to optimize it, replacing "for my $x (0 .. 10)" with a c-style optimized "for (int x = 0; x = 10; x++)" as an example. Perl also removes redundant or unreachable code.

      Since function calls are symbolicly invoked, it's easy at run-time to replace (even temporarily) one AST sub-tree with another.. And the "eval" statement facilitates this.

      The fact that the JVM runs machine instructions which on most platforms has to be emulated isn't much different than the fact that the AST nodes are very similar to machine instructions.

      The big difference of course is that parrot instuctions (perl 6), python instructions, and java instructions are directly serializable, while perl 5 instructions are not. The perl5 distillers that I have seen create c-code which re-initializes the AST tree from a set of constants.

      But this is a mere oversite on perl5's part; mainly because it was rarely ever desired. I don't think that the fact that an instruction stream is directly serializable is what makes it byte-code or not.. Perl AST nodes have unique identifiers (the op-codes), and executing one op-code directly returns a pointer to the next node in the true. Parrot is very similar; the "byte code" node returns an offset of the instruction-stream to the beginning of the next byte-code (since there are variable number of args per instruction).

      But the key is that perl is NOT like TCL which does not even maintain an AST; instead it takes as an argument to a block the raw text. It then compiles that text to determine what the block does... Thus in a for loop, you recompile the body block each and every time. It's been a while since I've played w/ TCL, but I believe this allowed it to do some interesting tricks thanks to this highly dynamic execution environment. I think you could pass text as an argument to a function and it would run as code (but I'm too fuzy at this point). In perl, you either explictly pass a function pointer, or you explicitly call "eval". In java you have to have a standardized interface, so you can't pass arbitrary code around (though some nasty reflection mechnisms will look for the first function in a object's definition and invoke it; I've seen this in webwork).

      So if you want to play symantics, then no perl isn't byte-coded.. But what I think is more intersting is what the performance is like. And perl beats java's regular expression package, hands down.. Because there is a single op-code in perl to handle this (via a native optimized c-function) v.s. java running the entire re in bytecode land. Though java can do simple arithmetic significantly faster than perl. And the wheel goes round.

      --
      -Michael
    58. Re:BULLONEY!! by Bloater · · Score: 1

      I won't quote any of your post because this sort of replies to the general idea... That's why I said refcounting is hard.

      The easiest way to get non-leaky behaviour is malloc and free (or your preferred language's equivalent). C++ makes it really quite easy.

      I should rephrase: GC is a memory leak. refcounting is the only non-leaky way to automatically determine object lifetime, and refcounting is really, really *hard* to do right without using GC to avoid cycles preventing lifetime determination thus causing leaks.

      The advice I would give to new programmers is learn C++ and learn how to use proxies allocated in the stack frame, and learn how to determine object lifetime correctly. *Then* move on to Java and .NET and things like that. The greatest chefs all learned how to season their dishes, but once perfected, they just bung in a dollop of brown sauce.

    59. Re:BULLONEY!! by maraist · · Score: 1

      The advice I would give to new programmers is learn C++ and learn how to use proxies allocated in the stack frame, and learn how to determine object lifetime correctly. *Then* move on to Java and .NET and things like that. The greatest chefs all learned how to season their dishes, but once perfected, they just bung in a dollop of brown sauce.

      I'd probably agree for anyone that I wanted to see become a good programmer. Though I've been very interested in getting my wife to do some simple programming.. And believe me, I have no interest in scaring her off by making her go through the entire drill routine.. In fact, I'd prefer if we had a billion bad programmers than only a couple thousand good ones.

      --
      -Michael
    60. Re:BULLONEY!! by Anonymous Coward · · Score: 0

      I'm not about to forget my girlfriend's birthday, because my computer warns me about it three days ahead of time.

      This is how we know you're lying. Slashdot lamers don't have girlfriends.

    61. Re:BULLONEY!! by scharman · · Score: 1

      Umm.. remember, that java requires those same libraries to provide said things such as threading, etc. Java does not reinvent an entire new libc, etc.

      Hey, C will always win over Java for performance/size - people just deal with it! However, in general, Java productivity (especially for cross platform) is 2-5x higher. You just need to pick your poison.

      IMHO, I'm still amazed at the performance of JVM's and bow down before the coders writing them (We're not worthy!). However, I still prefer the stricter seperation between xVM and language in .NET (I really don't like some of the Java specifics in the JVM).

      Anyway, just my $0.22

    62. Re:BULLONEY!! by jma05 · · Score: 1

      >> So you take the responsiveness of an IDE as a measure for a language? That is nonsense.

      No I don't. I am answering the specific refutal made by the parent.

      >> You are claiming that Python as glue + C as language to do the heavy work is faster than Java, and in that sense: yes. So in fact you're not comparing Java to Python, but Java to C.

      I am comparing speed of "applications" as whole as they occur in the wild rather pure benchmarks or language implementations because that's what matters.

      >> I am a C++ and Java software engineer, working on very large projects for banking applications. We run Java (amongst others) on an MVS (IBM) mainframe, amongst others. As you might know, IBM mainframes are not bought, but paid per used CPU cycle! So we know damn well how efficient Java is.

      I am well aware of efficiency of Java. I process several gigabytes of text data with Java and it performs quite comparably as with equivalent IR engines written in C++. But so does Python (with much of the code running in native extensions of course). If I have any peeves about Java, it is memory bloat and percieved startup times. They are often not an issue on servers, but are on the desktop. My point is not to say Java is slow but to say that idiomatic Python is effectively as fast or faster than idiomatic Java. Yes! Java can use native toolkits and become even faster but that's not what most people do. But that exactly is what most people do when they use dynamic languages.

    63. Re:BULLONEY!! by WhiplashII · · Score: 1

      You can have both!

      I thought for sure that you were about to explain how you can now write code that compiles in both gcc and javac...

      --
      while (sig==sig) sig=!sig;
    64. Re:BULLONEY!! by WhiplashII · · Score: 1

      Yes, your right... I have made millions due to my knowlege of how to write fast Java portals...

      --
      while (sig==sig) sig=!sig;
    65. Re:BULLONEY!! by WhiplashII · · Score: 1

      You had some good points, but you went too far. The new native Java bytecode CPUs are just as "native" as x86 cpus are - all modern processors translate the executable machine language code given to them into microcode, and then execute the microcode. Even the 286 did this (really streching the meaning of modern, there)!

      --
      while (sig==sig) sig=!sig;
    66. Re:BULLONEY!! by Baki · · Score: 1

      Still, java as a language comes close to the speed of C++. So there is less need to "go native". However if you want to, it is no problem. It is hardly more difficult than in TCL (I have used TCL a lot as glue to bind self written modules and available libraries in C together). JNI is not difficult, and we use it too. We don't use it to write our own C modules, because it just isn't worthwhile with Java. But we do use it to bind in existing libraries (such as openssh and some in-house developed networking libraries), and once you know how to do it it doesn't take more time than with similar mechanisms in scripting languages. People have done it for GUI toolkits, e.g. http://java-gnome.sourceforge.net/cgi-bin/bin/view and http://developer.kde.org/language-bindings/java/. There is no technical reason at all that Java can't do the same thing Python can (binding in lots of existing modules) except that the need is hardly there.

    67. Re:BULLONEY!! by emilper · · Score: 1
      [...] a language interpreter such as Perl. Not exactly a fair comparison - Yes, Perl counts as "real-world", but in an interpreter, [...]
      Perl is not interpreted ...
    68. Re:BULLONEY!! by m50d · · Score: 1
      There is no technical reason at all that Java can't do the same thing Python can (binding in lots of existing modules)

      No. But the Java culture is not to do that, and not to use the bindings that exist, because Java people refuse to admit that Java is too slow to do a good gui toolkit in.

      --
      I am trolling
    69. Re:BULLONEY!! by m50d · · Score: 1
      Perl does some byte-compilation but also is an order of magnitute slower than truely compiled languages such as Java, C++ and C#

      Java is no more truly compiled than perl or python. They just had the marketing genius to make the byte-compiler a separate program, making people claim Java runs much faster.

      (Java and C# being just-in-time compiled, which is about as good as compiled in advanced with todays technology, and theoretically could even outperform)

      It could never outperform, people making these comparisons always forget the cost of doing this compilation.

      The latter three are about 10% within each others range, most benchmarks I have done indicate C++ is fastest, Java about 0-30% slower, and C# about 10% slower than Java (C# tests done 1 year ago).

      I've seen benchmark after benchmark telling me that Java is not slow, but my real-world experience is that it is.

      All tests are library/API neutral, i.e. I did not test the speed of some C++ GUI toolkit such as Qt versus a Java GUI toolkit such as AWT/Swing, but only tested pure language features and "core" stuff.

      Swing is part of the Java language and a large part of the reason for its slowness. I suppose you can't compare to C++ since that has no included toolkit, but it's still a comparison that should be made.

      Claiming that python, clearly an order of magnitude slower than compiled languages, is faster than Java is an absolute joke and proves that you have never done or read some serious benchmarks.

      I've read plenty of benchmarks. Benchmarks don't mean shit when it takes half a second after clicking on the button before a menu will appear.

      --
      I am trolling
    70. Re:BULLONEY!! by m50d · · Score: 1
      I'm a huge python fan, but what you stated is blatantly false. Python is around 700 times slower than java, on a good day. Perl is around 95 times slower than java.

      You can throw all the benchmarks you like at me, but just try using programs in each for ten minutes.

      For any gui related work though you'd never know it, the "responsivess" of an application depends on the gui toolkit. In java , just don't use swing if you want an app that feels fast.

      Fair enough, but in that case:

      • Java isn't "write once run anywhere" for GUI programs
      • Java is then slower, though only a little, than other languages with the same features, since we can compare to modern compiled languages.
      • Java's standard library is horribly pointlessly bloated.
      Use SWT or GTK, its quite simple.

      Java people wave this around, why don't the applications do it?

      Gui applications do things in discrete steps, so a python app can feel as fast as a java app because nothing is usually happening for more than a few milliseconds.

      But then java apps should feel as fast as python apps, when they feel much slower.

      Implementing any heavy performance servers or just about anything else that requires heavy duty calculations (like 100 million calculations per second) you just can't do in python. I use python all the time, but don't be naive and look past its limitations.

      I haven't looked at heavy performance stuff, I'm just comparing desktop applications that I use.

      --
      I am trolling
    71. Re:BULLONEY!! by aaronl · · Score: 1

      Surprisingly enough, it often does come down to money. Sure, the difference in price for 16MB vs 32MB isn't much when you're putting together a PC for yourself, but the difference of a few dollars is of major importance when you're doing mass market. Companies often make choices about knocking a few cents off the price of something by messing about with vendors.

    72. Re:BULLONEY!! by ultranova · · Score: 1

      The easiest way to get non-leaky behaviour is malloc and free (or your preferred language's equivalent). C++ makes it really quite easy.

      No, the easiest way to get non-leaky behaviour is to use a purely functional programming language, because then all the allocations are (at least conceptually) on stack, and all the memory allocated by a function can be freed as soon as the function terminates (except, of course, the return value).

      The easiest way to manage heap is to not have heap ;).

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    73. Re:BULLONEY!! by HuguesT · · Score: 1

      20 years ago, in 1985, my computer could only run one program at a time, and 32kB mattered because I only got 128kB in it.

      Now my computer may have 2000 the same amount of memory, but runs approximately 1000 processes at the same time. Therefore it would piss me off greatly if each and every one of them required 100MB to run.

      That's why I appreciate my small daemons to only require 32kB or so and I generally hate programs which require a different, separate JVM to run. This is also why writing everything in Java is not a great idea.

    74. Re:BULLONEY!! by gaj · · Score: 1
      Certainly true. And I would never argue that Java can be smaller than or, in an absolute sense in the real world, faster than, C. Hell, I make a living programming in Java, I know what a memory hog it is. On the speed front, OTOH, very well written Java on a very well written JVM (or using a native compiler) can be competitive. Not faster, but fast enough.

      Anyway, I just wanted to point out that using a JVM intended for embedded use was appropriate when comparing on basis of space, just as you'd carefully choose your libraries when coding C in a memery sparse environment.

      As for picking my own poison, given my druthers I'd be coding in Python/Pyrex.

    75. Re:BULLONEY!! by Xyrus · · Score: 1

      "What? you mean Gcc starts emulating instructions that if implimented in hardware would give you far greater performance? (before you say it. Yes it does. it is EMULATING behaviour that does not exist natively.)"

      Correct. If you do a 16-bit division and the processor does not support it, then the compiler will produce a series of opcodes to replicate the behavior. But this sort of thing only happens if the compiler target CPU does not have native opcodes for an operation.

      "The 8 bit micro has top provide a development environment that supports 32 bit math whether emulated or not."

      How is this different from C? The only real difference is that in C if you don't want to use it, you can cut it out entirely.

      "For example I am currently playing around with JOP http://www.jopdesign.com/ This is a processor whose native instruction set is java byte code."

      Well, kind of. The JOP is an FPGA, so its only real native instrcutions are in the HDL. The JOP processor could be reprogrammed to emulate just about any architecture you wanted it to. FPGAs are cool, but they do have their drawbacks such as higher power consumption and slower than their ASIC counterparts, but that's another subject.

      "Unless C can compile code to JBC then it would have to run in an emulation layer on this processor (I have yet to see a c compiler that can produce java byte code. It Could be done I just have not seen it yet)"

      I have seen several discussions on this, and as yet no one really thinks it's a worthwhile endeavor. The geek factor is pretty high, but it wouldn't serve any useful purpose. The closest thing that exists to this C# and managed C++ in .NET. But those target their own VM.

      I'd like to see it anyway. :)

      Regardless, since the FPGA is reprogrammable there would be no need to compile to the java bytecode. It might be just as effective to write a new HDL for the FPGA and have it run like whatever your original target CPU was.

      "No they are not. Bytecode is machine code for a "java virtual machine"."

      I'm going to disagree on your terminology. The term opcode has always been used to define a native CPU instruction. Bytecode is a virtual machine instruction. Mixing the two can be misleading.

      "C and java require a "virtual machine" in the same way. However Java targets one architecutre (java byte code) and C targets many (any instruction set that can be targeted by your compiler)."

      I'm going to disagree here as well. The term virtual machine just simply does not apply to native compiled languages, as there is nothing virtual about the hardware to which you are compiling to. Java does compile to a virtual machine, as for the most part there aren't many machines out there that support Java natively.

      "Jop, Cjip, aJ-100, are all processors that run bytecode natively. Even sun produced one back in 95 (cant remeber the name but it was a hacked up sparc)"

      You are correct. The JOP is an FPGA but the AJ-100 and CJIP are ASICS that do have java opcodes. But in these cases, there is no longer a virtual machine or bytecode for that matter. You have java being compiled down to native machine architecture and instructions. The terms of virtual machine and bytcode no longer apply, IMHO.

      ~X~

      --
      ~X~
    76. Re:BULLONEY!! by Xyrus · · Score: 1

      Yep. I was wrong on that, but I've been out of the J2ME scene for awhile and haven't been keeping pace with the new developements.

      There are indeed native java processors. In this case though, I think the terms bytecode and virtual machine should not be used as that is misleading. In these cases, java produces machine opcodes for the CPU, like any other compiled language.

      ~X~

      --
      ~X~
    77. Re:BULLONEY!! by matfud · · Score: 1

      > Well, kind of. The JOP is an FPGA, so its only real native instrcutions are in the HDL. The JOP processor could be reprogrammed to emulate just about any
      > architecture you wanted it to. FPGAs are cool, but they do have their drawbacks such as higher power consumption and slower than their ASIC counterparts,
      > but that's another subject.

      Seems to me that JOP is a processor defined in HDL. It has a native instruction set consiting of bytecode instructions. It has a simpler underlying microcode that is used to handle the more complex bytecode instructions. The fact that it is currently being run on a FPGA is niether here nor there.

      > I'm going to disagree here as well. The term virtual machine just simply does not apply to native compiled languages, as there is nothing virtual about the
      > hardware to which you are compiling to. Java does compile to a virtual machine, as for the most part there aren't many machines out there that support
      > Java natively.

      You seem to be implying that java bytecode ceases to be bytecode when you run it on a java processor, but is bytecode when you run it in a virtual machine. Its the same stuff, it hasn't changed. Does code compiled for the motoroller 68k instruction set suddenly become bytecode when you try to run it in mame? does it somehow change?

      Does code compiled for a x86 processor run natively? Considering most x86 processors emulate (albeit in hardware) the x86 instruction set on top of a "risc"ish core the definitions become ambiguous.

      Anyway it interests me. The whole concept of processors with direct support for high level languages. The lack of pointers in java mean that many of the reasons you would normally have a mmu for cease to exist (in smaller systems anyway) ( you can't bugger up memory that does not belong to you). The garbage collector can allocate all avaialble memory on the system and manage it efficiently. Some nice ideas, especially for embedded systems.

      matfud

    78. Re:BULLONEY!! by Bloater · · Score: 1

      > Though I've been very interested in getting my wife to do some simple programming.. And believe me, I have no interest in scaring her off by making her go through the entire drill routine..

      Yeah, I suppose you should get em hooked with scripting first. Something fairly nice, like python.

      Or bash so they can see automation at work, and love programming for its obvious benefits.

    79. Re:BULLONEY!! by Bloater · · Score: 1

      > No, the easiest way to get non-leaky behaviour is to use a purely functional programming language.

      Perhaps in "clean", certainly not in Haskell, unlambda is very leaky as you have to use shitloads of stack for a long time. It's pretty difficult to avoid leaky behaviour in Haskell, but I don't know what sort of annotations you can do in clean to get it to statically analyse.

    80. Re:BULLONEY!! by Xyrus · · Score: 1

      "Seems to me that JOP is a processor defined in HDL."

      Yep.

      "It has a native instruction set consiting of bytecode instructions. It has a simpler underlying microcode that is used to handle the more complex bytecode instructions."

      Yep.

      "The fact that it is currently being run on a FPGA is niether here nor there."

      I was just pointing out that the JOP is an FPGA, not a traditional ASIC CPU. That's all. The other processors you named are indeed native java machines, in the traditional sense.

      "You seem to be implying that java bytecode ceases to be bytecode when you run it on a java processor, but is bytecode when you run it in a virtual machine. Its the same stuff, it hasn't changed."

      The bytecode has not changed, but how it's executed has. When I hear "bytecode", I think interpereted. When I hear "opcode", I think executed. On a PC, bytecode is interpereted into opcodes that execute. On a java processor, java opcodes execute.

      But this is the stuff of flame wars.

      "Does code compiled for the motoroller 68k instruction set suddenly become bytecode when you try to run it in mame? does it somehow change?"

      No, since it's being run through an emulator. But then again, how is an emulator different from a virtual machine? An emulator emulates existing hardware, while the Java VM IS it's hardware. Though it can easily be said that a PC is emulating the VM.

      Not so clear cut anymore.

      "Does code compiled for a x86 processor run natively? Considering most x86 processors emulate (albeit in hardware) the x86 instruction set on top of a "risc"ish core the definitions become ambiguous."

      One of my peeves with the x86 family. You can't write any lower than the instruction set of the cpu, so for all intents and purposes it is "native". What the cpu does beyond that point is beyond your control. Though strictly speaking, the x86 is a "higher level" language sitting on top of a risc-like core.

      With jave on "native" cores, it does get more difficult to find clear cut definitions. The shades of gray win again. :)

      "Anyway it interests me. The whole concept of processors with direct support for high level languages. The lack of pointers in java mean that many of the reasons you would normally have a mmu for cease to exist (in smaller systems anyway) ( you can't bugger up memory that does not belong to you). The garbage collector can allocate all avaialble memory on the system and manage it efficiently. Some nice ideas, especially for embedded systems."

      For smaller systems, yes I'd agree that an MMU is redundant. However for larger complex systems, I'd recommend having one. Or at least, having one you can switch to in case you need to optimize memry usage better than a general purpose GC.

      ~X~

      --
      ~X~
  10. As I see it. by Z00L00K · · Score: 3, Interesting

    The memory allocation management routines are normally running when the JVM thinks it's best, but as a programmer it is usually possible to predict the best time when to actually take care of the housekeeping. Even if the memory management cleanup takes the same time in both cases Java has a tendency to issue them in the middle of everything. So if I as a programmer does the garbage collection at the end of a displayed page and Java does it uncontrollable in the middle of the page the latter case is more annoying to the user.

    --
    If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    1. Re:As I see it. by Anonymous Coward · · Score: 1, Interesting

      This is why you can call System.gc() to give the JVM suggestions about when to run the garbage collector.

      Most developers shouldn't be thinking about this stuff though. Let the JVM worry about optimizations and garbage collections! The article provides a very nice example of this philosophy: java developers don't have to worry about allocating objects on the stack or the heap. The JVM will make the optimal decision based on escape analysis, in a way that is completely transparent to the developer.

      In .NET OTOH, you are encouraged to manually declare value types (=objects allocated on the stack). Unfortunately the semantics of your code depend on this decision when you start boxing and casting your objects. "Applied Microsoft .NET Framework programming" by Jeffrey Richter has a good example of Value Type weirdness on page 333.

    2. Re:As I see it. by sulam · · Score: 1

      If you run a non-incremental garbage collection routine, and you completely fill up your old generation, yes you can have this happen. However, the default is incremental collection, which will never cause the behavior you describe. Your knowledge of GC is as out of date as your knowledge of Java performance.

    3. Re:As I see it. by Hangeron · · Score: 1

      They say that it's easy to shoot yourself in the foot with C/C++ memory management, but Java makes my feet like squiggly spaghetti and I don't even know where I stand.

    4. Re:As I see it. by p3d0 · · Score: 1

      So call System.gc() at the end of each page. Then the only reason it should happen again mid-page is if you actually run out of memory, and then it's unavoidable.

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    5. Re:As I see it. by anthony_dipierro · · Score: 1

      Most developers shouldn't be thinking about this stuff though.

      Correct, but at least one developer on each programming team should be.

    6. Re:As I see it. by Anonymous Coward · · Score: 0

      Or better yet, before and after the page, so it has as much memory as it can to load each page.

    7. Re:As I see it. by p3d0 · · Score: 1

      I wouldn't do it before each page. Then the time consumed by GC is on the critical path for the user's perception of latency.

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    8. Re:As I see it. by eckes · · Score: 1

      On a multi-user server which is concurrently used there is no such thing as "middle of the page". However you are right, for single user applications it might make sense to hint the GC. I guess this is where RT-Java will come to an rescue.

      (And well, malloc heap reorganisaton in C is not that pleasant, also).

      Gruss
      Bernd

  11. Article somewhat ignores the fatness of the JVM by expro · · Score: 4, Informative

    How many JVMs can you afford to run on your system for different apps, and how can you make sure they are all the right size, the garbage collectors are in an appropriate mode that can keep up with generated garbage, etc. I can run lots of native apps, which in many cases have no need for a significant heap like Java brings into the picture in far less space than a single JVM. A JVM runs much heavier on the system, and when I run Netbeans, it is continuously on the verge of eating my 1.2 GB powerbook alive, in fact I have to frequently restart Netbeans to get memory back. It has a long way to go in real practical terms even if they have theoretical solutions to some of the problems. I am porting my server software away from Java for the same reasons. This is JDK 1.4, and I am about to try it on 1.5, but I don't think there is that much difference.

    1. Re:Article somewhat ignores the fatness of the JVM by LarsWestergren · · Score: 4, Informative

      How many JVMs can you afford to run on your system for different apps, and how can you make sure they are all the right size, the garbage collectors are in an appropriate mode that can keep up with generated garbage, etc.

      Try "java -X". You will see that you can decide what the "right" size is. See this link, a guy forces the JVM to run a web server on 16 mb of memory and still get decent performance.

      --

      Being bitter is drinking poison and hoping someone else will die

    2. Re:Article somewhat ignores the fatness of the JVM by Anonymous Coward · · Score: 1, Funny

      ...it is continuously on the verge of eating my 1.2 GB powerbook alive

      Ahhh, using those good ol' 614MB DIMMs, eh?

    3. Re:Article somewhat ignores the fatness of the JVM by jherber · · Score: 1

      what you are saying doesn't jive with the netbeans configuration file:

      netbeans_default_options="-J-Xms32m -J-Xmx128m -J-XX:PermSize=32m -J-XX:MaxPermSize=96m -J-Xverify:none"

      which is guarenteed to only give the jvm a maximum of 128 megabytes.

    4. Re:Article somewhat ignores the fatness of the JVM by eraserewind · · Score: 1
      which is guarenteed to only give the jvm a maximum of 128 megabytes.
      128MB, that small huh?
    5. Re:Article somewhat ignores the fatness of the JVM by expro · · Score: 2, Insightful

      And the command qualifiers claim the same thing in a ps view of the system, but the memory consumed rises towards 1GB. This is not unusual where Java is concerned. I have run JVMs for years and never found one willing to live within its bounds.

    6. Re:Article somewhat ignores the fatness of the JVM by hedge_death_shootout · · Score: 1

      when I run Netbeans, it is continuously on the verge of eating my 1.2 GB powerbook alive

      Mate, when I run native apps like Firefox on my 1.4GHz Mac Mini (1/2 gig memory, before the zealots start prematurely diagnosing the problem), it can be slow as shite. A couple of SWFs embedded in the page, the twirly beachball is wont to appear, and the flash animation runs at low single figures fps.
      Basically low performance hardware is going to have low performance.
      .
      .
      .
      .
      (Especially when you run Netbeans)

    7. Re:Article somewhat ignores the fatness of the JVM by expro · · Score: 1

      Ahhh, using those good ol' 614MB DIMMs, eh?

      No. The powerbook comes with 256 MB built in, to which I added a 1GB chip. There is only one slot to add memory. This is 12".

    8. Re:Article somewhat ignores the fatness of the JVM by NormalVisual · · Score: 1

      It's been my experience that Flash under Firefox pretty much firewalls the machine regardless of clock speed. That's not a "native app" issue, that's a problem with the Flash plug-in, Firefox, or both.

      /wishes the Flash problems with Firefox were fixed
      //wishes Firefox could do form variables properly
      ///uses mostly Opera now

      --
      Please stand clear of the doors, por favor mantenganse alejado de las puertas
    9. Re:Article somewhat ignores the fatness of the JVM by Anonymous Coward · · Score: 0

      Hard to call FF totally native, since most of the UI is javascript, and there's about three additional layers between the app and the native drawing.

    10. Re:Article somewhat ignores the fatness of the JVM by hedge_death_shootout · · Score: 1

      Yes, to be fair, Firefox+OSX+Flash is knackered.

    11. Re:Article somewhat ignores the fatness of the JVM by Bastian · · Score: 4, Insightful

      Manually determining how much memory to give to an application was one of the things that us Mac users were more than happy to leave behind with the transition to OS X. Hell, we were more than happy to kill that "feature." Dancing on its coffin and all that. Are you seriously suggesting the world go back?

      Besides, I thought the biggest examples of Java was that it was all cool and dynamic and took care of things for you. It seems fair to me to expect such a language/platform to be smart enough to figure out that it's not polite to walk to the buffet, heap three plates with a ridiculous pile of food, and go back to the table and graze on a few pieces of celery, leaving the rest of the food untouched.

    12. Re:Article somewhat ignores the fatness of the JVM by dnoyeb · · Score: 1

      Netbeans != java. Netbeans has sucked for a while IMHO. Try Eclipse. If you have tested your SERVER software and found it wanting thats one thing. But if you test somebody else's app and found it wanting, and decide you need to dump your app, thats just odd.

      JRE 1.5 is the first JRE to share OS resources between other instances of the JRE, so I should expect 1.5 will be better with regards to your sharing complaint.

    13. Re:Article somewhat ignores the fatness of the JVM by dnoyeb · · Score: 1

      I should also note that desktop java by default is limited to using 64MB plus whatever the JRE uses. So there is NO WAY your netbeans could have used 1.2GB. Eclipse by default is tuned to use about 40MB.

      You should check again. Your program will crash with an out of memory error long before i get to even 100MB let alone 1.2GB.

    14. Re:Article somewhat ignores the fatness of the JVM by sulam · · Score: 1

      Easy answer, don't run Netbeans. And your statement that 1.5 is not that different from 1.4 is completely incorrect. In 1.4 and before, the JVM made assumptions that were appropriate for client-side apps despite the fact that most of the Java code in the world runs on the server. In 1.5 the defaults got changed to something that makes sense for servers. For most server-side apps, db or network performance are the primary bottlenecks -- not the middleware.

    15. Re:Article somewhat ignores the fatness of the JVM by Anonymous Coward · · Score: 0

      Netbeans is actually a piece of junk, and nobody in their right minds doubts that Swing is a nice idea but a really really poor implementation. If you want to see a performant Java UI (and an excellent IDE to boot) check out IntelliJ Idea (http://www.intellij.com/).
      As for server apps, I've consistenty seen a properly written Java server outperform its Perl/PHP/CGI predecessors by orders of magnitude.

    16. Re:Article somewhat ignores the fatness of the JVM by dubl-u · · Score: 1

      A JVM runs much heavier on the system, and when I run Netbeans, it is continuously on the verge of eating my 1.2 GB powerbook alive, in fact I have to frequently restart Netbeans to get memory back.

      I don't know if that's an Apple problem or a Netbeans problem, but I don't have similar issues on an Intel Linux box using IntelliJ IDEA with a half-gig of RAM.

    17. Re:Article somewhat ignores the fatness of the JVM by Hurricane78 · · Score: 1

      1.2GB??? My JBuilder 2005 seldomly goes over 100MB!
      Maybe you're using the wrong RAD-software. ;)

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
    18. Re:Article somewhat ignores the fatness of the JVM by matfud · · Score: 1

      Thats why you have the option of putting up a little sign that says "one plate at a time please". You CAN specify how much or little memory a java app uses (an even how the garbage collector works) but you don't HAVE to.

    19. Re:Article somewhat ignores the fatness of the JVM by Wastl · · Score: 1
      Indeed, one of the major improvements of JDK 1.5 (Java 5) is the possibility to share a single JVM in multiple applications. Also, the overall performance and memory usage of JDK1.5 has been improved significantly compared to JDK1.4.

      Personally, I have been programming with JDK 1.5 for quite some while now and find my productivity greatly improved. Using "generics", the Java container classes are now as powerful (or even more so) as C++. The extended for-loop is now as easy to use as foreach in many scripting languages (Python etc.), but much faster and strongly typed.

      Sebastian

    20. Re:Article somewhat ignores the fatness of the JVM by Anonymous Coward · · Score: 0

      Since 1.5, JVMs share memory, at least for the standard library classes but possibly for others as well. This is also why startup times are much faster - the second time you start an application most of the classes it needs are already loaded.

    21. Re:Article somewhat ignores the fatness of the JVM by Pieroxy · · Score: 1

      Why are you bragging so loudly about something you don't even know the first thing about? You can specify plenty of things about java's heap size when starting a program, such as minimum heap, maximum heap, increment, etc...

      What is wrong about that again?

    22. Re:Article somewhat ignores the fatness of the JVM by X · · Score: 1

      The "fatness" perception of JVM's is actually pretty misleading. A great deal of that memory is not part of the working set for the JVM. For more details check out this excellent article which mentions how Mustang now reduces the "perceived" memory requirements of the JVM by as much as half by simply changing how jar's are loaded.

      That said, Netbeans does tend to be a hideous memory pig.

      --
      sigs are a waste of space
    23. Re:Article somewhat ignores the fatness of the JVM by Bastian · · Score: 2, Insightful

      Having it be something I have to think about is what's wrong with it. Duh. This is 21st century desktop computing we're talking about, for goodness' sake. Be a good neighbor. Start with a small memory footprint, and grow it if you need to. Just like a native app.

    24. Re:Article somewhat ignores the fatness of the JVM by LarsWestergren · · Score: 1

      Manually determining how much memory to give to an application was one of the things that us Mac users were more than happy to leave behind with the transition to OS X. Hell, we were more than happy to kill that "feature." Dancing on its coffin and all that. Are you seriously suggesting the world go back?

      What we have left behind is having the programmer decide how much memory a program needs. This guy was complaining that he thought the Java programs were using too much memory. I pointed out that as the system administrator, he CAN decide how much memory the VM takes on startup, a pretty nifty feature if you ask me.

      The system administrator knows a lot more about the resources of the machine and how they should be distributed. Most people never use that functionality though.

      --

      Being bitter is drinking poison and hoping someone else will die

    25. Re:Article somewhat ignores the fatness of the JVM by Pieroxy · · Score: 1

      Having it be something I have to think about

      What I just described to you are options you can pass to the JVM on startup. As with every option, they are optional, so you can just forget about them all and let the JVM deal with it on its own.

      Apparently, you are just against the word 'java', so any kind of argumentation is pointless as it will always be evil for you. Fine, just use whatever you see fit, but don't bother Java programmers with pointless remarks.

    26. Re:Article somewhat ignores the fatness of the JVM by vingilot · · Score: 1

      As an end user you should not have to worry about what to set your memory sizes to be. As a developer you should determine what your application's memory requirements should be and package your application accordingly for the end user. I wouldn't complain if you are a developer and end user. That said you can use an adaptive size policy for your generations to keep the jvm size smaller. The jvm size will grow and shrink as it needs to. Understanding ergonomics of GC is at least as important as understanding how to free memory in C/C++.

    27. Re:Article somewhat ignores the fatness of the JVM by Bastian · · Score: 1

      And what I'm saying is, fuck the options. Why do they have to exist? They aren't there for any other program I use on my computer. As I said several posts back, I view those options not as a feature, but as a throwback to computing headaches that everyone hated (and that were a common complaint about MacOS) back in the 1990s.

      You act like options are categorically good. They aren't. Manual memory management controls on a desktop application are a Bad Thing, for the same reason that manual fuel/air mixture controls are a Bad Thing on a consumer automobile.

      Fine, just use whatever you see fit, but don't bother Java programmers with pointless remarks.

      In the world where I live, users don't use applications for programmers, programmers write applications for users. Programmers who ignore this fact find that people don't like to use their applications.

      Tell me, have you seen Java making many inroads to the desktop computing market? It seems to me that it has fared little better than Linux.

    28. Re:Article somewhat ignores the fatness of the JVM by Pieroxy · · Score: 1

      These options are tools for developpers and are on many occasions useful on servers. So what you are telling me is that EVERY language is bad because you can debug it. What user in his right mind would like to debug an application? So every program in the whole world must be evil, because it has options no end-user would use.

      You need to open up. The fact that you CAN cap the memory allocation of a JVM is not a drawback. It is a feature, albeit one that isn't all that usefull for desktop end users. Does that makes Java a bad programming language? Nope.

      Manual memory management controls on a desktop application are a Bad Thing
      When using it, most certainly. When programming it, not sure. So why should developers be deprived of something you don't like? Why don't you want JVMs be usefull for everyone?

      for the same reason that manual fuel/air mixture controls are a Bad Thing on a consumer automobile
      ALL electronic cars have a slot somewhere where a garage can plug a computer and tune your fuel/air mixture. So all cars that use electronic fuel/air mixing are as evil as Java from your point of view: You can tweak them manually. Of course, if nobody tweaks them, they work out of the box, just as Java does.

      Tell me, have you seen Java making many inroads to the desktop computing market?
      Well, that must be because you can tweak the JVM's memory management. For sure.

  12. Doesn't poke holes at all by Anonymous Coward · · Score: 0

    The article explains what in theory can be done by smart VMs. But all the examples in the article aren't tested in practise. Maybe the escape analysis the author describes works as advertised. But without actually testing and analysing real code produced and without actual benchmarks the article doesn't proof a thing. One thing the author seems to forget is that you would at least need a fallback mechanism when a method is overridden in a subclass (all the examples don't use final classes or methods). A subclass could override one of the get() methods and put some values in a cache (to keep some statistics for example). In such a case the VM has to detect such a case and "de-optimise" the inlinded code again. Maybe this can be done without too much overhead. But only really measuring these things in real world applications will tell.

    I would love to have pointers to real data though.

    1. Re:Doesn't poke holes at all by fish+waffle · · Score: 2, Informative

      But all the examples in the article aren't tested in practise. Maybe the escape analysis the author describes works as advertised. But without actually testing and analysing real code produced and without actual benchmarks the article doesn't proof a thing

      The author is giving you a high-level, greatly edited view of some of the major optimization techniques in use today. The original academic/technical papers on which that is based demonstrate/measure their techniques on various benchmarks.

      One thing the author seems to forget is that you would at least need a fallback mechanism when a method is overridden in a subclass

      This is well-known. Code-patching, on-stack replacement, pre-existence etc are used in production jits to recover from that kind of thing. This paper has a decent summary of current approaches:

  13. Partial Retraction by hedge_death_shootout · · Score: 1

    Network-bound java servlet applications may perform better in built up areas, due to the higher bandwidth of urban ADSL connections.

  14. Article Actually Argues Something Else by PepeGSay · · Score: 5, Informative

    This article is actually debunking some people's reasons why Java has poor performance. It does little to debunk my actual real world experience that it *is* slow. I'm glad to see that performance has increased alot, but I remember some all (well 90% or something) Java applications, like the original JBuilder, that made me want to claw my eyeballs out when using them. Those apps and other early apps are where Java's performance issues really took hold in many people's psyche.

    1. Re:Article Actually Argues Something Else by NeoBeans · · Score: 3, Insightful
      I remember some all (well 90% or something) Java applications, like the original JBuilder, that made me want to claw my eyeballs out when using them.

      Valid point... for 1999. But Java has been through a lot of changes since "the original JBuilder" came out. There have been three major changes to the class libraries (1.2, 1.4, and the 5.0).

      Honestly, I understand why people are down on Java -- it's because there have always been two strengths to the Java "platform":

      1. It provides a simple programming model (single inheritance, indirect memory management, ...)
      2. A rich class library for specific tasks that are easy to learn (but difficult to master, obviously).

      ...and early implementations weren't able to keep up with native code in any way, shape or form.

      That said, I think you hit the nail ont the head -- people are still thinking in terms of 1999 and not 2005 when they think of Java -- at least on Slashdot. But the typical Java developer is busy writing enterprise apps, not writing kernel code, device drivers, or anything else that requires C/C++.

    2. Re:Article Actually Argues Something Else by Bastian · · Score: 1

      people are still thinking in terms of 1999 and not 2005 when they think of Java

      A lot of us are still using computers that were built in 1999. Java's class libraries and VM and such may have improved since then, but judging from what my computer does with Java apps here in 2005, most of that performance improvement that you're seeing is the work of Intel, not Sun.

    3. Re:Article Actually Argues Something Else by Anonymous Coward · · Score: 0

      JBuilder is a very big Swing application and Swing in early Java versions was slow. It's betetr now and there is also an alternative to Swing: SWT from the Eclipse project (Azureus is using SWT). Overall, Java might not be the best pick for a GUI app and it definitely was not good for GUI 4-6 years ago. Server side or any headless system in general is a different story.

    4. Re:Article Actually Argues Something Else by hobuddy · · Score: 2, Insightful

      Odd, then, that NetBeans and Eclipse are still slower than a sedated elephant on my Athlon 64 3200+ with 512 MB RAM. My computer must be living in a time warp.

      Or maybe the truth is that Java is "effectively sluggish, though not technically slow" because its runtime optimization techniques require such huge amounts of RAM.

      Although I'm well aware of the limitations of the Great Computer Language Shootout as a tool for measuring a language's overall utility, it does tell the naked truth about performance. When I see an easy-to-use language whose design makes it easier to write reusable code than Java using somewhat less CPU time and typically FOUR TIMES less memory , it makes me suspect that well-intentioned Java apologists like you have never really attempted an objective evaluation of the performance compromises inherent in Java's design.

      --
      Erlang.org: wow
    5. Re:Article Actually Argues Something Else by alan_dershowitz · · Score: 2, Interesting
      Odd, then, that NetBeans and Eclipse are still slower than a sedated elephant on my Athlon 64 3200+ with 512 MB RAM. My computer must be living in a time warp.


      It must be, so far I'm running Eclipse and/or Oracle JDeveloper on all the following platforms with no problems:


      Dell P4 2Ghz 512MB RAM, Windows 2000
      Toshiba P4 2Ghz laptop 512MB RAM, Gentoo Linux (2.6 kernel)
      Athlon XP 1900, 1GB RAM, WinXP/Gentoo Linux dual boot


      I will give you a caveat. JDeveloper was pretty crusty until version 10G came out. Runs pretty nice now. Eclipse is no problem on any of them. If you are doing Struts development, I can tell you that I was occasionally running out of RAM at 512MB. Of course, I'm running JDeveloper, a J2EE server, and my app all at the same time, so that's not too crazy.


      I'm not saying they don't run like crap on your machine, I have no idea. All I know is that the company where I work, we have a few hundred people with the exact same machine specs that I do, and we don't have the problem that you are having.


      All these things eat the shit out of resources, but they do not run slow, so I half agree with you, and I half don't. I don't know what the problem is that makes it take up all the resources, but java is not slow. I've been playing with JOGL, an OpenGL java wrapper library, and no one would mistake the results for slow. Maybe this is unfair, but rendering 2D OpenGL in Java is WAY faster than rendering native GDI in Windows.

    6. Re:Article Actually Argues Something Else by Lord+Crc · · Score: 1

      Odd, then, that NetBeans and Eclipse are still slower than a sedated elephant on my Athlon 64 3200+ with 512 MB RAM. My computer must be living in a time warp.

      Can't comment on NetBeans, but Eclipse is just a tad slower than VS.Net 2003 on my machine, which matches your specs. Eclipse takes a bit longer to load (around 20 seconds after a fresh reboot), but that doesn't matter much.

    7. Re:Article Actually Argues Something Else by Decaff · · Score: 1

      but judging from what my computer does with Java apps here in 2005, most of that performance improvement that you're seeing is the work of Intel, not Sun.

      No, it is Sun and IBM. The quality of JIT and Hotspot systems has improved phenomenally in the past few years. Performance of Java 5.0 is way ahead (many times) that of Java 1.3 or 1.2.

    8. Re:Article Actually Argues Something Else by NoOneInParticular · · Score: 1

      What the article basically says is that java memory allocations/deallocations are absolutely not slow. Anyone who knows a bit about garbage collection knows that this should be the case. However, what it forgets to mention is that java simply uses such stupendous amounts of memory that it is bound to slow down even the fastest allocation technique. Traversing 512 MB of allocated memory/garbage takes time.

    9. Re:Article Actually Argues Something Else by killjoe · · Score: 1

      Honestly, who uses dylan and for what? I don't think it's fair to try and compare dylan with java. Java has a huge and rich library while you have to code everything yourself in dylan. I think python or ruby is a fairer comparison. If java loses mindshare it will be to ruby and python, not dylan or lisp.

      Having said that why people don't adopt more esoteric languages like dylan, lisp or even erlang is a mystery to me. Shouldn't we all use the best possible tools?

      --
      evil is as evil does
    10. Re:Article Actually Argues Something Else by Superfarstucker · · Score: 1

      Eclipse gives decent performance on my notebook with the clock looked at 600 mhz, as good as any other application of that size at least... say office or whatnot. At 1.4 ghz it is quite snappy.

    11. Re:Article Actually Argues Something Else by bani · · Score: 1

      thing is, people waited and waited and waited and waited and waited for a java that didn't suck. java's poor reputation became pretty much cast in stone after nearly a decade of waiting. if java has only recently managed to fix the legions of major performance issues, it's rather late now.

      "modern" applications like eclipse and azureus are so piggish and slow that it really doesn't feel like anything has changed since 1999.

    12. Re:Article Actually Argues Something Else by Bastian · · Score: 1

      That's the thing that annoys me about a lot of Java performance talks. The folks who defend it provide a lot of theory, talk about xxx JVM being faster, XXX app being faster, roundabout arguments like that.

      You can provide all the hypothesis and conjecture you want. That will not change the fact that, sitting here at home, on my computer, Java apps are enough slower than equivalent native apps that it is noticeable to me, the user. Usually they are enough slower that it is annoying to me, the user. Even the poster children. Eclipse may be great to a lot of people, but personally, I'm a bit dismayed by it. I thought the days of being able to type faster than the the text would appear on the screen died back when your average modem's speed wasn't represented by a three digit number followed by the word 'baud.'

      Hundreds of millions of instructions per second on a heavily multi-pipelined CPU backed up by a gigantic multi-tiered cache system and a gigabyte of RAM, and this is the best I get? Screw that. If I can use my eyes to tell that Java is slow, then it's going to take a lot more than a few fancy words to convince me that Java is not slow.

    13. Re:Article Actually Argues Something Else by Decaff · · Score: 1

      That's the thing that annoys me about a lot of Java performance talks. The folks who defend it provide a lot of theory, talk about xxx JVM being faster, XXX app being faster, roundabout arguments like that.

      What theory? I am talking established fact. The newer JREs ARE faster. Let me show you some java numerical benchmarks:

      http://www.shudo.net/jit/perf/

      Java 1.5.x is faster than Java 1.4.x which is faster than Java 1.3.x

      You can provide all the hypothesis and conjecture you want.

      It is not hypothesis or conjecture. There are demo applications provided with each Java JDK. Try them. Time them.

      Hundreds of millions of instructions per second on a heavily multi-pipelined CPU backed up by a gigantic multi-tiered cache system and a gigabyte of RAM, and this is the best I get?

      This is tedious. I heard exactly the same arguments false arguments against C++ 20 years ago. There was a myth that C++ (as against assembler) was slow, so many users and developers had convinced themselves (after experiencing a few badly written apps) that it was, and that it could never be practical.

    14. Re:Article Actually Argues Something Else by Bastian · · Score: 1

      Benchmarks! Wooo! So now we know that Java can run benchmarks and example programs really fast.

      Now let's look at the real world instead. Why not download Azureus or AEJEE and compare them to similar apps that are written in native code?

    15. Re:Article Actually Argues Something Else by Decaff · · Score: 1

      Benchmarks! Wooo! So now we know that Java can run benchmarks and example programs really fast.

      Actually, those aren't just benchmarks. They are code that has been used for decades because they illustrate real use. The numerical methods they test are used in thousands of applications that require high-performance numerics and data structure handling.

      That is why Linpack isn't just any old benchmark - it is respected. It is used to rank the performance of supercomputers.

      http://www.top500.org/lists/linpack.php

      That Java is up to running Linpack at speed is a significant and unquestionable indication of high performance.

      Now let's look at the real world instead. Why not download Azureus or AEJEE and compare them to similar apps that are written in native code?

      I have tried AEJEE. I have to admit it is pretty awful! The GUI is slow. It looks like some sort of dreadful GNOME emulation.

      However, why not try another real-world app - JEdit. Under Java 1.5 it starts up fast and has a GUI speed that no-one can complain about.

      I use Java GUI apps (NetBeans) for my development. I would be the first to say that it was slow and barely usable many years ago, but now it is fast and sleek.

      I would be interested in what you mean by native code? C? C++? They are translated to native code before they run. Java? That is native code - translated to native code as it runs (this cached native code is then re-used). I guess you must mean hand-coded assembler... well who does that these days?

    16. Re:Article Actually Argues Something Else by jafuser · · Score: 1

      I'm running Eclipse 3.1 on a dual 733Mhz system with 640MB of memory.

      It does take longer to start Eclipse than those other applications, but once it's loaded, the UI is just as responsive as any other big 2D application (Firefox, Outlook, Word, Excel, etc.) on this system.

      --
      Please consider making an automatic monthly recurring donation to the EFF
    17. Re:Article Actually Argues Something Else by Anonymous Coward · · Score: 0

      "modern" applications like eclipse and azureus are so piggish and slow that it really doesn't feel like anything has changed since 1999.

      Maybe you should upgrade that 486 and add another 16MB of memory.

    18. Re:Article Actually Argues Something Else by MemoryDragon · · Score: 1

      Actually not really, I used to think that lots of the improvements come from the proc, but then I ran a 1.4 jdk on one of those 1999 machines, and guess what, it was fast.

    19. Re:Article Actually Argues Something Else by MemoryDragon · · Score: 1

      That recently was arund 40 months ago, when 1.4 was released, 1.4 was the first release which used native rendering on Windows for the 2d parts. The VM became fast around 1.2 but Swing had lots of performance issues until 1.4.

    20. Re:Article Actually Argues Something Else by MemoryDragon · · Score: 1

      You mean something like eclipse and jdeveloper. Eclipse uses native platform widgets and basically behaves like every other ide, JDeveloper 10g uses Swing and renders the UI faster than Mozilla if I run both side by side, it is very snappy.

  15. Re:Counter arguments by LarsWestergren · · Score: 4, Insightful

    You so called counter argument is 6 years old... a lot of it weren't true to begin with, and a lot of things have happened since then.

    In the end though, the MOST important thing is that these days, processor cycles are cheap. Programmer cycles are expensive. Therefore it makes sense to sacrifice a little bit of program performance to get more productive programmers.

    --

    Being bitter is drinking poison and hoping someone else will die

  16. The problem I have is that by bhurt · · Score: 4, Informative

    the people who keep telling me allocation in Java is slow (much slower than 10 instructions) are generally experienced Java programmers. I use Ocaml, so I'm quite aware of how fast a generational garbage collector can be (btw, on the x86 in Ocaml, allocations are only 5 simple instructions). But from all first hand reports I've heard, Java allocation is still slow. It may be faster than C++, but it's still slow.

    1. Re:The problem I have is that by EvilJohn · · Score: 1

      How can a single pointer increment be slow? Allocation in Sun's JVM is a single pointer op.

      --

      Less Talk, More Beer.
    2. Re:The problem I have is that by sjasja · · Score: 1
      the people who keep telling me allocation in Java is slow (much slower than 10 instructions) are generally experienced Java programmers.

      In that case "experience" does not mean "knowledgeable", it just means "old". Or "working for Microsoft and lying about the competition".

      Java on my PC can allocate and garbage collect about 170 million objects per second. Account for loop overhead, GC, whatnot, and on a 1.6 GHz CPU 10 instructions per allocation sounds about right.

    3. Re:The problem I have is that by ucblockhead · · Score: 3, Insightful
      In C++, it only requires 1 instruction to allocate on the stack. Less than that, actually, if you are allocating multiple objects in one scope.

      You can't just compare Java allocation to:

      Foo *foo = new Foo();

      You also have to compare it to:

      Foo foo;

      Experienced C++ programmers will prefer the latter both because it is faster and because you don't have to worry about freeing it. One of the problems with a lot of the "See, Java's faster than C++!" comparisons is that they tend to translate directly from Java to C++, ignoring the things you can do in C++ but not Java (like stack allocation) that have a huge performance impact.

      --
      The cake is a pie
    4. Re:The problem I have is that by Anonymous Coward · · Score: 1, Informative

      One of the problems with comparing stack allocations in C to the unavailability of programmer-directed stack allocations in Java is that the JVM can figure out when to do stack allocations automatically via escape analysis and can do stack allocations more aggressively than a C programmer by doing automatic function inlining where appropriate.

    5. Re:The problem I have is that by Anonymous Coward · · Score: 0

      What I find irritating is the presumption that memory allocation in C++ is one and the same as calling malloc & free. There are innumerable different ways to implement memory management in C++ because the language lets you choose the appropriate implementation for each case, if necessary. This level of flexibility is far more important to me than how many instructions a typical malloc call takes, as is the predictability about when it takes place. In some application this flexibility and predictability are less important than easing the programming burden, in which automatic garbage collection is awfully nice. Use the appropriate tool for the task.

    6. Re:The problem I have is that by Anonymous Coward · · Score: 2, Insightful

      But from all first hand reports I've heard, Java allocation is still slow.

      Kep in mind that allocation in Java also includes initialization. Arrays are zeroed, object references are nulled etc. This is a good thing in general but it sure does not make allocation any faster.

    7. Re:The problem I have is that by ucblockhead · · Score: 1

      Why is that a problem? That's all the more reason to compare a Java program to a C program using stack allocation. If Java is doing it as well or better than a programming doing it manually, then it should produce faster code.

      --
      The cake is a pie
    8. Re:The problem I have is that by X · · Score: 1

      Congratulations on posting a comment without RTFA! ;-)

      The article talks specifically about this and cites how the Mustang JVM does stack allocation.

      --
      sigs are a waste of space
    9. Re:The problem I have is that by ucblockhead · · Score: 1

      Congratulations, you missed the point of the comment! ;-)

      My comment is talking about how Java comparisons generally compare doing "Foo f = new Foo()" with "Foo *f = new Foo()", ignoring the speed C++ programmers do by manually doing stack allocation.

      --
      The cake is a pie
    10. Re:The problem I have is that by X · · Score: 1

      I totally got the point of your comment. The comment is totally irrelevant to the article. If you'd read the article, you would note the section titled "Stack Allocation", which actually takes up roughly half of the article. They do compare against manually doing stack allocation in C++. They cite it as being faster than heap allocation and of course infinitely faster than heap deallocation. Then they talk about how Mustang now does stack allocation where possible.

      On the other hand, it's even quicker to not read the article and just make off-hand generalizations based on the Slashdot summary. ;-)

      --
      sigs are a waste of space
  17. Obligatory by Anonymous Coward · · Score: 0
    As usual I must point out that Java is very fast. Mainly becuase it natively compiles the most oft used .class files into super fast C binary. There's no noticeable difference in speed these days.

    The best way to think of it is: Java = C (the cleanest of C!) & Java extension for portability and interoperability etc. SADLY most novices just dont get this. AND Java garbage collection is now next generation and way ahead of anything else out there. It's alomost flawless.

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

      Crossing the JNI will always be slower.

    2. Re:Obligatory by Anonymous Coward · · Score: 0

      > super fast C binary.

      That doesn't make sence. C is a language, not a binary format. However Perl...

  18. Re:Counter arguments by Anonymous Coward · · Score: 2, Funny

    Programmer cycles are expensive.

    Not if you're counting in rupees.

  19. If I had a dime for everytime I heard that.... by ShyGuy91284 · · Score: 2, Interesting

    I've had many professors say that Java is nowhere near as slow as it used to be, and that it was just a myth now that it is that much slower the C or another language that doesn't rely on VMs. In most applications, I guess it's actually equal enough to C to be considered as an alternative. Although it doesn't have anywhere near the rich number of libraries C/C++ works with (I'd like to see someone make a cutting edge game in Java).

    --
    In undeveloped countries, the consumer controls the market. In capitalist America, the market controls you.
    1. Re:If I had a dime for everytime I heard that.... by LarsWestergren · · Score: 3, Informative

      (I'd like to see someone make a cutting edge game in Java).

      There are lots of games done in Java, mainly for mobile phones through J2ME. A few of them might have cutting edge gameplay (though I've yet to see one), but it is unlikely to see cutting edge graphics. Still, there are some pretty impressive things you can do with JOGL.

      --

      Being bitter is drinking poison and hoping someone else will die

    2. Re:If I had a dime for everytime I heard that.... by eraserewind · · Score: 3, Informative

      On the graphics thing, I don't see why not Java. Next gen phones will have HW accelerated 3d graphics. Check out the TI OMAP 2420 embedded multimedia processor specifications for a look at what the future may bring.

    3. Re:If I had a dime for everytime I heard that.... by deaddrunk · · Score: 1

      I don't know about cutting edge but Wurm Online is a 3d MMORPG written in Java and it seems to work pretty well.

      --
      Does a Christian soccer team even need a goalkeeper?
    4. Re:If I had a dime for everytime I heard that.... by DrXym · · Score: 0, Troll
      Although it doesn't have anywhere near the rich number of libraries C/C++ works with (I'd like to see someone make a cutting edge game in Java).

      I disagree with the first part of that statement. Java hands down wipes the floor with C++ even if you deck it out with STL and Boost++. Not only does it have libraries for all the usual things language runtimes provide, but encryption, UI, database, graphics, sound plus a raft of enterprise level libs.

      You might be cobble together libs for C++ which do these things, but I bet they don't run cross-platform. Even the likes of OpenGL require some platform specific code.

      I don't believe you will ever see a cutting edge game in Java (unless you consider 2D orthogonal Puzzle Pirates to be cutting edge), but I bet you a hell of a lot of MMPORG type games are using Java somewhere in the backend. In fact if I were doing an MMPORG I'd probably code up most of the back-end stuff in Java unless we were talking about a game which *really* hammered the server. Most games would have components for account maintenance, maps, NPCs, object databases, RNGs etc. I don't think it would be any trouble to run substantial chunks of that on Java.

    5. Re:If I had a dime for everytime I heard that.... by dnoyeb · · Score: 1

      Because even in C the fast graphics routines are coded in assembly.

    6. Re:If I had a dime for everytime I heard that.... by Sky+Cry · · Score: 1

      Another example - Chrome. Don't know "how much Java" it is, but it received a Duke's Choice Award last year.

    7. Re:If I had a dime for everytime I heard that.... by BruceCage · · Score: 1

      On that note I'd like to mention the following:
      Jake 2.
      Undead Arena.

      Both of which were discussed right here.

      And there's an interesting commercial game called Tribal Trouble (with a demo available).

      --
      Perfect is the enemy of done.
    8. Re:If I had a dime for everytime I heard that.... by dubl-u · · Score: 1

      There are lots of games done in Java, mainly for mobile phones through J2ME.

      Note also the MMORPG Puzzle Pirates which is Java both on desktop and server. It's not cutting edge in the sense of pushing the boundaries of the latest graphics cards, but then I wouldn't do that in Java anyhow. But Puzzle Pirates shows you can make a commercially and critically successful modern game in Java.

    9. Re:If I had a dime for everytime I heard that.... by tepples · · Score: 1

      There are lots of games done in Java, mainly for mobile phones through J2ME.

      So how can I try those games if I'm not willing to spend $960 for a 2-year mobile phone service commitment?

    10. Re:If I had a dime for everytime I heard that.... by jmccay · · Score: 2, Insightful

      I've had many professors say that Java is nowhere near as slow as it used to be, and that it was just a myth now that it is that much slower the C or another language that doesn't rely on VMs. In most applications, I guess it's actually equal enough to C to be considered as an alternative.

            Have they used the same machine to compare the performance, of all the different versions, on each time they compared? Also, how fast was the machine? I have a feeling that some of the people are comparing Java using fast computers with a lot of memory. I have 3 (usuable) computers: 1 P2 350, 1 P3 900 (loaner), & 1 P4 3G. I would not even want to try to run a complex java application on the P2 & P3 machines. The P4 is fast enough where using a VM is not going to make a difference. If you want to compare a Java to C++ use a slower machine (less than a gig speed & memory) it's more realistic of what people might have at home. C/C++ will win hands down on slow machines. I might also note that this article is from IBM Developer works which continually promotes Java, and I doubt it's in the there best interests to say C++ is better.

      --
      At the next eco-hypocrisy-meeting, count the private jets used to get to the meeting. Should be interesting to see that
    11. Re:If I had a dime for everytime I heard that.... by LarsWestergren · · Score: 1

      There are plenty to download for free, then you can send them to your mobile for instance through Bluetooth OBEX push. Works fine even under Linux, I've tried it myself.

      --

      Being bitter is drinking poison and hoping someone else will die

    12. Re:If I had a dime for everytime I heard that.... by tepples · · Score: 1

      There are plenty to download for free, then you can send them to your mobile

      I do not have a J2ME capable mobile phone yet because I can't afford one. The cheapest SIM-free smart phone that I could find costs $300, and I'm still trying to find a job. Is it possible to run J2ME games in a PC using free software, proprietary software available at no charge, or proprietary software available for less than 100 USD for one seat?

      for instance through Bluetooth OBEX push.

      Does this Bluetooth thing work even with phones sold by prepaid service providers? Or does, for instance, Virgin lock its phones so that I can't just buy a Virgin phone and a Bluetooth adapter for my PC and transfer games that way?

    13. Re:If I had a dime for everytime I heard that.... by LarsWestergren · · Score: 1

      Is it possible to run J2ME games in a PC using free software, proprietary software available at no charge, or proprietary software available for less than 100 USD for one seat?

      Yes, just google for J2ME emulators, I think Sun even has one included when you download the J2ME development kit. I know for sure Sony Ericsson/Nokia/Motorola et al have emulators. You might have to register at their developer sites first, but it should be free if you are a student or doing non-commercial development. After all, they want developers to make software that works as good as possible for their own devices.

      Mobile developer sites:
      Sony Ericsson
      Nokia
      Samsung
      Motorola

      Some good intro sites:
      J2ME Gamer
      Midlet.org

      Does this Bluetooth thing work even with phones sold by prepaid service providers? Or does, for instance, Virgin lock its phones so that I can't just buy a Virgin phone and a Bluetooth adapter for my PC and transfer games that way?

      I don't know how things work in the US, but I haven't heard of anyone locking Bluetooth file transfers on the phone, it would defeat the whole purpose of having Bluetooth. So you should be able to buy a simple Bluetooth USB dongle for your PC ($20) and then use a OBEX push program to transfer the game. The phone senses what the file is (game, image, mp3...) and where to put it, and will ask you if you want to accept it.

      Over the air transmission though (OTA) is often locked to the service provider you got the SIM from.

      I used Mandrake 10.1 when I was playing around and all drivers and programs were available as official packages on the CDs. No compiling or configuring needed after install to get Bluetooth working, everything worked like a charm.

      --

      Being bitter is drinking poison and hoping someone else will die

  20. Lisp & Smalltalk by GnuVince · · Score: 1, Offtopic

    While he's at it, could he also address the myths that Lisp and Smalltalk are slow too? Because they're not, they're pretty fast (though not as fast as C) and they offer vastly improved programming environments which leads to vastly better development time, which C can never hope to achieve.

    1. Re:Lisp & Smalltalk by Anonymous Coward · · Score: 0

      Uh I don't think anyone who knows anything would ever debate that Lisp at least is nearly on par with C. Lisp compilers are legendary in their quality of generated code and have had much longer than even C compilers to mature. I don't even program Lisp and even I know that.

  21. First! by Anonymous Coward · · Score: 5, Funny

    First post here from my Java workstation. Take that!

  22. maybe, but.. by Anonymous Coward · · Score: 0

    what if java's allocation may be non-slow? What counts is that java applets and AWT/Swing applications were slow in the late 90's, and by damn-it, thats what we slashdotters like to base our opinions of java on!

  23. The performance red herring by MarkEst1973 · · Score: 4, Insightful
    The laws of optimization are:

    1. Make it work.
    2. Make it work well.
    3. Make it work fast

    And #3 is the most interesting... how fast is fast? In an absolute sense, sure, C/C++ will always be faster. But does the end user notice this in a webapp? NO!

    I have a p3 450mhz box running Tomcat/MySql. It serves my local applications fast enough. The server can render the page much more quickly than my browser (on a p4 1.5ghz box) can render it. As a webapp, java on an old machine is plenty fast.

    Java as a desktop GUI is an altogether different story, but I'm not using java on the desktop. This point is moot to me.

    "Fast enough" to not be noticeable. That is the secret of #3. In a webapp, this is easily achieved in java.

    1. Re:The performance red herring by smallpaul · · Score: 1

      In an absolute sense, sure, C/C++ will always be faster. But does the end user notice this in a webapp? NO!

      That's the wrong criterion. In a webapp there is not one "end user". There are end users plural. And the question is how many can be served on a single server. That's the appropriate performance measurement for a webapp.

      Does that mean I would use C/C++ for a webapp? Not typically. But I would at least make the decision based upon the right measurement!

    2. Re:The performance red herring by Anonymous Coward · · Score: 0

      The laws of optimization are:
      1. Make it work.
      2. Make it work well.
      3. Make it work fast


      Very good post. And of course, the problem in the real world is that most C/C++ programmers have this scale inverted, and try to enforce their inversion on the rest of the sane world. I call it "C Programmer's Disease". Others have had other names for it (Knuth's opinion is well known, for example). It's the inability to differentiate importances, and it affects all of their work negatively.

    3. Re:The performance red herring by m50d · · Score: 1
      Java as a desktop GUI is an altogether different story, but I'm not using java on the desktop. This point is moot to me.

      Ok, but you can't blame people for saying Java is slow. Anything using swing is incredibly unusably slow.

      --
      I am trolling
    4. Re:The performance red herring by mpcooke3 · · Score: 1, Insightful

      In an absolute sense, sure, C/C++ will always be faster.

      Clearly that is not true, as the article points out, repeated malloc calls can be slow compared to a VM allocating large blocks of memory. Deallocation can also be lighter weight.

      Also a JIT can somtimes make better compilation optimizations as it has access to runtime information not available to a traditional compiler.

      That is not to say C/C++ can't be faster, or that isn't faster most of the time - just that it's not guaranteed to be faster.

      Most of the JVM memory issues (memory hogging issues and bloat) I blame on the fact that it isn't well integrated into the OS and tends not to share memory between "instances" issues that I guess won't occur with .NET. I know java 1.5 is suppose to address some of these performance issues on the desktop.

    5. Re:The performance red herring by ajs · · Score: 1

      "I have a p3 450mhz box running Tomcat/MySql. It serves my local applications fast enough. The server can render the page much more quickly than my browser (on a p4 1.5ghz box) can render it."

      I just want to note that this is a horrible metric. What you care about is not that a single browser can be fed by your program, but how well it performs under the load of dozens of simultaneous page generations.

      Single page generation metrics lead to very dissapointing real-world results.

    6. Re:The performance red herring by LarsWestergren · · Score: 1

      Anything using swing is incredibly unusably slow.

      Try downloading a demo of IDEA IntelliJ. It hogs memory, true, but it is fast AND pretty.

      --

      Being bitter is drinking poison and hoping someone else will die

    7. Re:The performance red herring by ucblockhead · · Score: 2, Insightful

      The thing is that programs don't sit around doing nothing but allocation. (If the speed of memory allocation is a factor in your program's speed, you have worse issues the language!) One of the big areas where Java performance fails is in its collection classes. The STL containers run much faster than the Java containers. This is inherent in the design. The Java containers will always be slower because of the "container of Objects" design. Sun could have fixed this with generics, but they chose to layer it on top of their "container of Objects" design rather than making it an alternative (as Microsoft did with C#.)

      This is important because the speed of most application programs spend most of their time manipulating data structures.

      Also, you're running bytecode, so you're automatically running at half-speed. Yes, JIT and optimization can recover some of this, but you can't ignore the effect.

      Last time I used Java, one of the problems was that the garbage collector tended to lock everything for a significant period (0.5-1 second) even though the average deallocation time was smaller. If this happens in a GUI event, the UI will lock for a noticible period making the app seem slower even if in terms of CPU usage it isn't. More modern garbage collectors may have fixed this. I have no idea. But average deallocation speed is not the only metric you have to look at. You also have to look at the peak time. free may be slower, but it'll never take an exceptionally large amount of time.

      --
      The cake is a pie
    8. Re:The performance red herring by Anonymous Coward · · Score: 0

      Yes. The unfortunate problem of malloc is that mallocing large blocks of memory at once is indeed known to be impossible.

    9. Re:The performance red herring by Anonymous Coward · · Score: 0

      >Anything using swing is incredibly unusably slow.

      True, that's why Java failed on the desktop.
      But in the Server market, it's the leader and rightly so.

    10. Re:The performance red herring by mpcooke3 · · Score: 1

      To be honest and I know this wasn't the original discussion I don't find the performance of the JIT that bad in terms of CPU. For web serving for example a cheapo dell can server serve well over 1.5k req/sec whilst doing some processing each request on a 1.5 JVM in server mode. This performance is good enough for server side processing. There are of course many advantages such as the excellent class library and jakarta projects.

      On the client side java is all but dead anyway due to a combination of the AWT/Swing crapness, microsoft killing it and the memory bloat issues. The one thing that was never an issue client side was the speed of running bytecode under a good JIT. Maybe the apps seemed slow but that was always swing or more likely the fact that your machine was swapping.

      Obviously you can't have a garbage collector kicking in on a real time embedded system. The garbage collector issue you mention has long since been fixed in all normal instances probably by the introduction of the better hybrid GCs.

      It will be interesting to see what becomes the dominant modern OO, VM based language/platform on Linux. With the java licensing fiasco and .NET being owned by M$ I am seeing a suprisingly large number of command line and GUI apps being written in python. I'm sure the performance of python in CPU/performance terms is way worse than java!

    11. Re:The performance red herring by mpcooke3 · · Score: 1

      it's not impossible of course and indeed you might want to do it if you were writing something like a urmm... garbage collector!

    12. Re:The performance red herring by 91degrees · · Score: 1

      Sometimes you need to make things work fast at the start. Some optimisations can be retrofitted (e.g. loop unrolling), but the basic efficiency of algorithms is something that should be in the design.

    13. Re:The performance red herring by anthony_dipierro · · Score: 1

      And we all know they don't have any garbage collection libraries for C/C++.

    14. Re:The performance red herring by mpcooke3 · · Score: 1

      You can get garbage collection for C/C++ and they have the same benefits/drawbacks as the ones in java, although the java ones are now quite advanced.

      I was only pointing out that garbage collection can improve speed over explicit allocate/deallocate calls - therefore the fact that java has garbage collection isn't neccessarily a disadvantage in terms of performance.

    15. Re:The performance red herring by anthony_dipierro · · Score: 1

      I was only pointing out that garbage collection can improve speed over explicit allocate/deallocate calls - therefore the fact that java has garbage collection isn't neccessarily a disadvantage in terms of performance.

      I'd say it's fairly rare that a well tuned program which explitly allocates and deallocates memory is going to perform better than dynamic garbage collection. In fact, it's pretty much impossible, because there's always going to be some overhead for the garbage collection algorithm itself which isn't useful in the software. Anything you can do in java you can do in assembly better. And anything you can do in assembly you can do in C. You might not want to spend the time programming it in, but it's possible, and 99% of the time you don't have to program it yourself anyway, because the compiler will optimize it for you.

      Yes, there's compiled java, but why bother kludging around with a language which was meant to be interpreted if you're going to compile it? What we need is to make smarter compilers - shift the burden of programming on to the machines.

    16. Re:The performance red herring by anthony_dipierro · · Score: 1

      To be honest and I know this wasn't the original discussion I don't find the performance of the JIT that bad in terms of CPU. For web serving for example a cheapo dell can server serve well over 1.5k req/sec whilst doing some processing each request on a 1.5 JVM in server mode.

      First of all, web serving is easy in that you're almost never CPU-limited. Secondly, web servers run for a really long period of time. JIT compliation can approach the theoretical performance of compiled software in the long run. In reality it's not unheard of to actually exceed the performance, because JIT compilation usually employs more dynamic techniques. Yes, in theory you could have self-modifying compiled C-code, but how often do we see that?

      The biggest problems I experience with java are startup time and memory usage. Both can be blamed on JIT compilation, I suppose, and the memory problem will tend to lessen over time.

      For the server-side I don't mind java that much. For high-performance software I personally prefer vanilla C with essentially no dynamically allocated memory at all, but some people don't find it easy to work in that kind of environment. The bottom line though is that as long as you have a scalable architecture performance is only going to affect the number of machines you have to buy, and machines are usually much cheaper than programmers.

      It will be interesting to see what becomes the dominant modern OO, VM based language/platform on Linux.

      Hopefully we're going to start moving to an environment where language doesn't particularly matter. If just a small fraction of the work being spent on natural language translation was spent on computer language translation we'd probably already be there.

    17. Re:The performance red herring by mpcooke3 · · Score: 1

      A good JIT is the smarter compiler.

      Regardless of the performance issues the future of software development is going to be running non-native code on a virtual machine as this has so many advtantages including portability/distribution, security and efficiency of developing large scale systems.

      Most new enterprise server side software is now being developed in Java or .NET. With the release of the next version of windows and Visual Studio most client side software will also run on a VM. Linux is bound to catch up eventually either through the Java, the .NET or another route (python?).

      Another thing to note is that it was always possible to write more efficient assembler than C, but it was often easier to write more efficient C than assembler due to better code layout, easier management of libraries, code reuse and the manageability of developing larger apps.
      A lot of people find the same is true when comparing C to Java - Garbage collection being a good example of this.

      why bother kludging around with a language which was meant to be interpreted if you're going to compile it?

      Given that we want the security, stability, portability and other benefits that a virtual machine provides and that the virtual machine runs non-native bytecode and that the JIT is nearly as fast as compiled code and faster in some circumstances - compiling java code to native is pointless from a performance perspective in most practical cases.

      In fact GCJ compiled java is usually slower than running under a modern JIT. The reasons for compiling to native is probably more to do with the license restrictions on redistributing the Sun JVM. Due to the licensing restrictions most distros won't contain a full java implementation by default and therefore native comilation and the use of classlibrary may be the only way to conveniently redistribture your java on most linux distros.

    18. Re:The performance red herring by anthony_dipierro · · Score: 1

      A good JIT is the smarter compiler.

      In theory? In a study of the average compiler? In a head to head comparison of the most popular JIT compiler with gcc? What?

      Regardless of the performance issues the future of software development is going to be running non-native code on a virtual machine as this has so many advtantages including portability/distribution, security and efficiency of developing large scale systems.

      Quite frankly, I don't see these advantages. It's trivial to recompile an app for each platform, and this is the most secure way to do things as well.

      Another thing to note is that it was always possible to write more efficient assembler than C, but it was often easier to write more efficient C than assembler due to better code layout, easier management of libraries, code reuse and the manageability of developing larger apps.

      You can write assembler in C, and seemlessly switch from one to another (nothing like the kludge of running native code with java). The vast majority of the time you don't need to though because the compiler will create the same machine code as your assembler would anyway. C is largely just a shorthand for assembler. So this is a terrible comparison.

      Given that we want the security, stability, portability and other benefits that a virtual machine provides and that the virtual machine runs non-native bytecode and that the JIT is nearly as fast as compiled code and faster in some circumstances - compiling java code to native is pointless from a performance perspective in most practical cases.

      Good JIT compilation requires a lot of memory and a significant amount of CPU. I don't see how you can say avoiding that overhead is pointless in all but the most trivial of circumstances.

      In fact GCJ compiled java is usually slower than running under a modern JIT.

      I don't deny that. Java wasn't meant to be compiled, and good compilers haven't been written for it. That's my whole point.

      The reasons for compiling to native is probably more to do with the license restrictions on redistributing the Sun JVM. Due to the licensing restrictions most distros won't contain a full java implementation by default and therefore native comilation and the use of classlibrary may be the only way to conveniently redistribture your java on most linux distros.

      Woohoo. Now I see what you mean about the many advantages in portability/distribution, security and efficiency.

    19. Re:The performance red herring by mpcooke3 · · Score: 1

      Memory allocation leaks, direct memory addressing errors, buffer over-runs and a lack of a good enforced security sandbox for the application, lack of garbage collection.

      I can't imagine you really think the recompilation of source code for N different platforms and the need to package separately for all those platforms too is actually a good thing in its-self?

      There are many reasons why i'm sure VMs will win out, the performance penulty where there is one is small compared to the quite large gains in development speed and improved code quality in developing large scale apps.

      Anyway... we could argue this one all night and I don't disagree that you can write such and such a bit of code more efficiently in C but I stand by my prediction that over the next few years, less and less code will be natively compiled. Compiling code to a native format will be slowly phased out in the same way that these days you don't often see people write CPU specific assembler.

    20. Re:The performance red herring by anthony_dipierro · · Score: 1

      Memory allocation leaks, direct memory addressing errors, buffer over-runs and a lack of a good enforced security sandbox for the application, lack of garbage collection.

      All of which can be resolved through compile-time and run time techniques without resorting to java. And in the case of garbage collection, you can choose to use garbage collection for some parts of the program and use explicit allocation for other parts.

      I can't imagine you really think the recompilation of source code for N different platforms and the need to package separately for all those platforms too is actually a good thing in its-self?

      Actually, yes, I do. I compile all the software I run on my Linux box from the source code, because this results in a better optimized binary. But my point was that recompiling an application a few times isn't that big of a deal. With JIT you actually have every user compiling their software every single time they run it. Makes no sense when you could have the author compile it 4 or 5 times for everyone.

      There are many reasons why i'm sure VMs will win out, the performance penulty where there is one is small compared to the quite large gains in development speed and improved code quality in developing large scale apps.

      Whether or not a language uses a VM has absolutely zero to do with development speed and code quality. A programming language is merely a way for a human to communicate an algorithm to a computer. Whether the computer is going to ultimately store that algorithm in machine code or byte code is irrelevant to how fast and accurately that communication can take place.

      Compiling code to a native format will be slowly phased out in the same way that these days you don't often see people write CPU specific assembler.

      But you seem to be ignoring the fact that writing CPU specific assembler is still being done by the compiler. Yes, I think writing software directly in C is going to be phased out, but unless the actual architecture of hardware changes I don't see any reason not to store machine code in between runs of the software. That seems to me like you're intentionally hamstringing the system.

    21. Re:The performance red herring by mpcooke3 · · Score: 1

      But you seem to be ignoring the fact that writing CPU specific assembler is still being done by the compiler. Yes, I think writing software directly in C is going to be phased out, but unless the actual architecture of hardware changes I don't see any reason not to store machine code in between runs of the software. That seems to me like you're intentionally hamstringing the system.

      Heh. I didn't say you shouldn't store machine code in between runs of the software.

      All I am saying is move the compiler to the client machine (which is more trusted by users anyway) add a few safety & runtime features and distribute applications as bytecode or source rather than binary.

      Like .Net or Java ;)

    22. Re:The performance red herring by anthony_dipierro · · Score: 1

      I didn't say you shouldn't store machine code in between runs of the software.

      Seems like that'd be the definition of compilation.

      All I am saying is move the compiler to the client machine (which is more trusted by users anyway) add a few safety & runtime features and distribute applications as bytecode or source rather than binary.

      Like .Net or Java ;)

      Or C, or C++, or perl, or fortran, or any language. You don't have to use Java to distribute source. In fact, one of the main purposes of Java seems to be to obfuscate the source.

      I'm not actually convinced that the advantages of local compilation outweigh the disadvantages in all situations, but for an awful lot of situations it does.

    23. Re:The performance red herring by mpcooke3 · · Score: 1

      Seems like that'd be the definition of compilation.

      Yes any time of compilation, my preferred type is a caching JIT compiler built into a virtual machine.

      Or C, or C++, or perl, or fortran, or any language.

      Sure i don't care about the language as long as it runs on my VM which of course won't support direct memory addressing and guarantees all objects are deallocated when they are no longer referenced, etc,
      Of course, that language isn't quite going to be like C or C++ anymore once we've taken out those dangerous error prone features and added a better security model. It could use some C++ like syntax though. I don't know what we'd call it, maybe C#. A kind of C/C++ for this decade.

      I much prefer to trust my Virtual machine than hope every C coder in the world is using all the software libraries, compile time and runtime safety features/checks you mention.

  24. Interesting, but I doubt it'll work by vadim_t · · Score: 3, Interesting

    The copying collector sounds really fast indeed, but I can immediately see two problems:

    The first one is the need for a huge amount of memory. It would seem that the optimal way of dealing with this is restricting the amount of memory available to the application, otherwise any app can grow to the maximum size allowed by the VM, whether it needs it or not. But this sounds rather crappy to me, now every developer needs to figure out an right limit for the application.

    The second is that performance is going to suck when garbage collection is performed. The slowdown could be a lot larger than a single execution of malloc/free, especially if virtual memory is taken into account. The unused half of the memory will often be quickly moved to swap by the VM, especially when the process grows to sizes in the order of hundreds of MB. Then GC will force bringing all that back to RAM, while possibly swapping the previously used half to disk. Exactly the same situation as what's described with heap allocation, but a whole lot worse.

    It sounds to me that even if malloc is slower, it's a lot less inconvenient in applications like games, where something that is always slow can be taken into account, but where a sudden run of the GC could be really inconvenient.

    But this is not my area of experience, so it's just what came to mind. Can anybody confirm or refute these suspicions?

    1. Re:Interesting, but I doubt it'll work by Anonymous Coward · · Score: 0

      For your comment on huge memory use, that is a tradeoff. More garbage collection reduces the need for future allocation, but costs more in speed. Java generally makes the assumption that memory is cheap and favors speed (which is why even modern Java programs tend to bloat in memory size beyond their needs).

      For performance, the only time performance suffers is during compaction. Remember, any time an object is freed, it is just *marked* as free (simplification, but close enough). Compaction itself costs but is only needed on those occasions when memory starts becoming tight. And it usually isn't needed at all in the "young" heap area, since the deallocated memory of other young objects can be reused for the next object in need of allocation. On the few occasions it is needed (a whole lot of small objects on the "old" heap area are fragmenting the memory too much) it will cost. Upshot is, the garbage collector is a separate thread in Java. If you program is doing any significant amount of I/O (from the hard disk, network card or heaven help you, the *user*) the garbage collector can do a compaction essentially for free while waiting for input.

      The GC usually need not bring any dead data out of swap; certain data about objects is stored independent of the object to reduce that problem, so the GC can just tell the OS to free it (and keep in mind, the OS doesn't manually zero the swap space either, so both JVM and OS get to be lazy).

      Finally, keep in mind that you can run manual garbage collections. So if you are really afraid something you are about to do could cause an inconvenient mid-processing collection, just manually start a collection ahead of time (ideally while another thread is loading data for you or the like).

      I will acknowledge that this type of memory managment is optimized for allocation. malloc is an extremely expensive call (relatively speaking) which is why they do block allocations and then manually manage everything with the GC, eliminating that cost. Essentially they make allocation orders of magnitude faster in exchange for small potential slowdowns in deallocation.

              -ShadowRanger

    2. Re:Interesting, but I doubt it'll work by sulam · · Score: 1

      Yes, I can refute your suspicions. Incremental garbage collection algorithms exist and are used in the JVM's GC.

    3. Re:Interesting, but I doubt it'll work by DrJimbo · · Score: 1
      ShadowRanger said:
      Compaction itself costs but is only needed on those occasions when memory starts becoming tight. And it usually isn't needed at all in the "young" heap area, since the deallocated memory of other young objects can be reused for the next object in need of allocation.
      You've lost me here. Perhaps it is due to my lack of knowledge about generational gc.

      I thought the original article was boasting that Java gc allocation was very fast because it didn't need to walk free lists in order to allocate. Instead it just grabbed memory from the top of the half-heap that was currently active.

      How can deallocated memory be reused without the overhead of free lists?

      ShadowRanger said:

      The GC usually need not bring any dead data out of swap; certain data about objects is stored independent of the object to reduce that problem, so the GC can just tell the OS to free it (and keep in mind, the OS doesn't manually zero the swap space either, so both JVM and OS get to be lazy).
      I agree that the gc can tell the OS to free the unused half of the heap so the garbage in it need not be read back in from swap. But the gc will then need to ask the OS for a new huge block of memory, half the size of the heap. This means the OS will have move other active memory into swap in order to have enough space in RAM for both halves of the heap when the copying from one half to the other is occurring.

      Granted, the VM manager might be smart enough to do the freeing of RAM incrementally, it still seems to me that no matter how you slice it, if the heap is large enough, copying one half of the heap to the other half is going to require a lot of swapping.

      --
      We don't see the world as it is, we see it as we are.
      -- Anais Nin
    4. Re:Interesting, but I doubt it'll work by 5pp000 · · Score: 1
      Your suspicions were true concerning the first copying collectors, but all modern, production-quality copying collectors are generational. This means that memory is divided up into at least two generations. Objects are originally allocated in the youngest generation, which is given a fairly small amount of memory and collected frequently; those that survive some number of collections are promoted to the next older generation, which is substantially larger and collected considerably less frequently; and so on for as many generations as the collector supports. Since most objects die young, most of the garbage is picked up by the youngest-generation collections, which are fast because the amount of memory involved is small. Thus, the oldest generations fill up more slowly.

      What you want to do as the oldest, largest generation fills up depends on the application. Collecting this generation is indeed going to take some time. In many situations it makes more sense to kill the process and restart it than to try to collect that generation.

      I'm speaking generally here and not about the JVMs in particular. Sun and IBM have both put a huge amount of work into their collectors and may have a workable way to collect the oldest generation. With the Lisp implementations with which I am familiar, however, restarting the process is almost always more practical. The advantage of the generational collectors is that one doesn't have to do that too often, as the older generations tend to fill slowly.

      --
      Your god may be dead, but mine aren't!
    5. Re:Interesting, but I doubt it'll work by dubl-u · · Score: 1

      The copying collector sounds really fast indeed, but I can immediately see two problems: The first one is the need for a huge amount of memory. [...] The second is that performance is going to suck when garbage collection is performed.

      I think that's more an effect of his simplified explanations. There are some pretty obvious optimizations that I'm sure Sun has taken. One of them he mentions: by doing thread-local pools, you parallelize things. That also means smaller buffers, so the cleanups are less likely to be noticeable, and easier to schedule when the thread is idle or blocked.

      Further, he only mentions the copying GC when talking about young-generation GC. Since it only has to hold long-lived objects for a little while, I'd bet it will be a relatively small fraction of total memory. My guess is that they use something else that's more complicated for longer-lived objects. But they can afford it: because they've handled 95% of the allocation/deallocation cheaply, that gives you a lot more juice to handle the long-lived stuff.

      It would seem that the optimal way of dealing with this is restricting the amount of memory available to the application, otherwise any app can grow to the maximum size allowed by the VM, whether it needs it or not. But this sounds rather crappy to me, now every developer needs to figure out an right limit for the application.

      I do find that long-running 1.4 JVMs will slowly creep up in usage, even though there should be no need. In practice it's a little annoying, but I can live with it. I'd rather we had more knobs to twist, especially from inside the JVM. E.g. being able to say, "right now you can do GC for 50 ms". Or to hint to it about how happy I am to trade RAM usage vs CPU usage.

      I'd also like more collaboration between the JVM and the host OS. If a system has a half-gig of RAM free and is currently under heavy CPU load, the JVM can be pretty slack for a while, and there's no need to throw OutOfMemory errors. But if the system is RAM-constrained and starting to swap, it's be great if the JVM automatically started freeing RAM and giving it back. Doing GC across swapped memory would suck much worse than a very aggressive GC.

    6. Re:Interesting, but I doubt it'll work by kaffiene · · Score: 1

      I've coded up a lot of mini games in Java and C++. What I've found is that Java/OpenGL performance is pretty much exactly the same as C++/OpenGL.

      I'm currently working on a 2d game - I've compared C++/SDL versus Java and found that performance is identical although in this case I'm going with C++/SDL because I found that the Java version suffered from some JIT stuttering at the start which I couldn't get rid of.

      I've never had that stuttering problem in 3d, so either I fucked up with the code, or perhaps the fact that the 3d games offload rendering meant that it wasn't a noticible effect in that context.

      At any rate, my conclusion is that Java performance is fine in raw throughput, but sometimes you can have issues with smoothness. My other conclusion would be that people who think Java is slow are talking crap. I code C++ and Java and my choosing between them is an issue of how I want to distribute code rather than a performance issue.

    7. Re:Interesting, but I doubt it'll work by MSBob · · Score: 1

      Have you tried turning incremental garbage collector? It offers improved "smootheness" at a slight performance penalty (ie never "stops the world" when performing GC).

      --
      Your pizza just the way you ought to have it.
    8. Re:Interesting, but I doubt it'll work by MSBob · · Score: 1

      Have you tried turning on the incremental garbage collector? It offers much "smoother" performance at a slight throughput penalty (ie never "stops the world" when doing GC). I think the option is -Xincgc or something like that.

      --
      Your pizza just the way you ought to have it.
    9. Re:Interesting, but I doubt it'll work by sean.geek.nz · · Score: 1

      dead right re memory space.

      the copy collector isn't new (it's been around since 2002). But the big problem for modern JVMs is memory. Paging sucks.

    10. Re:Interesting, but I doubt it'll work by kaffiene · · Score: 1

      Yeah, I did play a bit with different GC'rs and startup parameters. To be honest, I'm not convinced it's Java's fault - I really didn't analyse the problem all that carefully. The thing is, for this game I'm deliberately trying to make the potential audience as wide as possible (hence not using 3d accelleration, which I'd usually do) and I just thought not using Java might just be simpler in that instance. As I was kinda 50/50 about how I was going to implement the game, this issue just tipped me in another direction. I might well use Java for other future projects (I *am* using Java for my map editor ;o) )

      Also, it was a fairly bleeding edge version of Java and I didn't experiment much, so I can't claim this is definitively a Java issue. Probably my crap coding =)

    11. Re:Interesting, but I doubt it'll work by Anonymous Coward · · Score: 0

      Try -XX:MaxGCPauseMillis=500
      if your app isn't very memory hungry (I use 2000 for Eclipse and never notice any pause).

      Here's my eclipse command line

      eclipse.exe -vmargs -Xms128M -Xmx700M -XX:MaxGCPauseMillis=2000

  25. Agency9 by Anonymous Coward · · Score: 0
  26. But Java's /still/ slow. by Anonymous Coward · · Score: 0

    No matter what the theory says, your average Java application could be written to be more resource efficient, overall, in C/C++. That's the experience. (So Java's either inherently slower, or your average Java programmer is just really really bad at writing efficient algorithms.) Maybe Java will some day meet the assembly-level languages. I do doubt it, but I'll permit the possibility.

    What I'm more interested in is porting this supposed efficiency to C/C++, if it's so useful. First, can we demonstrate that the model doesn't beget yet more allocation (which could shoot it in the foot)? It doesn't seem to at first glance. So, what's stopping a C++ coder from calling a monstrous malloc(), then using their own memory management routines on their userspace heap? Nothing at all. That's basically what Java has to do anyway (well, it probably uses brk()...)

  27. This is Not News by putko · · Score: 4, Interesting

    Here is a paper (PostScript) from 1987 on the topic of GC being faster than manual allocation.

    The author went on to make a very fast GC that set speed records.

    If you are looking for factual arguments, with performance measurements and so on, just look at his work over the last few decades -- you'll see he did a lot of work in these very practical areas.

    When you see how productive guys like him can be, it makes me wish that some people would just stay alive, and keep working, for a few hundred years more, instead of our typical mortal lifespans.

    --
    http://www.thebricktestament.com/the_law/when_to_s tone_your_children/dt21_18a.html
    1. Re:This is Not News by Sirch · · Score: 2, Funny

      "When you see how productive guys like him can be, it makes me wish that some people would just stay alive, and keep working, for a few hundred years more, instead of our typical mortal lifespans"

      ... but that would be circumventing God's garbage collector! Just as in Java, when God has no more use for you, he'll "collect" you on his own timetable.

      Of course, you could always suggest someone is collected with a shotgun...

      Laugh, funny etc.

    2. Re:This is Not News by joto · · Score: 1
      Actually, the paper is pretty much an urban legend itself, as it makes very unrealistic assumptions. It assumes that using ~10 times as much memory as you really need is without cost. It isn't. First, cache is important, and if you use a lot of memory, you will lose, due to memory being slow. Secondly, RAM is expensive, and in the 32-bit world, address-spaces are limited.

      The paper is raising some important theoretical points, but there's a reason no language implementation is using it's ideas. The assumptions made in the paper may have made sense in 1987, when everybody assumed we would soon have large amounts of RAM, and nobody expected that the large amounts of RAM we would get would be so slow that PC's would need 3-level cache-hierarchies.

      Appel is certainly a very clever guy, but anyone quoting this paper today, is either a troll, or simply uninformed.

    3. Re:This is Not News by napir · · Score: 1

      "Garbage Collection can be very fast. Indeed, there is a much quoted argument that the amortized cost of copying garbage collection tends to zero, as memory tends to infinity. Novice functional programmers often report that on their machines, memory is a constant, not a variable, and this constant has to be uncomfortably large for their programs to run well."

          -- Mads Tofte & Jean-Pierre Talpin, 1994

      Appel's SML/NJ collector is good, but by no means did it completely solve the GC problem.

  28. MOD THIS UP!!!!!! +9 FUNNY by Anonymous Coward · · Score: 0

    This is the funniest post I have ever seen on Slashdot!

    Think about the article and the n look at the post! Mod parent way up!

    1. Re:MOD THIS UP!!!!!! +9 FUNNY by wheany · · Score: 4, Funny

      Oh yeah! Now that you mention it, it really is funny! You see, the article talks about how Java is not as slow as is generally believed, but then the grandparent says that he posted the message using Java! That's not funny as such, but it is when you consider that it's supposedly the first post! And it's funny to think that he might have actually been the first to post the message, but since he was using Java, its slowness caused the message to be actually posted waaay late!

      Too funny!

    2. Re:MOD THIS UP!!!!!! +9 FUNNY by Ray+Alloc · · Score: 0

      Well, one could say of your luminous understanding of that obvious joke that you understand fast, when you are told slowly.

  29. pff by Anonymous Coward · · Score: 0

    It's not the speed that is an issue, so much as the inability of java to function well outside of number crunching. Its graphical toolkits are crap, slow, non cross platform and ugly. As well as this it can't be used efficiently for 3d, sure there's java 3d, a terrible kludgy hack on top of opengl. If i could use java efficiently for programming graphical applications then i might consider it.

  30. expense comes with the paradigm by jherber · · Score: 1

    java's microbenchmarks prove where it doesn't have problems.

    the java platform's mantra is "create and use objects". when you compare java to languages that allow objects, but are not heavily object oriented in terms of their supporting framework and libraries, then what you are seeing is the expense of the OO paradigm.

  31. Re:Counter arguments by Michalson · · Score: 5, Insightful

    Then use Delphi, or better yet, C#. (or even Python and a few other choices)

    Faster productivity, less bugs, no ram guzzling 5 minute startup. Java isn't the only language that reduces development time, it's just the only one (besides VB) that makes you sacrifice big things to get it.

  32. urban performance? by wiggle.e · · Score: 1

    I thought this was about the seattle music scene...

    Seriously shouldn't it be "Java Performance Urban Legends"

  33. Re:Duh Stack wins whats to agonize over? by dalleboy · · Score: 0, Flamebait

    Perhaps the web server is written in Java?

  34. Whiskey Tango Foxtrot??? by Anonymous Coward · · Score: 0

    WTF??? You claim that since Java is fast enough for you, running a webapp, on older hardware, running locally, for a single user, it must be fast enough for everyone? Suppose, just for the sake of argument, that there are more than one users! Suppose you are CNN.com and that webapp has to serve 2 or 3,000 users per second. Is Java fast enough then? Is it faster than C++? Is it faster than C? Are you retarded??

    1. Re:Whiskey Tango Foxtrot??? by parryFromIndia · · Score: 2, Interesting

      OP's comment is based on the fact that Java is usually deployed on those big iron Sun boxes (8-way minimum, 16-way, 32-way etc. with 32Gb RAM etc. - you get the picture.) Any darn thing runs reasonably fast on these machines. And when things execute in-memory and are JIT'ed there is no reason to believe Java code will execute slower than say C/C++ code. Plus lots of design patterns have grown to make up where Java performance sucks - Use huge thread pools to avoid creating threads on demand, cache as much as you can, pool objects to avoid doing new on big objects etc. Java/J2EE makes it possible to write robust server side applications quickly without having to deal with low level details. People pay a big price for this by having to buy those big boxes on the server side. It could be argued that smart C/C++ programmers can build something more reliable/scalable with less resources - but matter of the fact is that world is full of lazy "high-level" "abstract" "mediocre" programmers. Destop is a different matter altogether - people still have machines with mere 256Mb RAM with one pale CPU - C/C++ rocks there. Java sucks badly on the desktop - Graphics/Drawing is slow, startup time is horrible, simple apps can require boat load of memory and on top of this the UI looks nasty. Just a data point - Microsoft's VC# IDE requires 29Mb - it's written in C/C++ and embeds the C# VM. Netbeans and Eclipse - last I checked they needed atleast 100Mb!

    2. Re:Whiskey Tango Foxtrot??? by Anonymous Coward · · Score: 0

      The reason the Java IDEs seem to use so much memory is that Java applications mmap the classpath jars on startup. rt.jar alone (the one containing the J2SE libraries) is 50 MB. Because of the way mmap works, that doesn't mean all of that is actually resident in memory.

    3. Re:Whiskey Tango Foxtrot??? by parryFromIndia · · Score: 1

      Absolutely true, it just changes the perception and wastes virtual address space. They could separate the rt.jar into smaller pieces though - console, gui, networking, corba orb, .... they all could be separate jars mapped on demand. This has an added benefit of more available address space - server side apps need it to work better with the 32bit JVM's address space limits.

    4. Re:Whiskey Tango Foxtrot??? by MemoryDragon · · Score: 1

      Java seems to be fast enough, because stuff like ebay, www.weather.com, walmart.com etc... all run on java, and they do that happily.

  35. yes, illiterate people can't read by Anonymous Coward · · Score: 0

    get educated

  36. good programmers by willCode4Beer.com · · Score: 5, Insightful

    A *good* C++ programmer will probably write code that outperforms the equivalent in Java. A *good* C+ programmer will remember to deallocate all of his objects to prevent memory leaks. A *good* C++ programmer will copy his strings correctly to prevent buffer overflow exploits.

    If you have been involved in developmnent for any reasonable amount of time or worked on projects of reasonable size, you know that *good* programmers are hard to come by. When you add the real world to the picture you find that simple things like garbage collection and a virtual machine can make a mediocre java programmer outperform a mediocre C++ programmer.

    If schools actually learned to produce good programmers, and HR departments learned how to identify them, and job interviews verified them, we wouldn't be having this discussion.

    --
    ----- If communism is a system where the government owns business, what do you call a system where business owns govern
    1. Re:good programmers by carlislematthew · · Score: 3, Informative
      You're absolutely correct, except perhaps in the last paragraph. Programming is as much about aptitude as it is about education and experience. Some people will *never* be good programmers no matter what you do with them.

      I have programmed (in many different languages) since I was about 9 and regard myself as a good programmer - who doesn't? ;) Anyway, I now hire and manage programmers and have interviewed probably about a hundred people for programming positions. Most of them are total shit. They couldn't program their way out of a paper bag. Their resume looks great and they have all the acronyms and say the right things. Then I ask them to code a function to reverse the order of a string with allocating as little extra memory as possible. Less than 50% of people can do it right. A simple algorithm like this is easy to check in your head and they just don't get it.

      One of the other more "nasty" questions I ask is for people to do a number to hex-string conversion algorithm. I've only have ONE person do it right. Most just stare at me. They don't understand binary! They mostly have CS degrees so they were taught, but their brains don't really get it. It's very interesting because most people don't understand what a number is at a base level - it's astounding. I could go on...

    2. Re:good programmers by shadow_slicer · · Score: 1
      I don't know. I think that everyone could probably be a good programmer if they practiced enough. You say you've been programming since you were 9. I've been programming since I was about that old as well. But a lot of the CS and SE major's first programming experience is freshman year in college. This puts them 10 years behind. There's no way they can gain the amount of experience they need to be a good programmer over the course of 4 years (Especially since they probably don't program outside of classes).
      How long after you started programming did you become what you would call a "good" programmer? (I know it took me at least 7 years...)

      Though reversing a string seems like an interesting problem...
      void reversestring(char *str, int len)
      {
      int i;
      for (i = 0; i < len/2; i++)
      {
      str[i] ^= str[len-i-1];
      str[len-i-l] ^= str[i];
      str[i] ^= str[len-i-1];
      }
      }
      Though this solution doesn't work with multibyte character sets....
    3. Re:good programmers by carlislematthew · · Score: 1
      Yes, it took me several years before I became a good programmer. Perhaps at the age of 15 or 16 or so, especially because it was a hobby thing. It should take less time if you have a teacher, and a job where you do it for 40 hours week. :)

      Something I believe strongly is that learning at an early age is the only way to be *really* good at thinking in a different way. I started to program in assembly language when I was 12, so I have a different way of thinking about numbers than most people do. I'm not sure that it's as easy to teach an 18 year old the kinds of things that a more moldable child can learn.

      There are some people that just have the right kind of brain for programming. Often they like logic puzzles, crosswords, and so on. These people will usually make better programmers than those that don't like puzzles because they're confusing and boring, and just started to program at the age of 25 because that's where the money is.

      I'm jaded though - I've interviewed far too many shitty programmers, and seen far too many people in programming that went on a VB programming course in 2000 and complained for the next three years that they couldn't get a job.

    4. Re:good programmers by oliverthered · · Score: 1

      Ah the old xor trick (can't say I've ever had to use it in a real environment though).

      Though this solution doesn't work with multibyte character sets....
      Easy....

      void reversestring(unsigned short *str, int len)
      {
          int i;
          for (i = 0; i len/2; i++)
          {
              str[i] ^= str[len-i-1];
              str[len-i-l] ^= str[i];
              str[i] ^= str[len-i-1];
          }
      }

      Also, your using a tiny bit more memory than you need to (at least 1 int without compiler optimization) because i++ expands to i = i + 1 which means you need a copy of i, if you used ++i which expands to inc i then you don't need a copy.

      --
      thank God the internet isn't a human right.
    5. Re:good programmers by UOZaphod · · Score: 1
      Here's my variation on the ReverseString. It uses the XOR swap as well (like the other guy--beat me to the punch), but uses pointers instead of all the arithmentic inside of array indices.

      It also doesn't require a length to be passed, and checks if the pointer is not NULL.
      void ReverseString(char *ptr1)
      {
        char *ptr2;
       
        if (ptr1 && *ptr1)
        {
            for (ptr2 = ptr1 + 1; *ptr2; ptr2++);
       
            for (ptr2--; ptr2 > ptr1; )
            {
              *ptr1 ^= *ptr2;
              *ptr2 ^= *ptr1;
              *(ptr1++) ^= *(ptr2--);
            }
        }
      }
      --
      "The unicode stuff in the latest version is working fabulously well. My russian mafia friends are ecstatic."
    6. Re:good programmers by willCode4Beer.com · · Score: 1

      If their first programming experience is in college, then this is a big sign to question why they are chosing this profession.
      The ones who chose to code because they love it, generally will have taught themselves to program long before college. Generally, these people tend to be good programmers.

      One thing the parent was pointing out, many people with years of 'experience' (impressive resumes) are still missing the basics. I used to give interviewees a simple string parsing question. I've had MIT grads with years of 'experience' in every acronym and buzz word not even know how to compile their code.
      Of course, I am sure there are some prople who learn to code in college, and never do it in their spare time who become good programmers. I've just never met one. If the schools get better at teaching the subject, maybe I will one day.

      --
      ----- If communism is a system where the government owns business, what do you call a system where business owns govern
    7. Re:good programmers by Anonymous Coward · · Score: 0

      But that does not take care of multi char characters (assuming unicode).

    8. Re:good programmers by GuyWithLag · · Score: 2, Interesting
      Also, your using a tiny bit more memory than you need to (at least 1 int without compiler optimization) because i++ expands to i = i + 1 which means you need a copy of i, if you used ++i which expands to inc i then you don't need a copy.

      Hear that glass breaking? That's your credibilty going out the window... The statement i++; where i is an int will produce exactly the same code with ++i; and i=i+1; on an optimizing compiler, and no extra memory (or registers) will be used. Note that i is an int, not an object with overloaded operators...

      Here's a problem: write the same programm, but don't use any extra variables.
    9. Re:good programmers by UOZaphod · · Score: 1

      As a side note... using a local char variable as temporary storage for the swap would likely be faster than the XOR swap, considering all the pointer dereferencing that has to be done.

      However, the rules specified allocating the least amount of memory as possible, so I assumed even local variables would count against it.

      --
      "The unicode stuff in the latest version is working fabulously well. My russian mafia friends are ecstatic."
    10. Re:good programmers by carlislematthew · · Score: 1

      Now, could anybody else make it any *more* complicated? I can still just about understand what it is you're doing, so we're not quite there yet. ;)

    11. Re:good programmers by oliverthered · · Score: 1

      I guess you missed the 'at least 1 int without compiler optimization' bit of my comment, and you can't 100% guarantee that the compiler won't use and extra int. Anyhow I thought the idea is for the programmer to produce the fastest code possible not the compiler, you may as well write the code in Java.....

      --
      thank God the internet isn't a human right.
    12. Re:good programmers by Henry+V+.009 · · Score: 2, Insightful
      #include <string>
      #include <algorithm>
      using namespace std;
      int main(void){
      string s("Please reverse me");
      reverse(s.begin(),s.end());
      }
      What do I win? (Better be a job.)
    13. Re:good programmers by oliverthered · · Score: 1

      It doesn't take care of every case, but I've never seen Unicode outside 2 bytes in use, the example was to show that the code could be adapted to fix other character sets very easily.

      --
      thank God the internet isn't a human right.
    14. Re:good programmers by UOZaphod · · Score: 1

      If I recall, the only stipulation was "code a function to reverse the order of a string with allocating as little extra memory as possible".

      It doesn't say anything about being fast, efficient, easy to understand :)

      So I coded something in which the only allocation is a single local pointer.

      I think one of the other posters was right though about (x++) expanding to (x = x + 1)

      I'm thinking about refactoring the code to use pre-increment/decrement only.

      --
      "The unicode stuff in the latest version is working fabulously well. My russian mafia friends are ecstatic."
    15. Re:good programmers by UOZaphod · · Score: 1
      How's this:
      void ReverseString(char *ptr1)
      {
        char *ptr2;
       
        if (ptr1 && *ptr1)
        {
            for (ptr2 = ptr1; *(++ptr2); );
       
            for (--ptr2; ptr2 > ptr1; ++ptr1, --ptr2)
            {
              *ptr1 ^= *ptr2;
              *ptr2 ^= *ptr1;
              *ptr1 ^= *ptr2;
            }
        }
      }
      I think I've been using post-increment too much... using pre-increment seems to generate code that is more readable.
      --
      "The unicode stuff in the latest version is working fabulously well. My russian mafia friends are ecstatic."
    16. Re:good programmers by carlislematthew · · Score: 1

      Fair enough. Your solution is good and allocates very little memory. However, I would also accept a solution that allocated one more byte and was more readable. :)

    17. Re:good programmers by Desult · · Score: 1

      This is a fun little problem.

      To my mind, the obvious solution is this:

      char* target;
      char temp;
      int i;
      for (i = 0; i < strlen(target)/2; i++)
      {
        temp = target[i];
        target[i] = target[strlen(target)-1-i];
        target[strlen(target)-1-i] = temp;
      }

      But then I thought, hey, there must be a cheat way to do it better! So I came up with this:

      char* target;
      int len = strlen(target);
      int copyPtr;
      for (copyPtr = 0; copyPtr < len/2; copyPtr++)
      {
        target[len] = target[copyPtr];
        target[copyPtr] = target[len-1-copyPtr];
        target[len-1-copyPtr] = target[len];
        target[len] = 0;
      }

      But this is worse. Since we're clobbering the null terminator, we can't rely on strlen in the body of the loop, so in the final analysis we're using 2 integers rather than a char and an integer, which in most systems nowadays, is actually worse memory usage (8 vs 5 bytes).

      I fiddled around with other solutions, including using a function call and incrementing the base pointer. This really didn't work... I found an alternative representation of the initial solution. No more i, but we have to maintain len... and if the code isn't used in a function call, we're short a char* to the start of the string. D'oh!

      char* target;
      int len = strlen(target);
      char temp;
      while(len > 0)
      {
        temp = targ[0];
        targ[0]=targ[len-1];
        targ[len-1]=temp;
        targ++;
        len--;
      }

      So it seems that the trivial, obvious solution is actually the best solution! Firstly I am curious if this is the answer you were looking for; I am not the best at seeing neat algorithmic tricks to optimize processes. Secondly, if it is right, I am curious if you would think twice about hiring someone who tried to do the tricks above. They grasp the language, but in their mad rush to be "smarter", they actually create WORSE solutions (both in style and in, as here, actual results).

      I am also curious if there is a solution that uses less than char (1 byte) + an integer (generally 4 bytes nowadays)? I surely haven't found one in the 30 minutes I've thought about it! =)

      --
      -Greg
    18. Re:good programmers by Junks+Jerzey · · Score: 1

      Anyone I interviewed who pulled out the xor-swap would immediately be pinned as a wannabe. The normal code, with a temporary, is both clearer and faster.

    19. Re:good programmers by carlislematthew · · Score: 2, Interesting
      In an interview, I used to tell people that they could use strlen, but not other string functions. I stopped telling people that a couple of years ago and sometimes people give a solution like yours. If you weren't an axe murderer and you actually gave me the real solution afterwards (after I clarify I want *you* to implement it), then you'd definately be in the running to get a job. :)

      BTW - your solution allocates about 4 squigabytes of memory, but that's OK because it all gets allocated by someone else, so it doesn't count. ;)

    20. Re:good programmers by UOZaphod · · Score: 1
      Extra byte, more readable... (and should actually be fairly fast as well) :)
      void ReverseString(char *phead)
      {
        char *ptail;
        char ch;
       
        if (phead && *phead)
        {
            for (ptail = phead; *(++ptail); );
       
            for (--ptail; ptail > phead; ++phead, --ptail)
            {
              ch = *ptail;
              *ptail = *phead;
              *phead = ch;
            }
        }
      }
      --
      "The unicode stuff in the latest version is working fabulously well. My russian mafia friends are ecstatic."
    21. Re:good programmers by oliverthered · · Score: 1

      That's why 'theoretical' questions are bad. For instance someone who's just left collage will probably know things like the xor swap and all kinds of other weird algorithms that are hardly any use. I would suggest on focusing on the big picture just as much as a little picture, questions like (but obviously more complete) 'foo kept returning bad results, what do you think the problem could be' are far more important and require a greater knowledge and skill, and will probably save your neck one day. You could also ask candidates to think of optimizations for a design, or point out flaws in the design.

      --
      thank God the internet isn't a human right.
    22. Re:good programmers by carlislematthew · · Score: 1
      The first solution is the easiest and simplest, although I'm not sure about the strlen repetition.

      I'm not actually sure that the last two solutions you did will actually work... It's early here. :)

      When I'm asking this question I want someone to write a function that uses minimal memory but is still readable. Then, if they know other ways to optimize even further, they can get bonus points by offering to implement addition solutions that would save X more bytes, but would unfortunately be not as readable. Doing exactly what I say (i.e. minimal memory usage!) is not necessarily the exact answer to the question. Reject authority! :)

    23. Re:good programmers by UOZaphod · · Score: 1

      What, are you sore you didn't think of it yourself?

      Look, the stipulation was to allocate the least amount of memory as possible. It didn't say anything about local variables being an exception to the rule.

      You can eliminate one more local variable using an XOR swap.

      If I knew I could have two local variables I would code it like the final revision of my own solution.

      --
      "The unicode stuff in the latest version is working fabulously well. My russian mafia friends are ecstatic."
    24. Re:good programmers by corngrower · · Score: 1

      Clearer - yes. Faster - probably not.

    25. Re:good programmers by carlislematthew · · Score: 1

      How about something else.. It's a little more subjective, but implement the same function but where you attempt to balance minimal memory usage with readability. Assume you are a contractor and all code is to be passed off to the internal development team afterwards, so it must be maintained by someone else that you don't know.

    26. Re:good programmers by Kjella · · Score: 1

      One of the other more "nasty" questions I ask is for people to do a number to hex-string conversion algorithm. I've only have ONE person do it right. Most just stare at me.

      Honestly?
      #include <QString>
      QString toHex( uint i )
      {
          return QString::number( i , 16 );
      }

      For straight C++, I'd have an const char array with 0...f, and build a string using array[i % 16] and i / 16 alternately. I'm sure you can do it slightly faster with & 0x00000001 to find the mod value and >> 4 if you know the endianness of the computer.

      --
      Live today, because you never know what tomorrow brings
    27. Re:good programmers by Anonymous Coward · · Score: 0

      And here we see, in essence, why C/C++ sucks for writing reliable and maintainable code.

      Yes, using XOR is a "clever hack" (one that many of us have seen before, no doubt. I have, certainly), but what does it gain in this case? You save one byte of RAM. So? My Palm has a gigabyte of RAM. Woo-hoo! I've saved one billionth of my available memory! And it's been saved for the length of time before the function call returns and the stack gets unwound! Awesome!

      Now, what have you lost? You've created unreadable, unmaintainable code that is almost certainly harder for the compiler to optimize. You've also violated type safety by treating a variable of one type (a character) as a variable of a completely different type (a one byte integer). Someone else points out that this will break, horribly, if you're using a multi-byte character set. Now, imagine that someone else is given the task of internationalizing a large code base that contains your "clever hack" string-reverse code somewhere deep in its bowels. All of a sudden that one byte saving doesn't look so "clever", does it?

      If you asked me to do this in a job interview, I'd come up with the XOR solution. Then I'd tell you, in detail, why it's a horribly shitty way to write code.

      I suspect I wouldn't get the job. :-)

    28. Re:good programmers by carlislematthew · · Score: 1
      Yes, straight C would be nice. No printf. :)

      Mathematicians do some crazy divide, remainder, often recursive solution. Most just confuse themselves.

      The bit sifting method is the way to go in my experience. However, most programmers don't know about bits - they've been programming in Java for too long. :) Here we go - I've really started a debate now!!!!

    29. Re:good programmers by carlislematthew · · Score: 1
      You would be incorrect. I prefer people to either write the code the way I asked and *then* tell me why it shouldn't be done that way, OR they should tell me beforehand why they *won't* do it a certain way, and why.

      The only problem I would have with hiring you is the potential diplomacy issues. ;)

    30. Re:good programmers by Henry+V+.009 · · Score: 2, Informative
      Okay, you have intrigued me. Here is my solution. No extra memory needed for a temp variable due to a dirty trick. But I strongly advise you not hire anybody who does this. There will be tears.
      #include <cstring>
      int main(void){
      using std::strlen;
      char c[] = "Please reverse me";
      int length = std::strlen(c);
      for (int i=0;i < length/2; ++i){
      c[length] = c[i];
      c[i] = c[length - 1 - i];
      c[length - 1 - i] = c[length];
      }
      c[length] = '\0';
      }
      Also, I'm afraid that I'd never get the interview. No coding experience and have never taken a class in it. Fun hobby though.
    31. Re:good programmers by UOZaphod · · Score: 1
      Well, this is about as readable as I can make it while sticking with the original concept of using pointers (it appears slashdot likes to mess with my formatting though):
      void ReverseString(char *phead)
      {
        char *ptail;
        char temp;
       
      // check for NULL pointer or zero-length
       
        if (phead && *phead)
        {
       
      // find tail of string
       
            for (ptail = phead; *(++ptail); );
       
      // work from outside toward middle
       
            for (--ptail; ptail > phead; ++phead, --ptail)
            {
       
      // swap head and tail
       
              temp = *ptail;
              *ptail = *phead;
              *phead = temp;
            }
        }
      }
      --
      "The unicode stuff in the latest version is working fabulously well. My russian mafia friends are ecstatic."
    32. Re:good programmers by carlislematthew · · Score: 1
      Cool - nice - that's probably as readable as it can get with pointers. Having said that, I prefer a non-pointer implementation with just using []. It compiles to something very similar and is much easier to understand as it uses the simpler concept of arrays as opposed to the "tricky" (for many) concept of pointers.

      You're obviously a good programmer - that's not in question. My concern when I hire people is that they be good, and they appreciate that others may not be as good. It's a gray area for sure.

    33. Re:good programmers by carlislematthew · · Score: 2, Informative
      Yes, you'd probably never get an interview. If someone has zero experience *and* zero "official" education then it's difficult to get an interview for a job programming.

      However, your solution is interesting. Using the null termination for your temporary space is an interesting way of saving a byte. But you're right, I'd prefer an actual variable to be used.

      Ever considered a career in programming?

    34. Re:good programmers by Bloater · · Score: 1

      In an interview as I was asked how I would parse XML. I said I would use an XML parsing library... They gave me the job.

    35. Re:good programmers by mrsam · · Score: 1

      a virtual machine can make a mediocre java programmer outperform a mediocre C++ programmer.

      Here's a trick question. You're a project manager in a large firm, who is responsible for delivering a core application, basically a "company-jewels" kind of a deal.

      Question: would you prefer to hire a "mediocre java programmer", for this position, or "a mediocre C++ programmer"?

    36. Re:good programmers by UOZaphod · · Score: 1

      Hmm... I guess I just don't think of things that way. I don't think of pointer usage as being "tricky". In fact, I consider array indexing to be inefficient, especially when an expression is being used as the index. When compiled, the resulting code has to evaluate an extra expression every time the array is indexed, which it then adds that to base address of the array. Thus you have extraneous computations, to say nothing about the temporary storage that needs to be used. Even when using a straight variable as the index, it still has to be added to the base address.

      I would find it extremely uncomfortable to be forced to use array indexing when using pointers would be faster and more efficient (and, to me, very easy to understand).

      --
      "The unicode stuff in the latest version is working fabulously well. My russian mafia friends are ecstatic."
    37. Re:good programmers by Anonymous Coward · · Score: 0
      If their first programming experience is in college, then this is a big sign to question why they are chosing this profession.
      Yep, I know what you mean. I have a friend who's an architect. She hadn't designed and built any buildings until she went to school to get her degree. Obviously I question her commitment to her profession since she wasn't building sand castles since she was nine.

      Seriously. Think about how strange your comment sounds. Maybe the person had never been exposed to programming before. Windows doesn't come with Perl or a C compiler. Maybe the person didn't know they enjoyed programming until they tried it in college.

    38. Re:good programmers by Henry+V+.009 · · Score: 1
      Ever considered a career in programming?
      To be honest, I always had. But I seem to have blundered into a career in System Administration, where I have got some experience. I just got a job offer as Unix Admin for a fair-sized campus network, and I'll probably take it. It's really fun work, and the pay is good. But like I said, programming is a hobby for me, and I've got a couple garage projects going that I'm sure I'll release eventually.
    39. Re:good programmers by Bloater · · Score: 1

      > One of the other more "nasty" questions I ask is for people to do a number to hex-string conversion algorithm. I've only have ONE person do it right.

      #include <string>
      #include <sstream>
      #include <iomanip>

      using namespace std;

      template<class T>
      string tohex (T n)
      {
              ostringstream stream;
              stream << hex << n;
              return stream.str();
      }

    40. Re:good programmers by carlislematthew · · Score: 1

      Well, you'll probably eventually get bored with sys admin work if programming is a really interesting hobby for you. Consider taking a couple of classes, perhaps just for resume purposes, and while at the job take the initiative to program some systems for them on your spare time if necessary. I've hired people that have come into programming on the exact route that I'm describing.

    41. Re:good programmers by carlislematthew · · Score: 1
      I wonder how much more efficient the pointer algorithm is. I suspect (but don't know) that the compiler and horrendously complicated CPU instructions will make the array indexing solution nearly as efficient as the pointer version. For example, there is a x86 instruction that accesses some memory that is a certain offset from a base pointer, so the compiler should optimize to use that. In addition, the time it takes to call the function may be the biggest overhead. Who knows...

      If I could be inspired enough to get away from the sofa and laptop, and get onto my dev workstation then I could find out. :)

      Do you work with a team of programmers? If so, it's quite possibly the case that some of them don't really get pointers. Some never will. We could all make the case that they *should* understand them, but they don't, and sometimes you just have to deal with that. Others will maintain your code after you're gone, and if they don't get pointers, then they could really mess things up.

    42. Re:good programmers by aaronl · · Score: 1

      You aren't going to write the fastest code possible if you don't bother to learn the quirks of the compiler. The same would be true of the run-time optimizations of Java. You won't write good code if you refuse to learn what you need to know.

    43. Re:good programmers by aaronl · · Score: 1

      Funny, but honestly, you know damn well that if that was the only condition for you getting the job, then the company is staffed by idiots. All that established is that you would probably use the right tool for the job.

    44. Re:good programmers by baadger · · Score: 2, Interesting
      This little discussion tree is flooded with code each with various advantages and disadvantages... so of course I felt the urge to investigate the problem myself and contribute something.

      I started off looking at the x86 instruction set and then googling for "XCHG reverse string" and voila, came up with this page that, aswell as covering some some of the methods described in this little discussion tree, has a final comment thats extra-specially interesting:

      In practice, for most compilers on Intel hardware the code

      int tmp;
      tmp = *b;
      *b = *a;
      *a = tmp;

      will compile into a single XCHG instruction. However, most compilers will not figure out the equivalent

      b ^= a;
      a ^= b;
      b ^= a;

      Ham Fisted
      Saturday, August 21, 2004


      Of course, if you didn't trust your compiler (or working toward multiple architectures) you could always use some compiler directives and some embedded asm?

      Is it possible to write this function using nothing but reigsters and the memory occupied by the string? Anyone care to give it a go? >)
    45. Re:good programmers by Decaff · · Score: 1

      A *good* C++ programmer will probably write code that outperforms the equivalent in Java

      This is frequently not true now, and will almost certainly not be the usual situation for much longer. Why? Because of the increasing quality of the Java Hotspot optimising system. The Java Hotspot system profiles code as at runs and tweaks code optimisation (inlining, constant rearranging, loop unrolling, array bound check removal etc.) and the machine code (instruction ordering) based on real performance, not in-advance guesses (as with C++ pre-compilation). Because this can be done on-demand and because the Hotspot system can include highly specific processor optimisations, there is a good chance that general Java code performance (which already approaches C++ in most cases) is likely to be improve significantly in coming years.

    46. Re:good programmers by larry+bagina · · Score: 1
      You can eliminate one more local variable using an XOR swap.

      Compilers play tricks behind your back. Stuff like keeping local variables in registers, and creating extra local variables to handle intermediaries of complex expressions.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    47. Re:good programmers by MrFlannel · · Score: 1

      Use XOR.

      --
      Clones are people two.
    48. Re:good programmers by man_of_mr_e · · Score: 3, Insightful

      Unfortunately, asking a interviewee to write code on the spot only tests the interviewees critical thinking capabilities. No their programming skill.

      When an interviewee comes to an interview, his state of mind is on passing HR related questions. He's prepared for questions like "Why did you leave your last job" or "What's your greatest flaw", not writing code on the spot.

      Most programmers I know have to be "in the zone" to write good code, and can't just jump from one mode to another instantaneously. That's why programmers need to be given nice quiet areas and left alone for long periods of time to get stuff done. Constant interruptions and distractions prevent them from being "in the zone".

      While critical thinking may be a good trait, it's not a very common one, especially to programmers. Maybe THAT is why so few of them can do what you ask, not that they're incapable, but rather that they just weren't expecting it and can't switch gears that fast.

    49. Re:good programmers by gazuga · · Score: 1

      IIRC, there is nothing in the C++ specs that guarantee the left-to-right order of evaulating statements (not sure about C). So there is a possiblity that some day, on some compiler, *phead could be evaluated first, and BAM! You've just dereferenced a null pointer...

      --
      "I turn away with fright and horror from the lamentable evil of functions which do not have derivatives."
    50. Re:good programmers by larry+bagina · · Score: 1
      we're using 2 integers rather than a char and an integer, which in most systems nowadays, is actually worse memory usage (8 vs 5 bytes).

      In an array of characters, 1 character is 1 byte, but in a struct or the heap or the stack, variables are word-aligned for faster memory access. A char and an int both use 4 bytes (on a 32-bit system).

      Of course, the compiler can (will) optimize your temp variable into a register, so it's just syntactic sugar for your benefit.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    51. Re:good programmers by gazuga · · Score: 1

      Looks like I stand corrected:

      "The sequence points in the logical expressions such as && and || and ternary operator ?: and the comma operator mean that the left hand side operand is evaluated before the right hand side operand. These few operands are the only operands in C++ that introduce sequence points."

      From http://www.langer.camelot.de/Articles/VSJ/Sequence Points/SequencePoints.html

      --
      "I turn away with fright and horror from the lamentable evil of functions which do not have derivatives."
    52. Re:good programmers by Anonymous Coward · · Score: 0

      Seriously, it seems to me that you just have a stick up your anus and get a hard on from playing Mr. Super Smart. Apart from the bad idea of jumping at people with your silly exercises in an interview situation, doing crap like "reversing a string while allocating the least amount of memory" is totally worthless. Hello? Are you still stuck in the Commodore 64 era?

      When I was younger and memory was limited, I used to do stunts like that too. But I've gotten with the times and focus on other aspects of software now that memory and cycles are cheap in most cases. Hell, even the most performance critical games are written 99% in C and not in assembly anymore.

      Wake up.

      And remove that stick from your rectum.

    53. Re:good programmers by scotch · · Score: 1

      string tohex (const T & s)
      ...

      --
      XML causes global warming.
    54. Re:good programmers by Henry+V+.009 · · Score: 1
      I admit that I dislike ever having to think about bits. That's the correct solution for this problem, but not the one I thought of first. Here is my "mathematician's solution." The only advantage that I can see is that I can reuse my radix conversion code with a couple of changes for arbitrary bases. Only really useful if it just so happens that you are putting together a C++ library to compete with GMP. (Well, be as good as, if not compete—but then again, expression templates and other tricks may beat pure C.)
      #include <deque>
      #include <string>
      #include "boost/foreach.hpp" //This is going to be in boost 1.34

      using namespace std;
      using namespace boost;

      int main(void){
      int num = 1234567;

      //RADIX CONVERSION HERE
      typedef deque<int> hex_cont;
      hex_cont hex_in_cont;
      while (num!=0){
      hex_in_cont.push_front(num%16);
      num = num/16;
      }
      if (hex_in_cont.empty()) hex_in_cont.push_front(0);
      //END RADIX CONVERSION

      //MOVE FROM CONTAINER TO STRING
      string hex_as_str;
      BOOST_FOREACH(int i, hex_in_cont){
      char hexit_char;
      if (i<10){
      hexit_char = i + 48;
      }else{
      hexit_char = i + 55;
      }
      hex_as_str += hexit_char;
      }
      hex_as_str += "x16";
      //END MOVE FROM CONTAINER TO STRING

      return 0;
      }
    55. Re:good programmers by Anonymous Coward · · Score: 0
      I consider array indexing to be inefficient, especially when an expression is being used as the index. When compiled, the resulting code has to evaluate an extra expression every time the array is indexed, which it then adds that to base address of the array. Thus you have extraneous computations, to say nothing about the temporary storage that needs to be used. Even when using a straight variable as the index, it still has to be added to the base address.

      Even toy compilers written for college compiler construction classes handle those sorts of optimizations.

    56. Re:good programmers by scotch · · Score: 1
      I find your interview question telling of the kind of programmer you are, maybe even the kind of software shop you work in, and I might be inclined to reject your company as an employer given that question, all things being equal. Basically, your question has three salient parts:

      1. Can the applicant write code at all?
      2. Does the applicant know the xor trick for swapping variables?
      3. Does the applicant consider existing solutions?

      The first part is legitimate. Even though the question is so routine that when I googled for "C++ interview questions" some time ago, it can up near the top in several links, there is utility in seeing if the applicant can acually write code. You'd be better off thinking of a question that everyone and their grandma doesn't use to make sure the applicant hasn't memorized the solution.

      The second part is what would score you negative points in my book. Just about everyone knows the xor swap trick. No one uses it in real code though because it is in general a bad idea. Testing whether someone would remember this bit of trivia and produce inferior code is a poor reflection upon you. At the C and C++ level, you trust the compiler for this and use the temporary. If you're writing a compiler or working with some strange embedded device, you'll likely be using assembler or C extensions anyway, so I don't think the question applies to that field.

      In C++ code, I would accept the temporary but would give extra credit to someone who used swap(), and correcly introduced std::swap into the scope and made a generic solution to the problem.

      Regarding the third part, I would also subtract points for anyone who didn't at least mention that they would use a library function to do this in the real world. If you leave the question unspecified for use of libs/tools, you can get a sense to whether the applicant is a reinvent-the-wheel kind of person.

      --
      XML causes global warming.
    57. Re:good programmers by petermgreen · · Score: 1

      its nice as a challange but if you are thinking about optimising to the last byte you will probablly not be coding in a high level language anyway.

      for example on a PIC18 you could probablly do this using just the working register and the file select registerers that are needed to do indirect addressing but i doubt you'd get a program in C to compile down to that you'd probablly have to do it in asm if it was really that critical.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    58. Re:good programmers by petermgreen · · Score: 1

      divide, remainder

      note that any decent compiler will turn devides and remainders using constant powers of two into bit shifts anyway.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    59. Re:good programmers by oliverthered · · Score: 1

      I generally know the quirks of the compiler (I can even write a 'fast' word processor in VB 3 and that's interpreted), and when I'm unsure about what the compiler it going to do, and it seems important, I profile the code to find out what is going to be fastest, and look at the assembler if it's available, when targeting a single platform. Most of the time 'design patterns' can give you better performance increases than small code tweaks, working with SQL really teaches you how much performance can be gained depending on the way that you look at the data and the way you write code to deal with the data.

      Nowadays, most of the time with modern compilers, you don't have to bother with the minor code tweaks (like ++i vs i++) because the compiler will generate the fastest code, but you do have to worry about things like:

      strcat(a, b);
      strcat(a, c);
      strcat(a, d);
      strcat(a, e);

      when you can do:

      int len = 0;
      int alen = 0;

      len = strlen(b);
      if(alen + len maxlen - 1) {
          memcpy(a + alen, b, len + 1);
          alen += len;
      }

      len = strlen(c);
      if(alen + len maxlen - 1) {
          memcpy(a + alen, c, len + 1);
          alen += len;
      }

      etc...

      and avoid doing what is effectively a strlen on a for every strcat, you should whereever possible reuse any data that you already have about a situation to generate the most optimal code, that applies to Java as much as C or VB or Lisp and Prologue.

      --
      thank God the internet isn't a human right.
    60. Re:good programmers by anthony_dipierro · · Score: 1

      Question: would you prefer to hire a "mediocre java programmer", for this position, or "a mediocre C++ programmer"?

      Answer: no.

    61. Re:good programmers by Anonymous Coward · · Score: 0
      Though reversing a string seems like an interesting problem...

      Meh.
      void reverseStringInPlace(char *start)
      {
        char *end = start;
        while (*end) ++end;
        while (start < end)
        {
          char c = *start;
          *start = *end;
          *end = c;
          ++start; --end;
        }
      }
      I expect the two local variables to be optimized into registers. The parameter likely will be too, but you'll almost certainly need space in the stack frame for it.

      Though this solution doesn't work with multibyte character sets....

      And that's why string processing is evil. I wouldn't worry about it too much though, reversing a string is generally meaningless linguistically anyway. As far as it is meaningful, you'd have to work by glyph rather than character, which is even worse.
    62. Re:good programmers by WillerZ · · Score: 1

      It's faster because it accesses memory once per character (and a char variable which even a dumb compiler will stick in a register), rather than the 3 times per character needed by the hand-'optimised' xor technique.

      --
      I guess today is a passable day to die.
    63. Re:good programmers by Anonymous Coward · · Score: 0

      sex, drugs and code man!

    64. Re:good programmers by willCode4Beer.com · · Score: 1

      I would hope that she maybe went to the library and studied other peoples architectural experience. I hope she chose her profession because she will love doing it. If none of these are true then maybe you should question her commitment if you were hiring her. However, that doesn't mean you should disqualify her, maybe she has grown to love it. Truth is, I am not qualified to interview someone for an architectural position. I am qualified to interview someone for a developer position.

      Programming is different in that the resources required to get started are small. Its expensive to build a building, its cheap to run a compiler. There are literally thousands of *free* online tutorials to teach almost every programming language invented.
      Claiming windows doesn't come with any kind of dev environment is bogus. Windows may suck for dev but, its not completely barren.
      Lets see there is:
      debug - many a dev started learning assembly with debug
      QBasic - many a wannabe started with this
      DOS shell and bat interpreter - weak version of shell scripting but, completely functional
      windows scripting host - combined with notepad means you are writing applications (with of w/o a gui) in JScript/VBScript
      Internet Explorer - combined with notepad can have you writing JScript/VBScript in seconds

      While none of these is a first class dev environment, they are all sufficient to get started programming with no money and a borrowed computer. If an interest develops, then a *real* environment can be downloaded. Then other things can be downloaded (for free). You mentioned Perl and C. Great examples. There are many others. An OS oriented toward developers could as well specifically BSD or Linux. Even the MACs came with AppleScript plus in browser scripting. Now that the Mac is a real OS it has even better dev tools.

      My point was based on general observation of interviewees that I've had in front of me. To be honest, I don't even look at resumes anymore, 90% of the resumes I've seen are 90% lies. I just give candidates a simple programming problem and sit next to them while they solve it. I want to see the thought process (if there is one) used to solve the problem. When I first meet a candidate, I am unbiased by their "experience" or education. I really only care about one thing, "can they do the job".

      --
      ----- If communism is a system where the government owns business, what do you call a system where business owns govern
    65. Re:good programmers by willCode4Beer.com · · Score: 1

      You could do like every resume I see and lie. Just say all those admin jobs were really programming jobs.
      I think the guy I recently interviewed changed his janitorial experience into programming experience on his resume.

      --
      ----- If communism is a system where the government owns business, what do you call a system where business owns govern
    66. Re:good programmers by ensignyu · · Score: 1

      If you're curious, there's another no-temp-space swapping trick using XOR that doesn't clobber anything.

    67. Re:good programmers by The+Dark · · Score: 1

      In fairness, his name is "bloater".

      --
      sig's not here
    68. Re:good programmers by maraist · · Score: 1

      If you have been involved in developmnent for any reasonable amount of time or worked on projects of reasonable size, you know that *good* programmers are hard to come by.

      I'll come back to this.

      If schools actually learned to produce good programmers, and HR departments learned how to identify them, and job interviews verified them, we wouldn't be having this discussion.

      Ah.. there's the bullshit.. Right where I can find it.

      Guess what.. I've tutored people in collage.. Their dumb as a brick, some of them... I can't see how the school could possibly turn people of the wrong mind-set into good programmers. The only possible way of reconsiling your two statements that I've outlined is to outsource almost ALL of our programming to Russia and China.. Two places w/ strong math carriculum (a core requirement of being a good programmer). Their sheer number of citizens subjected to painful degrees of mathmatics has a weeding-out process that leaves a large number of highly qualified logicians (a better name for a *good* programer).

      That being said. Do you blame the consumer for not being able to program their VCR? Not if your the Venture capitalist. You identify a market where VCRs and Microwaves are not being properly used.. Likewise w/ digital walk-men.. The iPod is a testiment to the idiocy of Americana. It's "easy to use". Who gives a crap? The people that can't figure out complicated devices do.

      What we want is a world of advancement.. Where people recognize the value of directed automation.. I want a consumer to be able to see the value in programatically configuring the lights in their house, the temperature of water, the TV schedule, etc. Then people will market to that techno-involved consumer.. Then they'll have economies of scale for the geek-toys that I'd love to have but aren't currently manufactured. We were shown all sorts of really cool stuff in the 60's that were never created, mostly because there was no market for them.

      Back to the more specific topic at hand. GIVEN that programmers are not all geniouses.. That when you're a business and you have more work than you can handle on time, you HAVE to hire people.. And you can't afford a $120K/yr salary (and even if you did, you couldn't be sure that someone deserved that salary). What can you do? The answer is to adopt good management skills.

      When you have good management, you can work with less skilled/qualified workers and still produce high quality code. Management involves the choice of tools that facilitate good quality end products. It involes a series of other things that don't relate to the topic at hand, so I'll stop here.

      The end result for this discussion is that screw the argument that a "good" programmer could write in C++ as well as a crappy programmer in VB or Java.. Guess what.. As a manager, I'd hire the crappy one and throw VB at him. I'd save more money that way and get the project done quicker.

      Though thankfully I'm not a manager.. I just write Java.

      --
      -Michael
    69. Re:good programmers by prockcore · · Score: 1

      Is it possible to write this function using nothing but reigsters and the memory occupied by the string? Anyone care to give it a go?
      char str[]="This is a test";
      char *s=str,*e=str+strlen(str)-1;
      while (e>s)
      {
          *s^=*e;
          *e^=*s;
          *s++^=*e--;
      }
      There, reverse a string in-place using only registers.
    70. Re:good programmers by prockcore · · Score: 1
      Here's another way to do it, btw, it's slower (you have to loop through the string 1 and a half times), but it is more interesting. :)
      char str[]="This is a test";
      char *s=str,*e=str+strlen(str)-1;
      while (e>=str) *s++^=*e--;
      while (e<s) *e++^=*s--;
      It only works on strings that are even in length.
    71. Re:good programmers by Anonymous Coward · · Score: 0

      "Programmers agonize over whether to allocate on the stack or on the heap."

      You forgot that good 'programmers' realize people who say things such as the above have no clue how either the stack or heap work.

    72. Re:good programmers by carlislematthew · · Score: 1
      Over the past 5 years I've only ever hired good programmers, and I always test them. It works. That's not opinion.

      Programmers have to be "in the zone" to be highly productive and work on really difficult problems. However. ay decent programmer worth his/her salt can do simple algorithms on the spot. For example, I had a ton of people submit solutions to the simple problem I asked. They weren't in the zone either...

    73. Re:good programmers by carlislematthew · · Score: 1
      Likewise, I would never hire someone like you. I find you to be mildy rude and you lack humility.

      Regarding the XOR part - I actually don't like it at all. I find it to be an awkward "trick".

    74. Re:good programmers by carlislematthew · · Score: 1

      Totally! If someone lies but they can actually program really well, I don't give a shit. If they lie but then they can't program, then they don't last very long and they're out on their ear. When you make that clear in the interview process (nicely of course), most people realize that there is no incentive to saying you can do something when you can't.

    75. Re:good programmers by Anonymous Coward · · Score: 0

      Not to burst anyone's bubble... the Original Poster is asking for a number to hex string algorithm.... What I have seen so far is people using someone else's number-to-hex-string algorithm (namely, the library's algorithm). I would certainly see myself asking the very same question and i would expect the candidate to come up with an algorithm.... using someone else's algorithm only tells me that you can lookup a reference manual (or online help); which, in itself, is a useful trait. Another useful trait is to be able to follow directions (in this case, to come up with a number-to-hex-string algorithm)

    76. Re:good programmers by man_of_mr_e · · Score: 1

      I still think you're ignoring the obvious. You only hire what you consider to be good programmers, because those are the people that pass your test. While indeed, you do get good programmers, you're also NOT hiring good programmers that simply "froze up" during your interview, or were simply not mentally in the programming mind frame at the time of the interview.

      I disagree completely that good programmers can always come up with good algorithms on the spot. I disagree that even a majority would. You clearly haven't been on the other side of the desk in recent memory or you would understand that interviews are things programmers don't do very well. They tend not to be "social" and don't often like talking about themselves. Thus, they're in an uncomfortable situation in which they've probably spent a TON of time preparing themselves for the kinds of interview questions they've come to expect, not "Quick! think up an elegant solution that's highly optimized right now!"

      Now of course there are plenty of programmers that ARE comfortable in those situations, and lots that CAN think logically in such situations, but you're discriminating against a possibly otherwise qualified candidate that can't play your game.

      If critical thinking is important to your selection criteria, then make it such, but don't pretend that just because someone can't come up with an algorithm on the spot, they're not a good programmer.

      As for people answering the question here on slashdot.. DUH. Most of us read slashdot while we're waiting for our code to compile, or on lunch break, or just when we're frustrated with a problem and need a distraction. Most of us are "in the zone" when we read slashdot, so of course you're getting responses from people here, and because they have the opportunity to think about it while not under pressure, you're getting some good responses.

      I just think your interview style is targeted not at good programmers, but at critical thinkers (ie, people that can think quickly and under pressure, and when they least expect it). And, that's certainly a good trait to have, but please don't call people bad programmers if they don't have that trait.

    77. Re:good programmers by scotch · · Score: 2, Funny
      I fail to see how I was rude or boastful. Perhaps you are too sensitive? As an interviewer, I am receptive to criticism that will help me conduct more productive interviews.

      Though we have common ground in our opinion of the XOR trick, I guess we can agree that you'll never hire me and I'll never work for you. I can live with that arrangement if you can. Just to make sure you don't accidently hire me, whenever you interview, ask the question: "Are you willing to have sex for promotions?". I will repsond: "No, but I'll put out for a better office". That way, you'll know it's me, and I'll know it's you.

      --
      XML causes global warming.
    78. Re:good programmers by baadger · · Score: 1

      ...i meant in assembly. :(

    79. Re:good programmers by Junks+Jerzey · · Score: 1

      You can eliminate one more local variable using an XOR swap.

      You're trying to outthink the compiler and failing.

    80. Re:good programmers by chad.koehler · · Score: 1

      Are we talking about C or C++?

      void reverse_string(std::string& r)
      {
      std::reverse(r.begin(), r.end());
      }

      If you're talking about STANDARD C++, this is probably the BEST answer that you can get, but somehow, I think it's not what you're looking for...

    81. Re:good programmers by chad.koehler · · Score: 1

      I mod you up but I already posted (the SAME reply) :)
      I'd hire you on the spot, no way there is a better C++ implementation.
      Dirty tricks, register hacks, imbedded ASM aside, if you want your other developers to be able to READ AND UNDERSTAND the code, this is the hands down winner.

    82. Re:good programmers by carlislematthew · · Score: 1
      I agree with what you say, which is why this one question is not the beginning and end of the interview. It is simply *one* part of it - not all things are black and white. I recently hired a guy who really struggled on the critical-thinking/programming test, but I hired him because I knew he was nervous and he would be the right fit for the job. He's been at the company for 9 months now and he's awesome. He's not the best critical thinker, as you describe, but he slowly and surely comes up with a good and solid solution and his code is almost entirely bug-free.

    83. Re:good programmers by Bloater · · Score: 1

      If I was asked to write a native number representation to hex string algorithm using a given set of primitives then yes, fine. If the primitives are not specified, then, as far as I can see, simplest, most straightforward wins every time. At some point, you are using somebody else's work since the language defines operators on numbers and dereferencing of arrays - if the langauge also defines a "convert-to-hexstring" construct, that is a primitive operation too. Some computers have even been designed with a primitive number representation that *is* a hex string and implementing a number to hex string algorithm in assembler for that platform is rather easy.

      If they asked for it in freestanding C, I would have used a for loop, bit shifts, array dereference and assignment as my primitives (coincidentally, I wrote such a function a few days earlier to work on a freestanding implementation), if they asked for it in hosted C, I would have used sprintf.

      If you want a particular result, and you want them to follow instructions, you have to give the instructions properly because one man's up is another man's down.

    84. Re:good programmers by corngrower · · Score: 1

      Actually it would have to access memory twice. Once to read, once to write. A good code optimizer would put the temp in a register. But also in the xor version, a good code optimizer would also not write the initial xor value back to memory. But after writing pseudo assembly code for both, I'll concede, the swap version is likely to be faster.
      Swap version:
      Load R0 A
      Load R1 B
      Store R1 A
      Store R0 B

      Xor Version
      Load R0 A
      Load R1 B
      XOR R0 R1 ; R0 XOR R1 R0
      XOR R0 R1
      Store R0 A
      Store R1 B

      These would essentially be the instructions executed by a 2 operand risc processor. Although each requries the same number of memory accesses, the swap version doesn't require the three xors. One may be able to execute the xor version in fewer instructions, but it would require a additional memory accesses, which (if cache is not present) could be much slower than the three xors.
      However an xor verson could work even if only one Register is available:

    85. Re:good programmers by ggambett · · Score: 1

      AND lower 4 bits (0x0F), add to '0' or 'A' - 10, shift 4 bits right, repeat. Then use reverse_string() ;) I can't say I'm surprised by what you say though. My students (Computer Graphics, 6th semester of the 10-semester degree) have some trouble with relatively simple things, and I'm sure most of them couldn't even understand the question.

      Funniest moment ever : after the texture mapping lecture I gave them an assignment to read a texture from a raw file, explaining that each component of the RGB triplets is one byte, and the texels are ordered left to right, bottom to top. Someone posts to the mailing list complaining that he opened the raw file in Notepad but couldn't figure it out, "it only has a lot of weird symbols".

      I thought it was a problem with our university, or with our country, though. The problem is more widespread than I believed :\

    86. Re:good programmers by CableModemSniper · · Score: 1

      If you want to play those games: #!/usr/bin/env ruby s = ""Please reverse me." reversed = s.reverse # or in place s.reverse!

      --
      Why not fork?
    87. Re:good programmers by Knetzar · · Score: 1

      I think the problem relates to us passing people that don't deserve it. Teachers and professors need to make sure students understand the basics before they are allowed to pass the class. I'm sick of them allowing people to pass based on effort alone, since effort doesn't mean you're prepared for subsequent classes.

    88. Re:good programmers by joeslugg · · Score: 1

      I haven't read the rest of the thread this goes with, but I just wanted to comment on what you wrote above. I totally agree with you about aptitude - or lack thereof - among some who call themselves "programmers." But I think it's important to remember the massive breadth that "programming" includes. A high-level database guru likely has no need to know the secret garden of assembler, for example. So it becomes critical to be certain about which aptitude "sector" you are trying to test.

      Secondly, the aptitude test itself. Personally, I don't write code with pen and paper. I use a text editor and QWERTY-style keyboard. If you were to administer a programming aptitude test in an environment I'm more familiar with, I'll probably do pretty well. But I've been in that interview where I'm asked to write an algorithm in C on the whiteboard, and it was far more difficult. I can't move lines of code around and refactor on-the-fly (which happens to be my style of code writing) the way I can with an editor. That environmental difference may have caused an imprecise measurement of my aptitude for the interviewer. I guess I'd just like to see code tests administered at a terminal - maybe with the proctor sitting alongside to watch, XP-style.

      One final anecdote:
      I worked in a QA group and a fellow engineer would insist on including a challenging "aptitude test" for interviewing candidates. If a resume had a particular routing protocol listed, he would expect deep knowledge about every bit of every field in that protocol header. To me (and to most of the candidates) this seemed a bit senseless. The header fields are available for reference on the protocol poster, or decoded for you in the packet sniffer. There's really little advantage to have them committed to memory. It's the higher-level protocol operations - perhaps timeouts and their consequences - that had more importance for that particular job. So even though he was testing their aptitude for a certain knowledge sector, it was the wrong one for the job we were trying to fill.

    89. Re:good programmers by 19thNervousBreakdown · · Score: 1

      // Convert uint to c string. Returns null pointer on failure.
      char* num_to_hex (unsigned int const number, char* buffer, size_t len) {

        // Current digit being converted.
        size_t digit = 0;

        // Clear the buffer.
        for (digit = 0; digit != len; ++digit) {
          buffer[digit] = '\0';
        |

        // Conversion loop.
        while (number) {

          // Make sure we didn't overflow our buffer.
          if (digit == len) {
            return 0;
          }

          // Convert least significant digit to hex.
          buffer[digit] = number % 16;
          if (buffer[digit] < 10) {
            buffer[digit] += '0';
          } else {
            buffer[digit] += 'A' - 10;
          }

          // For arbitrary base this would be a divide, but shift number down
          // for speed since it will always be base 16.
          number >>= 4;

          // Next hex digit.
          ++digit;

        }

        // Reverse the string. Don't do it this way, but two birds with
        // one stone can't be passed up ;)
        --digit;
        for (int i = 0; i < (digit) >> 1; ++i) {
          buffer[i        ] ^= buffer[digit - i];
          buffer[digit - i] ^= buffer[i        ];
          buffer[i        ] ^= buffer[digit - i];
        }

      }

      Only one person could come up with that? Man, if that would even get me a _shot_ at a job around here I'd be surprised. Oh well.

      (Hope I didn't make a mistake)

      --
      <xml><I><am><so><damn>Web 2.0</damn></so></am></I></xml>
    90. Re:good programmers by carlislematthew · · Score: 1
      I entirely agree with all you've said. It's important to be very flexible as it's a very odd way to program. However, what you *can* see in this environment is *how* people program, also under pressure (i.e. deadlines). They do it in different ways and it's interesting to watch and listen to how people solve problems. I've hired people that have done poorly on the whiteboard but I've *known* that they were good because of their thought process - they just needed more time, and a computer!

      Regarding the bit-fields: I personally wouldn't regard that as an aptitude test and agree with your sentiment that it was senseless as you can just look it up almost instantly. I would classify that under knowledge instead of aptitude. Sure, programming is a mix of both, but the test you mention is almost entirely knowledge.

    91. Re:good programmers by ggambett · · Score: 1

      I agree completely. But the "don't pass based on the effort" policy must be honored by the whole university. I get 6th semester students and I'm supposed to teach them Computer Graphics. But when the difficulties of the students aren't related to CG itself but to programming or other prerequisite knowledge, how am I supposed to evaluate them? If I decide to be strict, very few people would pass. On the other hand, if I acknowledge their lack of fundamentals and am more lenient, I'm perpetuating the problem. Often it's a delicate balance, unfortunately.

    92. Re:good programmers by Knetzar · · Score: 1

      What's wrong with letting only a few people pass?

      My favorite professor had a great reputation..."You'll learn and then you'll fail."

    93. Re:good programmers by ggambett · · Score: 1

      Nothing wrong, and it would be much better in the long term, but it can get difficult if you go against the policies of the university. For a young and relatively new guy as myself, at least.

    94. Re:good programmers by nickos · · Score: 1

      Just thought I'd mention that this is nice because it means you can do things like:

      if (easyTest() && hardTest())

      and hardTest will only be executed if easyTest returns true.

    95. Re:good programmers by dolmen.fr · · Score: 1

      I'm sure I would not hire you if you present your first solution.

      Replace strlen() by its implementation and think about it.

    96. Re:good programmers by rkww · · Score: 1

      Perhaps he was looking for something a little less verbose...

      static char* __helper(char *to, int foo)
      {
          if (foo >= 16)
                to = __helper(to, foo / 16);
          *to++ = "0123456789abcdef"[foo % 16];
          return to;
      }

      void int_to_hex(char* buffer, int value)
      {
          *__helper(buffer, value) = 0;
      }

    97. Re:good programmers by Anonymous Coward · · Score: 0

      note that any decent compiler will turn devides and remainders using constant powers of two into bit shifts anyway.

      Hopefully not always: http://blogs.msdn.com/oldnewthing/archive/2005/05/ 27/422551.aspx

  37. Mod parent Funny! by BerntB · · Score: 1
    Parent was Funny.

    Alternative, the author is an idiot savant that never overwrite memory in C, but still isn't smart enough to realize why it happens to other programmers (and realize that it slows development down, not makes it impossible, which his argument about writing OS kernels in C seems to assume).

    --
    Karma: Excellent (My Karma? I wish...:-( )
  38. A lot of programmers are ignorant. by Anonymous Coward · · Score: 0

    Java and C# programs tend to slow down for another reason, the programmers. I have seen a lot of programmers who throw and catch exceptions like candies, lock out entire functions as critical sections and what not. Although C# and Java does make programming easier by hiding details, they make it also make easier to do things that may slow down program execution.

  39. Re:Counter arguments by mikaelhg · · Score: 5, Interesting

    Programmer cycles are expensive.

    Indeed. It might be worth (pardon my pun) reiterating what those cycles really are, in regard to application performance.

    In all languages I know of, you get some library functions ready-made, and you need to code some stuff yourself.

    Most performance problems occur in the code you made yourself.

    In my experience, you get most bang for buck when you are able to efficiently allocate your programmer time to a) program a functionally complete draft version, b) optimize those parts which need optimization and c) maintain the program, in a manner which is BALANCED, but biased towards maintenance.

    De facto, you get better balance between those things, and most bang for buck, using languages such as Java, as opposed to languages such as C++, because (say) Java offers a pretty coherent conceptual framework (class libraries) for creating your draft in a maintainable way, provides default access to excellent non-invasive performance measurement tools such as YourKit and JProfiler which let you objectively find out where you need to do performance work.

    This means you can do only the optimization work that is necessary, and create optimized packages which extend the default class library interfaces which means that generally maintenance programmers don't have to put nearly as much work into figuring out how the optimizations affect the draft work.

    It's not perfect, but it gets you more bang for buck, which is what matters to you when you manage resources.

    Not the default developer perspective, I know.

  40. Java GC is slower but it doesn't matter by Anonymous Coward · · Score: 0

    In most cases it's other factors contributing to performance problems, mostly i/o. If it's memory, you buy extra memory. If it's cpu, you buy faster cpu's. If you can. If you can't then you have a problem if you go to multi-core cpu's. Multi-core cpu's are the Achille's heel of garbage collection since it requires a "stop the world" synchronization to safely avoid race conditions in determinine what memory is referenced or not. "Stop the world" is hugely expensive on multi-cores. There are specialized multi-core cpu's for java out there but they tend to run the jvm's on single cores with relatively few hardware threads to avoid this problem.

    1. Re:Java GC is slower but it doesn't matter by matfud · · Score: 1

      "Stop the world" is necessary on multicore CPUs, however it happens very rarely.

      Most VM's will split the new generation between the "threads" (ie a thread local memory and associated GC). The the thread can allocate its own local memory and only synch when necessary.

      Java is often prefered for multi cpu systems as it has a very well defined threading mechanism as part of the language. That means a multithreaded app is portable (and performant).

  41. Re:Counter arguments by gl4ss · · Score: 1

    *by Anonymous Coward on Sunday October 09, @09:42AM (#13750252)
    Programmer cycles are expensive.

    Not if you're counting in rupees.*

    development time always costs.. no matter how cheap your coder is, you could still make more bucks if you had the product in hand faster.

    currently I'm doing symbian c++.. and I'd much rather use java, I'd write more reliable code and do it faster as well(I'm not a superman and we all _know_ that everyone does mistakes sometimes - and quite frankly symbian c++ just makes it more probable that I'll end up doing one or two mistakes along the way) - if it were possible in any way, sadly, the product is not possible to be coded in java on the target platforms - the j2me vm's are too restrictive.

    --
    world was created 5 seconds before this post as it is.
  42. Really? by Mark_MF-WN · · Score: 4, Informative

    Really? Can provide a few REAL world examples? Can you name one? Personally, I'm running Azureus and Netbeans right now, and they're not perceptably different from C++ desktop applications like KDevelop or OpenOffice.

    1. Re:Really? by Skye16 · · Score: 1

      Start time is noticeably faster on both, even without any torrents in Azureus kicking. Netbeans has a lot of IO stuff to do, which is usually what slows an application's load time, but still, they both take a ridiculously long period of time compared to, say, Kazaa and .NET (yes, .NET actually loads FASTER than Netbeans (or, it did as of Friday)).

    2. Re:Really? by Timmmm · · Score: 1

      Personally, I'm running Azureus and Netbeans right now, and they're not perceptably different from C++ desktop applications like KDevelop or OpenOffice.

      Hmmm... I also use Azureus (it seems to be the only useful java app so far written), and while it is good, the GUI is horribly slow. For example if I go to the 'files' tab of a torrent I can watch as it populates the first column and then fills in the rest of the details. It takes about 2 seconds. Most of the GUI does seem reasonably fast though so maybe it is the fault of the Azureus developers.

    3. Re:Really? by bani · · Score: 1

      azureus is dog slow, and takes >500mb of virtual memory and >100mb of real memory. yeah, great example there.

      and uh, comparing azureus/netbeans to openoffice ? can I have some of whatever you're smoking?

    4. Re:Really? by Anonymous Coward · · Score: 0

      How about a real apples to apples comparison. Maple switched to java for their gui frontend (for who the hell knows what reason) and ships their old classic gui frontend (probably written in C++) with it. Not only is the java one wayyyy slow but it uses a shitload of ram.

  43. Java memory allocation vs. malloc by iambarry · · Score: 5, Interesting

    The article's main point is that Java's memory allocation is faster than malloc, and it's garbage collection is better than cumulative free's.

    However, thats not the problem. All memory in a Java program has to be allocated dynamically. Other languages offer static memory alternatives. Static memory use will be more efficient in many cases.

    The my language is faster than yours argument is inherently stupid. There is no "best" language. You need to use the right tool for the right job.

    --Barry

    1. Re:Java memory allocation vs. malloc by sjasja · · Score: 1
      All memory in a Java program has to be allocated dynamically. Other languages offer static memory alternatives. Static memory use will be more efficient in many cases.

      Here is how you can allocate variables in Java:

      static int n;
      static char text[] = new char[10000];
      The first line allocates a static variable, just like a static/extern int in C. The second line does indeed cause a dynamic allocation. This happens when the class is loaded and takes about 10 machine instructions. That is of the order of 0.000000001 seconds on a 1 GHz CPU.

      It's a weird program that has so many static variables that 0.000000001 second once time startup costs add up to something that matters.

    2. Re:Java memory allocation vs. malloc by JesseMcDonald · · Score: 1

      I think the point was that in C or C++ (for example) that array could be allocated on the stack. The savings in startup time are, as you pointed out, minimal. However, the array would automatically be deallocated when the function returned, as part of the normal stack-unwinding code, with almost no additional cost. In particular, there is no need to use free() at all. Of course, this approach can only be used when no references to the array is retained after the function returns.

      --
      "The state is that great fiction by which everyone tries to live at the expense of everyone else." - Bastiat
    3. Re:Java memory allocation vs. malloc by Anonymous Coward · · Score: 0

      RTFA. Look for escape analysis. Just as garbage collection beats manual object-at-a-time freeing, escape analysis beats manual stack allocation.

    4. Re:Java memory allocation vs. malloc by Anonymous Coward · · Score: 1, Informative

      Did you miss the part of the article where he explains how the new JVM performs memory allocation on the stack through escape analysis?

    5. Re:Java memory allocation vs. malloc by njyoder · · Score: 1

      RTFA yourself. The article said nothing like that, it says the opposite. Escape analysis involves storing things on the stack because, AS THE ARTICLE STATES, stack allocation is very effecient.

    6. Re:Java memory allocation vs. malloc by iambarry · · Score: 1
      Did you miss the part of the article where he explains how the new JVM performs memory allocation on the stack through escape analysis?

      Uh, yup. I'm sorry to say I just scanned the article at first. Re-read it later.

      I still say its about using the right language for the job. Static memory is a powerful tool, useful to solve many problems.

      Some problems that are best solved with static memory use will have solutions best implemented in C.

      Even if the JVM optimizes variables to the stack through escape analysis, its a blind optimization. Programmers will not necessarily know if their variables will be on the stack or not. They may make coding mistakes that remove vars from the stack. They may worry too much, and spend effort to get vars on the stack that is not required.

      Java is great, and the JVM has clearly been greatly improved over the years, don't get me wrong. However, its still not the best language for every memory use model, never will be, and that's the way it should be.

      --Barry
  44. Bragging about ignorance by gvc · · Score: 1

    Rather than promoting your prejudice, why not RTFA, or this 19-year-old paper.

    I'll await your learned rebuttal.

    1. Re:Bragging about ignorance by Junks+Jerzey · · Score: 1

      Actually, that paper has been shot down numerous times since its publication. I dont' mean by Slashdotters, but by other published papers. Appel's argument is true in theory, but cache effects make stack allocation faster.

    2. Re:Bragging about ignorance by gvc · · Score: 1

      I wouldn't quite say shot down. It is the subject of legitimate debate. The fact is that garbage collection is competitive with stack allocation, that manual allocation and free are error-prone and inefficient.

      Boehm is an advocate of in-place automatic collection, as opposed to stack allocation.

      If you care to point to one of the references that "shoots down" Appel, I'd be prepared to comment on it. Otherwise its just hearsay, isn't it?

    3. Re:Bragging about ignorance by Anonymous Coward · · Score: 0

      "It is the subject of legitimate debate."

      Stack allocations are free, because the compiler has to store the registers it wants to use for a function and allocates a stack frame to do it. It just allocates more by subtracting more from the stack pointer for your automatics. The release is equally free, but you have to read the instruction set to see why.

      "The fact is that garbage collection"
      You can't get better than zero cycles no matter how wasteful your algorithm is in memory or how fast your heap search is. You must call the allocate and free functions and those take a stack frame allocation each, so its simply not possible to compete in this reality with the speed of a stack frame allocation.

    4. Re:Bragging about ignorance by gvc · · Score: 1

      Where in "int foo(int x, int y){return x+y;}" does it say "stack frame?"

    5. Re:Bragging about ignorance by Mortlath · · Score: 1
      I see that you don't have an understanding of assembly code.

      Every function has a stack frame. The compiler generates one for every function. It only takes one operation to allocate some memory on the stack, just decrement the stack pointer.

      As far as I can see, there is nothing more efficient than one assembly operation.

    6. Re:Bragging about ignorance by gvc · · Score: 1
      I see that you don't have an understanding ...


      As far as I can see ...


      Your vision is impaired.

    7. Re:Bragging about ignorance by gvc · · Score: 1
      it only takes one operation to allocate some memory on the stack, just decrement the stack pointer.

      Uh huh. And check for stack overflow? Or do you work in Redmond?

      And then are you planning to free the storage?

      How many operations do you think GC takes? Did you read the reference? Of course not.

    8. Re:Bragging about ignorance by Mortlath · · Score: 1
      Uh huh. And check for stack overflow? Or do you work in Redmond?

      Stack overflow is handled the same way the an out of memory error is handled - with an exception.

      And then are you planning to free the storage?

      Free the storage on the stack? The storage on the stack is automatically released when the function call has ended. The compiler can also increment the stack pointer as well to release the top of the stack.

      How many operations do you think GC takes? Did you read the reference? Of course not.

      I have not read the reference, but I do know that garbage collection has overhead associated with it. Overhead from the function call to the GC, overhead from the operating system when the program requests a block of memory, and overhead from the book-keeping that the GC must do to keep track of that memory.

      Bottom line: Stack allocation is always faster, but it's not always the best option. Dynamic memory allocation is much more useful at times.

    9. Re:Bragging about ignorance by Anonymous Coward · · Score: 0


      Compare:
      *pObj = malloc(100);

      Notice that you allocated 1 object on the stack (a pointer to hold the address of the object)
      and 1 heap block.

      Compare that with:
      char iObj[100];

      Notice that you allocated only 1 objetc on the stack.

      Inside malloc, it has variables too. They are also allocated on the stack. So you can never ever match the performance of stack allocations with a heap allocator.

      When you return x+y, the compiler needs to save some registers to do that operation in, so it saves them on the stack in your stack frame. If you have changed the value of x or y then your stack frame would have contained the value of x or y depending on the optimization setting.

      e.g.
      int foo(int x)
      {
        x= x+1;
        return x;
      }

      void foobar()
      {
        int x=100;
        foo(x); // afterward x is still 100
      }

      When you called foo, the compiler stores a copy of x in the stackframe for the foo function.

      Do you understand now?

    10. Re:Bragging about ignorance by gvc · · Score: 2, Informative
      I have not read the reference

      OK, I'll enlighten you. Well, not you, who stubbornly refuse to be enlightened, but somebody else who may be reading.

      With a stack or with copying GC, you do allocation by doing a simple add (or subtract) and a check for overflow. On many architectures the check can be implemented using dynamic address translation (virtual memory) capability of the hardware.

      With a stack you must pop the stack when you're done. Another simple arithmetic operation. With garbage collection, you do nothing at this time. Running score: stack 2 operations (push,pop); GC 1 operation (allocate).

      But with GC you eventuallly run out of space so you copy all the in-use storage. Here's a formula:

      in-use == allocated - freed .
      That is, the total number of pieces of in-use storage is strictly less (and in practice substantially less) that the number of allocations. Running score: stack 2 operations * #allocations; GC 1 operation * #allocations + 1 operation * (substantially less than #allocations).

      That is, for each allocation a stack regimen does a push and a pop, and GC does an allocation and some fraction (substantially less than 1) of a copy.

      While I'm at it I'll point out that there are many cases in which procedures may be implemented without using dynamic allocation - stack or GC-ed - at all . Your allusion to that mystical compiler that works some sort of stack magic "for free" is simply wrong.

  45. java's overhead by Vladimir · · Score: 1

    it would be interesting to see what is the overhead of the "Object" for different JDKs on 32/64 bits implementation? If class {int x,y;} takes 128 bytes, why would I care about speed of the memory allocation? They also mention thread specific allocators which are nice, but only if your program is nowhere close to max memory.

  46. Truth vs Perception by SmallFurryCreature · · Score: 2, Insightful
    I don't code in java so my only experience with it is through applications. Most notably Freenet and Azureus and Eclipse. All are brilliant apps that absolutly excell at what they do. There is however not a single person that can with a straight face claim that these programs do not hog resourcers like a .... well like a java app.

    Simply put there may be fast efficient tiny java programs out there but I don't see them. I don't really care about how garbage is collected. All I care is that a simple editor gobbles up memory like it was some kind of FPS. Sure I love the fact that I can use the same editor with the same extensions (to a point) on my home linux machines and work evil OS machines BUT it comes at a price and that is a lot of memory.

    Perhaps Sun has indeed improved java massivly over those horribly slow and crashing java applets we had a few years ago that were so going to take over the net by storm. Perhaps all the problems are just due to certain public java programs being badly written.

    It doesn't matter, java is slow, c is fast. Instead of having written this article perhaps the author should have examined some common java memory hog programs and analyzed wether the fault lies with java OR the coding in question OR and this is an option few consider, that JAVA apps and C apps are often compared like apple and oranges. Azureus vs Bittorrent (a tiny and far simpler app) Eclipse vs VI etc etc.

    A lot of languages deal with mis-reprensatation. I don't exactly feel sorry for the bad rep that java has as many java fanboys happily spread un-truths themselves. Like java vs PHP vs ASP for web development. Judging from my own experiences all this is just one giant "Your mom is so fat ...." competition.

    --

    MMO Quests are like orgasms:

    You may solo them, I prefer them in a group.

    1. Re:Truth vs Perception by the+eric+conspiracy · · Score: 2, Interesting

      Simply put there may be fast efficient tiny java programs out there but I don't see them.

      If Java was as bad as you say it would NOT be so popular in embedded devices. There is a huge disconnect between the archaic concept of Java as a slow pig and the real world popularity of Java on small systems like printers and cell phones.

    2. Re:Truth vs Perception by Helios1182 · · Score: 1

      Eclipse is a resource hog because it is a massive application. It has a ton of features and plugins. Most people also run it with hundreds of classes and thousands of lines of codes loaded.

    3. Re:Truth vs Perception by Dogtanian · · Score: 2, Informative

      If Java was as bad as you say it would NOT be so popular in embedded devices. There is a huge disconnect between the archaic concept of Java as a slow pig and the real world popularity of Java on small systems like printers and cell phones.

      Doesn't that use J2ME though? And, I would assume, J2ME gives you less facilities than J2SE and J2EE, so are we comparing like with like?

      Not saying, you're wrong, I just want to know if the comparison is valid.

      --
      "Slashdot - News and Chat Sites Deviant". (Click "homepage" link above for details).
    4. Re:Truth vs Perception by M.+Baranczak · · Score: 1

      I don't code in java so my only experience with it is through applications.

      Desktop apps are definitely Java's weakest point. (I should know, I've written a couple of them.) This is a problem with the GUI libraries, not with the language, or the core libraries, or the Java programmers. Unfortunately, a lot of people only think of Java in terms of desktop apps. This right there is the main reason why Java still has such a bad reputation.

    5. Re:Truth vs Perception by DeadMeat+(TM) · · Score: 1
      Doesn't that use J2ME though? And, I would assume, J2ME gives you less facilities than J2SE and J2EE, so are we comparing like with like?
      (Note: lots of technical abbreviations follow. There's no way I'm going to link to definitions of all of them. Use Google, or shoot Sun's marketing team; preferably, both.)

      J2ME is an umbrella term that covers basically any Java runtime targetted at something larger than a smart card but smaller than a desktop. That includes two different VM specifications and several different class libraries running on top of those VMs.

      When most people talk about "J2ME", they're talking about one or another version of the MIDP class library running on top of a CLDC-compliant VM, since that's what nearly all mobile phones use. Besides having a much smaller class library, the VM places some restrictions on apps that aren't present in J2SE runtimes. For example, there's no built-in object serialization mechanism, and reflection is fairly limited. Nor do older CLDC VMs support float or double primitives (these were added in a later version of the specification).

      So, in some ways, it's not possible to make a direct 1-to-1 performance comparison. For example, MIDP uses a completely different UI library from J2SE, with a completely different set of capabilities. MIDP's LCDUI toolkit is designed to perform well on small devices, at the cost of apps looking completely different from device to device. Swing, on the other hand, is designed to have largely the same look-and-feel on any platform, but you pay a pretty heavy performance penalty for using it. (Sun claims that Swing doesn't actually carry a big performance penalty anymore, but in my personal experience, they're full of it.) Comparing the two isn't fair, since they set out to do different things on different kinds of devices.

      This particular article, though, is only concerned about the cost of memory allocation and garbage collection. J2ME uses the same memory allocation model as J2SE, and so the comparison is apt in this case.

    6. Re:Truth vs Perception by Dogtanian · · Score: 1

      Pretty informative, I think I'll bookmark this, thanks.

      FWIW, I used Swing in 2002 on my (then current machine) Pentium-233.

      It reminded me of my 8MHz Amiga 500 on a bad day... I tend to subscribe to the theory that Intel provided Sun with the "performance increase" of Swing; after all, it's just about usable on my current 1.8MHz P4 :-/

      --
      "Slashdot - News and Chat Sites Deviant". (Click "homepage" link above for details).
  47. OMG LOL!!! by Anonymous Coward · · Score: 0

    Are you kidding? You're saying that Azureus, a BitTorrent client, is "not perceptably different from" a multi-language graphical IDE or a full blown office productivity suite??? From your statement it sounds like Java, or at least Azureus, is pathetically slow compare to C++ desktop applications.

    Why don't you try comparing two BitTorrent clients instead? Try comparing Azureus with KTorrent, a C++ BitTorrent client. You will find that KTorrent is orders of magnitude faster and also uses a tiny fraction of the memory that Azureus uses.

    Apples to apples, Java is SLOOOOWWWWW...

    1. Re:OMG LOL!!! by sdhankin · · Score: 0, Redundant

      So what you're saying is that KTorrent is just Azureus recoded in C++? If so, your argument is rock solid. Otherwise, you really are comparing apples and oranges.

      I can come up with two implementations of a non-trivial task that "do the same thing" where one is orders of magnitude faster than the other, regardless of the language it is coded in.

      Unless you are comparing essentially the same implementation, the comparison is meaningless.

    2. Re:OMG LOL!!! by anthony_dipierro · · Score: 1

      Unless you are comparing essentially the same implementation, the comparison is meaningless.

      The fact that no one has come up with a decent java version of any of the software I currently use does lead me to conclusions, though.

      I'm all for making a programmer's job easier, but I think the way to do that is with development tools on top of C. In ten years or less it'll probably be a moot point anyway, as there will be tools out there to translate any programming language into any other one anyway.

  48. Fire and forget memory management by defile · · Score: 2, Insightful

    I think automatic garbage collection is great, but _my_ problems with Java's memory allocator have little to do with performance. Rather, it sucks so hard at dealing with out-of-memory conditions.

    Why would you ever run out of memory? If you're on a microcomputer, you tend to have an arbitrary limit anyway. The JDK default is 64MB max heap. This is to prevent runaways, but setting the heap size to some arbitrarily high number has really awful performance characteristics -- god help you if you set the number higher than the amount of RAM you have available, or applications that want to share the machine. There's a whole other rant about how stupid automatic garbage collection is on a timeshared environment (like a server), but it's not the point I want to make.

    The point I want to make: since Java is supposed to run everywhere, you really can find environments where you only have 1 or 2MB of heap to play with. Having constrained resources is nothing new to programmers, they've been dealing with it forever. But Java's allocator combined with constrained resources leaves you with very little wiggle room.

    If you've ever developed a Java applicatoin that manages an in-core cache you might have experienced how fucked you are when you get around to the logic of cache expiration. Ideally you can keep cache forever, as long as a) you know it's not stale, and b) you don't need the memory for something better. A is not a problem in Java, but setting up a system to facilitate B is actually really hard. In C/C++ you can wrap malloc() so that if it fails, you can start dumping cache until it succeeds. The solution is elegant, dare I say beautiful.

    In Java this is totally impossible. When you run out of memory the garbage collector is tripped, and if it can't free anything up it generates an OOM exception. You can't realistically catch these exceptions -- they can bubble up from anywhere at any time. The only place you can catch them is at the top of your program loop and the only good it does there is let you say "OUT OF MEMORY" in a user friendly way before exiting the application -- assuming you have the resources left to even say that of course.

    So how does this effect your cache model? Well, you end up having to guess at how much cache to maintain. Guess too high and your application breaks when it's run in a low memory environment. Guess too low and you're not caching enough, the user experience suffers when it has no reason to. The above scenario is just one example.

    Essentially, the problem is one of prioritized memory. Java gives you no usable way of saying memory allocated for purpose X is fine as long as purpose Y is not short. Designers and apologists can make excuses for why Java doesn't support this and maybe provide a good reason, but those reasons hardly qualify Java as a general purpose programming language.

    Goto also.

    1. Re:Fire and forget memory management by thammoud · · Score: 1

      You must not have learned about Soft and Weak references in Java. The VM does most of the work that you would need to do in C++. In Java, implementing caches is pretty trivial in comparison to C or C++.

    2. Re:Fire and forget memory management by Mr.+Shiny+And+New · · Score: 2, Informative

      In C/C++ you can wrap malloc() so that if it fails, you can start dumping cache until it succeeds. The solution is elegant, dare I say beautiful.
      In Java this is totally impossible.

      In Java there are things called weak references which you can use for this exact purpose. A weak reference is a pointer to a pointer, but the pointed-to object is considered available for garbage collection (as long as it isn't referred to anywhere else). This means you can do this:

      Object toBeCached = new Object();
      WeakReference wr = new WeakReference();
      wr.set(toBeCached);
      cache.put(cacheKey, wr);

      This, obviously, could be handled inside the cache for better encapuslation. But the point is that when garbage-collection runs, the items in the cache are fair game for collection. The obvious problem is that the GC will reap objects in random order, or it may even reap the most-recently-allocated objects first. But if that's a problem for you then you can probably make your cache smarter, such as keeping strong references to newer objects.

    3. Re:Fire and forget memory management by Anonymous Coward · · Score: 0

      WeakReference is not supported in J2ME

      :(

    4. Re:Fire and forget memory management by smack.addict · · Score: 1

      I have a smart caching system that handles this for you. It's open source, but I have not uploaded a recent release to a web site. Anyone wanting it can email george dot reese at valtira dot com to get a copy. My current version is for Java 5.

    5. Re:Fire and forget memory management by defile · · Score: 1

      This, obviously, could be handled inside the cache for better encapuslation. But the point is that when garbage-collection runs, the items in the cache are fair game for collection. The obvious problem is that the GC will reap objects in random order, or it may even reap the most-recently-allocated objects first.

      This is better than nothing but still not optimal. I'm also unclear, are objects with weak references equally eligible for collection as objects with no references? If so, what's the point? Garbage collection runs are common. Losing LRU cache behavior is also a real suck-point.

      I much rather guarantee the behavior I want by defining it than praying the JVM Does the Right Thing.

    6. Re:Fire and forget memory management by dnoyeb · · Score: 1

      actually its not the weak reference but the soft reference that is cleared when memory is needed. And OOM are not thrown anywhere. They are thrown only where you see 'new'.

      If you saying java does not let you manage memory as a programmer, you are correct. You need to adjust your JRE settings.

    7. Re:Fire and forget memory management by 26199 · · Score: 1

      You can. I forget the details, but the mechanisms available are very flexible... try looking up phantom references and reference queues.

    8. Re:Fire and forget memory management by IamTheRealMike · · Score: 1

      It's supported by MIDP2, but isn't quite so useful while most GCs do nothing about fragmentation as there's no guarantee free memory over time won't simply drop and drop (unless you are very careful to ensure object sizes tesselate).

    9. Re:Fire and forget memory management by chickenwing · · Score: 1

      Have you looked at the java.lang.ref package? I typically use a combination of WeakReferences, SoftReferences, and ReferenceQueues to solve this problem. SoftReferences allow the garbage collector to collect softly reachable Objects when the JVM needs the memory (before a OutOfMemory error is thrown). ReferenceQueues allow you to find out when Objects are considered garbage by the JVM.

    10. Re:Fire and forget memory management by Anonymous Coward · · Score: 0

      Direct link to keep the spam bots happy: george.reese@valtira.com

    11. Re:Fire and forget memory management by Anonymous Coward · · Score: 0

      OMG do you torture small animals too?

  49. You may see a diff in 1.5 by willCode4Beer.com · · Score: 2, Informative

    Sun is introducing shared memory in the new VM that should alleviate this somewhat.
    The idea is that the majority of the "fatness" comes from the libaries. If you only have to load the core libraries once, and each VM can use them then additional VMs won't add so much overhead.
    If this works, I'm wondering, will we get side-effects from the over-abuse of static member variables.

    --
    ----- If communism is a system where the government owns business, what do you call a system where business owns govern
    1. Re:You may see a diff in 1.5 by Anonymous Coward · · Score: 0

      ITYM Java 6, or Java 7, or Java 8, depending on when they feel this feature is ready for prime time.

    2. Re:You may see a diff in 1.5 by bani · · Score: 1

      so basically we're over a decade into java, and they're still having to fix major performance issues with java.

      not to mention java has now fragmented into j2me/j2ee. wonder how much more it will fragment/diverge. j2we (web edition) anyone? maybe j2ge (gui edition)?

    3. Re:You may see a diff in 1.5 by qbwiz · · Score: 1

      We might not get any problems because of static member variables. Each VM will create its mutable own data and objects, but the code and constants will probably remain in one place. The ratio of mutable/constant (overall, including code) in the Java libraries is probably very low.

      --
      Ewige Blumenkraft.
  50. Anonymous Cowards Can't Write by Doc+Ruby · · Score: 1

    Anonymous kettle Coward, learn to capitalize and punctuate before spewing garbage about "getting educated" and illiteracy.

    --

    --
    make install -not war

  51. Re:Counter arguments by laffer1 · · Score: 2, Insightful

    C# and VB.NET are almost identical in features. What do you "sacrifice" that is really important? The .NET framework is still there. C# is just java like syntax for .NET. Its not 100% better as its billed by microsoft and consultants. I agree vb6 sucked.

    The java vm startup time is a problem for client apps, but server side its not a big deal. Running tomcat with servlets, jsp and the like is very fast. .NET app startup time is slower than running a program written in another language as well. Try running the ati control panel (.net version). Now that is slow. Limewire loads faster and its a java app.

  52. Re:Counter arguments by m50d · · Score: 2, Insightful
    In the end though, the MOST important thing is that these days, processor cycles are cheap.

    The typical home machine these days is still sub-ghz, and Java performs so poorly as to be unusable on such machines.

    --
    I am trolling
  53. Maybe, there is a bit more to it, then just memory by dzafez · · Score: 3, Funny

    I haven't done anything with java in the last 5 years.
    *everybody.screem("w00t!");*

    I can understand the discussion about memory allocation is legitimate.
    *everybody.agree();*

    Now, saying this would not be the case anymore, so hence java is fast now, would be false.
    *everybody.status = iritated;*

    Writing jevecode does make yu handle a lot of errors...
    *everybody.ask("is this not good?");* ...BY HAND!! IT WILL NOT COMPILE ELSEWAY.
    *some.ask("is this not good?");*

    Maybe there is a loss of speed for handling all those errors as well.
    *FirstHalfOfCoders.grab(stone);*

    C coders don't check for every possible error.
    *SecondHalfOfCoders.grab(stone);*

    Maybe, sometimes, it is ok for a programmer, if from that code, there could
    be errors. While on the other side you buy speed with insecurity.
    *FirstHalfOfCoders.throw(stone);*
    *SecondHalfOfCoders.throw(stone);*
    *me.troll();*

    AND BY THE WAY; I LOVE THE "GOTO" STATEMENT!
    *me.run(away);*

  54. Good C++ programmers don't program C in C++ by Henry+V+.009 · · Score: 2, Informative
    A *good* C+ programmer will remember to deallocate all of his objects to prevent memory leaks. A *good* C++ programmer will copy his strings correctly to prevent buffer overflow exploits.
    No he won't. Because if he has to think about either of those things, he is programming C in a C++ environment. And is therefore not a *good* C++ programmer. His code is probably not even exception safe. He'd be kicked off any decent C++ programming team rather quickly. That aside, I'm reminded of a joke that does go somewhat against my point, but is still funny:

    Bjarne Stroustrup : why so many people use "C++" just as "C" ?
    Dennis Ritchie : because you named the language "C++", not "++C"
    1. Re:Good C++ programmers don't program C in C++ by KarmaMB84 · · Score: 1

      I wasn't aware that C++ eliminated the issues with pointers and deallocation. I do agree with the strings part, though.

    2. Re:Good C++ programmers don't program C in C++ by Henry+V+.009 · · Score: 1

      In C++, the proper coding style is RAII. If you really need to use a pointer somewhere, you use a smart pointer from boost or standard auto_ptr. And as if anybody needed more reasons to code this way, the possibility of exceptions tends to make anything else incorrect.

    3. Re:Good C++ programmers don't program C in C++ by swillden · · Score: 2, Informative

      I wasn't aware that C++ eliminated the issues with pointers and deallocation.

      With proper use of smart pointers, it does. Not completely, but very close.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    4. Re:Good C++ programmers don't program C in C++ by radtea · · Score: 1


      The use of smart pointers in C++ is only a complete solution when you have control of 100% of the code. Those of us who write libs for other people, and heavily use libs from other people, are stuck with dumb pointers for interfaces, at least until the next pass at the STL finally gives us a standard for something smarter than auto_ptr.

      I can use Boost's counted_ptr or whatever internally, but the interface is always going to be lowest common denominator because I can't realistically expect people to use whatever my choice is for their smart pointer unless it's part of the STL.

      --
      Blasphemy is a human right. Blasphemophobia kills.
    5. Re:Good C++ programmers don't program C in C++ by swillden · · Score: 1

      The use of smart pointers in C++ is only a complete solution when you have control of 100% of the code.

      True. It's the points of interface with other code are where the "almost" comes in. In the present, I actually prefer libraries interfaces to operate with "naked" pointers. When I get a pointer from such an interface, I immediately wrap it, and when I have to hand a pointer to such an interface, it's easy to call the appropriate smart pointer method to get at the underlying pointer. All of this requires both discipline and thought (especially if the library may hold onto pointers), but only at the interface points. The code that you do control 100% can very easily be leak-free and safe.

      In the future, perhaps we'll get some good standard smart pointer types and libraries can begin using those. Dealing with multiple libraries, each of which has its own smart pointer types (and its own string types, ugh) can be a royal PITA.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    6. Re:Good C++ programmers don't program C in C++ by Henry+V+.009 · · Score: 1

      I've got good news for you then, the boost smart pointer types are already in the standard committee's TR1.

    7. Re:Good C++ programmers don't program C in C++ by swillden · · Score: 1

      That is, indeed, good news!

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  55. Re:Counter arguments by Silverlancer · · Score: 1

    I ran a test last year doing simple arithmetic comparisons between Java and C++.

    Java won. The Just-In-Time Compiler makes Java incredibly fast. Java seems slow not because it is, but because a lot of Java programmers are just downright lazy and refuse to code efficiently.

  56. Performance is mostly about the design/code by JavaNPerl · · Score: 3, Interesting

    I have been doing Java programming for several years now and ported many C/C++ applications to Java, mostly server side apps and I'd say roughly 85% of the time the Java apps outperformed the originals, sometimes by an order of magnitude. Now these were more redesigns than straight ports and the performance gains were not because Java was any better from a performance standpoint, but because design is more of a factor in speed than the language used, especially for larger applications. Usually when I find big performance hurdles that are hard for me to overcome, I find I would have same issues in most languages, so finding a better design is usually the solution. If you are writing small - medium apps or mostly GUI apps then I might have reservations about Java, but for larger apps Java is a good choice.

  57. garbage collection and Java and efficiency by idlake · · Score: 1

    Garbage collection is generally more efficient, byte for byte allocated, than malloc.

    The problem is that Java programmers and Java libraries tend to be written in such a way that they do a lot more memory allocation, just because it's so easy to do. The quality of Java code in general is not very impressive (and this include Sun's own libraries). And Java itself makes writing efficient code harder than it needs to be.

    So, people can write highly efficient code in garbage collected languages, and even in Java. But Java programmers generally don't bother, and that's the reason why Java has such a bad reputation, and it deserves it.

    1. Re:garbage collection and Java and efficiency by Anonymous Coward · · Score: 0

      And Java itself makes writing efficient code harder than it needs to be.

      Definition of efficient code actually depends on the project. Most of the time, efficient code is the code that is easy to write without too many dangerous bugs, easy to debug, easy to deploy and easy and maintain. And Java is the right language when you use such definition.

    2. Re:garbage collection and Java and efficiency by idlake · · Score: 1

      Most of the time, efficient code is the code that is easy to write without too many dangerous bugs, easy to debug, easy to deploy and easy and maintain. And Java is the right language when you use such definition.

      I agree that writing good, straightforward code is what one should aim for, but you can do that in many languages (C/C++ being notable exceptions). The problem with Java is that straightforward code tends to be unnecessarily slow, and that is why Java deserves its reputation for being a "slow language". It has nothing to do with garbage collection, and everything with language misfeatures specific to Java.

  58. Re:Counter arguments by LarsWestergren · · Score: 4, Informative

    The typical home machine these days is still sub-ghz, and Java performs so poorly as to be unusable on such machines.

    A typical mobile phone is sub-ghz too, and there is plenty of J2ME software running on them...

    Java rocks on limited devices AND as server software. It is only on the desktop it isn't a big hit. Yet.

    --

    Being bitter is drinking poison and hoping someone else will die

  59. Re:Counter arguments by junklight · · Score: 1

    did you read *either* of the articles?

  60. java is slower than C by petermgreen · · Score: 1
    --
    note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
  61. as good as Perl's? by jbellis · · Score: 1

    it's significantly better.

    if you RTFA you'd get some ideas as to why. perl's garbage collector is very, very stupid by comparison.

    1. Re:as good as Perl's? by Doc+Ruby · · Score: 1

      Yeah, and I also understated how much more shareable is Java code than Perl code. So what? Why don't you drop that chip from your shoulder and help improve the discussion, rather than look for sidetracking arguments about your personal language jihads?

      --

      --
      make install -not war

    2. Re:as good as Perl's? by DougWebb · · Score: 1

      I read the article, and it doesn't say anything at all about Perl. It just mentions the name of the language once, in a somewhat ambiguous context.

      One of my colleagues, who dislikes both Perl and Java, made this comparison: In Java, when you allocate an object, you have no control over when it gets deallocated, and you have no guaranteed way of performing some action just before it does. In contrast, a Perl object gets deallocated precisely when the last reference pointing to it is removed, and if it has a DESTROY method then that method will be called just before deallocation.

      Perl's approach allows you to use a common C++ idiom for accessing resources: you define a class that represents the resource (file, socket, memory pool, etc). To get access to the resource you create an object, and to release the resource you destroy the object (let it go out of scope.) You use the object constructor and destructor to set up access and to safely release access. (ie: opening/locking a file and unlocking/closing the file.) With a proper design, this approach to resource allocation fits nicely with exception handling, because if an exception occurs your resource objects will wind up going out of scope, and their destructors will take care of cleaning up.

      Since Java objects don't/can't behave this way, you can't use this idiom, and that makes resource allocation much more complex and error prone, especially when you start to deal with exception handling. For this reason, my colleague preferred Perl over Java.

      (Or course, his true loves are C++ and Python; he likes the scripting language idea, but prefer's Python's OOP handcuffs over Perl's free-for-all OOP model.)

    3. Re:as good as Perl's? by M.+Baranczak · · Score: 1

      In Java, when you allocate an object, you have no control over when it gets deallocated,

      You have some control, just not much. But why exactly is this a problem? If you're done using an object, the garbage collector takes care of it; why should you care when exactly it gets deallocated? If your object is holding onto some resource that needs to get released ASAP, then you add a method which releases that resource - there's no need to deallocate the object.

      and you have no guaranteed way of performing some action just before it does.

      That's absolutely wrong: you can override finalize(). (BTW, I write Java code for a living, and I can't even remember the last time I actually had to do that. Most of the time, the JVM and the core libraries take care of any clean-up automatically.)

    4. Re:as good as Perl's? by NoOneInParticular · · Score: 1
      ... then you add a method which releases that resource - there's no need to deallocate the object.

      And the issue with this is that the Resource Acquisition Is Initialization idiom is broken, and you are suddenly forced to do resource management. In a language like Perl/Python or even C++ using shared pointers, you don't do explicit deallocations, and also no explicit resource management, and all works even in the presence of exceptions. Resource management is not as ubiquitous as memory management, but errors in it can be even more dangerous. I prefer to open a file and know that it gets closed when it goes out of scope.

    5. Re:as good as Perl's? by Anonymous Coward · · Score: 0
      Why don't you drop that chip from your shoulder and help improve the discussion

      Or what? You are gonna start with the nazi racial slurs, as usual?

    6. Re:as good as Perl's? by Doc+Ruby · · Score: 1

      No, you started. Nazi. BTW, you can't blame your naziness on your "race", whichever that might be. It's your own damn fault, and you brought it up.

      --

      --
      make install -not war

    7. Re:as good as Perl's? by aled · · Score: 1

      The problem you have is trying to implement the Resource Acquisition Is Initialization idiom that was designed for C++ in Java. Stop trying, it's useless because Java has not the concept of destructors. Is as useless as trying to end Java strings with '\0'.
      Design patterns may be specific to a programming language. Better use of your time would be learning what possibilities exists in Java.

      --

      "I think this line is mostly filler"
  62. Re:Counter arguments by ckaminski · · Score: 1

    I disagree.

    I've just built an order taking system Java/SWing for laptops for trade-show personnel to take orders in real time with 1000 listed products. I developed the system on a PII-600 (a nearly 6yo HP Omnibook 6000) to deploy on something equal to or better. It's almost indistinguishable from a C++/MFC app I might have authored in my youth.

    I think there's something to be said for bloated frameworks (cough - weblogix) but Java itself is not overly handicapped wrt performance.

  63. Cool code no longer means fast by jolshefsky · · Score: 2, Interesting

    I've never believed that Java's garbage collection is the root cause for its slowness. I do believe that Java's GC is the cause for its random (and more notably, its inconveniently timed) stutters.

    I think the more general Java slowness comes from the obfuscation of efficiency. In C for instance, ugly code correlated with inefficient code. This is no longer the case for object-oriented programming in general, and it is possibly worst correlated in Java.

    The example in the article provides a starting point for what I'm saying. It's based on the algorithm for a point in some Cartesian graphics system:

    public class Point {
    private int x, y;
    public Point(int x, int y) {
    this.x = x; this.y = y;
    }
    public Point(Point p) { this(p.x, p.y); }
    public int getX() { return x; }
    public int getY() { return y; }
    }

    public class Component {
    private Point location;
    public Point getLocation() { return new Point(location); }

    public double getDistanceFrom(Component other) {
    Point otherLocation = other.getLocation();
    int deltaX = otherLocation.getX() - location.getX();
    int deltaY = otherLocation.getY() - location.getY();
    return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
    }
    }

    The Component.getDistanceFrom() algorithm is considered "good OO style." By using bad style, though, you can break the pretty encapsulation -- and make "bad OO style" -- but get a performance gain:

    public double getDistanceFrom(Component other) {
    int deltaX = other.location.getX() - location.getX();
    int deltaY = other.location.getY() - location.getY();
    return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
    }
    }

    Both code blocks require the math (two subtracts, two multiplies, an add, and a square root) but the original block (unoptimized) also requires the allocation of the Point object and the two memory copies to store the (x,y) location.

    This is a trivial example, but my point is that in a complex Java project, readable and elegant code bears no correlation to fast and efficient code. I believe this is why Java is slow.

    --
    --- Jason Olshefsky

    Karma: Poser (mostly affected by adding this line long after everyone else did)

    1. Re:Cool code no longer means fast by AmishSlayer · · Score: 1
      This argument is as flimsy as your point:

      Both code blocks require the math (two subtracts, two multiplies, an add, and a square root) but the original block (unoptimized) also requires the allocation of the Point object and the two memory copies to store the (x,y) location.

      Unless you clone the object it is a shallow copy.... that is to say it is a reference variable pointing to the same Point object, not a refernce variable pointing to a whole new Point object.

      Furthermore the compiler will optimize your code.... compile the class both ways and compare the byte code instruction with javap -c Point

      the method is the same for both idioms:

      public Point(Point);
      Code:
      0: aload_0
      1: aload_1
      2: getfield #2; //Field x:I
      5: aload_1
      6: getfield #3; //Field y:I
      9: invokespecial #4; //Method "<init>":(II)V
      12: return


      I suspect that most of you "performance" issues do not really exist, but rather, they stem from a lack of knowledge and poor perception on your part.
    2. Re:Cool code no longer means fast by kingkade · · Score: 1

      Didn't you read the *whole* article? The "getDistanceFrom()" example was there to show you *can* have "elegant", safe code transparently and safley optimzed by the JIT compiler to be the same EXACT code as the unsafe, fast example precisely because the jitter can notice what a static compiler cannot (in this case a static compiler can do escape analysis as well), TOTALLY removing any allocations.
      Even if the Java and C++ did not do this, why would that be your reason for believing only Java is slow? It would have the same effect on both of them -- namely having an unnecessary allocation of Point.

    3. Re:Cool code no longer means fast by Anonymous Coward · · Score: 0

      Incidentally, a Point wouldn't be a shallow copy because it's a value-type.

    4. Re:Cool code no longer means fast by patio11 · · Score: 2, Interesting
      You'll find that your two examples will compile to the same bytecode in any modern Java compiler. Trust me, after literally two months of trying every line-by-line optimization I could think of to squeeze every tenth of a percent out of the main loop I came to the conclusion that the guys at both Sun and IBM (jikes compiler) are just freakish code gods and that I should never, ever, ever attempt any optimization below the level of algorithm selection. How freakishly good was this compiler? I had an algorithm for solving N-Queens that could be implemented as either iterative or recursive. Obviously, in n-queens the recursive algorithm has a guaranteed maximum depth, so I would presumably gain a lot of speedup by going with iteration and avoiding the overhead with a billion function calls, right? Oh, wrong! I ran literally 10,000 trials and the difference was statistical noise, something like two hundredths of a percent in favor of the recursive algorithm (I know, WTF). Then I go digging for the answers why and a wise sage imparted on me the lesson I have just imparted on you -- Trust Your Compiler.


      (Oh, by the way -- other tricks they used to tell you in the early days of Java, like trying to make the getX() inlineable or breaking the standards they taught you in CS101 and replacing foo.getBar() with foo.bar, are also pretty much useless. The Compiler Knows All.)


      P.S. I eventually abandoned Java entirely for the tight-loop and rewrote that as a stand-alone C app, keeping Java for the networking and logic for the distributed application (which used, lets see, approximately 1/100000000000000000 of the amount of cycles as the actual computation loop did, that being mostly the point). C, unsuprisingly, beat Java by a factor of roughly 100 in terms of speed (a tight loop doing bit-level operations on integers, and I had the luxury of using GPLed code written by the guy who set the world record in this field as a base to start on, which meant the C, which both benefitted from hand human optimization and a much more mature compiler which was literally built to do this sort of thing, ate Java for lunch).

    5. Re:Cool code no longer means fast by Anonymous Coward · · Score: 0

      WTF??

      Point p = bew Point(); //original
      Point p2 = p; //shallow copy (both p and p2 point to the same object
      Point p3 = p.clone(); //deep copy (makes a new object that is a copy of p)

    6. Re:Cool code no longer means fast by nerdwarrior · · Score: 5, Insightful

      Except, you're wrong. You're assuming that the compiler is doing *no* optimization. So, how would a compiler treat the first "inefficient" code example? Let's take a look:

      public double getDistanceFrom(Component other) {
      Point otherLocation = other.getLocation();
      int deltaX = otherLocation.x - location.x;
      int deltaY = otherLocation.getY() - location.getY();
      return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
      }

      Look at the implementation of getLocation(). It's a simple non-recursive procedure. In virtually all compilers, a simple procedure like this is going to be inlined, producing:

      public double getDistanceFrom(Component other) {
      Point otherLocation = new Point(other.location) ;
      int deltaX = otherLocation.getX() - location.getX();
      int deltaY = otherLocation.getY() - location.getY();
      return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
      }

      (Note that to the compiler, all variables are effectively public, so this would not be an access violation.)

      Next, the compiler can (easily) prove (by inspection) that Point(Point) is a copying constructor. As a result, it can replace the use of new Point(other.location) with other.location so long as it proves it will not modify otherLocation, and of course, it can prove this quite easily by inspection of getDistanceFrom(). This results in:

      public double getDistanceFrom(Component other) {
      Point otherLocation = other.location ;
      int deltaX = otherLocation.getX() - location.getX();
      int deltaY = otherLocation.getY() - location.getY();
      return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
      }

      Also, note that getX() and getY() are also simple non-recursive leaf procedures, so the compiler would have inlined them at the same time, so you would actually get code equivalent to this:

      public double getDistanceFrom(Component other) {
      Point otherLocation = other.location ;
      int deltaX = otherLocation.x - location.y;
      int deltaY = otherLocation.y - location.y;
      return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
      }

      Which is now faster that your hand-written "optimization." Note in fact, that you "over-optimized" by replacing otherLocation with other.location twice. If a compiler were actually dumb enough to implement it that way, literally, it would have involved an extra (and needless) pointer dereference to get the value of other.location twice, when it already had it sitting in a register. (Fortunally, most any compiler nowadays would have caught your "optimization" and fixed it.)

      In fact, the compiler wouldn't stop here. It might even rearrange the order in which it fetches x and y to avoid cache pollution and misses. Do you consider that each time you fetch a variable? Most programmers don't, and shouldn't. The moral of the story is that most programmers fail to realize how smart compilers have become. Compiler writers design optimizations with "good coding practices" such as this in mind, and the programmer will be rewarded if he or she uses them.

    7. Re:Cool code no longer means fast by jolshefsky · · Score: 1

      D'oh! I'll concede this specific example ... my argument was largely based on two things:

      1. I tried a Java-based office-bundle package a year ago and it was so resource-intensive and intolerably slow that I assumed Java just hasn't changed much.
      2. A quick glance at the old resume reveals that my Java experience ended in 1999 or so and hence is woefully out of date.

      However, I think part of my point is still valid: that efficiency and elegance are not correlated in object-oriented programming, and particularly in Java. Your argument (and most others in this thread and in the original article) is that the optimizing compilers allow elegant code with good OO practices to work efficiently.

      I'm using a particularly trivial example, and because of that, it would require an inordinately convoluted trick to fool the compiler. For instance, if the copy constructor had additional code that the compiler was unable to fit into a pattern (I don't know ... make a call to an external C function) then it couldn't validly optimize out the constructor call and allocation of a new object.

      What I'm getting at is that in a procedural language, if an algorithm is elegant, it is efficient -- a programmer can rely on direct assumptions like, "the library calls I use in this algorithm are explicitly written to be fast." In this Java example, there is a further assumption that "the compiler will be able to optimize out the allocation and construction of the Point object that I have specifically requested."

      Do you see what I'm getting at? That the good OO programming practice of coding "Point otherLocation = other.getLocation()" is done because the copy constructor for Point may have some side effects that are important -- this specific example is too trivial, but I think it's obvious that more complex object hierarchies can have issues like this (for instance, a serial unique ID [but since it is never used before the object goes out of scope, that would probably be optimized out too, right?]). However, the efficiency of Component.getDistanceFrom() now depends on the copy constructor being able to be optimized out, and that seems to be a rather non-obvious requirement.

      On the other hand, it may be that all the bases are covered. For instance, maybe the rule for an object that claims to be efficient is that copy constructors shall only make copies of members. More likely than not, it's that I have degree in procedural programming but almost all of my OO training is on-the-job, and that modern OO computer programming courses cover that stuff just as the procedural courses I took did.

      --
      --- Jason Olshefsky

      Karma: Poser (mostly affected by adding this line long after everyone else did)

    8. Re:Cool code no longer means fast by p3d0 · · Score: 1
      I do believe that Java's GC is the cause for its random (and more notably, its inconveniently timed) stutters.
      In interactive apps, that's more likely to be a problem with the JIT compiler kicking in at inopportune times.
      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    9. Re:Cool code no longer means fast by dubl-u · · Score: 1
      This is a trivial example, but my point is that in a complex Java project, readable and elegant code bears no correlation to fast and efficient code. I believe this is why Java is slow.

      I disagree. Most of the ugly systems I see are also slow. In my sample, at least, design clarity is strongly correlated with speed.

      Good OO style can come at a moderate resource cost, although this article points out that JVMs get better and better at turning common OO structures into resource-optimal structures at run-time. But good OO style also gives you increased flexibility and maintainability. When you get to the point of optimizing, a clean design makes it much easier to find slow points and make them fast easily.

      Here's my process:
      1. make it work
      2. make it right
      3. make it fast

      First, I get something working. Then I refactor the design to be clear and easy to understand. Only then do I worry much about speed. Most of the time I can get the speed I want without design distortion. On the rare occasions when I get speed by, say, breaking encapsulation, I do the minimum necessary and mark it clearly so that when the next generation of the JVM makes my tweaks obsolete, somebody can easily put things back.

      But really, a surprising number of my performance issues go away at the design cleanup stage. A lot of performance problems are really design problems.
    10. Re:Cool code no longer means fast by matfud · · Score: 1

      And if you had read the article you would have seen that your first example can and in applicable circumstances, will be converted to your second example by the JVM (as long as it does not break the logic behind the encapsulation you placed there). In fact the article explicitly says how this can occur. All this while still maintaining robust and reliable code.

      No need to break encapsulation or compromise on design to get a performance increase. The VM will perform that optimisation for you while allowing you to write well structured and maintainable code.

      I do think you have a point. Generalization, object oriented design, well structured, reliable and reusable software do all tend to impact performance. Its nice that the performance can be reclaimed by "hotspot" compilers rather then having to compromise your design for the sake of performance.

    11. Re:Cool code no longer means fast by napir · · Score: 1

      You're simply wrong. Unless you specify it explicitly, JIT compilation is done in the background, so you'll never wait for a method to compile (it will be run in the interpreter). Full-heap GCs can show noticable to annoying pauses, as the parent poster notes.

    12. Re:Cool code no longer means fast by kvigor · · Score: 1

      You'll find that your two examples will compile to the same bytecode in any modern Java compiler.

      Do you count the Sun's current JDK release as a "modern compiler"? If so, you may find the following interesting:

      (kvigor@mojo tmp)$ cat Component.java
      public class Component {
      private Point location;
      public Point getLocation() { return new Point(location); }

      public double getDistanceFrom(Component other) {
      Point otherLocation = other.getLocation();
      int deltaX = otherLocation.getX() - location.getX();
      int deltaY = otherLocation.getY() - location.getY();
      return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
      }

      public double getDistanceFromOptimized(Component other) {
      Point otherLocation = other.location ;
      int deltaX = otherLocation.getX() - location.getX();
      int deltaY = otherLocation.getY() - location.getY();
      return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
      }
      }
      (kvigor@mojo tmp)$ ~/jdk/jdk1.5.0_05/bin/javac Component.java
      (kvigor@mojo tmp)$ ~/jdk/jdk1.5.0_05/bin/javap -c Component
      Compiled from "Component.java"
      public class Component extends java.lang.Object{
      public Component();
      Code:
      0: aload_0 // comment added to pad average line length because slashcode is teh SUXXOR
      1: invokespecial #1; //Method java/lang/Object."":()V
      4: return // comment added to pad average line length because slashcode is teh SUXXOR

      public Point getLocation();
      Code:
      0: new #2; //class Point
      3: dup // comment added to pad average line length because slashcode is teh SUXXOR
      4: aload_0 // comment added to pad average line length because slashcode is teh SUXXOR
      5: getfield #3; //Field location:LPoint;
      8: invokespecial #4; //Method Point."":(LPoint;)V
      11: areturn

      public double getDistanceFrom(Component);
      Code:
      0: aload_1
      1: invokevirtual #5; //Method getLocation:()LPoint;
      4: astore_2
      5: aload_2
      6: invokevirtual #6; //Method Point.getX:()I
      9: aload_0
      10: getfield #3; //Field location:LPoint;
      13: invokevirtual #6; //Method Point.getX:()I
      16: isub
      17: istore_3
      18: aload_2
      19: invokevirtual #7; //Method Point.getY:()I
      22: aload_0
      23: getfield #3; //Field location:LPoint;
      26: invokevirtual #7; //Method Point.getY:()I
      29: isub
      30: istore 4
      32: iload_3
      33: iload_3
      34: imul

    13. Re:Cool code no longer means fast by cow-orker · · Score: 1

      Except you are wrong. The compiler can optimize zilch here, because:

      public double getDistanceFrom(Component other) {
      Point otherLocation = other.getLocation();

      `other' may be of any subclass of `Component' and therefore may override `getLocation' in any ways it sees fit. The same goes for `otherLocation' if `other' decides to create something of a subclass of `Point'. Particularly, `getLocation' might keep a reference to the newly created `Point', thereby making the cited stack allocation invalid, and it might return a class with more data, making your unfolding invalid. In short, the compiler needs global information (the dynamic type of `other') to optimize anything, and due to seperate compilation and dynamic linking, this information is unavailable in principle.

      The JVM may have this information, as the article states, but only when `getDistanceFrom' is actually called. At this point it could either check the dynamic type of `other' and dispatch to a statically optimized version (which is probably useless, considering that in Java nearly everything is expressed in terms of interfaces and not concrete classes) or dynamically inline `getLocation' and then optimize. Stack allocation however is still impossible if anything after `getLocation' is called with `otherLocation' as parameter, unless that too is inlined and (statically!) "escape analyzed". But all this inlining and analysing amount to somewhat more work than a heap allocation. Add to that, that after inlining the code block may be unwieldy large and too complex to analyze, making all this effort completely useless.

      In short, all these optimizations may be possible, but always at a cost. The cost may be negligible, but that depends on the application. A micro benchmark is no application. I believe all this propaganda, when I see a Java application that feels fast. I've seen enough that feel sluggish. (Anyone remember Corel Office? Yeah, that was a fast Java application. It disappeared very quickly because of its outrageous demands regarding CPU power and memory.)

      BTW, I just love Haskell. Naively programmed it is very elegant, but incurs a performance cost. Yeah, yeah, a sufficently smart compiler could cure cancer and turn lead into gold, blah blah. Bullshit, it's mostly theoretical, exactly as theoretical as the "smart JVM". In reality, fast code is possible, but takes work and is often at odds with elegant code. If the Java advocates only acknowledged that the magic JVM is no silver bullet and that other technologies might have their niches, too, I might even take them seriously.

    14. Re:Cool code no longer means fast by zipwow · · Score: 1

      When you say that the usage of getLocation() in getDistanceFrom(..) is "good OO style", do you mean that you'd write the same code in other OO languages, like C++? If so, isn't this a complaint about OO style that has nothing to do with Java? The problems you list here with the allocation of new objects are as relevant to C++ as they are to Java.

      --
      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.
    15. Re:Cool code no longer means fast by zipwow · · Score: 1

      Oops, yes you do:

      "This is no longer the case for object-oriented programming in general, and it is possibly worst correlated in Java."

      I don't see where Java is a worse offender than anywhere else, though.

      --
      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.
    16. Re:Cool code no longer means fast by p3d0 · · Score: 1
      Allow me to introduce myself. I am the lead developer of the AMD64 port of the Java JIT compiler developed by a major company. Obviously that doesn't mean my word is gospel on JIT issues. I only hope it will give you pause to think before you dismiss my remarks again.

      If you're running on a uniprocessor, the JIT (at least our JIT) never waits for the interpreter. The reasoning is that Java is primarily a server-side technology, and so throughput is paramount. For throughput, once you decide you're going to compile a method, it's always better to compile it before executing it.

      The downside of this policy becomes apparent when running an interactive app. The user clicks on a button, causing some Java code to run, causing the invocation counts on some methods fall to zero, causing them to get JITted at precisely the wrong moment, from an interactivity point of view. Just when the user expects a response, the JIT comes along and makes her wait.

      Obviously other policies are possible for interactive apps, and some other JVMs probably use such policies. We may start employing such a policy in a future release.

      Also, on a multiprocessor (even with hyperthreading or multi-core processors) this is usually no longer a problem because, as you say, one thread will continue interpreting the method while another compiles it.

      However, with modern JVMs, with generational concurrent garbage collection... If you're noticing GC pauses, you may not be using your JVM's best available GC policy.

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
  64. Maybe you should look harder. by Some+Random+Username · · Score: 1

    Look at any of the BSDs. There's 3 complete unix operating systems, kernel and userland, all in C. And yet, somehow, memory leaks are simply not an issue. Sure, they happen once in a while, but not often enough to be a problem. Yeah, memory leaks abound in poorly written, buggy piles of crap like mozilla, but that's my point. If you have problems with memory leaks, then you are the problem, not C.

    1. Re:Maybe you should look harder. by TheRaven64 · · Score: 2, Interesting

      Most memory leaks I have seen in C come from the simple fact that it is not possible to allocate space on the previous stack frame. If the runtime included a mechanism for moving an allocation to the caller's stack frame (which would be trivial to implement) then most of them would go away. One other work around for this which I have seen is to have separate call and data stacks. Rather than calling malloc, you call a function which gives you a block of RAM on the top of the data stack. The data stack can be pushed and popped independently of the call stack, so a function that needs to return an arbitrary amount of data simply allocates it on the data stack, and returns a pointer to it. The pointer remains valid until the next time the data stack is popped.

      --
      I am TheRaven on Soylent News
    2. Re:Maybe you should look harder. by Dwonis · · Score: 1
      If the runtime included a mechanism for moving an allocation to the caller's stack frame (which would be trivial to implement)

      Trivial to implement? How?

    3. Re:Maybe you should look harder. by qbwiz · · Score: 1

      I doubt that its trivial, but with some work with the compiler (assuming you only use one compiler), you could automagically use space that the caller has pre-declared. You can already do this by declaring an object on the stack, and passing a pointer to the object into the function. I don't feel like working on the corner cases (e.g. multiple levels of callers), but its certainly feasible. Worthwhile, maybe not.

      --
      Ewige Blumenkraft.
    4. Re:Maybe you should look harder. by shmlco · · Score: 1

      Most things are trivial except for the "corner" cases.

      --
      Any sect, cult, or religion will legislate its creed into law if it acquires the political power to do so.
    5. Re:Maybe you should look harder. by Ace+Rimmer · · Score: 1

      NAME
                    alloca - memory allocator

      SYNOPSIS
                    #include

                    void *alloca(size_t size);

      DESCRIPTION
                    The alloca function allocates size bytes of space in the stack frame of the caller.
                    This temporary space is automatically freed when the function that called alloca
                    returns to its caller.

      RETURN VALUE
                    The alloca function returns a pointer to the beginning of the allocated space. If the
                    allocation causes stack overflow, program behaviour is undefined.

      CONFORMING TO
                    There is evidence that the alloca function appeared in 32v, pwb, pwb.2, 3bsd, and 4bsd.
                    There is a man page for it in BSD 4.3. Linux uses the GNU version. This function is
                    not in POSIX or SUSv3.

      (C) GNU

      --

      :wq

    6. Re:Maybe you should look harder. by TheRaven64 · · Score: 1

      Yes, that's half of the solution. Unfortunately, it's a real pain to use recursively. What you really want is to have a mechanism that does for data what exceptions do for flow - allow something to be thrown an arbitrary distance up the stack.

      --
      I am TheRaven on Soylent News
  65. Re:Counter arguments by Anonymous Coward · · Score: 0

    The typical home machine is more than 5 years old (or a Mac)? I doubt it.

  66. Firefox, with its layers, is way better than Java by expro · · Score: 1

    Firefox even has its own garbage collection in the Javascript interpretation, but it's memory performance is orders of magnitude better than Java-based applications including NetBeans.

  67. Re:Counter arguments by Anonymous Coward · · Score: 0

    It depends on what kind of software you're developing. If it's an inhouse business or vertical enterprise application, you're right. If it's an operating system, RDBMS, video game, or office productivity suite, every bit of performance matters a lot.

  68. Re:Counter arguments by Anonymous Coward · · Score: 0

    So you're saying you dont care about how slow the client runs? What a great argument...

  69. Programs by MoogMan · · Score: 4, Insightful

    Unfortunately, programs such as Azureus, which run piggishly slow on a 1.2GHz laptop do nothing to dispell these 'performance myths'.

    1. Re:Programs by Matt+Perry · · Score: 2, Informative

      It sounds like there is something wrong with your laptop. I have a 1.3 GHz desktop machine at home. I run Azereus and it's as fast as any other application.

      --
      Slashdot: Failed Car Analogies. Amateur Lawyering. Anecdote Battles.
    2. Re:Programs by Anonymous Coward · · Score: 0

      This is so weird, I keep seeing the odd person say it but I've never experienced it myself so I wonder:

      - what kind of OS does these slow-Azureus-people use?
      - are their machines filled with all sorts of ugly things they're not aware of?
      - are they running old versions of Java and/or Azureus?
      - how many programs are they running at the same time? (I'm usually between 5 and 15 while using Azureus)
      - exactly what are they describing with "slow"? The startup? GUI updates? Downloading? Shutdown? Other programs/the CPU/RAM? The OS?
      - what kind of Userland are they in? Windows vanilla? KDE? Gnome? Windows BB-like? *nix BB-like?

      Do they have a lot of massive torrents active at the same time or something? If I have a lot of pages open at the same time in Firefox or Mozilla they can slow down to a crawl depending on how much else my system is doing - for example when shifting focus from one inactive but open program to Mozilla. Depending on how much else I'm doing this can become noticeable at 15+ tabs but I wouldn't call Mozilla slow because of that, it's simply that I'm maxing out my resources (Athlon 1800, 1GB RAM)...

      I use Azureus a lot, it can be a bit sluggish at startup and shutdown but so is Adobe Photoshop as well (much more so actually) or Adobe Acrobat Reader - and those two aren't Java. So what exactly is the argument for calling Azureus slow that has specifically to do with Java?

      I call bullshit from morons unless they can come with some real specifics.

    3. Re:Programs by Anonymous Coward · · Score: 0

      Of course, since you are using torrent mostly to do some movie/mp3 downloading you would feel a lot safer using some C/C++ program where a "bad" network package might crash your system or get you own3d, no?

      I think that especially for torrents (where you connect to tens of IPs so a firewall is not that helpfull) Java is a quite nice solution. Freenet is also build upon Java -- I wonder why.

    4. Re:Programs by m0rphin3 · · Score: 1

      Say what? I run it on a Pentium 2 / 266mhz, with plenty of CPU cycles to spare for serving files and streaming stuff to my Xbox. And that's with 30+ torrents. I'd examine my uber-1337 sysadmin skills if I were you.

      --
      for great justice
    5. Re:Programs by glesga_kiss · · Score: 1

      Like the guy above me, I'm running it on a Pentium II, 450 MHz with 64 meg of ram with Win XP. The box often runs eMule, pretty always has winamp playing (to multi-room amp :-). I use VNC to access it, which is very processor heavy for the screen scraping. Finally, I usually have Firefox running. Everything runs peachy.

    6. Re:Programs by Sycraft-fu · · Score: 1

      Guess something's wrong with my systems too. I have a 2.4Ghz P4 (with 2GB of RAM) at home and Azerus is slow. Ok maybe I should clarify, it isn't slow to work with, but it eats up all my CPU when it gets working. I can't really background it and go do other things except browse the web or other non-intensive tasks. If I play a game, everything drags to a halt. The reference BT client, I can background with no problems and do what I please. Az also seems to eat an inordinate amount of memory. Not that I don't have plenty, but I'd prefer my apps use as little as possible since I DO run some that use all of it from time to time.

    7. Re:Programs by matfud · · Score: 2, Insightful

      I would have to agree, especially on the firefox part. Leave it running for a couple of days, like I do when at work, and you will find it is using well over 1G of ram.

      Java has a huge problem with memory resources.It does not integrate well with the OS (ie it does not know when increasing its heap with cause frantic swappage). It does not work well on machines with small quantities of ram (unless you specify individual heap/gc parameters for all you java apps (which is well worth doing))

      However in server environments (and very low end devices) where you tend to only run one app at a time the performance is very good.

      Before you complain. I run IntelliJ idea, Tomcat, Ant (and a few other java apps) all at the same time (sometimes multiple copies of each) and have no problems. But the computer I run them on has 2 Gig of ram. With 1 Gig I was struggling a bit.

    8. Re:Programs by Anonymous Coward · · Score: 0

      Well, I for one just realized that azureus is written in java.

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

      SWT's fault i recon. Try netbeans for a proper java app.

    10. Re:Programs by bani · · Score: 1

      i have a desktop opteron with 1gb ram and azureus is still extremely sluggish compared to any other application including openoffice. azureus, with no torrents running, also takes many times MORE memory than openoffice! that's pretty amazing to me.

    11. Re:Programs by Fujisawa+Sensei · · Score: 1

      Works great on my 1.7 MHz Dell laptop, even when the POS speed stops down to 500 MHz.

      OTH the last few releases of Firefox have performed like shit.

      --
      If someone is passing you on the right, you are an asshole for driving in the wrong lane.
    12. Re:Programs by Anonymous Coward · · Score: 0

      That's been my experience too. I hate python, but when using python apps I've never experienced slowdowns and memory hogging (well, except for the official BT gui client, which is buggy and occasionally goes wild and sucks up all memory). Java apps though... fat city. Azureus *feels* slow, sucks up CPU time and quickly shoves everything else into swap... just like every other bloody Java app I've ever used.

      These articles always attract nutters claiming that Java is not slow... I have to wonder whether any of them ever use non-Java apps, or whether they are simply deluded, or marketing droids from Sun.

    13. Re:Programs by Anonymous Coward · · Score: 0

      I would have to agree, especially on the firefox part. Leave it running for a couple of days, like I do when at work, and you will find it is using well over 1G of ram.

      From top:

      14183 anonymous 15 0 205m 120m 23m S 0.0 11.9 50:12.72 firefox-bin

      Right...

    14. Re:Programs by matfud · · Score: 1

      So I exagerated a bit
      6312 anonymous 15 0 442m 258m 17m S 0.3 12.8 145:35.09 firefox-bin

      Its only using half a gig of ram after 2 or 3 weeks

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

      Azurseus is likely slow on your laptop for two reasons:
      - it is mostly I/O bound; laptop hard drives are slow and, if you use a wireless network, the network has high latency;
      - the screen refreshes are slow leading to an impression, rightly, that it is slow. azureus has a fairly complex and dynamic interface and Java and particularly SWT can have slow refreshes if not programmed carefully and conscienciously. This involves threading, I/O, and scheduling which are not amendable by naive implementations.

  70. You should consider reality by Doc+Ruby · · Score: 1

    C doesn't program itself. These "language in a vacuum" arguments are specious, nonconstructive navelgazing.

    --

    --
    make install -not war

  71. What a bunch of FUD by SlayerDave · · Score: 3, Interesting
    From TFA:

    The common code path for new Object() in HotSpot 1.4.2 and later is approximately 10 machine instructions (data provided by Sun; see Resources), whereas the best performing malloc implementations in C require on average between 60 and 100 instructions per call (Detlefs, et. al.; see Resources).

    Wow, that's really shocking. Until you actually look at the Detlef paper and realize that it was published in 1994, 11 years ago!! Who knows, maybe things have improved a bit in 11 years. The author certainly thinks Java is getting better; maybe it's possible that C/C++ compilers have improved as well.

    1. Re:What a bunch of FUD by sjasja · · Score: 2, Interesting
      maybe it's possible that C/C++ compilers have improved as well.

      Unfortunately it seems nobody really has come up with radically better malloc/free in 11 years. Small tweaks probably yes.

      But if you benchmark your favorite C/C++ compiler (just run "free(malloc(16))" in a loop) you'll find that malloc/free indeed is of the order of 10 times slower than a similar loop in Java. There is no great conspiracy here; this is easy enough to verify yourself.

    2. Re:What a bunch of FUD by dubl-u · · Score: 1

      Wow, that's really shocking. Until you actually look at the Detlef paper and realize that it was published in 1994, 11 years ago!! Who knows, maybe things have improved a bit in 11 years. The author certainly thinks Java is getting better; maybe it's possible that C/C++ compilers have improved as well.

      So let me get this straight. You're accusing somebody of spreading FUD and your sole evidence is, uh, nothing? What do the U and D stand for again, hmmmm?

    3. Re:What a bunch of FUD by Sangui5 · · Score: 5, Informative

      Additionally, even if it takes more instructions per call, glibc malloc() will return freshly used "hot" memory to you, while the JVM will return the coldest memory to you--the author of the article admits that this is a problem, but it is worse than they say.

      First, you definately have an L1 cache miss. On a P4, that is a 28 cycle penalty. You also likely have an L2 cache miss. Fast DDR2 memory has an access latency of about 76 ns--call it 220 processor clock cycles. If you miss the D-TLB, then add another 57 cycles. Total cost of your "fast" allocator--305 cycles of memory access latency. 305 is somewhat higher than 100.

      Even worse, if you are on a system with a lesser amount of memory, you may miss main memory entirely, causing a page fault. That'll cost you several milliseconds waiting for the disk. That really really hurts, since 8 milliseconds latency from disk is twenty-four million cycles at 3 GHz. 24 million, 24,000,000, 2.4 * 10^6, no matter how you write it, that's a lot of cycles to allocate memory.

      All of a sudden, 100 instructions to hit hot memory seems cheap.

    4. Re:What a bunch of FUD by Anonymous Coward · · Score: 0

      Right instincts, wrong analysis. The allocators in the current JVMs are smart enough to optimize for cache misses, unlike malloc() which returns whatever the OS deems ok at the moment.

      It's not really allocation that makes the JVM slow, it's the collection phase. Allocation in any modern JVM is a pointer increment, nothing more.

    5. Re:What a bunch of FUD by matfud · · Score: 1

      C++ compilers cannot improve in this regard. Thier performance is determined by the underlying OS allocation mechaisms. Yep, Malloc normally involves a context switch into the kernel (slow) and then has to search for a free block large enough to hold your request.
      Compare that to java that does little more then increment a pointer in its most common call path.

    6. Re:What a bunch of FUD by Sangui5 · · Score: 1

      malloc() does not context switch into the kernel for most allocation events. The general case is that it looks at your request size, and then it goes to its list of that size and gives you the top chunk. malloc() is a library call, not a system call.

      malloc() will call into the kernel for two rare cases. The first is if it needs to extend the heap, which happens as you've consumed a lot of heap. By default most of your address space is not mapped by the OS to VM pages--accesses to unmapped pages is a segmentation fault. malloc() will call brk() to ask the OS to extend the heap--in multiples of a page at a time, and only occassionally. This is only near the "normal" case if you never free memory.

      The other time malloc traps into the kernel is if you've allocated a very large chunk in one call (I believe the glibc implementation considers 1MB to be large). In this case, malloc will request a separate mmap from the OS, separate from the normal heap space. Since chunks this large are rare, this too is not a signifigent source of context switch overhead.

    7. Re:What a bunch of FUD by Sangui5 · · Score: 3, Informative

      The allocators in the current JVMs are smart enough to optimize for cache misses
      Allocation in any modern JVM is a pointer increment, nothing more

      So which is it? Smart enough to optimize for cache misses or just a pointer increment? You can't have both.

      The author of the article claims that, for 'new' objects, a modern VM uses a "stop-and-copy" style garbage collector with a few twists to cheapen the liveness detection (i.e. escape analysis). A disadvantage of such an allocator is that any new allocation to the heap will happen in some of the least-recently used memory. Also, every time you GC, you have to relocate all of your memory, forcing you to horribly pollute your cache, and turning all of your previously hot pages cold.

      unlike malloc() which returns whatever the OS deems ok at the moment.
      malloc() is a library call, not a system call. The OS is only involved if you need to extend the heap or if you've just allocated a very large object. So far as 'deems ok at the moment', the most recently used memory is what is generally returned (plus or minus size fitting to keep fragmentation under control). This maximizes locality, and minimizes your physical footprint. With a smaller resident set, more physical memory is available for things like other programs, disk buffers/caches, etc. which leads to even better performance.

      A simple allocator like described in the article may be "cheap" in terms of cycles, but it is very expensive in its side-effects.

    8. Re:What a bunch of FUD by phantomfive · · Score: 1

      wow, that is a great analysis. I am interested to know how you learned all that. My CS degree taught me enough to understand everything you said, but where did you get all those numbers from? And how did you learn the operation of glibc malloc()? I am not trying to troll, just want to know so I can know too.

      --
      Qxe4
    9. Re:What a bunch of FUD by Sangui5 · · Score: 1

      The miss penalty times I googled for review site where they'd benchmarked it. If you look, you can probably get more accurate numbers from Intel. For the disk latency, the manufacturer of a disk will generally report some sort of access latency number, but overall, a "fast" 7200 RPM disk has a latency of about 8 ms.

      So far as how malloc() works, well, it is open source. But some discussion on malloc design can be found at http://gee.cs.oswego.edu/dl/html/malloc.html. More simple information can be found linked at http://www.cs.utk.edu/~plank/plank/classes/cs360/l ecture_notes.html (again, just a quick google).

      Mostly, it comes down to that my area is systems and architecture. My job is to know all those little details about how things interact. This was just a quickie. No guarantees it is right--I'm using other people's numbers, and just my recollection of how malloc() behaves. If this were more serious than /. then I'd dig through Intel's processor manuals for more exact numbers, figure out which (if any) of those latencies can happen in parallel, measure things myself to verify, etc. I'd also write a small program to do a lot of mallocs and frees and see what addresses are returned to verify the locality properties.

      If I were really really serious, I'd come up with a benchmark program that allocates and frees memory, of various sizes with various working sets and object lifetimes, and measure the execution time for both Java and C. I'd use something like VTune (http://www.intel.com/cd/software/products/asmo-na /eng/vtune/index.htm) or SimICS (http://www.virtutech.com/) (with a timing model, say GEMS (http://www.cs.wisc.edu/gems/tutorial.html)) to analyze exactly where the differences are coming from.

      And then I'd write it up and submit the results to SIGMETRICS, PLDI, OOPSLA, or some other conference, because I just spent a metric butload of time tracing down shortcomings in the GC implementation of various JVMs as compared to programmer managed memory allocation. If somebody is willing to pay me, I still might, but as it is, back of the envelope is all you'll get.

    10. Re:What a bunch of FUD by Hugo+Graffiti · · Score: 1
      Additionally, even if it takes more instructions per call, glibc malloc() will return freshly used "hot" memory to you, while the JVM will return the coldest memory to you--the author of the article admits that this is a problem, but it is worse than they say.

      The JVM does not return the "coldest" memory to you. The vast majority of small to medium allocations are satisfied from a thread local heap which is effectively a stack. So the memory for your current allocation is hot, it's just a few bytes beyond the location of the last object you allocated.

  72. Just for you by MochaMan · · Score: 3, Informative

    Here's a link in case you ever get the urge to write some Java code.

    1. Re:Just for you by Anonymous Coward · · Score: 0

      Should give this link to the eclipse team. Because GC loves to happen everytime I'm typing code. Why can't it just do the GC 2 minutes earlier when i wasn't doing anything.

  73. Ok, the JVM allocation works by Orycterope · · Score: 1, Flamebait

    So, the JVM allocation works, and there's no performance bottleneck there. But where is it? Why is Java still so painfully slow?

    Java used anywhere, from webservers to full client apps just feels and even *looks* slow! Stop coming up with pointless articles. Find the problem and fix it.

    --
    Just because your voice reaches halfway around the world doesn't mean you are wiser than when it reached only to the end
    1. Re:Ok, the JVM allocation works by Anonymous Coward · · Score: 0

      You're stupid. The point of this article is that Java programmers should not worry about object allocation as much as some do.

  74. Re:Counter arguments by Midnight+Thunder · · Score: 2, Insightful

    Five minutes startup times is also a myth. Most small to medium size Java application I have start in under a minute. Of course the more dependencies and the larger the application the more time it will take. I suppose we could compare this to you average game, written in C/C++, which can take over two minutes before you are ready to go.

    For an enterprise application, running as a server, start-up time is not really an issue. What does matter is ho well it does once it is running.

    --
    Jumpstart the tartan drive.
  75. Re:Counter arguments by Orycterope · · Score: 1

    Sure. I also ran a test last year doing simple arithmetic comparisons between Java and C++.

    Guess what, C++ won. There goes your argument.

    Nevermind the fact that what you did is compare one JVM to one compiler generated binary...

    --
    Just because your voice reaches halfway around the world doesn't mean you are wiser than when it reached only to the end
  76. Re:Counter arguments by dorkygeek · · Score: 1

    Have you read the article you link against? You don't know a lot about compiler design, do you? Well, don't feel bad, you're not alone. The author of your article does not seem to know a lot about compilers either!

    Some comments:

    1. All Objects are Allocated on the Heap

    Java only allocates primitive data types like int and double and object references on the stack. All objects are allocated on the heap. [...] Anybody using these will definitely hate trading a zero-time stack allocation for a constant-time heap allocation. Put that in a loop and that becomes O (n) vs. zero. Add another loop and you get O (n^2) vs. again, zero.

    Zero time allocation? This may be true only if you use these values inside the same method or pass them exactly one method call upwards. If you pass them further, you get O(n) complexity for copying the values on the stack. Passing them m+1 methods upwards from allocation point, gives you O(m*n) copy time. Against O(n) allocation time for objects on the heap.

    2. Lots of Casts

    [...] Unfortunately, Java doesn't have templates, so Java code is typically full of casts. What does that mean for performance? Well, all casts in Java are dynamic casts, which are expensive. How expensive? [...] The fastest thing you could do is assign a number to each class and then have a matrix that tells if any two classes are related, and if they are, what is the offset that needs to be added to the pointer in order to make the cast. In that case, the pseudo-code for the cast would look something like this:

    (1) DestinationClass makeCast (Object o, Class destinationClass) {
    (2) Class sourceClass = o.getClass (); // JIT compile-time
    (3) int sourceClassId = sourceClass.getId (); // JIT compile-time

    (4) int destinationId = destinationClass.getId ();

    (5) int offset = ourTable [sourceClassId][destinationClassId];

    (6) if (offset != ILLEGAL_OFFSET_VALUE) {
    (7) return <object o adjusted for offset>;
    (8) }
    (9) else {
    (10) throw new IllegalCastException ();
    (11) }
    (12) }

    Quite a lot of code, this little cast!

    Yes, quite a lot of code, indeed. But only because you don't have the slightest clue about compilers!

    Line (1) Why is your method returning a "destinationClass"?? A dynamic cast check has to return either true or false, but certainly not a class.

    Line (4) Determining the cast target during run-time? Are you nuts?! This happens during compile time! Or since when can the static type of a variable change during run-time??

    Line (7) Adjusted? Adjusted for what?? There is absolutely no need for "adding" an "offset". Why would you want to do this? The ancestors of a class in the class hierarchy are fixed at compile time, i.e. if you have a field a in class A and fields a and b in class B which inherits from class A, then field a in class A has index 0, fields a and b in class B have index 1 and 2. Example:

    A a = new B();
    System.out.println(a.a) // prints value at index 0
    B b = (B) a;
    System.out.println(b.a) // prints value at index 1
    System.out.println(b.b) // prints value at index 2

    The indices are known at compile-time!! A cast only has to return yes or no, valid or invalid.

    3. Increased Memory Use

    Java programs use about double the memory of comparable C++ programs to store the data. There are three reasons for this:

    • 1. Programs that utilize automatic garbage collection typically use about 50% more memory that pr
    --
    Windows is like decaf - it tastes like the real thing, but it won't get you through the day.
  77. Re:Counter arguments by Anonymous Coward · · Score: 0

    What is the point of garbage collection in a JVM when it takes a few hundred megs just to start up?  (*nix)

    The only people saying that processor cycles and ram is cheap are those that can afford a 4gig system with a quad opteron and they run a command line system.

    The rest of us live in a reality where software IS poorly written and sucks cpu and ram in a bad way.  X, Mozilla, gaim, apcupsd, artsd, it isn't at all unusual to have all of these running at the same time.

    root     21303  0.8 15.1 294828 155172 ?       SL   Sep01 462:11 X
    root      8404  0.1  0.0  33940   148 ?        Rsl  Aug29  64:42 apcupsd
    david    21395  0.0  0.7 135776  7224 ?        S    Sep01  16:05 artsd
    david     2615  0.7 26.2 487972 268656 ?       S    Sep20 213:12 gaim
    david      948  0.3 13.8 427656 141404 ?       Sl   Oct07  11:35 seamonkey

    If I start up a jvm, bang, another hundred megs and tons of cpu gone.

    david     7023  0.0  0.1   4776  1088 ?        S    11:37   0:00 limewire
    david     7024 24.2 11.0 1435432 112584 ?      Sl   11:37   0:10 java -cp

    (process name edited for readability)

    In all the time that I have used java in the last ten years, java on *nix has always been a beast.

    Maybe I'm wrong but I wasn't under the impression that software is designed to only run one program at a time on a computer.

    Garbage collection should take second place to garbage creation...

  78. Be prudent in what is Java and what is Native by cpu_fusion · · Score: 1

    One approach to speeding up Java applications involves drawing a prudent line between what will be done in Java vs. native code. Java purists may claim that anything less than 100% pure Java is evil, and there are trade-offs, particularly in the area of security. If you're pragmatic, and use the right tool for the right job, don't be afraid to use native libraries where appropriate. You don't have to go all or nothing.

    For example, to speed up Java apps running on the client (not in a browser, full applications), use Eclipse's SWT. SWT is a UI toolkit that (mostly) uses the underlying Windowing system's widgets, rather than trying to draw everything in Java. As you might expect, this leads to some nice behavior from a performance standpoint. For example, try resizing windows in Eclipse on Windows XP. You'll notice very smooth redraws of the underlying components while the window resizes, just like a C++ app. Now try the same thing in Netbeans.

    Similar solutions exist for accessing OpenGL natively, rather than using a more "Java heavy" library like "Java 3d."

    1. Re:Be prudent in what is Java and what is Native by TheRaven64 · · Score: 1
      For example, try resizing windows in Eclipse on Windows XP. You'll notice very smooth redraws of the underlying components while the window resizes, just like a C++ app

      I tried resizing Azureus (the only SWT app I've used) on OS X. Unlike Swing apps (which resize nicely) and every other OS X app, Azureus only gives me an outline to resize. Once I have selected a new size, I need to wait for a little while as the controls re-draw. Sometimes I need to resize to force a redraw, since the controls don't seem to do this themselves. Oh, and as it runs, the CPU usage gradually climbs until it is at 100%.

      --
      I am TheRaven on Soylent News
  79. The issue (for me) is when, not how long by sixpaw · · Score: 1

    I'm willing to believe that Java allocation/deallocation, in bulk, is better than C++ when amortized over the course of an entire application. The problem is the lack of control; while this is no longer an issue in most parts of the development world, for real-time applications -- and gaming in particular -- performance has to be good from start to finish; taking a time hit to free up memory is fine when you do it yourself at the end of a level, but not so cheerful when it happens automatically in the middle of your boss fight. This isn't a fatal flaw (my current side programming project is a Java-based game), but it's an inherent aspect of the language that severely hampers its applicability to some programming jobs.

  80. Re:Counter arguments by m50d · · Score: 1
    The typical home machine is more than 5 years old (or a Mac)?

    Or, in most cases, wasn't top of the range when it was bought.

    --
    I am trolling
  81. Real benefit of C++ is not performance... by ivec · · Score: 2
    Is this serious??
    Programmers agonize over whether to allocate on the stack or on the heap.

    I have never felt the last bit of anxiety when choosing to "allocate" an object on the stack. I do not even call this an allocation, I just use a local variable that happens to be an object.
    I only allocate an object on the heap when I know this object needs to be exported from the function -- which is something I'd better be aware of by design.
    Stack-allocation is an easy, default, way of life in C++. It is even a key idiom for managing non-memory resources (RAII).

    When programming in C or Java, what makes me agonize is to manually ensure that (non-memory) resources are released properly and in a timely fashin (files, locks, communication ports, etc). try...finally blocks, anyone ?
  82. Re:Counter arguments by Kuros_overkill · · Score: 1

    Agreed. There are few things more fustrating than forced twiddle thumb time because an app is loading. Sure, for most apps it's probably only 10-20 seconds of idle time for the worker, but that can add up over the day. One must consider the full ramifications of "Sacrificed Processer Cycles". If it's in house, it's easy, who gets payed more, programer or end user. If, however, you are doing a comercial app, you are wasting your constomers time. Do it enough and they will go to your competitor.

  83. Re:Counter arguments by sulam · · Score: 2, Informative

    While I'm sure you can point to a Java program which takes 5 minutes to start, these are the exception in the Java world, not the rule. In fact, the JVM takes seconds (a small number of seconds, less than 5) on all of my systems, including P3's as well as older AMD's. It takes less than 2s on my Athlon 4800+. I can go from Tomcat not running to it being completely started up and serving requests in 4s on my PC, and 11s on my older G5. My IDE, which is extremely feature-rich, takes ~90s to get to where I can start typing code from a completely cold start, in a middling (30K LOC) project. That includes a ton of lib caching and such, so that it can do incremental compilation in real time. It takes 16s to restart once that caching is done.

    As far as guzzling RAM goes, all programs these days guzzle RAM, and they're right to do so, because RAM is cheap. This is not unique to Java, the IDE I mentioned uses 56M once it's really going, surely not an unreasonable amount of memory for such a complex app. Java is still not the best choice for small scripts, Python would be better if your program is going to be mostly startup/shutdown time. C# is no better than Java though. Don't forget you need most of .Net in memory for your C# program, and that's no small chunk of RAM. The first time you start up a .Net app of any size you're going to be waiting for it to draw for just as long. And it's no better for scripts, just how fast does Mono start up anyway?

  84. Re:Counter arguments by Anonymous Coward · · Score: 0

    What are these "big things"? Inline assembly blocks? Besides, why should they use Delphi or C# rather than Java, if they're all the same to you?

  85. Re:Counter arguments by Anonymous Coward · · Score: 2, Interesting

    A typical mobile phone is sub-ghz too, and there is plenty of J2ME software running on them...

    Java rocks on limited devices AND as server software. It is only on the desktop it isn't a big hit. Yet.


    Ha! That's a good one. I work with mobile phones, though I personally don't use J2ME. All the programmers I work with do though (the carrier chooses). J2ME really sucks.

    The J2ME spec has a lot of fuzzy places and "MAY"s. You will find the full spectrum of possibilities in such places. There are also many imlpementations that blatently fail to meet the spec. (I've heard that boolean operators *sometimes* short-circuit, but I'm not sure I believe that.)

    Fixed point math is common for these small systems. In Java, you end up looking like Lisp. FP.sqrt(FP.add(FP.mul(a,a),FP.mul(b,b))); Yuck. In C++, you look like C++. sqrt(a*a+b*b);

    Then there's the jar size limits. Some phones only give you 64k to work with. And on top of that, each new class and function adds to the size of your app. So if you want to do some nice modular OO design, forget it. With C++, no problem. There are no size limits (aside from usable memory) and extra classes/functions are nearly free. Again, in C++ you can reuse loops and wrapper code to shrink code size, passing in a function pointer for the inner part. In Java? The extra overhead for the class you'd need to work that way cancel out the benefit.

    Garbage collectors typically used in J2ME are way behind server and client versions. And when they don't work well enough automatically, system.gc() might force a garbage collection. Maybe, if you're lucky and the manufacturer felt like implementing it.

    J2ME phones are almost universally one notch slower than the BREW equivalent. Some of the Samsung phones have poor performance under BREW, but are simple dreadful with J2ME. It's the difference between getting 4-5 frames per second and getting 1-2 seconds per frame. And if you're doing funky stuff with bitmaps that the phone has a slow implementation for, in C++ you can walk around the implementation and do it yourself. In Java, you're screwed.

    J2ME is a joke.

  86. Re:Counter arguments by EvanED · · Score: 1

    C# is just java like syntax for .NET.

    "Too much syntactic sugar leads to code cavities", but C# has a LOT of syntactic niceties that Java doesn't. (Operator Overloading being a prime example.) Some benefits go beyond mere syntax, for instance generics support in .NET 2.0 is superior to Java 5's.

  87. The problem with Java by Henry+V+.009 · · Score: 2, Insightful

    Garbage collection is nice. It does its job and it does that job well.

    But garbage collection only helps you manage one sort of resource. In C++, the RAII techniques that help you manage memory are good for every resource, from file handlers to database connections. Resource management in Java is not so nice. Often it is quite a hassle.

    Also, if you really want the benefit of garbage collection in C++, simply compile your program using something like the Boehm Garbage Collector.

    1. Re:The problem with Java by sulam · · Score: 1

      I assume you're referring to destructors, which Java has as well. However, they often aren't used because any exceptions thrown in them (in either language) have the potential to leave you in a bad state with the resource leaked anyway.

    2. Re:The problem with Java by Henry+V+.009 · · Score: 2, Insightful

      Destructors throwing exceptions? In C++ one should never allow an exception to leave a destructor. (See Item 11 of "More Effective C++" by Scott Meyers for a good discussion of this.) If there is no way to avoid doing something in a destructor that can throw, you should use a catch statement to take care of things.

    3. Re:The problem with Java by Anonymous Coward · · Score: 0

      Java has destructors now? Really? How do they work with a 'leave the object on the GC and it'll be cleaned away when memory is tight' paradigm?

      Unless you meant finalisers... those things that break the GC from running efficiently (as they have to be moved to a separate heap for cleanup next time as you cannot run code whilst the GC is compacting), and may not even be called at program termination.

      They were a bodge way back when they were introduced, I was at an IBM conference when they admitted that destructors weren't part of the language.. but they were working on a quick fix for the problem. The quick 'fix' is still with us.

    4. Re:The problem with Java by matfud · · Score: 1

      "But garbage collection only helps you manage one sort of resource. In C++, the RAII techniques that help you manage memory are good for every resource, from file handlers to database connections. Resource management in Java is not so nice. Often it is quite a hassle."

      Good point. Java is very poor at handling non memory resources. Most software asks the user to release the resources and if they don't it attempts to clear up using finalization, which in my opiniion is a truely nasty hack to get around the fact that the coder using the software forgot to clean up after himself. The GC and finalization is NOT appropriate for handling non memory resources.

      The worst case of this I have come across is Mapped Memory (you can do it in java). If you map a block of memory, then drop references to it, it will not be cleaned up until the GC decides to. This causes a problem as virtual address space is quite limited oin 32 bit systems. So if you allocate lots of memory mapped blocks it will run out of virtual address space. When its does this it will run out of address space (which it thinks is memory) and attempt to free physical memory. Humm there is negligible physical memory to free!. Hence in general the GC does not finalize the objects holding the memory mapped resources. So your program fails. (Worse than that, there is no method to manually free the underlying resources (shear bad design)).

      Its ashame there are few better ways to do it in java. (actually in many situations good design can help alot but not always)

      And yes I do like java. Its the edge conditions that piss me off. Lukily they are rarely relevent.

      matfud

    5. Re:The problem with Java by Temporal · · Score: 1

      Finalizers are not destructors! If you are using finalizers like destructors you need to stop doing that. Finalizers are totally non-deterministic. They may never actually run, or they may run long after the object stopped being used. They also kill GC performance. You should almost never use them.

  88. Re:Java Urban Performance Legends by codepunk · · Score: 0

    Might help if I spelled shit right.

    --


    Got Code?
  89. Multiple inheritance is the simple model by 2901 · · Score: 1

    Single inheritance is the one that is simple to implement. As an application programmer I want the one that is simple to use and that means not having to program around language limitations.

    1. Re:Multiple inheritance is the simple model by alan_dershowitz · · Score: 1

      Single inheritance solves the problem of inheritance ambiguity between parent classes, which in my experience has been a good thing. But yes, there have been times when it looked like I was going to be repeating a lot of code, because I needed a little of class X and a little of class y for class z. First of all, this is an indicator that you built your inheritance model wrong. However, there are circumstances where you have similar chunks of code that get used in disparate fashions in similarly related classes. I suggest checking out the builder pattern sometime, which solves this problem.

      It is my opinion that it's very easy to see many of Java's language features as weaknesses, because one looking in on the outside a) is not an advanced level Java programmer, and b) are distracted by the similarities to C++, so they only see what the language doesn't have.

      There are definitely things that Java doesn't have that it's the weaker for. I miss closures and other features of dynamic languages constantly. So do a lot of other people too, because you see hacks for it like reflection and bytecode injection. When I was at the last JavaONE convention, they claimed that they were developing dynamic language extensions for version 6. However, I don't miss multiple inheritance too much.

      Gosling has talked about adding multiple inheritance to Java before, but I don't know if that was serious or just musing.

    2. Re:Multiple inheritance is the simple model by bnenning · · Score: 1

      There are definitely things that Java doesn't have that it's the weaker for. I miss closures and other features of dynamic languages constantly.

      Me too. Check out Groovy.

      --
      How to solve most of our problems: 1.Lots of nuclear plants. 2.Cure aging.
  90. sw engineering state of affairs by m1tch57 · · Score: 0, Redundant

    all the energy released by a an article that is conceptually flawed... it is supposed to be an engineering discipline. engineering disciplines are about using the mathematical models to make appropriate decisions trading off different abilities to get the best "fit" for the desired result. verticle and horizontal understanding of technologies, their uses, strengths, weaknesses, & costs can be a complicated. as shown by the replys to this article. too bad such energy isn't funnelled into create better usable models about how to make technology choices for the job at hand...

  91. Custom mallocs by Mybrid · · Score: 4, Insightful
    It is interesting that the benchmark was done against the standard malloc when I've found that most high performance systems software implement their own malloc and other systems code based upon workload characteristics.

    Which is the point.

    Systems programmers write systems code. There is no one size fits all. There is no silver bullet. Comparing out-of-the-box C/C++ to out-of-the-box Java is a non-starter in my opinion because I've never used out-of-the-box C/C++ for large scale performance applications. What Google did in writing custom systems software is something that cannot happen with Java and is the accepted practice for C/C++.

    Java programmers write applications in a "one-size-fits-all" performance environment. Comparing Java to C/C++ is like comparing apples to oranges.

    Serious C/C++ systems programmers write their own malloc and systems software.

    1. Re:Custom mallocs by David+Leppik · · Score: 1
      Serious C/C++ systems programmers write their own malloc and systems software. I guess I'm just a silly C/C++ programmer. :-) Seriously, though, in the last two weeks I've started on two C projects, after having worked nearly exclusively Java for the last four years:
      • A telephony application, where talking to the ISDN card is done through C, since it's the least buggy API. I'm going to use C just to bridge between the card and Java; the business logic is done in Java, so that I can reuse four years worth of code that accurately models our business.
      • An xscreensaver module I'm hacking on in my free time that maps the maze screensaver onto a rotating 3D torus.

      In both cases I'm using C not because it is the best language for the problem, but because of external constraints. I suspect that most C/C++ programmers are in this situation. Hardly anyone writes desktop applications in Java or other garbage-collected languages. And if you write command-line accessible apps for Linux, C is still the language of choice, if for no other reason than to reduce dependencies.

      In fact, I'd wager that 99% of Linux applictions on any of the major distros are written in C or C++ but don't use custom malloc implementations.

    2. Re:Custom mallocs by Mybrid · · Score: 1
      In fact, I'd wager that 99% of Linux applictions on any of the major distros are written in C or C++ but don't use custom malloc implementations.

      Well, I actually don't dispute anything you say. Obviously malloc is fast enough for most people 99% of the time or someone would've fixed it by now. I personally don't work on desktop applications but server software.

      But, here is the ironic thing, in all the years I've been doing benchmarking malloc has yet to be the big problem except in really performance intensive server applications like databases.

      I think it is Amdahls law which states optimizing 50% of 1% of your peformance problem is not optimizing 50%, but 0.5%. I find disk IO is far more the frequent performance problem than machine memory.

      My claim is that in those instances where malloc actually is a known bottleneck in C/C++, like a database server, then it is time to roll your own.

      Try rolling your own memory allocation routine in Java. Can't be done.

  92. Re:Counter arguments by Anonymous Coward · · Score: 0

    I'm not a developer, but I will choose a natively compiled program over a java program every time. I want my computer to respond as fast as possible every time and there is no comparison.

  93. Re:Maybe, there is a bit more to it, then just mem by bladesjester · · Score: 1

    //My response to the Java bashers
    benderResponse.bite(ass, shiny, metal); //thank you and have a nice day

    --
    Everything I need to know I learned by killing smart people and eating their brains.
  94. Re:Java Urban Performance Legends by kingkade · · Score: 1

    Might also help if you kept your banal, "me too!" comments from contributing to the low signal-to-noise ratio. Say someting useful instead of trying to impress some anonymous strangers or making yourself feel better by receiving a "Funny" mod.

  95. How can you argue for C# and not VB.Net by jbplou · · Score: 1

    VB.Net complies to the same code has C# if you turn on remove overflow checking and options strick. So how can you lump VB into a differenct category than C#?

    1. Re:How can you argue for C# and not VB.Net by Brannoch · · Score: 1

      He was arguing against VB, not VB.Net. They are quite different languages, particularly in implementaion.

    2. Re:How can you argue for C# and not VB.Net by jbplou · · Score: 1

      So he was arguing against a language that is no longer in production by it vendor. VB 6 came out when 1999 maybe. Current VB is VB.Net go to Microsofts site go to Visual Basic and you will see it is about VB.Net which is the current Visual Basic.

  96. Re:Counter arguments by CyricZ · · Score: 1

    You do realize that a checkers game written in Java running on a J2ME-enabled cell phone doesn't compare to any significant client application, correct?

    Don't forget that John Carmack published an article discussing his dislike of J2ME.

    --
    Cyric Zndovzny at your service.
  97. Desert Topping or Floor Wax? by Anonymous Coward · · Score: 0

    I thought Java was our savior, to lead us against the scourge that is Microsoft. Ha! Let's replace one bloated and buggy piece of software with one equally bloated and albeit less buggy piece of software. Slow, slow, slow. It started off as any day now you'll see Java take off to It's not your father's Java anymore. It still sucks. It's way too complicated. I'd use it before C# or VB or .NET anyday. I was far more productive with PHP and MySQL in a few days than I was with Java. Of course, I already knew Perl. Python looks even more promising. C++ has a steep learning curve too, but it's a real language and worth the effort. Java, is it a desert topping or a floor wax? It's both!

    Fuck Java. I've said it before and I'll say it again. Java is only good for keeping programmers employed at companies who bought into the Java hype. And who are loathe to admit they already spent too much money. It could be worse though. They could be using Oracle, a great system, that is too complicated to make effective use of.

  98. Java: A Political Language by Anonymous Coward · · Score: 0

    I've come to terms now with Java's place in the annals of programming.

    It's a political language. It's a language you learn to get a job.

    It does not appear to be a language you should write any commercial applications in.

    I'm going to get hated for this but that's how I feel. I've never seen a Java app that wasn't really bloated and slow.

    Puzzle Pirates is a prime example. If that application had been written in something like C/C++, it would run a hundred times faster. It's dog slow and laggy no matter what system you have. I just built a new PC with the fastest processor, best graphics card, hooked up on a full T1 to the net with no other traffic on the pipe and still YPP runs like a dog.

    I have yet to see any impressive commercial Java application. I'm sure there are some out there, but on the average, this language seems to me, to be a system you embrace because you're required to, for one reason or another; not because it's the best choice for any given application beyond some embedded web page eye candy.

  99. Allocating all my RAM is fast, but it's not nice. by Vorlath · · Score: 1

    Since when has allocating all my RAM in exchange for speed ever been a way to break a "myth"?

    Ask anyone who's used a Java app. If you leave it open for a while, it'll take quite a long time to get it to continue because it uses so much RAM that it has to be flushed out to disk for me to use anything else. A "paper" cannot dispell personal experience.

    Java has been hit hard about its slowness for a very long time. We all know about the tradeoff between memory and speed. And now Java goes to one extreme and tries to pass it off as if it's just as fast (and in some [nut]cases) even faster than C or C++. Sorry, but I'm not that stupid. I'd rather believe in conspiracy theories than believe the nonsense that Java is faster than C/C++.

    Garbage collection is probably the single best cause of producing below par programmers. Some programmers think that because Java has a garbage collector that you don't need to deallocate your objects. This is really scary on many levels. Also, some people even go so far as to say because you don't have to worry about it (which is again false BTW), your software will run faster. I'm simply incredulous. It's like saying I don't have to worry about the amount of fuel in a car race.

    Going with the analogy, Java runs fine on its first tank, but as soon as it gets low, it needs a fuel tanker. With C/C++, sometimes it may seem like it's taking slightly longer fueling up than it should, but that's because it's environmentally friendly and only consumes what it needs. Java uses a one-stop pit strategy where they steal fuel from the other teams and throws shrapnel in front of other cars. C++ is a well oiled machine that uses proper pit strategy and will still be around long after the other cars have been disqualified (killed and uninstalled).

    I'll take C/C++ (Formula 1) or any other compiled language anyday over the ramhog that is Java (SUV).

  100. Re:Counter arguments by Anonymous Coward · · Score: 0

    If you had not noticed most mobile phones are pretty crap at obaying any kind of standards not just J2ME. The company I work for spends a huge amount of time and resources trying to get stuff to look the same on all devices. In fact the software to do that is our major product (again nothing to do with downloadable code (or java)). Just trying to handle the half arsed way in which mobile devices try to render WAP/HTML/CSS (and more importantly knowing which devices can handle which protocols) is more then enough. Let alone expecting them to write BREW (or java ofr that matter) apis well.

    If you think that manufacturers will put much effort into properly supporting ANY standards then you are deluding yourself.

  101. Re:Counter arguments by Bloater · · Score: 1

    > C# has a LOT of syntactic niceties that Java doesn't

    The "override", and "new" keywords for methods are really nice. plus the "in" and "out" modifiers for method arguments too. Then there's the "using" compound statements.

    C# the language really *is* better than Java. And I hate Microsoft as much as anybody else but then Nemerle is better than C# so I don't feel too bad about it ;)

  102. Why it's slow: General Purpose=Glacial Performance by Maxmin · · Score: 1

    In my experience, Java's slowness issues stem not from the bytecode JVM, but rather J2SE's class libraries, and generally the object-oriented approach to solving problems.

    Now, before you attack that, I'm heavy into design patterns and all the rest. No problem there, but consider this: how many times does an original piece of data get touched, copied or transformed in a Java app?

    Case in point, parsing HTML or XML documents. Under the J2SE scheme of things, even a tiny XML document can result in hundreds if not thousands of objects being created, even if you're after just one piece of info in that document. That results from the *lazy* use of Java's built-in parsers, which are inefficient due to their abstract nature.

    You have to carefully monitor where your data goes, and what gets done with it, in a Java application that makes heavy use of J2SE's classes. They're entirely general purpose, which is great when you need to slam out some code. But if you're at all interested in performance, you're screwed, because general purpose = glacial performance.

    When I can, code state machine parsers for problems like this, and look for other ways to avoid the heavily abstracted code that can result in data duplication and slow performance. JVMs today are quick, and code written from fundamentals of minimal work can achieve maximal performance.

    --
    O lord, bless this thy holy hand grenade, that with it thou mayest blow thine enemies to tiny bits, in thy mercy.
  103. Broken microbenchmarks by sjasja · · Score: 1

    The Shootout Benchmarks are short-running microbenchmarks. Just-in-time compiled environments (e.g. Java and .NET) have a startup time that is as high as 100-200 milliseconds. You can imagine what that looks like in an Ackermann benchmark whose total runtime is 120 milliseconds. A 100-millisecond startup time matters less in real applications.

    I converted the Ackermann and binary trees benchmarks from that site to run in a loop (to get JIT compilation happening). Java became faster than gcc. YMMV.

    1. Re:Broken microbenchmarks by bani · · Score: 1

      so basically you had to write your code in a special way to get around the shortcomings of java's performance. this is not reassuring.

  104. Re:Counter arguments by Raven15 · · Score: 1
    The java vm startup time is a problem for client apps


    My company ships a desktop application with its own stripped down JVM, and the start time is very competitive with C/C++ programs. You double click the icon, the splash screen pops right up. We even had to add a sleep timer in there so that it would be guaranteed to stay up long enough for the user to see it. If we didn't do that, it would disappear within one second, which is all the time it takes to initialize all of the SWT interface stuff.

    We also have a guy on another project that's working in C++, and he's constantly behind the schedule curve. Obviously one data point doesn't make a good case study, but I guarantee it's easier to go fix a NullPointerException that tells me its location than what he has to do to track down some obscure pointer bug.
  105. Re:Counter arguments by whereiswaldo · · Score: 1

    Java and C/C++ are platform independent languages. Delphi is Windows only and owned by a company with a very questionable future (forget about Kylix). C# is basically Windows only as well.
    As far as productivity, it depends what you're doing. Java UI's take longer to implement (that might not even be true for SWT interfaces) but the core language of Java is very fast to write code in. Regarding startup time, Java can take longer but these days you have the option of specifying what role your app will be playing: a long running server app or a desktop application. The latter is designed to start up faster.
    And finally, no language is a silver bullet. You need to factor in a lot of things when choosing your programming language.

  106. Re:Counter arguments by marcovje · · Score: 2, Informative


    > Delphi is Windows only and owned by a company with a very questionable future (forget about Kylix). C# is > basically Windows only as well.

    The Borland implementation of Delphi is, but others aren't:

    http://lazarus.freepascal.org/

  107. Re:Counter arguments by TheSunborn · · Score: 1

    We need to do something similary.
    Do you have any documentation on how you stripped it down?

    And how about the legal problems? The license for the jre say that you are not allowed to remove ANY part of the jre, except thoose mentioned in a very short list. -(

  108. Pick the right tool for the right job by ShipIt · · Score: 1

    There's nothing that turns me off more than the one-size-fits-all zealotry that often comes from the Java camp. One size does not fit all. It never has, and it never will.

    Programming languages are tools. Pick the appropriate tool for the specific job. More specifically, understand the capabilities and deficiencies of a wide range of languages and map those appropriately to the specific problem domain you've been asked to tackle.

    Examples:

    *) Production quality, single-user, cross-platform application: Java is at the top of my list.

    *) Production quality network service with deterministic behavior under load and soft-to-firm response-time requirements: Hard to beat C w/ Linux here.

    *) Quick and dirty lab-only tool to thrash through some test results: Yep, it's Perl.

    Engineering is all about trade-offs. Understanding your problem and the tools you have to solve it with are critical. Making a poor choice, especially early on, can be disastrous. Even though I don't discount the performance enhancements Java has enjoyed over the years, I'd be very hard-pressed to select a virtual-machine based language/system for any performance critical application requiring a deterministic response.

    Pounding a square peg into a round hole by insisting on one language for everything doesn't demonstrate a lot of design-maturity or sophistication on the part of those making such claims.

    I've worked this into my interview questions for new hires as well and have found it to be a pretty good indicator of who I'm dealing with, experience-wise. (hint: the guy who insisted on smalltalk for everything did not get the job)

    1. Re:Pick the right tool for the right job by Anonymous Coward · · Score: 0

      *) Production quality network service with deterministic behavior under load and soft-to-firm response-time requirements: Hard to beat C w/ Linux here.

      You sure are inconsistent. One second you oppose "one-size-fits-all zealotry" and the next you claim that the best solution for the above example is C. Give me a break. You've said nothing meaningful about what the network service actually does, but you're sure that C is most likely the best choice.

      There are a host of reasons why C makes a poor choice for any network service. The high rate of security problems caused by incompentent developers nears the top of that list. To ignore that and recommend C anyway demonstrates a lack of real-world experience or very poor judgement.

    2. Re:Pick the right tool for the right job by ShipIt · · Score: 1

      You sure are inconsistent. One second you oppose "one-size-fits-all zealotry" and the next you claim that the best solution for the above example is C. Give me a break. You've said nothing meaningful about what the network service actually does, but you're sure that C is most likely the best choice.

      I believe you may have missed my point with the examples. I presented three separate problem domains and recommended three separate languages that might be appropriate given the very high-level descriptions I provided [I didn't mean to imply C/Java/Perl were the only choices]. One point of the examples is to show that "one-size-fits-all" for all three, in their totality, is likely sub-optimal. This most certainly is consistent with my point.

      There are a host of reasons why C makes a poor choice for any network service. The high rate of security problems caused by incompentent developers nears the top of that list. To ignore that and recommend C anyway demonstrates a lack of real-world experience or very poor judgement.

      Other languages do not have incompetent programmers or are excluded from security problems? Who's lacking real-world experience and demonstrating poor judgement here?

      I think programmer competency is a bit of a red-herring since it could effect any project, regardless of language or problem domain. My point remains: pick the right tool for the right job. As a corollary, picking the right people (ie competent) for the job is equally as important.

  109. Syntax errors in this!! by Anonymous Coward · · Score: 0

    Hold on a moment, there are a lot of errors here!!

    It's Java, it should be:
    System.all.group.second.half.of.coders.grab(stone) ;

  110. Re:Counter arguments by Anonymous Coward · · Score: 0

    "Delphi...owned by a company with a very questionable future"

    I first heard doubts about Borland's future in 1984. Even then it was a commonly held belief. Well, you just keep repeating it. Since nothing lasts forever, you are bound to be correct one day.

  111. Give it up already by shaitand · · Score: 1

    All anyone has to do to determine java is slow is run a practical application written in java. You can give examples and hypothesis and benchmarks all day long. It still won't change the fact that I can put a java app on joe blows desktop and will get a, "Damn this is slow." comment with all but the most trivial apps, each and every time.

    1. Re:Give it up already by Anonymous Coward · · Score: 0

      You mean like Azureus?
      Jackass.

    2. Re:Give it up already by shaitand · · Score: 1

      yup, exactly. Great app in terms of function and usability... or it would be if it weren't written in java. No torrent app should EVER use a significant cpu load, but the windows version of Azureus will sit at 30-99% cpu at all times.

    3. Re:Give it up already by 6*7 · · Score: 1

      Well a torrent app should use atleast a bunch of cpu wil doing checksums. And Azureus does checksum a lot compared to the reference bittorrent client.

      It also is the biggest resource hog on my "file server", about half the memory (+- 300Mb) and 15-35% cpu (on a 500Mhz P3 (going 100% when doing a full checksum on completion)). All this with about 25 torrents running which amount to something like 5Mbps of traffic. And having a somewhat decent UI.

      To bad there apprears to be a memory leak somewhere, leaving a JVM running with Azureus for 40+ days got the machine in trouble with 1.5.0_02 (swapping), 1.5.0_04 _seems_ to do a better job.

  112. Java designed for humans, not performance. by Mybrid · · Score: 1
    Java programmers design code to comply with object models and software engineering design standards so as to optimize human development and maintenance time. The money question is does the human time savings in writing code in a homogeneous environment unduly sacrifice too much computer performance? Java as a homogeneous language can never compete with a versital, swiss army knife party animal like C. C was designed to allow unfettered access to anything and everything with imposing minimal software engineering restrictions. Java imposes infinitely more software engineering restrictions and constraints to optimize human time whem compared to C. Things like array bounds checking means more work means more time which means Java will always be slower than C.

    Java, as Larry Wall stated, is one of those "stay-at-home" competitive language that works best in a pure environment. As opposed to say Perl which is a regular party animal and plays well with everything. Although, I have to say, I've never had the occasion to invoke Java from Perl.

    Java programmers design code to object oriented methodology and do not design primarily for performance. Java is not a systems programming language. Java is a software engineering language designed to optimize human time and not computer time.

    From the Social Engineering chapter in the Perl camel book reference guide:

    Languages have different personalities. You can classify computer languages by how introverted or extroverted they are; for instance, Icon and Lisp are stay-at-home languages, while Tcl and the various shells are party animals. Self-sufficient languages prefer to compete with other languages, while social languages prefer to cooperate with other languages. As usual, Perl tries to do both.

    So this chapter is about relationships. Until now we've looked inward at the competitive nature of Perl, but now we need to look outward and see the cooperative nature of Perl. If we really mean what we say about Perl being a glue language, then we can't just talk about glue; we have to talk about the various kinds of things you can glue together. A glob of glue by itself isn't very interesting.

    Perl doesn't just glue together other computer languages. It also glues together command line interpreters, operating systems, processes, machines, devices, networks, databases, institutions, cultures, Web pages, GUIs, peers, servers, and clients, not to mention people like system administrators, users, and of course, hackers, both naughty and nice. In fact, Perl is rather competitive about being cooperative.

    If one is going to start a project with performance as the top priority, one would not design it in Java because most assuredly one is not going to have the luxury of a homogeneous environment but will need to play well with others using a language like C/C++. Case in point are databases. Java's interface to MySQL is still slower than C/C++ or Perl.

    The question is how best to balance human performance time with the software engineering design philosophies that optimize human time in languages like Java with that of computer performance time and systems that lie out side of the Java native spectrum and defeat the "stay-at-home" homogeneous design requirement of not playing with other languages like C/C++, COBOL, etc.

    If a performance project requires heavy integration and interaction with multiple systems outside of Java one would not choose Java, but one could choose C/C++.

  113. I hate Java. by JPriest · · Score: 1, Interesting
    Throw all the white papers you want at the argument. All the java software I use is still slow so I am going to continue to hate it.

    Also one more point I would like to make: The point of Java is write once run anywhere. Sure in theory I can use the same application on multiple operating systems. The problem is that many of them have specific version requirements for the JVM I am using. Even with 2 or 3 Java applications on my PC there is a trial and error process of trying to find a JVM that all 2 or 3 applications can run on.

    So I can write _one_ application and run it anywhere, as long as noby elses Java application using a seperate JVM version is already there.

    --
    Saying Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders.
    1. Re:I hate Java. by Doctor+Memory · · Score: 1

      I haven't run into a problem, as long as I have a fairly recent JVM. I ran into a problem just yesterday where I only had a v1.4.1 JVM, and I wanted to run Tomcat 5.5.12, which requres Java 1.5. So I installed 1.5.0_05 and everything's just fine. All my old apps continue to work, and Tomcat is happy.

      I suppose there could be a problem if you're using some old pre-Java2 code, but there was not a lot of that to begin with, so it's not been an issue that I've run in to.

      --
      Just junk food for thought...
  114. Re:Counter arguments by Anonymous Coward · · Score: 0

    "You double click the icon, the splash screen pops right up. We even had to add a sleep timer in there"

    Ah yes, greatly optimise and then throw it all away just so you can remind the user can catch a glance at that big shiney (but expensive) version number...hey! that number could be a bit higher couldn't it?

    Is there an option in your app to disable the splash screen?

  115. Re:Counter arguments by aaronl · · Score: 4, Insightful

    See, that right there is a huge chunk of the whole problem. If programmers weren't being lazy and arrogant jerks and assuming that nobody cares about how poorly designed and coded their algorithms are, or how blatently horrible their memory usage is, we would have a lot fewer problems.

    I don't care that Java will get there at some point, or that it's better now. I care about whether it actually works right, and right now it does not. It does have too long a startup, most of the UI toolkits are horribly slow, it does not follow native platform UI conventions, and it is just not as nice to use a Java app as it is an equally well written native app. It does take far too memory, especially compared to other languages. Even the cross-platform nature of the code is largely a lie. Different JREs don't support the same things, and many platforms lack a JRE. There are massive differences between the various editions of Java so as to make it useless to try to write something across them. Your Java app written against "Vendor X Version Y Edition Z JRE" should work fine on any other platform with the same version of "Vendor X Version Y Edition Z JRE". That's all you can safely say without a good amount more testing.

    However, most of all, my CPU time and RAM might be cheap, but they are abused every time I use an application written in that mindset. I have memory needlessly abused, and CPU time needlessly wasted every time I run some poorly coded program. That means that I lose time and productivity every time I run your poorly written app. That attitude pisses me off, why we should all squander our system resources so that a few lazy programmers can write some app a little faster and with less effort, rather than doing their job right.

    Programmer cycles are a lot cheaper than making thousands of people upgrade their hardware. I imagine those programmer cycles are a few orders of magnitude cheaper.

  116. Let's be realistic by localman · · Score: 1

    Java is fast enough for most tasks, and the GC is a wonderful convenience.

    But let's not go overboard. I started writing a 2D vector game in Java a couple years back that included rudimentary physics. I tried the Windows, Linux, and Apple JVM's at the time, and as things got more complicated I ran into a lot of performance problems, namely, a notable split second lag every couple seconds where the GC would kick in and lock everything. After trying every trick I could find, I converted to C++ and got an immediate huge performance boost -- well over 10x -- without any further optimization.

    I'm sure JVM's have come a long way, but I just fired it up under the latest Apple JVM (I'm sure folks will tell me that's the worst one...) and the performance was still notably less than the C++ version.

    I'm not trying to put Java down, here, but let's not make pretend it's super fast. It's not. Neither is perl, my day-to-day language of choice. But that's okay because different languages have their place. C++ is fast. And frankly, when I did the Java to C++ conversion, the code didn't even look much different.

    Enjoy whatever you use...

  117. I spend a lot of time with Quantify by mi · · Score: 1
    ... profiling a huge C program.

    And I've never seen malloc/calloc/free anywhere among the top time-consuming functions...

    Maybe, Java's allocation/deallocation is even faster, of course.

    --
    In Soviet Washington the swamp drains you.
    1. Re:I spend a lot of time with Quantify by Anonymous Coward · · Score: 0

      object creation is, traditionally, the most time-consuming operation. However.. in C++ objects are usually created on the stack (and so super fast), and even malloc creation (using new - most libs implement one on top of the other) doesn't take that much time.

      I think the issue with C++ is most real-world apps don't create objects all over the damn place (unlike Java), so you won't see much performance problems from the relatively few that are created.

      Compare with Java where just working with an int takes so much time creating temporary objects to store and manipulate it.

  118. BAH. by Wolfier · · Score: 1

    Until a JVM implemented in pure Java works as well as a JVM implemented in C/C++ (like all of today's JVMs), Java's still slow.

    They got the concept right. The implementation is crap.

    1. Re:BAH. by the+eric+conspiracy · · Score: 1

      Until a JVM implemented in pure Java

      Unless you have CPUs that handle Java byte codes natively this sort of implementation is going to be very unlikely.

    2. Re:BAH. by salimma · · Score: 1

      RIP, MAJC .. oh, if only.

      --
      Michel
      Fedora Project Contribut
  119. inherently slow? only partly. by markhahn · · Score: 1

    it's not that GC is slow, it's that the comparison is invalid. malloc libraries are designed to minimize or at least keep low the amount of wasted space. GC trades off extra space for the performance of contiguous arena allocation. malloc could do that too, and its fast path would be identical. the slow path matters, too. further, a GC language necessarily trades off contiguous allocation vs some sort of indirection or pointer-editing. that is, GC has to be able to move memory objects, so the simplest (historic, inefficient, naive) implementation is to always just indirect through an object table. that extra memory reference is much more important than shaving off a few cycles of the allocation fast-path, since the cost is taken on every reference.

  120. Re:Counter arguments by DrXym · · Score: 2, Interesting
    C# or rather the CLR, is of comparable speed to Java. I use both day to day and don't perceive any difference between the two EXCEPT as far as UI performance goes. Windows.Forms is a lot faster than Swing, though probably no faster than SWT. This is due to it using native controls, and having no layout models to speak of. In fact Swing probably has no small part to play in the perceived speed of Java.

    Startup of Java seems a little slower than CLR but not markedly slower. Mono's startup is hardly a speed demon either. In all, I think most of the hype around the CLR is just that - hype. The CLR is a lot nicer virtual machine, and C# is as close to C++ / Java that I couldn't care which language I'm writing to, but the performance differences are IMHO neglible.

    As an example of how fast Java is, I have written a poker simulator which plays 1000 games from a deck of cards which is shuffled 1000 times for each game. The hands from each game are then sorted, and scored. It's very Vector and LinkedList intensive and each loop probably sees a dozen or so temporary Vectors or arrays used during comparison - i.e. 1,000,000 iterations with many more nested within. It takes just over a second on my 1.8 Ghz PC.

    As far as I'm concerned, that's plenty fast. I reckon I could probably halve the time if I bothered to replace all the vectors with fixed arrays.

    It would be hard to compare Delphi (as in traditional Delphi) to either C# or Java since it is a compiled language. I don't know what Borland are doing with it these days so I wouldn't be surprised if it's gone the CLR route too.

  121. Garbage Collection: not just for C by OpenGLFan · · Score: 1

    Gah. If you use C (or better, C++), and you like it, and you like garbage collection, why not just use a garbage collection in C? I haven't written anything particularly huge lately, but the Boehm-Demers-Weiser one seems pretty solid. It's the best of all worlds -- you let the garbage collector handle most of your memory recollection. Remember the 90-10 rule ("90% of execution time is spent in 10% of the code"), so if there's a chunk that really needs manual allocation you can do that too. And the performance? Wonderful! Bump-pointer allocation means new objects get there fast.

    There's no such thing as a wart-free language, but in C++, lack of garbage collection isn't one anymore.

    1. Re:Garbage Collection: not just for C by aled · · Score: 1

      It have been around many years and may be usefull, but the thought of a GC library in a language that don't know about GC and allows pointer manipulation gives me shudders.

      --

      "I think this line is mostly filler"
  122. Re:Counter arguments by Anonymous Coward · · Score: 0

    When processor cycles are expensive you use something fast in execution, like C.
    When programmer cycles are expensive you use something fast to write in, like Python.
    When brain cycles are expensive you use something an idiot would choose, like Java.

  123. Malloc is a function by Anonymous Coward · · Score: 0

    malloc is a function, and when you call functions the stack is used to pass parameters, so no matter how clever you write your heap allocator it is always at least 2 stack frame allocation more work than a stack frame allocation!

    (1 to allocate a heap block, 1 to free a heap block).
    And that ignores the heap searching algo overhead.

    Your stack allocations are totally free, because they are allocated when your function is called.

    1. Re:Malloc is a function by Anonymous Coward · · Score: 0

      malloc is a function, and when you call functions the stack is used to pass parameters
      Not if it's inlined.
      In a modern JVM, allocations on hot paths are inlined. So, dynamically, almost all allocations are performed without a function call.
      (I'm a different Mr. Coward)

  124. Re:Counter arguments by Anonymous Coward · · Score: 0

    Or, if you are doing web apps, use Ruby on Rails. You'll never look back.

  125. Re:Counter arguments by ctzan · · Score: 0, Flamebait
    While I'm sure you can point to a Java program which takes 5 minutes to start, these are the exception in the Java world, not the rule.
    Yes. here Java programs take only 3 minutes to start.
  126. What Language is the JVM coded in again? by Secret+Rabbit · · Score: 1

    I find it rather amusing that these "studies" claim the JVM to be more efficient that C/C++ when the language that the JVM is coded in is C/C++ (or a like language).

    Bloody rediculous.

    The only way that they are going to get favourable numbers is by cooking them... big surprise.

    1. Re:What Language is the JVM coded in again? by feijai · · Score: 0
      Bloody rediculous
      The state of British spelling these days...
  127. Re:Java Urban Performance Legends by Anonymous Coward · · Score: 0

    irony.

  128. They're wrong by Anonymous Coward · · Score: 0

    Garbage collection will never be as efficient as direct memory management.

  129. C and C++ by vlad_petric · · Score: 1

    Slightly OT, but why do people put C and C++ in the same performance class ? The performance difference between the two is quite significant, especially if you use gcc/g++. I once try to port a big project from C into C++, without actually converting the code into classes (not a big deal, since the incompatibilities were really small). At some point I had the code compile under both gcc and g++. Interestingly enough, with g++ the code was about 30% slower.

    --

    The Raven

    1. Re:C and C++ by Anonymous+Brave+Guy · · Score: 1
      Slightly OT, but why do people put C and C++ in the same performance class ?

      It probably is OT, but for general interest: because they are.

      The evolution of C++ has followed the "zero overhead principle" pretty strictly, which basically means that if you don't use a feature, you shouldn't pay for it, and if you do, it should be at least as good as getting the same result "by hand".

      For a while, C had an advantage because it was simpler to optimise and compilers had a few years' head start. That is rarely the case today. GCC sucks for performance, BTW -- it's portable, but not fast -- so forget using that as any kind of benchmarking tool.

      These days, C++ should actually be faster than analogous C code for some things, mainly because templates allow more effective inlining and more aggressive optimisation (C's qsort vs. C++'s std::sort being the typical example) and because C++'s higher level tools allow the programmer to represent more of their design intent in the code, which in turn provides more information for the optimiser to take into consideration.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  130. Other slowness -- slow to load by Latent+Heat · · Score: 1

    There is a whole 'nother source of Java slowness -- the JVM startup and loading the classes used by your app. It is not just that some Java apps are slow, they take forever to get going.

    1. Re:Other slowness -- slow to load by Maxmin · · Score: 1

      True, true. I mostly develop java for server-based apps, the kind that run for months on end. The startup penalty's not felt there. For desktop apps, having to download a 50MB JRE is pretty much out of the question, when it comes to online distribution. This probably has a lot to do with why Java isn't a favorite language among desktop shareware or utility authors. I look forward to GCJ and other native compilers making Java apps a teeny bit smaller for users to download.

      --
      O lord, bless this thy holy hand grenade, that with it thou mayest blow thine enemies to tiny bits, in thy mercy.
  131. Signal processing by tepples · · Score: 1

    Similarly, why should we risk forgetting to deallocate stuff from the heap, when we can have the computer do it itself?

    Because you don't want to risk falling behind on the incoming and outgoing signals. A lot of the applications of embedded devices and handheld devices are signal-processing applications, and they must run in some semblance of real time. Even video games are soft-real-time signal processing applications that turn signals from the controller into video and audio signals. When you need to maintain a (hard or soft) latency guarantee between the input and output signals, you have to design for the worst case, not the average case. Taking a break to GC the heap is often not an option. Or has incremental collection on the heap become as fast as malloc/free?

    1. Re:Signal processing by maraist · · Score: 1

      Or has incremental collection on the heap become as fast as malloc/free?

      Sun's JVM is rather nice w/ incremental collections (called low-latency GC). It definitely has an overall performance penalty w.r.t. the stop-the-world copying-collector, but if you have multiple CPU's then the bulk of the work can occur in parallel, with only a small portion actually stopping the world.

      Even if you don't have parallel CPU's if you can properly schedule the GC thread to run only when the CPU load is low (or memory is getting full), it can take advantage of pauses in work-load.

      Theoretically you have to spend 5 30% of your time in memory management no matter what architecture you use. Thus you need that overhead in CPU performance anyway.. Thus a background GC running on a single CPU should still not degrade performance below the performance requirement of the application. It's just a minor added cost when there's no second CPU to offload work to.

      That being said, you never GC until you've used up your free-allocation stack in Java.. Thus if you are worried about real-time, then it's entirely like that your main work-flow will not be allocating and deallocating large amounts of material mid work-flow. Instead of constructing a new StringBuffer, you can reuse a thread-local StringBuffer and call sb.setSize(0) or some such thing.. I've seen this done in JDBC drivers. I rarely see GC times in excess of 0.01 seconds (except when the entire system is heavily loaded and normal response time already exceeds a second).

      Granted, you have no control over how 3'rd party libraries (including the standard SUN libraries) handle memory allocation; though I'm sure J2ME is more sensitive to overt allocation.

      --
      -Michael
  132. Re:Counter arguments by Anonymous+Brave+Guy · · Score: 2, Interesting
    In all languages I know of, you get some library functions ready-made, and you need to code some stuff yourself.

    Most performance problems occur in the code you made yourself.

    Unless, like me, you're the guy who's writing that library that everyone else depends on, in which case the two are the same thing for practical purposes. In that case, trust me, you still use something like C or C++.

    Here are a few reasons why:

    • C(++) has value types. What TFA describes as if it's some sort of clever optimisation -- the detection of objects that can only be accessed within a single stack frame and can therefore be reduced to stack or register storage -- is the default in C(++).
    • Java uses "portable" floating point rules, which theoretically means 100% consistent results on all platforms (definitely a plus, unless you write naive floating point code like the example distance function in TFA and waste all the benefits anyway) but also unfortunately means that instructions often implemented as fast operations on a processor have to be effectively recoded by hand because those fast operations aren't precisely specified to match the Java spec.
    • No-one really uses malloc and free on a large scale in fast code. In fact, we strain to avoid using the C++ analogues, new and delete, and make extensive use of data structures and memory allocation algorithms we control ourselves to facilitate this. Java's performance is always going to be bounded relative to C++'s here, because I can always write an equivalent GC in the worst case, and usually I can do better. (There is a fair argument that most programmers will get this for free in Java, and will not invest the time and effort to produce equivalent code in C(++), but remember that I'm talking from the perspective of the guys who do, because we write the libraries everyone else uses.)

    Any of those in isolation is game, set and match against the arguments in the article. Put together, you get the same picture most of us have painted all along: Java's performance is adequate for non-critical tasks, but it's nowhere near the top of the pile when it really matters.

    BTW, in case anyone's wondering: yes, I do work on widely-used, performance-sensitive mathematical library for a living, and yes, as it happens I really have spent the last few weeks researching ways to increase the performance of that library even further.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  133. eclipse is not slow by Baki · · Score: 1

    I don't know about netbeans, but I use eclipse (3.0 and 3.1) more than 8 hours a day and it is not slow. I have 1GB of RAM, but next to eclipse I'm running a weblogic (development) instance and lots of other normal office programs, and eclipse works very fast. It is really amazingly fast for such a complex GUI program. It has a very complex with lots of tabs, menus, browsing trees everywhere on the screen, all kept up to date in real time.

    Please, give it a serious try since your experience, the non-trivial last of which must be at least several years old. Slowness of Java is really a myth. It is very very irritating to see that myth kept alive by people repeating each other (and of course MSFT) for the last years without being open to review.

  134. Dont take Swing GUI apps as an example by steve_l · · Score: 1

    Yes, any Java GUI app written in swing crawls unless it has a lot of memory and a good CPU behind it. But that is because swing sucks, not Java itself.

    Or, to put it differently, "having sucky java apps is optional". Computation and networking can be pretty nippy. Because threading is easier, you can also make use of multi-core systems quite easily.

    What you cannot do in Java is go low-level when you need to issue cache prefetch opcodes, or directly address the SS2 parallel register set (Java1.4+ hands off all floating point operations to the SS2 registers/opcodes, but doesnt SIMD parallel ops).

    At the same time, how often is top-tier performance really needed. For many programs, time to market with stable apps matters more. This is potentially Java's big weakness: successor languages (e.g. Ruby) that offer even better productivity, without making performance tangibly worse.

  135. CPU intensive code in Java by magoghm · · Score: 1

    You can write high performance, CPU intensive code in Java. If you don't believe me just download jrMan and try it. If you want to compare with a C++ implementation you can download Aqsis which implements the same algorithm to render images.

  136. Re:Counter arguments by IamTheRealMike · · Score: 1
    It's not entirely a joke, but I'd agree with the majority of comments expressed above. I recently started doing some mobile phone programming, and come to the conclusion that Java on mobiles has only one redeeming: namely the type safety/code access security system. The rest is junk.

    Not only are the J2ME specs incredibly loose and full of optional material, but nearly every phone has bugs in their implementations. Apparently Suns engineers have never heard of "conformance tests" - even basic stuff like drawRGB to negative co-ordinates doesn't work right on most phones.

    Worse though is Java itself. The Java compiler provided by Sun is an absolute waste of space. It does virtually NO optimisation itself, relying on the JVM to do it all, which is great except the micro-edition "kvm" runtime doesn't do any optimisation either because they didn't have space to make it do more than the very basics. Worse, all the usual flaws it has are still there - an asinine insistence on treating unreachable code as a fatal error, lack of a pre-processor (which you need for mobile development as phones are so different), etc.

    Javas runtime performance is atrocious. Only the very newest phones run it anywhere near acceptable speeds if you're doing anything graphics "intensive" (like basic animation). Instead of pre-compiling the code to native at install time, which would seem to be the obvious solution, the KVM still seems to use just-in-time compilation.

    The biggest difficulty though tends to be heap fragmentation. Most phones do not use a compacting GC, with the result that it's very easy to make an app that runs fine for a few minutes then barfs because the heap has become fragmented. Java desperately needs manual memory management extensions, stack allocation or the ability to run multiple heaps but instead Sun are simply pushing a micro-edition of HotSpot - apparently waiting for the hardware to catch up so they can cover up what a useless hunk of junk Java is. It's alright for the article to talk about escape analysis - a technique that isn't actually implemented in any shipping desktop or server JVM yet, but how many years would it be until such a basic thing as allocating objects on the stack instead of the heap runs on mobile phones?

    There are only two reasons to use Java on mobile phones - the security, and the number of people who know Java. Unfortunately although there is a huge market of (cheap?) Java programmers, people who know Java but not C++ are likely to screw it up because they don't really understand what's going on underneath the hood and so don't understand how to write efficient code.

  137. Re:Counter arguments by Decaff · · Score: 1

    The java vm startup time is a problem for client apps, but server side its not a big deal.

    This is yet another urban myth about Java. I have a 1.8GHz machine. Java 1.5.0_04.

    JEdit starts up in 3 seconds.
    The jsf demo Notepad.jar starts up in 2.5 seconds.
    SwingSet2 - the full Java GUI demo starts up in 7 seconds.

    So where is the problem?

  138. Re:Counter arguments by dnoyeb · · Score: 1

    With Java you get all these optimizations, not necessarily for 'free'. They are given to you based on whose JVM you choose to use. So you stick to applicaiton code, and let the JVM writers handle the GC and memory code. Anyway you look at it _somebody_ is writing that GC and memory code; Even if you choose to program in Java, the GC/memory portions are written in C/C++ anyway. And yes, while my program has been the same since 1999, the jvm its run it has gotten better so now my program is better and I have not touched in in 5 years. Woot \o/

    The comparison is foolish. You can't compare C/C++ to java. You can however compare C/C++ to a particular implementaiton of Java such as the sun 1.4.2_09 JVM or the sun 1.5.0 JVM, etc. Anything else is apples to oranges.

  139. Re:Counter arguments by mikaelhg · · Score: 1

    Unless, like me, you're the guy who's writing that library that everyone else depends on, in which case the two are the same thing for practical purposes. In that case, trust me, you still use something like C or C++.

    Horses for courses.

    In the 1% of programming projects where this is true, it makes sense to use the right tool for the job like you're clearly doing.

    In the other 99%, requirements aren't so stringent in that direction, but might be towards, say, the cost perspective, in which case again, Java-like languages and environments are appropriate.

    There are incredible advantages in standardising on a platform such as Java, and planning forward in such a way that the organisation is able to make exceptions in cases such as yours, where it makes good business sense.

  140. Re:Counter arguments by Decaff · · Score: 1

    Or, if you are doing web apps, use Ruby on Rails. You'll never look back.

    Unless you need to make dramatic changes to your database schema. Or have to port to a different database with different SQL and column naming conventions. They you will look back a lot.

  141. Re:Counter arguments by man_of_mr_e · · Score: 1

    Delphi now compiles to .NET code, and .NET runs on Mono, which runs on several platforms. It's not Windows Only. The compiler might be, but the output isn't.

  142. Those are not the laws of optimization I learned. by Estanislao+Mart�nez · · Score: 1
    The laws of optimization that I learned are the following:
    1. Don't do it!
    2. (Advanced programmers only) Don't do it yet.
  143. Re:Counter arguments by cpeterso · · Score: 1


    J2ME JVMs are so buggy and inconsistent that JAMDAT has to create 100 different builds and packages to support different J2ME VM bugs and different screen sizes and resolutions.

  144. Re:Counter arguments by Anonymous Coward · · Score: 0
    Five minutes startup times is also a myth. Most small to medium size Java application I have start in under a minute.

    And this is supposed to be good? How about applications that you want to startup in a fraction of a second? Imagine if every time we did an ls, grep,... in Linux we had to wait up to a minute for it to start up.

    The incredible startup overhead of Java is absurd. I wrote a simple mathematical browser applet whose equivalent in C runs in perhaps 10 msec. The Java applet it takes almost a minute of disk thrashing on a 2GHz machine to initialize, which is like 5000 times slower - not 20% slower, not twice as slow, but 5000 times as slow!. Yes, once it starts its speed is reasonable, but the applet is supposed to let you instantly do an occasional calculation and be done with it.

  145. Re:Java designed for humans, not performance. by Mutatis+Mutandis · · Score: 1

    I have been using Java for a long time, for server software, server-side methods and client-side applications. In general, through not always, interacting with databases. I have also written C++ code, both for similar purposes and for hardware control.

    My experience is that in a well-written Java application, the performance of the JVM is usually not the real cause of performance bottlenecks that can be felt by the user. Design errors can make Java code slow; it may be a relatively "easy" language but the programmer still has to understand very well what he or she is doing, and seemingly unimportant choices can have serious performance impact -- just as in C++.

    Fortunately, understanding the system is much easier in Java than, in say, Visual C++ (to mention just one abomination from the deep.) I suspect that on average Java code contains fewer blunders with a serious performance impact than C++ code.

    Certainly, for the really high-speed parts of the code and for specialized purposes I too would still recommend to use C++, but for 95% of all code there is no reason not to write it in Java. And it is fairly simple to integrate C++ code in Java.

    I harbour a suspicion that programmers who insist on writing all code in C++ or even C because they think that it will be faster, are largely the same people who insist on writing labyrinthine, unstable and unmaintainable code because they think that is faster. As you may suspect, I don't have a high opinion of programmers in general: I think that in general, only a third of professional programmers can be called competent (enough) to safely handle tools such as C++. The rest should be kept in to a sandbox.

    And besides, the majority of infuriatingly slow applications that I have seen were not written in Java: More typically these are the work of naive Visual C++ and Basic programmers, the kind of people who recalculate the layout of the entire screen when they need to change the display of a variable, or copy the content of an entire database to memory on start-up.

    A caveat, however: Java performance can depend enormously on how your system is set up. For example, the way the on-access scan of McAfee antivirus handles the Java JRE and other libraries is a bloody disgrace and results in painfully and unacceptably long startup times. But that is hardly Sun's fault. (Note for the next job interview: Ask what virus scanner they use.)

    I admit that relying on garbage collection can be unnerving for the C and C++ programmer. I think I was nervous about not explictly de-allocating memory for the first two years or so; then I got used to it. (And, despite finally acquiring Java habits, I do not forget to de-allocate in C++ code. If anything, I am more accurate in it than I used to be.)

    Ironically -- and this should serve as another caveat -- the biggest memory leak I ever created was in Java, not in C++. What I had overlooked is that the GC will not get rid of memory if a reference to it has been passed to a dialog; and I had forgotten to dispose of the dialog, which (very indirectly) controlled the display of a large data set.

  146. Re:Counter arguments by laffer1 · · Score: 1

    The problem isn't application code typically, its the VM startup time people complain about. If java is already running its fast, but if you are starting a vm from scratch (server vm in particular) it takes a few minutes. As an example, it takes 35 seconds to start up tomcat on my freebsd server including VM startup (java 1.4.2 native) and loading all the webapps. I've timed it.

    Server specs are a p4 2.4ghz with 1gb ram and freebsd 5.4 release.

  147. Real world results by man_of_mr_e · · Score: 2, Interesting

    While I agree that in theory, and in labratory conditions, Java is just as fast (sometimes faster) than C/C++, in practice it doesn't usually end up that way.

    The way normal people write code, and the libraries and functions that normal people use, java is slow as snot. I don't care why that is, it just is, and it makes me steer away from Java client applications if there is something that is native or .NET available instead.

    Real world results are different from labratory ones as far as Java is concerned in my book. And that's just my experience.

  148. What does gc have to do with anything? by Some+Random+Username · · Score: 1

    Garbage collection is not a magic bullet that makes memory leaks dissapear. You can forget you have a reference to something just as easily as you can forget to free something.

    1. Re:What does gc have to do with anything? by Mnemia · · Score: 2, Insightful

      I never said it was. I was just responding to the point that GC is unsuitable for hard realtime systems (which is false). It's simply another method of heap management, and can be implemented with realtime requirements in mind. I also never said that Java or any other current garbage-collected language is actually suitable for this. I'm just saying that there is nothing theoretically preventing these features from being used in realtime systems. Likely to do that we will want languages (or new features for existing languages) with more expressive means of specifying the realtime requirements in a high level way.

      (I do think that there are significant advantages to having a GOOD GC system that a lot of people ignore. They are simply another type of abstraction, which can be a gain when you have no need to worry about memory management implementation issues. Why should we reinvent the wheel over and over again when we can have the language designer develop a very sophisticated means of handling this automatically? There are times (such as in realtime situations) where you may want to get at the lower-level details, and that's fine. But in 90% of software written, this is absolutely unnecessary and leads to tons of bugs which could be avoided by using a higher level language.)

  149. Java performance by Anonymous Coward · · Score: 0

    Let me see here: on the one hand a C program will possible run very well in a particular environment. A interperted langauage- has to do several things- including guessing your hardware, optimise itself, not crash etc etc. and lets not forgot many of these things are done while your using it. I used J Office and was impressed. It did what I could want it to. Sure it had some bugs, some more anoying than others. Just my opinion is its issues were minor compared to the offic 2k (in fairness to office it was just released of OS X). Java 1.x sucked- plain and simple- it was terrible buggy. Java 1.5 sucked less. Java 2.0 is practicly a rewrite and works. I do agree the initial run of java applications is not particularly good. (J-office took 15 minuts the get going first launch. The second launch was 10. then 5 then just a few moments.) However it seemed to be as well written-suposedly their is a multithreaded edition that's even better and sexier.

  150. Re:Counter arguments by Anonymous Coward · · Score: 0

    I can write half the code with C#.NET than to implement it similiarly in Java. Also VS makes it alot easier to write gui components than Eclipse. .NET is really nice

  151. So why are all websites running Java slow as hell? by nazzdeq · · Score: 2, Insightful

    As soon as you go to a website and seed the dreaded .jsp extension, you know you're in for a wait. All the websites that use Java are just ridiculously slow. Name one that isn't. Could you imagine Google running Java and some JVM?

  152. Ooh by Anonymous Coward · · Score: 0

    Anyone that complains about java's being a bad language-How many of you are using Limwire or Azereus?-Your using Java

  153. swing is the slow part by MindDelay · · Score: 0

    i've never noticed much difference in performance in c++ or java, except when writing gui apps and using swing with java. swing is slower than any gui toolkit you can use in c/c++, at least any i've used. but non-gui java apps never seemed slower to me, who's been saying this?

    --
    Spiral out. Keep going...
  154. Article Summary and reality by radtea · · Score: 3, Insightful

    Summary: "If JVMs were smart, garbage collection would be fast."

    Reality: "JVMs are mostly very stupid, and you can never be sure what JVM your users are going to use, so in the real world of deployed applications garbage collection performance--and Java performance generally--is a nightmare."

    I am so tired of GC advocates talking smugly about theoretical scenarios. Who cares?. When I can run a Java app on an arbitrary JVM and not have it come to a grinding halt every once in a while as the garbage collector runs--or worse yet bring the machine to a grinding halt because the garbage collector never runs--only then will GC will be useful.

    The weasel-words in the article are worthy of a PHB: "the garbage collection approach tends to deal with memory management in large batches" Translation: "I wish GC dealt with memory management in large chunks, but it doesn't, so I can't in all honesty say it does, but I can imagine a theoretical scenario where it does, so I'll talk about that theoretical scenario that I wish was real instead of what is actually real."

    This is not to say that there aren't one or two decent JVMs out there that have decent GC performance. But having managed a large team that deployed a very powerful Java data analysis and visualization application, and having done work in the code myself, and having had to deal with user's real-world performance issues and having seen the incredible hoops my team had to go through to get decent performance, I can honestly say that up until last year, at least, Java was Not There with regard to GC and performance.

    The most telling proof: my team did such a good job and our app was so fast that many users didn't believe it was written in Java. It was users making that judgement, not developers. Users whose only exposure to Java was as users, and whose empirical observation of the language was that it resulted in extremely slow apps. They didn't observe that it was theoretically possible to write slow apps. They observed that it was really, really easy to write slow apps, in the same way it's really easy to write apps that fall over in C++, despite the fact that theoretically you can write C++ apps that never leak or crash due to developers screwing up memory.

    Every language has its strengths. Java is a good, robust language that is safe to put into the hands of junior developers to do things that would take a senior developer to do in C++. But its poor performance isn't a myth, nor is its tendency to hog system resources due to poor GC. Those are emprical facts, and this article introduces no actual data to demonstrate otherwise.

    --
    Blasphemy is a human right. Blasphemophobia kills.
    1. Re:Article Summary and reality by be-fan · · Score: 1

      Hey, let's not lump Java's failings in with GC in general. Java's memory management isn't exactly state-of-the-art. There are better GC algorithms, and more importantly, compiler optimizations that don't cause apps to allocate like crazy. Java compilers don't (yet) do any of these optimizations. The performance qualities of GC become much less relevant when you've got a compiler that doesn't do standard things like unboxing arrays of objects!

      --
      A deep unwavering belief is a sure sign you're missing something...
    2. Re:Article Summary and reality by the+eric+conspiracy · · Score: 1

      When I can run a Java app on an arbitrary JVM and not have it come to a grinding halt every once in a while as the garbage collector runs--or worse yet bring the machine to a grinding halt because the garbage collector never runs--only then will GC will be useful.

      Considering that current JVMs support parallelizing garbage collectors I am unimpressed with the above assertion.

    3. Re:Article Summary and reality by greg_barton · · Score: 1

      I am so tired of GC advocates talking smugly about theoretical scenarios. Who cares?. When I can run a Java app on an arbitrary JVM and not have it come to a grinding halt every once in a while as the garbage collector runs--or worse yet bring the machine to a grinding halt because the garbage collector never runs--only then will GC will be useful.

      Well, I'm tired of any programmer talk about theoretical scenarios. I want a proof that any program they create will do exactly what they say it does. And then I want them to guarentee that it won't crash, on any operating system, on any hardware. Otherwise I won't find it useful.

      (You do realize that my requests, as well as yours, are impossible, right? I'm talking both theoretically and practically...)

      Those are emprical facts, and this article introduces no actual data to demonstrate otherwise.

      I'd like to point out that, well, neither do you...

  155. The Least Efficient Can Be The Most Useful by oldCoder · · Score: 1
    The slowest interpreters can be the most useful languages, sometimes. Consider Javascript and the Unix shells. Absolute molasses, both of them. Absolutely essential.

    On the other hand, we absolutely cannot do without C or something very much like it. What else would we use to write the JVM in? And Perl?

    C is getting old, we need a replacement. C++ is too complex and error prone; At least -- we know we can do better than either C or C++ and keep the high performance. Look at the D programming language, as a proof of concept. Can we do better than D and keep the performance?

    --

    I18N == Intergalacticization
  156. Re:Counter arguments by EvanED · · Score: 1

    Oh, and deligates are another "beyond-syntax" feature that C# has and Java doesn't that IMO leads to MUCH cleaner code for stuff like interface design.

  157. speed kills by planetfinder · · Score: 2, Insightful

    I believe that, directly or indirectly, an unjustifide emphasis on execution speed is the one of the biggest causes
    of the failure of software projects. The problems usually begin with the choice of
    implementation languages. Programming languages should
    be chosen for the ease and cost effectiveness with which they can be used accurately and reliably generate
    a correct and maintainable application that satisfies the customer.
    In my experience selecting a language because it is "faster" than another language
    before it is even known what the speed issue is for an application is just a costly mistake.

    For speed critical parts of an application an experienced C++ programmer might be a without-which.
    A tool like JWrapper can be used to connect a Java application to an optimized C++ library.
    Speed requirements should usually be dealt with towards
    the end of the development. Most of the execution time is usually spent in a small fraction of the code.
    Only that portion of the code should be optimized because optimizations can be costly to derive and implement,
    costly to maintain, and more difficult to verify.

    In the interest of peacefull coexistence we might all agree that:
    1. Java is sometimes too slow
    2. C and C++ programs sometimes have memory leaks.
    3. Writing efficient, reuseable, object oriented programs in C++ can be an extremely subtle business and,
    as a result, good and efficient C++ programmers are harder to find.

  158. Re:Counter arguments by masklinn · · Score: 1

    And SciTE starts in roughly 0.5s... (the "true" notepad startup time being more or less null, making it just about infinitely faster than java)

    --
    "The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
  159. Re:Counter arguments by masklinn · · Score: 2, Insightful
    As far as productivity, it depends what you're doing. Java UI's take longer to implement (that might not even be true for SWT interfaces) but the core language of Java is very fast to write code in.

    Nope, not compared to Python or Ruby (which yield codes rougly 5 times smaller in a quarter of the production time), not compared to Lisp for an ol'timer, not even compared to C# (by a quite small margin though, but C# has a lot of very nice feature Java doesn't have).

    Writing Java is faster than writing C/C++ indeed, but not "very fast", not without any referential to compare to, because dev-time wise Java gets it's ass handed to it by much more agile languages.

    --
    "The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
  160. How about some actual DATA? by happycorp · · Score: 2, Interesting
    We can go on all day saying Java is slower, no it isn't, but no one's opinion is likely to be swayed.

    A quick web search turns up several surveys with lots of benchmarks,

    http://java.sys-con.com/read/45250.htm
    http://www.idiom.com/~zilla/Computer/javaCbenchmar k.html

    1. Re:How about some actual DATA? by bani · · Score: 1

      java might "not" be "slower" but every java application i have ever used, old or brand spanking new recent, are all very sluggish and massive resource hogs.

      people's current experience with java applications influences them far more than several year old microbenchmarks.

  161. Java, It's not fat its big boned. by pauldy · · Score: 2, Interesting

    This is about as much of a myth as the myth of the earth traveling around the sun. There is a lot more to allocating memory than this article lets on. Psuedocode will always be slower than machine code no matter how you slice it. You can do various tricks to make it seem faster by instruction count at certain things but in the end those same things can be applied to compiled code like c/c++. Most people can accept that as fact and move on using Java where it seems appropriate. Make all the excuses and extraordinary claims you wan tint the end Java is just plain old FAT n slow, anyone in any programming course who has used java can tell you that.

    Oh and it is hard to test out his little theory on the free malloc in C++ because you can't do the same thing in Java. You can try but it will get around to the free part when it gets good and ready and may not attempt the malloc until you use the memory.

    1. Re:Java, It's not fat its big boned. by Temporal · · Score: 1
      You can do various tricks to make it seem faster by instruction count at certain things but in the end those same things can be applied to compiled code like c/c++.

      I would love to see an implementation of malloc() which looks like:
      void* malloc(int size) {
        heapPointer += size;
        if (heapPointer > heapEnd)
          sweep();
        return heapPointer - size;
      }
      You can do this in a GC'd language. The GC can move objects around in memory later on to eliminate fragmentation. You obviously cannot do this in C since you cannot freely move memory in C.

      Hell, you can even remove the if statement in the above code if you just stick a guard page at the end of the heap. Then you could stick the heap pointer in a register and have heap allocation which is just as fast as stack allocation. Try doing that in C. Hint: You can't.
    2. Re:Java, It's not fat its big boned. by Henry+V+.009 · · Score: 1

      Two words: Memory pools.

    3. Re:Java, It's not fat its big boned. by rcamera · · Score: 1

      You obviously cannot do this in C since you cannot freely move memory in C

      guess again

      --
      Wave upon wave of demented avengers March cheerfully out of obscurity into the dream
    4. Re:Java, It's not fat its big boned. by Temporal · · Score: 1

      Um... last I checked memmove() does not find all existing pointers to the memory in question and update them to point at the new location.

    5. Re:Java, It's not fat its big boned. by Temporal · · Score: 1

      Memory pools are nice for applications that fit well with them, but they certainly can't serve as a general replacement for malloc().

    6. Re:Java, It's not fat its big boned. by rcamera · · Score: 1

      you can find all existing pointers and update them. it's not that difficult if you designed your application with this kind of thing in mind. and if you don't want to update pointers, use offsets. offsets remain correct regardless of address.

      --
      Wave upon wave of demented avengers March cheerfully out of obscurity into the dream
    7. Re:Java, It's not fat its big boned. by Temporal · · Score: 1

      you can find all existing pointers and update them. it's not that difficult if you designed your application with this kind of thing in mind.

      Would you care to describe how you would do this? I'm having trouble imagining a solution which is not terribly convoluted or inefficient.

      offsets remain correct regardless of address.

      Unless the objects change location relative to each other, which is the whole point of a compacting memory manager like what I was describing.

    8. Re:Java, It's not fat its big boned. by rcamera · · Score: 1

      a simple solution to updating pointers is to keep a circular list. when the position of one of your list elements changes, simple rip through your list and update the invalid pointers. i have found this to work quite well for lists on the order of 10s of thousands of elements (i never have to defragment, but i do realloc...). would you like some pseudocode to demonstrate this simple task? it sounds like you have a hard time visualizing anything pointer related...

      as far as offsets, why would objects NOT change relative to each other? i assume you have some sense and are NOT allocating one object at a time when you know more than one element of the same type will exist. if you are, then it's time to go back to your design and rethink things. now i see why you're so worried about fragmentation...

      --
      Wave upon wave of demented avengers March cheerfully out of obscurity into the dream
    9. Re:Java, It's not fat its big boned. by aled · · Score: 1

      Modern Java Virtual Machines do Just In Time compilation. Sun JVM "hotspot" decides what to compile based on when code is frequently used. Then it compiles to machine code. So Java can be as fast as machine code. See http://java.sun.com/products/hotspot/docs/whitepap er/Java_Hotspot_v1.4.1/Java_HSpot_WP_v1.4.1_1002_4 .html for more details.

      --

      "I think this line is mostly filler"
    10. Re:Java, It's not fat its big boned. by pauldy · · Score: 1

      You are missing some things here. The JVM has come a long way however the abstraction layer it provides inherently introduces the use of more CPU cycles for any given task, end of story. This code doesn't magically come in a form that just flops right on into a compiled cpu native form. A process has to convert it now if you discount the role of the JVM in interpretting and managing the code, memory ussage, and io resources yes you might conclude some of the assertations made in this article. A huge point left out of the articel is that using the technology you linked to create or destroy objects may or may not happen when asked to be created or destroyed. So I could run a loop that creates and destroys millions of objects for the jvm to simply turn around and ignore the request to allocate and free the memory for those objects because they were never used or not freed until the application exit. So who runs a loop that does nothing faster, Java or C++, try it for yourself and tell me that the JVMs JITC makes java run as fast as C++ code.

  162. Re:Counter arguments by Jonboy+X · · Score: 2, Interesting

    Ermm, one question: is your poker simulator multi-threaded? If not, try ArrayLists in place of your Vectors in the Java code. Vectors are internally synchronized, which will hit you for a pretty big performance penalty.

    Sorry, Vector over-use is one of my pet peeves. It's silly little programming goofs like this that make our programs slow, and give the anti-Java trolls more ammo.

    --

    "In a 32-bit world, you're a 2-bit user. You've got your own newsgroup, alt.total.loser." -Weird Al
  163. Re:Java designed for humans, not performance. by Mybrid · · Score: 1
    Certainly, for the really high-speed parts of the code and for specialized purposes I too would still recommend to use C++, but for 95% of all code there is no reason not to write it in Java. And it is fairly simple to integrate C++ code in Java.

    Certainly much of the Enterprise business world I've interacted with is under the same impression as this statement so you are in good company. Except that last part "And it is fairly simple to integrate C++ code in Java." . I'm curious if you could speak to your experience on how is it fairly simply to integrate Java with any other code. The JNI interface is very error prone and can have huge impacts on performance. When I consult for people wanting to interoperate Java with some other language the best solution is to go through some known interface protocol like SOAP or HTTP.

    In fact, sometimes the best way to interoperate distinct Java programs is to isolate them within different JVMs on different machines. Companies like EBay implement what they call "use case" machines where hardware isolates Java software release and performance problems.

    Java runs best as a SUSA environment, single user, single application. Java's JVM doesn't do well at all as MUMA, multi-user, multi-application environment unless you have a highly customzied environment as with web application servers. Web application servers are really a misnomer. They are not application servers. They are JVM environments that allow Java to scale to MUSA, multi user single application. The raw JVM assumes one application, one user in my opinion when one is considering performance.

  164. Linear allocation faster than 'block list search' by master_p · · Score: 1

    Java allocates objects linearly, i.e. it simply increases an index. When that index reaches the top of the garbage-collected memory, memory is defragmented.

    C++ and C have quite complex algorithms that search lists of blocks for either the biggest size or the closest to the requested size. In reality, manual allocation is slower than the Java model.

    But there is a very important problem with Java that C++ does not have: Java allocates all its objects on the heap, whereas in most C++ apps most objects live on the stack. This little difference makes C++ programs faster, even though allocation of Java objects is significantly faster.

    Another problem with Java is that Swing is slow, and therefore Java apps are perceived as slow. But it is only Swing that is slow, because Swing implements its own Window system, complete with region geometry.

    In the end, Java wins for me, because I simply don't have to track down pointers as in C. From the day I started to use Java, my productivity has skyrocketed, even if my programs 'feel' a little slower.

  165. Re:Counter arguments by NoOneInParticular · · Score: 1
    A quick comment on an otherwise excellent post:

    So, tell me, how is C++ implementing virtual method calss, without virtual method tables? Oh, and yes, fuck this synchronisation stuff, one thread will be enough for all applications!

    If a C++ class has virtual functions, there will be a virtual method table. However, if it doesn't, there will be none. A simple class for data storage will have zero byte overhead. Add synchronization (I think you mean semaphores?) and this will cost you that extra few bytes. But only when you need it.
    A Java object always comes with overhead, there is no way to get it out. The big difference between the philosophies of C++ and Java are that in C++ you don't pay for what you don't use. In Java you simply pay for everything, even if you don't need it. Don't need inheritance, but only data encapsulation? you pay for inheritance. Don't need synchronization? You pay.

    Just a question: how much memory does an ArrayList<Integer> of size 1000 take? In C++, a vector<int>(1000) takes 1000*4 bytes + 12 (3 pointers for vector). Last time I checked, a single Integer in Java takes 16 (!!!) bytes, 4 times more than strictly necessary. Arraylist itself comes at a nice 80 bytes (versus 12 for C++). Further, how much would a non-virtual class in C++ take that has a single integer data member? Yes, again 4 bytes. Add a virtual function table, and you're at 8 bytes, still half of that of Java. All these unavoidable bytes quickly add up, hence Java being a memory hog. One million of objects floating around? (can easily happen as you hardly have a choice avoiding objects) Eight megabyte gone for Object overhead alone.

  166. Java Still Useless To Me by nathanh · · Score: 1

    I recently decided to try out Eclipse - after hearing how brilliant it was - to replace Anjuta for C++ development. I notice an eclipse package is in Debian so I "apt-get install eclipse-sdk". Oh, it needs a Java SDK first. No worries, I'll just install one of those using apt. I'm sure this will be easy.

    Easy? Hah! Maybe it's easy for x86 users but us PPC users are out in the cold. After hours of fruitless searching I eventually chance upon the IBM Java SDK on the IBM website. It's only in RPM format, but a quick "alien" later and I have a package. I install it, go to run it, and the JRE crashes.

    So I simply delete the Java SDK and any hopes of using Eclipse on Linux/PPC. I'm not going to jump through hoops; if it doesn't "apt-get install" then I don't want to know about it.

    1. Re:Java Still Useless To Me by 6*7 · · Score: 1

      Maybe you should consider something else than Debian then (yellowdog?), since your main problem will be Debians policy considering to non-free java. It used to be a lot of work even on i386 (creating a deb from eg Suns JVM). Nowadays eclipse-sdk depends on eclipse-javac which depends on either java2-runtime or kaffee. That last one should be be available for ppc i guess.

  167. Re:Linear allocation faster than 'block list searc by be-fan · · Score: 1

    I always find it interesting to see how many C/C++ programmers think manual memory management is "fast". I think anybody spouting off about such topics should be required to have least *implemented* a fast malloc()/free(). It's a non-trivial task, and when you see that the hot-path is still dozens of instructions long, it really puts the cost of malloc() into perspective.

    --
    A deep unwavering belief is a sure sign you're missing something...
  168. Re:Counter arguments by Money+for+Nothin' · · Score: 1

    Eclipse and its parent project, IBM's WebSphere, are mighty big "exceptions" in the Java world.

    I agree though that C# is no better. VMs will always eat RAM and CPU time, and the vast majority of the time, they do so unnecessarily... (why run an app in a VM -- .NET or Java -- if your target end-user environment consists solely of your standard, homogenous x86/Win32 systems? Why not compile a native binary instead, which will run faster and be leaner in RAM and on disk (and thus, faster to distribute over a network)?)

    I do find it a bit humorous that you refer to your G5 as "older". The current top-of-the-line Apple box CPU generation is "old"? Hardly.

  169. I/o peformance? by cprice · · Score: 1


    So does JVM i/o performance, specifically disk, still suck the big one when dealing with moderate i/o loads?

  170. Java vs. PHP by Heembo · · Score: 2, Interesting

    I believe that this battle can be summed up in the battle of Java vs. PHP. Here we have a fully OO VM based language that has been widely deployed on both Unix and Solaris, vs. a (mostly) UNIX only scripting language turned web programming language with lots of web-specific features. I have developed large solutions in both languages, and it really comes down to: PHP rocks for quick-and-dirth websites. Put a PHP next to a Java guy to develop a basic ecommerce or content mgmt website, and PHP will TOAST that guy. Now required six-sigma reliability, 100+ hits per second, redundant servers w/ clustering, the ability to connect to multiple corporate database from different manufacturers, and other high-end enterprise features, and Java wins hands down. Not to mention of the security of PHP vs. the security of Java - PHP is "wide open" in many ways. USE a big hammer for a big nail, and a small hammer for a small nail. Java ran WebMD (many thousand hits per second, all data driven) with an early version of Java 1.1. - yes, we need to clean up the socket code some w/ SUN, but it worked, and it worked very well. The future looks to me .NET - Microsoft was brilliant - a well defined software app network architecture what is language agnostic. This time in a few years there will be many Java programmers writing web-service code behind the .net standard. Thanks for reading my stream-of-consciousness.

    --
    Horns are really just a broken halo.
  171. Re:Counter arguments by Com2Kid · · Score: 1
    plus the "in" and "out" modifiers for method arguments too.


    The return of Ada95! (Seriously, in the C# language manual they even mention Ada!)
  172. Re:Counter arguments by Anonymous+Brave+Guy · · Score: 1

    Yes, exactly. Java's performance hasn't suddenly found a silver bullet that enables it to beat well-written C or C++. However, for most applications, that doesn't matter.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  173. Re:Counter arguments by Trejkaz · · Score: 1

    Therefore it makes sense to sacrifice a little bit of program performance to get more productive programmers.

    And therefore, all enterprise development should switch to using Ruby.

    --
    Karma: It's all a bunch of tree-huggin' hippy crap!
  174. Re:Counter arguments by Com2Kid · · Score: 1
    As far as guzzling RAM goes, all programs these days guzzle RAM, and they're right to do so, because RAM is cheap.


    Hey screw you! What makes YOU think that YOU have the right to eat at my system's memory so I have to go out and buy more? You're a programmer? So what, your job is to write applications for the END USER, not to write applications As It Is Convenient To You.

    Besides, if EVERYONE takes up 100 Megs of Memory (about what the JavaVM with Eclipse running takes up, and my Explorer.exe process is sucking down another 100MB, and Acrobat is taking 32MB just with a single file loaded) pretty soon 1GB will not be enough, so users will upgrade, so programmers will think "hey we have more room to work with now" and they will get lazier and eventually 2GB will not be enough...

    It is stupid, REALLY stupid. Why should a text editor take up 100MB of RAM? Why can EMACS have a boatload of features (CD-Burning...) and take up less memory than a freaking .NET IRC client?

    Let me tell you why, it was because even with the GNU's non-conservative programming tactics (Stallman says in his Manifesto than the GNU during its founding years did not work to conserve memory, in the belief that computer power was expanding so fast that to do so was meaningless), they did not have such an ego about them as to abandon effort all together and just throw their apps willy nilly.

    Oh, and for the record, Dell's low end Dimension systems STILL ship with 256MB of RAM standard. At least now MOST of Dell's Business workstation's come with at least 512 MB of ram.

    VS2005, with a decently sized project open, 300MB of RAM or so. I had a 512 system, I could MAYBE browse the web while running it, had to deal with a lot of disk thrashing though.

    So tell me, with half a gigabyte of memory, why should my disk be thrashing like mad because I dare to have both an IDE and a web browser open at the same time? Don't tell me it is MS's fault, they are just following in the trend that Sun created: Please the programmer, forget about the end user.

    Of course with all of this running, Developers need a good 2GB+ of memory on their computers, which means they loose site even more of what kind of system's their end users are working on.
  175. Re:Counter arguments by Decaff · · Score: 1

    And SciTE starts in roughly 0.5s... (the "true" notepad startup time being more or less null, making it just about infinitely faster than java)

    I would be interested in an explanation of how a 2.5 second startup time has any relevance whatsoever to the general user.

  176. Re:Counter arguments by CockMonster · · Score: 1

    Symbian C++ isn't that difficult, it lacks documentation though. That's being worked on.

  177. Re:Counter arguments by Decaff · · Score: 1

    The problem isn't application code typically, its the VM startup time people complain about. If java is already running its fast, but if you are starting a vm from scratch (server vm in particular) it takes a few minutes. As an example, it takes 35 seconds to start up tomcat on my freebsd server including VM startup (java 1.4.2 native) and loading all the webapps. I've timed it.

    Server specs are a p4 2.4ghz with 1gb ram and freebsd 5.4 release.


    I am talking about VM startup time - that is included in the 2.5 seconds. I'm sorry, but server VM startup time does not take a few minutes, at least not on machines I deal with.

    Let me give you an example: AMK K7 - 1.8 GHz, 512MHz ram. Java 1.5.0_04

    The issue you are dealing with is the loading of all the webapps. This has nothing whatsoever to do with the VM startup time. A typical Tomcat installation may have to deal with half a dozen applications, all with security issues, JARs to load, and database applications to establish. It is basically like starting up an operating system!

    If you get bare tomcat (I use 5.0.28) I have found that I can access the management application only 5 seconds after startup.

    If you are going to comment on VM startup time, you need to test an application that actually measures that.

  178. Re:Counter arguments by Decaff · · Score: 1

    Let's take these myths one by one.

    I am using an AMD K7 Machine, Linux, 1.8 GHz, 512 MB memory.

    It does have too long a startup,

    JEdit, a popular Java programmers editor. Start up time 3 seconds.

    most of the UI toolkits are horribly slow,

    On the same machine I am using NetBeans. There is no delay in menu use, dialogs, text editors.

    it does not follow native platform UI conventions,

    On MacOS/X it follows native platform UI conventions exactly, as the implementation was written by Apple. On other platforms you can use SWT which not only follows the native UI, it IS the native UI! On the upcoming version of Windows, Swing will be guaranteed to be undetectably different from the native UI by both Microsoft and Sun.

    and it is just not as nice to use a Java app as it is an equally well written native app.

    Nice is subjective. Both NetBeans and Eclipse have won developer.com open source awards, so I guess a reasonable number of people find them nice.

    It does take far too memory, especially compared to other languages.

    I can start up the Java Swing Notepad demo in ... 3 megabytes of memory.
    I can start up the Java full GUI demo (SwingSet2) in 10 megabytes.
    I can run the Sun full-featured NetBeans IDE in only 64MB.

    Not my definition of 'far too much memory'.

    Even the cross-platform nature of the code is largely a lie.

    Nonsense. I use this nature of Java on a daily basis, as do tens (if not hundreds) of thousands of other developers. If you looked at the surveys you would see that it is entirely routine for developers to use both Windows and Linux to develop Java and to deploy on the other platform.

    Different JREs don't support the same things.

    They absolutely do if they are the same version of the JRE. They have to pass a compatibility test.

    There are massive differences between the various editions of Java so as to make it useless to try to write something across them.

    Well of course not! What do you expect? Do you expect the same binary program to work with different version of Linux or libc? Java is pretty much guaranteed backward compatible, but why should anyone expect a Java 5.0 app to work on Java 1.3?

    Your Java app written against "Vendor X Version Y Edition Z JRE" should work fine on any other platform with the same version of "Vendor X Version Y Edition Z JRE". That's all you can safely say without a good amount more testing.

    Since Java 1.2 I have never had any cross platform issues with Java. Java is so portable that Sun's NetBeans IDE will not only run totally unchanged on any Java 1.4 or above platform, it even runs totally unchanged on Java implementations from companies other than Sun's (BEA, IBM HP).

    There are guidelines for writing portable apps (such as don't use com.sun.* or sun.* packages). They are easy to follow. If you choose to ignore these, and you have issues about different vendors JREs it is your fault.

    I'm afraid that your points seem to me to be nothing but myths or FUD.

  179. Ever heard of SoftReference? by Anonymous Coward · · Score: 0

    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ ref/SoftReference.html

    It's been in the JDK for quite a while, and is exactly what you say is missing.

  180. Re:Counter arguments by sean.geek.nz · · Score: 1

    Mate, You're making clear that you don't use, or know much about, Java. Unlike, say, C++, choice of JVM and JRE is _not_ a mess of compatibility issues. It's backwards compatible and cross-platform compatible as all hell. Y Your claim that 'different JREs support different features' is just surreal. I've never seen any other language that is as good at backwards compatibility as Java (certainly not C++). Of course new features from Java 5.0 don't exist if someone runs in a JRE1.2. But the only way around that would be to freeze the language and never add a new feature ever. I spend a painful amount of time dealing with C++ issues with different compilers, I miss the ease of Java development.

  181. tradeoff by geo.georgi · · Score: 1

    This is really very good idea.
    Bit it just illustrates the typical tradeoff between speed and memory.
    Quick, but use twice the memory, or slow and don't use additional memory.

    Is this algorithm in use in the JVM garbage collector or in other languages with garbage collection?

  182. trusting the compiler by willCode4Beer.com · · Score: 1

    "if you didn't trust your compiler (or working toward multiple architectures) you could always use some compiler directives and some embedded asm"

    You could also just compile the code, and dis-assemble the resulting object code to *know* what the compiler is generating. But, I guess its more fun to use imagination and conjecture to create points to debate. :-)

    --
    ----- If communism is a system where the government owns business, what do you call a system where business owns govern
  183. code handoff by willCode4Beer.com · · Score: 1

    "Assume you are a contractor and all code is to be passed off to the internal development team afterwards"

    You are doomed no matter what you do in this situation. NIH syndrome take over and you'll get blamed for everything anyway. When there is a problem the in house people will tell their PHB that whatever you did caused the problem. The PHB won't understand anything anyway.

    --
    ----- If communism is a system where the government owns business, what do you call a system where business owns govern
    1. Re:code handoff by carlislematthew · · Score: 1

      A good PHB can code better than you can. Most cannot though, I'll give you that. :)

  184. The difference between malloc and new by exa · · Score: 1

    The C++ new and C malloc are not the same thing.

    In C++ allocation is a fast business. Open up stdlib code and see what I mean.

    In C, good applications use malloc carefully to minimize number of malloc calls.

    Also, especially in C++ we AVOID dynamic allocation as many others have observed.

    The author of the article is a mediocre programmer who does not know the nuances of his trade. I wonder if he could program in any other language than Java.

    --
    --exa--
  185. Re:So why are all websites running Java slow as he by the+eric+conspiracy · · Score: 1

    Name one that isn't

    I'll give you two. Ebay and Amazon.

  186. Re:Counter arguments by maraist · · Score: 1

    (Operator Overloading being a prime example.)

    Ugh, that's one of the things I don't miss from C++.

    Look at java's "toString" function.. It's identical in inception to a 1'st class operator.. Something defined for all objects and can be overloaded. But Java documentation says NEVER USE THIS FOR PRODUCTION CODE. In other words, it's intended for debugging purposes.. Though "stringBuffer.toString()" does use this as it's main purpose, but that's forgivable since it's obvious that it's it's sole purpose.

    Java could have had operator overloading if they merely implemented in the Object class something called:

    Object.add(Object o);

    likewise w/ sub, mul, div, mod, minus, index, invoke.

    Those are the overloadables that I remember from c++ at any rate.

    So I ask you. Why didn't they put them into the Object class? You could easily create a base interface for all your worker objects.

    interface Mathable { E add(E); E sub(E); ... }

    Then you'd have identical functionality to operator overloading (except for 3'rd party libraries, but you could easily use bytecode enhancement even there).

    So why don't we do this?

    What the hell does "Object result = myInputStream.add(myGraphicalWidget);" produce?

    It doesn't make any bloody sense? And that's the point. It makes sense to add NUMBERS, but not generic widgets. If it DOES make sense to add something to an object (being mutable) or to combine two objects and return a 3'rd (being immutable), then great.. Put them together accordingly.

    And guess what:

    Integer i = 5;
    Double d = 7.0;
    Long l = d % i;
    Works just fine in java 5, thank you very much.

    Otherwise, I'll keep my readibility of java over the following: /**
      * comment, I don't remember what this does, but isn't it cool?
      * I'm using operator overloading for no good reason
      */
    void foo(BusinessObject1 bo1, BusinessObject2 bo2)
    {
        return bo1 + bo2[bo1(0)];
    }

    --
    -Michael
  187. Re:Counter arguments by maraist · · Score: 1

    Don't forget he's talking about java 1.4 and you're talking about java 1.5. One of the design features of 1.5 was to have the startup process pre-JIT'd specific to a target platform; though SUN only supports like 10 environments including Linux x86-32, Linux x86-64, windows and solaris.

    So running a hello-world app is pretty darn fast in 1.5. But this doesn't do boo for a tomcat loading of 20 different app-contexts, each with 5 different explicitly defined servlets. And yeah, like you said, stock tomcat comes w/ like 6 application contexts including webdav and examples. My sys-admin never seems to remove them, so there's like a second or two of my startup time wasted.

    --
    -Michael
  188. Re:Counter arguments by bani · · Score: 1

    azureus (idle, no torrents running) takes 500mb of virtual memory and 100mb of real memory. when running, azureus is very sluggish. just like eclipse, by the way.

    openoffice takes 100mb of virtual and 30mb of real memory.

    what.the.fuck ?

  189. Quantifying the Performance of GC vs. malloc by Ristretto · · Score: 1
    While I find it difficult to argue with people who disagree with GC's software engineering benefits - which seem obvious to me - I have to say that I think the author of this article is missing the point. GC might well squeeze a few less instructions out of the allocation sequence, though this is not necessarily true for some well-tuned allocators.

    But the allocation sequence isn't the bottleneck -- it's all about the actual garbage collection itself. GC can be costly in terms of cycles and, if you're unfortunate enough to be running in low physical memory, page faults. The reorganization of memory may improve application locality, but that may not be enough to buy back the performance penalty.

    Rather than try to argue the case with hand-waving, my student Matthew Hertz and I performed experiments on an infrastructure that lets us replace garbage collection with malloc/free in Java programs so we can quantitiatively compare the cost of garbage collection. Our paper, to appear in OOPSLA 2005, shows that a good, generational copying garbage collector can match or slightly beat the performance of malloc/free -- but this requires 5X as much memory as the allocator. It's a classic space-time tradeoff. On the other hand, if you don't have enough RAM to hold the entire heap, though, garbage collection runs tens or hundreds of times slower.

    --
    Emery Berger
    Asst. Professor, Dept. of Computer Science
    University of Massachusetts Amherst

    1. Re:Quantifying the Performance of GC vs. malloc by X · · Score: 1

      I read your paper, and I do think there is some interesting research there. However, it seems that the way you went about doing things is going to limit the relevance of these findings. In particular, even when you are comparing malloc/free, the free calls are generated automatically. So, what you are comparing here is the advantages of having amortized free operations vs. the disadvantage of having to compute when such operations are done at runtime. So, the end result is not a very suprising conclusion: you need to amortize a lot of free operations to make up for the cost of having to compute when memory can be freed.

      Even that conclusion is somewhat limited, as the cost of malloc/free and GC'd memory management are limited to the specific tools you evaluated, which are clearly not the best available (although they are decent). However, there are lots of ways that I'd imagine the GC'd memory management could be improved.

      It also ignores the fact in a multithreaded environment, that the cost of computing the root set can be off-loaded to another thread (or threads). Particularly in a multiprocessing and I/O intensive context, this could all but eliminate the impact of these calculations on application thoroughput.

      The big question that crosses my mind though is this: your paper clearly demonstrates that at least with certain constraints, there are times when at *compile time* a compiler or JIT can and should determine when certain objects can and should be freed. This is kind of what Mustang's escape analysis achieves (although in a more limited way). An even more clever compiler can determine the set of objects which *might* be freeable. If done right, this can be integrated with the allocation of said objects to further simply things and improve performance. The end result would still qualify as an automatic memory managed system, and assuming some degree of non-determinism for the timing of deallocations, it would still be a garbage collected environment. Such a system should in theory be able to combine the performance benefits of your malloc/compiler-assigned free case with the amortized free benefits of your GC case.

      --
      sigs are a waste of space
    2. Re:Quantifying the Performance of GC vs. malloc by Ristretto · · Score: 1
      Thanks for your comments. I agree that the core result -- GC requires a substantial amount of space to reduce the frequency of collections, otherwise performance suffers -- shouldn't be surprising, but the existence of articles like the IBM one suggests otherwise...

      I do have a few comments about your comments, though. First, I don't understand your objection to the insertion of frees. This just simulates the effect of the programmer invoking free. We examine two cases: (1) where the free calls are as early as possible -- the last use of an object and (2) where the calls are as late as possible -- the last time the objects are reachable. This brackets the range of programmer behavior. We measure both cases. Both choices of when to free objects turn out to have surprisingly similar performance results, and in any event, all of the garbage collectors require a lot of space to reduce GC frequency (roughly 5X before runtime performance matches malloc/free).

      As for the tools used -- you work with the best you have available. That said, this is a pretty comprehensive study on a reasonably solid platform, though all the collectors are stop-the-world (all threads stop during collection). Concurrent GC is slower than non-concurrent GC, so including concurrent collectors wouldn't alter our results. However, parallel stop-the-world collectors would speed tracing (computing the root set is not the problem). We couldn't test such collectors because of infrastructural limitations, but we definitely want to revisit them later.

      One note: you shouldn't read our study to suggest anything about compile-time garbage collection beyond the fact that it basically changes the time-space tradeoff (it won't make programs faster when running in plentiful RAM). The oracles used to guide free calls are derived from profiling, not from static analysis. Escape analysis is great for reducing contention in the presence of multiple threads, but it's likely to be of limited value when you have generational collectors (insight: it only captures short-lived objects, precisely what generational collectors already handle superbly).

      Emery Berger
      Asst. Professor, Dept. of Computer Science
      University of Massachusetts Amherst

  190. In defence of C++ (Re:Robomaid) by joto · · Score: 1
    Just compare C++ Corba to Java Corba. In C++ Corba...

    The C++ Corba bindings are incredibly obtuse. The "smart" pointers there are incredibly "unsmart", and the semantics of memory management is rather strange.

    Upcasts are (conceptually?) new objects, meaning that you can free a CORBA_Object_ptr object, even if you have another *_ptr to a *::_narrow()'d version of it. In fact, you should, as that is the only way to guarantee the CORBA_Object ever gets freed! To keep some level of performance, while maintaining this obtuse semantics, even objects with plain pointers have to be reference-counter. Furthermore, when you (conceptually) deep copy an object with *::_duplicate(), in reality all you are doing is increasing a reference count. Thus, you will have to worry about reference counting whether you use CORBAs smart pointers or not! A further complication comes with out-parameters, which means that in addition to *_ptr, you will also need *_out for function out-arguments. All to keep the reference-counting (before we add smart pointers (the *_var types)) "sane".

    True enough, using the *_var types make CORBA look almost sane, but they are optional (for performance reasons), and this complicates the CORBA C++ binding a lot. Actually, I'm yet to be convinced that the *_var types actually work sane enough, or get a clear explanation of when they work, because everything in the C++ binding remains nonintuitive. With typical implementations of smart pointers, such as e.g. boost::shared_ptr, new objects will have a reference count of zero, untill they are managed by a smart pointer, and when the reference count decreases to zero, the object will be free'd. Given the obtuse semantics described above, this is not possible with CORBA, as each new object will have a reference count of 1

    Ok, maybe this explanation was as obtuse as the CORBA C++ bindings themselves, but it serves to illustrate my point. It would not be particularly hard to create a C++ CORBA binding that was as easy to use as Java's. It just happens that the CORBA C++ binding was designed by a committe that worried more about performance, multithreading, pre-standard-C++-compatibility, and the NIH-syndrome, than something clean and useful. IMHO, they should have left the micro-optimize-the-hell-out-of-it to the C binding, and left a clean C++ binding, but they didn't. Of course, all of this is in hindsight, at the time the bindings were created, I'm sure all the decisions made perfect sense!

  191. There's nothing like comparing apples to oranges.. by Assmasher · · Score: 1

    ... LOL. Comparing malloc to a memory manager is an early indicator of bias which I wouldn't point out if they had bothered to do so themselves (because it is valid to point out that C++ people tend to marginalize Java based upon performance out of hand and that's wrong.)

    But, to compare oranges to oranges, my texture resource manager (written in C++) returns batches of pre-allocated memory (like the Java system mentioned in the article) in less than 6 machine instructions.

    --
    Loading...
  192. Re:Counter arguments by maraist · · Score: 1

    I want my computer to respond as fast as possible every time and there is no comparison.

    So it's a good thing you don't write web applications then. As this philosphy requires either using something like inetd to efficiently delegate web requests to your propiretary web servers, or using a thin shell script which does nothing but invoke OS applications like "sort" and "grep". Welcome to 1993.

    The response time of a java application (w/ NIO support) is as fast as ANY c application (using UNIX select). Because the two applications are binarily equivalent. They both perform the same operations under the hood; just w/ different arrangements of code.

    The difference is that java is much easier to debug extend, and overlay than a c application. Yes, PHP, ASP, VBScript, Perl-Mason, etc are more easy to extend/deploy than a servlet. BUt JSP's are a middle-ground; you can attach a person's "public_html" directory to your tomcat instance and thus provide arbitrary JSP support in just a useable environment as a mod_perl directory.

    I assume that most people are complaining about java applications that are launched by the client.. But there's a reason why java applets are almost dead (replaced by flash). That's because script-kiddie web programmers want press-button-build application environments.. We call them RAD prototypers, but to each his/her own. Since Flash is easier to create, and prettier out of the box, flash overtook java.. But I don't hear ANYONE complaining about flash in this thread. Have you seen the load time of a flash app recently? It definitely isn't the bandwidth latency.

    We accept this unreasonable load-time of flash because we think of it differently than say notepad or "vi". And that's precisely the point. We interact with these tools in a different way. Slowly desktop applications are being replaced by online services. Will the transfer be complete? Doubtful; not unless viruses have their way.

    The irony is that the fastest growing application environment right now is javascript (e.g. AJAX). We've turned full circle back to the days GWBasic being the coolest thing on TV (think back to Richard Prior in Superman 3).

    --
    -Michael
  193. Okay by Trogre · · Score: 1

    So Java isn't slow anymore.

    It just lacks a decent FOSS implementation.

    --
    "Nine times out of ten, starting a fire is not the best way to solve the problem." - my wife
  194. Re:Counter arguments by maraist · · Score: 1

    Holy shit you're funny.

    Did you seriously miss the irony of what you just said?

    How dare programmers make me.. umm.. what's the word? "Upgrade" my hardware?

    So memory is a religious point of conservation, but you're probably pissed that you can't afford that new 4000+ AMD-64x2????????? w.t.f?

    What's the difference between needing more memory and more CPU speed?

    People use to write in assembly inside of 64KB of RAM through a serial bus on 8bit processors.. They had to emulate real numbers for god's sake. We could still be doing this if we actually cared about keeping the consumers from having to upgrade their hardware.

    The fact of the matter is that the cost of hardware is nothing compared to the cost of programming time.

    And these days the biggest problem w/ programs are BUGS. So anything that reduces the amount of bugs is a GOOD thing for consumers. And if that means using a different programming language (like perl, python, java or C#) which doesn't produce core dumps or memory leaks (well, some better than others'), then hey, that's what the industry has learned.. The fact that you don't recognize the value of platform v.s. your existing platform doesn't mean that's going to disuade the developers.. They're using their language of choice for a reason.. Either they are super-proficient in their platform of choice and are able to regularly produce reliable code, OR they recognize that they have to outsource a lot of their work and they don't trust the quality of their hiries or they know that the level of complexity is going to overwhelm the managearial process. The result in all cases is the a appropriate platform is chosen given the current demographics of hardware.

    So the reason you see 300Meg memory frames in IDE's like "idea" is because people that are willing to shell out $700 like myself for some software are willing to shell out a whoping $70 for the memory to run it. People that make little task-bar icons KNOW the demographic of their end user, so they don't create a tool that will consume 60Meg just to let them configure their graphics card.

    --
    -Michael
  195. Re:Counter arguments by maraist · · Score: 1

    minor nit-pick.

    Java and C/C++ are platform independent languages.
    But Java isn't == C/C++. You'd have to say
    Java/Swing/jboss == C++/KDE or C/GNOME

    Then you find that C++/KDE and C/GNOME are NOT cross-platform. Or at least, supported on very few platforms.

    We're not in CISC lab anymore, so we don't write little hello world apps that don't need a UI. When you write a C++ these days, you're talking about the full enchilada.. The end-to-end app.. And I'm not aware of non-geek tools that dont' require something more than a CLI. And I know of very few UI's that are cross-platform.

    THIS is where Java excels. Of course due to market conditions, Java hasn't taken off in this areana.. The horrific HTML + CSS + javascript world has taken Java's place here... But we're back to the early 80's days of C where you couldn't recompile the same app on a different platform (e.g. I.E. only or firefox only apps).

    --
    -Michael
  196. Re:Counter arguments by maraist · · Score: 1

    Not seeing how a card shuffling game is a good benchmark. Nor am I seeing how something that runs in less than a minute is a good benchmark.

    That's like the classic "how fast can I copy memory" benchmark which isn't even a good memory benchmark or the adding two numbers a billion times.

    --
    -Michael
  197. One fallacy in this article by ardran · · Score: 1
    (Public service announcement: Object pooling is now a serious performance loss for all but the most heavyweight of objects, and even then it is tricky to get right without introducing concurrency bottlenecks.)
    vs
    If the allocator were truly implemented as shown in Listing 1, the shared heapStart field would quickly become a significant concurrency bottleneck, as every allocation would involve acquiring the lock that guards this field. To avoid this problem, most JVMs use thread-local allocation blocks, where each thread allocates a larger chunk of memory from the heap and services small allocation requests sequentially out of that thread-local block.
    So wait, JVMs are okay because they can eliminate concurrency by using thread-local pools, but other pool allocators can't?
  198. Boehm Demers Weiser GC: 1988, AT&T: 1984 by SimHacker · · Score: 1

    The idea of a garbage collector for C has been around for a lot longer than 11 years.

    Hans-Juergen Boehm and Mark Weiser, "Garbage collection in an uncooperative environment", Software Practice and Experience, 18, 807-820 (1988).

    "Weiser experimented with a special version of the collector for tracing storage leaks; typically, the collector does a better job than programmers."

    Here's an even earlier reference from 1984 to a garbage collector for C, in a paper by Bjarne Stroustrup.

    Newsgroups: net.lang.c
    From: mark@umcp-cs.UUCP
    Date: Sat, 2-Jun-84 21:37:41 EDT
    Local: Sat, Jun 2 1984 6:37 pm
    Subject: garbage collection in C

    A footnote on page 11 of the AT&T Bell Labs Memo 109 entitled Data Abstraction in C, by Bjarne Stroustrup, says that a garbage collector version of the malloc function exists. Any one else ever heard of this? Know where I can get one?

    --
    Spoken: Mark Weiser ARPA: mark@maryland
    CSNet: mark@umcp-cs UUCP: {seismo,allegra}!umcp-cs!mark

    -Don

    --
    Take a look and feel free: http://www.PieMenu.com
  199. You Never Get a Second Chance by jalefkowit · · Score: 1

    I'm not a hard-core Java or C programmer, myself, so maybe there are fine technical details that I'm not privy to. But it seems to me that the primary lesson of the "Java is slow legend" is that proves the truth of the old saying:

    You never get a second chance to make a first impression.

    When Java first came out in the mid-90s, programs written in it ran sloooowly. This was especially true for the types of client-facing programs that people would notice were written in Java (things like applets).

    Today the JVM has been massively improved, hardware has gotten a couple of orders of magnitude faster, and Java programs aren't slow anymore. But people still think "Java == slow".

    Why? Because that was their first impression of Java. And it will take many years of contrary experience to overcome the power of that first impression.

    From my layman's point of view, Java has really only seemed to be adequate performance-wise for a few years now (I remember Eclipse being the first Java app I saw that really felt as snappy as a native app, and it launched in what, 2001?). So a lot of people still probably have a lot of hours they need to log working with modern Java apps before the "myth" gets completely dispelled...

  200. Re:Counter arguments by Anonymous Coward · · Score: 0
    You double click the icon, the splash screen pops right up. We even had to add a sleep timer in there so that it would be guaranteed to stay up long enough for the user to see it.

    I'm sick of apps that show splash screen for 3 seconds or more. And programmers who insert timing delays so I can admire that fucking splash for the 1000th time should be shot...in the face.

  201. Shifting the burden by Anonymous Coward · · Score: 0

    "The common code path for new Object() in HotSpot 1.4.2 and later is approximately 10 machine instructions"

    While that sounds very good, they don't add that there is overhead introduced in the form of reference tracking in managed-style languages. When each variable loses scope, its reference count is decremented. That operation, while not hugely impactful, is not entirely free. It takes at least a single testandset instruction. So if you are managing a large number of references to that object, you are shifting the burden to other places in the code.

    Nothing is free... you don't get 'bytecode portability' for free over native instructions. You can't compare a managed memory model new to a unmanaged memory model new because they aren't doing the same thing. You also can't compare program environments without also measuring startup and shutdown time.

    The bottom line for Java and CSharp is that byte code doesn't come for free...and modern C/C++ developers use object pools, not malloc/free. You might new an object quicker in Java, but if you compare overall execution times the extra cycles shake out in other places. But to compare an object oriented allocator to a general purpose byte allocator is a bit silly.

    Just remember...if bytecode were the fastest way to execute instructions on the processor, the processor would work with bytecode. But modern JVM's convert bytecode into native instructions, so they'll always be behind in performance no matter how optimized their memory management. Yes, simple repeated malloc/frees can be shown to be slow...but thats why concepts like reusable pooled objects came about. Thats why there are about 100 different malloc libraries, each claiming to be the fastest at some memory usage tradeoff.

    I just don't buy the BS that Java is as fast as native languages...even in memory management. If java can manage its memory quickly, so can I. Java isn't written in Java, now is it?

  202. Re:Counter arguments by Com2Kid · · Score: 1

    Holy shit you're funny.

    Did you seriously miss the irony of what you just said?

    How dare programmers make me.. umm.. what's the word? "Upgrade" my hardware?

    So memory is a religious point of conservation, but you're probably pissed that you can't afford that new 4000+ AMD-64x2????????? w.t.f?


    I'm more pissed that programmers can't figure out how to display a few widgets on my screen without needing 700mhz+ of CPU power to render them!

    Look at program features vs code size, it is NOT an even balance at all. Heck MS had that problem with Office XP, minimal new feature set, HUGE performance drop. Oops. Thankfully they cleaned their code up and released Office 2003.

    As for bugs, maybe if programmers didn't suck so much arse now days... you know, if they were made to actually think about their code rather than using the compiler as a debugger...

    When trying to squeeze every last byte (or bit!) of efficiency out of a code segment, that chunk of code is going to be looked over far more carefully than some OO class that is written once than just instantiated by people ever-after. More time is going to be spent thinking about the algorithms in use, how do they work, how reliable are they.

    There is a reason why the old mainframes were trusted to run so many facets of our lives, but so few (technical or non-technical types) are willing to trust modern OSs to run things like, say, airplanes.

    There was also a reason that Ada was used for a lot of aircraft programming, it is HORRIBLE for the programmer to use it, very very painful. Declaring a pointer to a variable takes 3 lines of code! (well you can squeeze it into two IIRC), compare this to the C derived languages, where, excepting Java, you have pointers sometimes with just one character.

    Implementing polymorphic objects in it is a pain, it made you think about exactly what you were doing VERY carefully, heck everything about Ada was like that.

    So of course the programming community killed it, after all, who wants to program in a language that is just "safe"?

    Then again I don't have much room to stand here, my favorite language is C, specifically because the compiler lets me pass darn nearly anything in as valid code (so long as the braces match up and I got the semicolons in place... :) )

    Programmers have lost sight of eloquence; tell me, why are you programming something in 100 megs when it could take, umm, A FEW HUNDRED KILOBYTES.

    Are modern programmers (myself included....) so bad that we need literally hundreds of megabytes of overhead to protect our dumb ass's from ourselves? Are we so out of touch with the machines we proclaim dominance over (or at least a good working relationship with) that we need to abstract ourselves 838,860,800 Bits away from our machines?
  203. Have you ever read the docs on System.gc? by ikewillis · · Score: 1
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ System.html

    Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse.

    You really have to love languages where a invocation "suggests" that the method "expend effort"

    When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.

    Good effort! You did your best, son! Good hussle out there. It's too bad you're still gobbling up 100MB of RAM, but don't worry tiger, we'll get 'em next time.

  204. GUI by Mark_MF-WN · · Score: 1

    The GUI is the one big problem with Java. Swing is a dog, despite being a considerable improvement over AWT (which is a dessicated undead dog from the paleozoic). Azureus is pretty good in general for the simple reason that it is very minimalistic with the GUI. It keeps things simple, and so it doesn't suffer.

  205. Re:Counter arguments by Decaff · · Score: 1

    Don't forget he's talking about java 1.4 and you're talking about java 1.5. One of the design features of 1.5 was to have the startup process pre-JIT'd specific to a target platform

    There is no pre-JITing as far as I can tell from the documentation. The reason for the faster start-up is that system classes are cached (not compiled) in a way that allows much faster loading.

    I tried the same tomcat startup on Java 1.4.2_04. Instead of 5 seconds (for 1.5.0) it took 7.

  206. Azureus doesn't use Swing by Anonymous Coward · · Score: 0

    it uses SWT.

  207. Um... by warrax_666 · · Score: 1

    JIT compiles the Java bytecode to native machine code -- which is, at least theoretically, potentially faster code than a C or C++ compiler can generate because it has more information. Sure, you could say that you could just implement a JVM/JIT on top of C/C++ for every program you write and get the same performance, but that's just silly.

    --
    HAND.
    1. Re:Um... by Secret+Rabbit · · Score: 1

      From what I read, we are talking about JVM (Java Virtual Machine). So, some java code gets compiled to byte code, which in turn gets run in a VM written and C/C++ (or some such).

      And you're going to have to enlighten us as to how compiling one language to machine code is faster than another language to machine code. Because of more information? What info are you talking about?

      Because from where I sit, that's just crazy talk.

    2. Re:Um... by warrax_666 · · Score: 1

      Extra information = loads of profiling information which can only be collected at runtime. (Yeah, I know... you can also profile C programs and use profiles to generate better code. However, this does not take memory allocation patterns and such into account).

      --
      HAND.
  208. Re:So why are all websites running Java slow as he by Anonymous Coward · · Score: 0

    Google IS running Java VMs. Java powers Gmail and Blogger, for example.

  209. Re:Those are not the laws of optimization I learne by phantomfive · · Score: 1

    Those rules seem inflexible to me, and sound like rules a professor would tell his students when he is tired of reading their unreadable attempts at optimization. Optimization is really useful if you need your program to go faster. Of course, if you don't know how to optimize, you will have trouble. Here is a very good page by Paul Hsieh about optimization:

    http://www.azillionmonkeys.com/qed/optimize.html

    --
    Qxe4
  210. What is the problem? by 2901 · · Score: 1
    Single inheritance solves the problem of inheritance ambiguity between parent classes.

    I don't see the problem

    Suppose I have a class name and I create a subclass place-name by adding a slot for a location. Meanwhile I need colours, both for my paints and my objects so I create a colour. Finally a create a class coloured-place-namefor named things in that are put in places and have colours, by multiple-inheritance, taking first place-name and then colour.

    At this point I have an inheritance ambiguity. Obviously place-name comes first, but what next, name or colour? What I don't see is why I should care.

    It is only going to matter if I have a method, act, defined for both name and colour. But how could that happen? I'm only using multiple inheritance because all three of place-name,coloured-place-name, and colour make sense. If only two of them made sense I would use single inheritance. So the meanings of act on the two classes are orthogonal, I don't want one shadowing the other.

    We really have a name clash, and need to sort out our names. Perhaps act on name should be speak, and act on colour should be paint

    OK the inheritance graph isn't totally ordered, but each method is only defined on a subset and, for any particular method, its subset will be totally ordered. So I cannot see a problem that actually matters in practice

    1. Re:What is the problem? by Anonymous Coward · · Score: 0

      If you're "mixing" classes that are orthogonal functionality-wise, you don't have a problem. However, consider class hierarchy

      A -> B
      A -> C
      B -> D
      C -> D

      (where -> means "is a parent class of").

      With the addition of the D class the semantics of the access to A's member variables can become very messy indeed.

    2. Re:What is the problem? by 2901 · · Score: 1

      I'm still not seeing any problem. I've tried making some classes as you describe

      CL-USER(1): (defclass a ()((one :accessor one :initarg :one)))
      CL-USER(2): (defclass b (a)((two :accessor two :initarg :two)))
      CL-USER(3): (defclass c (a)((three :accessor three :initarg :three)))
      CL-USER(4): (defclass d (b c)((four :accessor four :initarg :four)))
      CL-USER(5): (defvar o (make-instance 'd :one 1 :two 2 :three 3 :four 4))
      O
      CL-USER(6): (describe o)
      #<D @ #x1048d852> is an instance of #<STANDARD-CLASS D>:
        The following slots have :INSTANCE allocation:
          ONE 1
          THREE 3
          TWO 2
          FOUR 4

      but I'm not seeing why there is any difficulty. Look at the calculation of the class precedence list. The order must be D B C because that is the order they come in the definition of class D. The only question is "where does A go?". But (defclass C (A) ...) says that A must come after C. The list can only be D B C A. It is totally ordered by the constraints that are explicit in the class definitions.

      The only difference from single-inheritance is that B doesn't get slots from C.

  211. Re:Java designed for humans, not performance. by Mutatis+Mutandis · · Score: 1

    We have never encountered many problems with JNI interfaces, perhaps simply because we choose to keep this kind of interface as simple as possible and do not actually do it that often. Certainly I find it much less troublesome and time-consuming to generate and test a JNI interface than most others; although that may be largely down to experience.

    I remember that we once had one server-side JNI call we had enormous trouble with, making us try all kinds of ways around it, including testing three or four different VMs. Some were indeed more stable than others, but we finally discovered that it was our own fault because our JNI implementation had a bug in its memory management. We fixed that and the system became capable of running for indefinite time (i.e. until the hardware fails or we have a power cut) without human intervention, one any Sun JRE after 1.3. Actually, I recently saw that it still has an UTF string release bug in it, but apparently this doesn't cause any trouble (yet).

    Sometimes the system architecture calls for layering multiple interfaces -- as in PL/SQL calling Java calling C++ -- and that can be tricky, because you have to respect all the different 'boundary conditions'. But on the whole JNI is much better than some other interfacing technologies I have seen; especially the ones designed for specific systems.

  212. Re:Allocating all my RAM is fast, but it's not nic by 6*7 · · Score: 1

    I totally agree, someone should really rewrite Firefox. I have no idea what it is written in now but it really sounds like that java you mention.

  213. Re:Java designed for humans, not performance. by Mutatis+Mutandis · · Score: 1

    An additional comment: One reason I like to work in Java is that some of my software is single-user software in the most literal sense: There is one person using them, besides myself.

    Writing 15,000 lines of fairly complicated code for a single user, or four times as much for a dozen users, can make sense; although probably most software companies would disagree. However, I naturally want to do it in a language that offers rich libraries and is easy to troubleshoot. Java fits the bill almost perfectly; in many other languages I would be spending twice as much time on the same project.

    I can perfectly understand that people who write application servers for eBay, or office applications for an user base of millions, feel that Java is not the best choice for it. However, the economics of that are entirely different.

    I think that if you have to write an application that is too complicated or demanding for a script language, but also need to keep the investment in time and resources down, Java, mixed with a little C++ where necessary, is close to ideal. Before Java, I used a mix of Tcl/Tk and C++, and that was OK, but not great.

  214. Bwahaha! by cow-orker · · Score: 1

    In Java, the auto garbage collection is as good as Perl's

    It's just that Perl doesn't have GC, but shoddy reference counting, which is easily confused by cyclic references. If Java is as "good" as Perl there, that's not the best of advertisements.

  215. Stack allocation is free and always faster by Anonymous Coward · · Score: 0

    Your stack pointer in inside the chip in a special dedicated register.
    When a function is called it's stack frame is created to store the return address and storage for any registers that will be changed. It is allocated by simply subtracting a number from the stack register.
    Since its always allocated and always freed, to allocate some space for your automatics costs zero cycles - you simply subtract a bigger number from the stack pointer register.

    When you have something on a stack frame it is referenced using the stack pointer, so for example

    int foo()
    {
      int y = 100;

    }

    The variable y is actually some offset plus the stack pointer, the offset is coded into the program instruction because it is fixed.
    For example it may be the variable y will be something like (4+sp) and int y=100, becomes a "move 100 -> 4+sp".

    Notice that you did not need to store the address of the block, because the variable is always at a fixed offset from the stack pointer.
    Now consider the case of an allocated block, the address of that block has to be stored somewhere, normally IN THE STACK FRAME! Even if you made a really small program and the compiler was able to keep it in a register, because the register isn't dedicated to the purpose, the compiler would still have to save and restore it as part of the function entry.

    Please step back from your position and see that your position is incorrect.

    1. Re:Stack allocation is free and always faster by gvc · · Score: 1

      Mr. Coward, you are an idiot.

      If you implement procedures with a stack, the incremental cost of putting additional variables on the stack is small. But that stack allocation is not "for free" and we are talking about abandoning stack allocation in favour of heap allocation.

      You have replaced your magical mystical compiler with magical mystical hardware that gives you something for nothing. Not so. A hardware stack simply does some computations under the covers. You can use those same computations to allocate heap storage. Whereas with stack allocation you need a call and a ret instruction for every call, you only need the call instruction with heap allocation. You bank all the savings from not doing all those rets and the savings pay for the collection.

      I'm not going to bother to respond further. Believe what you want to believe.

    2. Re:Stack allocation is free and always faster by Anonymous Coward · · Score: 0

      "If you implement procedures with a stack, the incremental cost of putting additional variables on the stack is small."

      Not small, free, the incremental cost is free.

      Whether the compiler does a 'sub sp,12' and store only its function params & tempories or a 'sub sp,20' and allocates a couple of extra 'ints' or 'sub sp,200' for 50 extra ints, for your function aswell, it takes the same amount of time to do the subtraction.

      "You can use those same computations to allocate heap storage."
      Except you can't because the stack pointer has a dedicate register and so doesn't need to be saved, whereas any register you use to hold the heap address has to be stored and retrieve because its not dedicated. So you would simply end up storing your pointer ON THE STACK in the STACK FRAME.

      "Whereas with stack allocation you need a call and a ret instruction for every call,"

      No, the call and the ret are the result of program flow, suppose I replace the call with a jump instead, a function may be called in many places. Without saving the return address how would the function know where to return to?! The stack is there to solve this problem, there is not equivalent for an upward growing heap.

      "I'm not going to bother to respond further. Believe what you want to believe."
      Feel free to comment, its a while since I wrote a compiler but I'm happy to educate.

    3. Re:Stack allocation is free and always faster by gvc · · Score: 2, Interesting

      I'll try one more time. There is no rule that says the compiler has to translate function calls and return into assembly-language (stack-based) calls and returns. There is a technique, known as continuation passing, in which returns are never used. You may educate yourself by acquiring Appel's book "Compiling with continuations" or by reading Guy Steele's master's thesis or, indeed, by reading the references already given.

    4. Re:Stack allocation is free and always faster by Anonymous Coward · · Score: 0

      Whether the compiler does a 'sub sp,12' and store only its function params & tempories or a 'sub sp,20' and allocates a couple of extra 'ints' or 'sub sp,200' for 50 extra ints, for your function aswell, it takes the same amount of time to do the subtraction.
      The compiler does not need to do 'sub sb,??' at all if it allocates the function frame (including params, temporaries, return location) on the (GCed) heap instead of the stack. Indeed, this is routinely done in languages with first-class closures, where a frame can outlive its function. There's no reason it couldn't be done for C as well.
      (I'm a different Mr. Coward.)

  216. Re:So why are all websites running Java slow as he by JediTrainer · · Score: 1

    Well, let's see. My *bank* (TD Canada Trust) uses it for their online banking. It's never been anything but fast for me.

    I also work on my company's team developing our online applications, all in Java on the server side. Whenever we'd had a performance issue, it'd been traced to bad code, not the JVM. But our modest hardware is supporting users from all over the country, and our customers are the medium-large (+ gov't) businesses, and we have no trouble supporting them with this setup. Now we don't use JSP (I vetoed that approach because it doesn't enforce MVC well enough for my liking), but rather a Servlets+Velocity templates approach works well for us.

    --

    You can accomplish anything you set your mind to. The impossible just takes a little longer.
  217. Re:Java designed for humans, not performance. by Mybrid · · Score: 1

    Thanks for your thoughts.

  218. Re:Counter arguments by maraist · · Score: 1

    Programmers have lost sight of eloquence; tell me, why are you programming something in 100 megs when it could take, umm, A FEW HUNDRED KILOBYTES.

    Are modern programmers (myself included....) so bad that we need literally hundreds of megabytes of overhead to protect our dumb ass's from ourselves? Are we so out of touch with the machines we proclaim dominance over (or at least a good working relationship with) that we need to abstract ourselves 838,860,800 Bits away from our machines?


    This is a legitimate question.. The answer is that because anything can pass in "c" for code, it is impossible to validate and anylize the code correctly.. The best you can do is use heuristics. If you have, say a pointer to a function being passed around, and god forbid that you convert it to a void (sym void) or whatever the proper syntax was (I forget).. Then your analysis tools can not extend beyond that point.

    Perl and other symbolic languages have the same problem. C++ is a little better, but you can still write C code in C++, so the tool isn't fool proof.

    Why do I care? Because of the refactoring capabilities of modern programming IDE's. (Eclipse/Idea). I can perform a "safe delete" on a function or variable because the code can be anylized and determine precisely if anybody actually uses it (though reflection/aspected/bytecode-modification does put a tiny wrinkle on that). As a backup, to handle reflective invocations which would cause run-time failure, I can extend the usage-search to include strings in xml files or JSP files. Granted, this doesn't resolve dynamically constructed field names '"get" + methodName'. Renaming classes, renaming methods, renaming variables, fields, etc, are important for refactoring and the migration of code. When you work on large collaborative environments you have two options.. Maintain backward compatibility (explicitly defining cut-off points), or refactoring all code that touches your API. W/ refactoring tools, this is a mouse-click away.

    Moreover, my IDE can tell me if code is garunteed to generate a null pointer.. If nothing in the associated libraries can possibly return a null pointer (determined by literally searching for all sub-classes found in any 3'rd party library and anylizing their byte-code), then the editor knows that an immediate dereference after acquiring a value from a method call is safe.. If not, my IDE highlights the line as a probable error. That is absolutely impossible in a c/binary set of external libraries. Especially shared libraries.

    Now it's technically possible to deploy a Java application w/ a different set of libraries (especially if up upgrade those libraries after compilation), so it's not fool proof. But if you're interfacing w/ 3'rd party libraries you should probably have a rudimentary set of parameter/result validation code. But w/in your own library this technique is very powerful.

    Another incredibly useful tool is hack-removal.. Packages should minimize inter-package communication (and thereby inter-package dependency). W/ Analysis tools you can graphically determine the degree of inter-package relationship. And on a case by case basis determine if the design should be refactorered to remove the reference/dependency/etc. Ideally you shouldn't have bi-directional dependency. As you're coding, it's entirely likely that you'll make these bidirectional associations out of convinience or lack of consideration. But a post-facto code analysis is instrumental in weeding out these bad design issues.

    While this is possible to a certain degree in C, and a larger degree in C++, it is hard to do, and I've found few tools that do this in a reasonable manner. "source_navigator" by RedHat was ok, but wasn't very easy to use (at least w/ my editors of choice).

    The key is that "it compiles ship it" is less of a joke in Java than almost any other language. And THIS is why companies make use of Java for enterprise applications.

    --
    -Michael
  219. Re:Counter arguments by aled · · Score: 1

    But not significantly so that most people that today uses Java feels any need to leave for C#, unless it's a very personal preference.

    --

    "I think this line is mostly filler"
  220. Re:Counter arguments by EvanED · · Score: 1

    Look at java's "toString" function.. It's identical in inception to a 1'st class operator

    Um, except for the whole operator part.

    Something defined for all objects and can be overloaded

    Operators needn't be defined for all objects. In C++,
    vector<int> a, b;
    a = a + b

    doesn't work. That's because + isn't defined on vectors.

    Java could have had operator overloading if they merely implemented in the Object class something called Object.add(Object o);

    No, then there'd be a method called add. Java could have had operator overloading if you could write a + b if a had an add method that could take b as a parameter. You should review what operator overloading is. It provides an alternate syntax for method calls; a + b gets translated to a.operator+(b). (Assuming operator+ is a member function and not a free function yadda yadda yadda.)

    You could easily create a base interface for all your worker objects. interface Mathable { E add(E); E sub(E); ... } Then you'd have identical functionality to operator overloading ...except for the whole operator overloading bit. Again, review above. Operator overloading would let me write
    Complex a, b, c; ...
    a = b + c;


    The bottom line:
    Operator overloading is a tool. It can be misused. There's even a proposal before the C++0x standard committee to allow the following:
    vector<int> v;
    v += 1, 2, 3;

    to add 1 2 and 3 to the vector. This is (IMO) an abuse of OO. It doesn't make sense. Your example of giving generic widgets an add method doesn't make sense. So it shouldn't be done.

    But if I'm writing a complex number class, or a rational number class, I sure as heck would like to be able to say a + b instead of a.add(b), especially as the latter to me seems more like a += b than returning the sum without a side effect.

    It also allows a lot of other nice things. I'm a fan of cout in C++. I think cout << a << b; is a lot more readable than out.print(a); out.print(b);. You can't write an equivalent to printf in Java because you can't have a variable length parameter list.

    Finally, admittedly, operator overloading in Java would be little more than syntactic sugar. However, in C++ it's very important to generic programming. Operator overloading allows you to write, for instance, the valarray template class so that it will work with any data type. Or std::max:
    template <typename T>
    T max(T const & a, T const & b)
    {
          return ( a>b ? a : b);
    }

    Without operator overloading, you could write that and have it work for primitive types but not classes or you could replace the > with a method call and have it work for class types but not primitives, but you couldn't have it both ways.

    (Actually, that's not true. You could combine the two with some auxilary functions and template total specialization, but does that sound like fun? No way, and you'd wind up with a lot more duplicated code.)

  221. Re:Counter arguments by EvanED · · Score: 1

    You could combine the two with some auxilary functions and template total specialization

    Partial, not total. My bad.

    Oh yeah, and, for instance, VC++ hasn't supported that until the latest version. Good luck writing a proper max function without.

  222. Learn to read. by Some+Random+Username · · Score: 1

    I am talking about all 3 BSDs, complete unix operating systems, kernel and userland. They use CVS to maintain their code, cvs commits are sent to a mailing list so people can see what's going on. I get those messages. Memory leaks are very few and far between, despite development being very active, all the time.

  223. Or... (closure) by Anonymous Coward · · Score: 0

    Quite frankly I wrote a (thread-safe when necessary) reference counting handle template for C++ and so I don't need a garbage collector in the kind of applications that have non-trivial heap profiles.

    MEANWHILE I have useful destructors instead of "maybe later" finialize methods. Fo _me_ the non-starter feature of java is that I have to reference count manually _on_ _top_ _of_ the garbage collector if I want to have my objects perform end-of-life actions when they move out of reference. In C++ I can put close-and-clean functions in a destructor, in Java I have to manually close the object "when I know it's ready" which is the same amount of work as freeing an allocation "when I know it's ready".

    Tools have to match jobs. I do use Java on occasion, but only for toy-like applications that don't have to survive very long.

    One of my company's (C++) products was written solely by myself (to version 1.1, then was handed over to a maintainer and feature crew) has multi-month runtime requirements that it meets quite nicely. I put the heap issues to rest so early in the development cycle. The application _could_ have been written in java, except the fast recovery (etc) features that a proper distructor give me would have been impossible in Java. In C++ I throw an exception and the stack unwinds and I _KNOW_ with certanty that I wont have to self-contend with any object was abandoned by the unwinding. The destructors were invoked and completed in proper context and in unwinding-order. Java simply _doesn't_ have the ability to do that.

    An example you ask? Create a class that destructively accesses/updates a file at close time (lock files, db-journals, and state maps for instance). Now use a deterministic file naming system, so that thread X uses file name X. Now throw an exception from a point where the file is open, and catch that exception in a scope outside the file object's scope and then re-enter the scope after catching the exception...

    OK, in java you _could_ catch the exception at the scope where the file was allocated, close the file, and then re-throw the exception. But then you need to do the same thing for each scope-of-object for each object that is dependent on the file. Which will only work if you refrain from building complex object-structures on the heap (q.v. trees, etc). Well unless you... (recurse as necessary)...

    A reference counted handle object with proper destructors will traverse complex heap structures in depth first order, so objects can be written in closure (see "invariants" in OOD). Java finialize behavior only works in breadth first order, so the objects can and do not have closure without the programmer doing manual recursive cleanups.

    So the garbage collection time can be as fast as you please but there are a non-trivial set of programs that simply will not function in java without paying the "clean up cost" twice. Once by hand, and once again to discard the memory. The cost is paid in complexity and dependence resolution, none of which is "easier" than heap management and all of which requires the same attention to, and possesses the same semantic pitfalls as, faulty heap management.

    Software, and by extension, languages that help you when you _don't_ want the help are (IMHO) more harmful than languages that don't help you when you do.

    It's "better" to have an additive environment, where you put in the features you want and need, then a subtractive environment where you ignore the features you don't need and _hope_ that they don't do you harm. (q.v. every object in java is a mutex but if you dont need it to be the execution environment... what exactly? just pretends it isn't?)

  224. Re:Counter arguments by aled · · Score: 1

    Not that much! remember, baby steps.

    --

    "I think this line is mostly filler"
  225. Re:Counter arguments by Com2Kid · · Score: 1

    Thank you, that makes a lot more sense than "because we want to and it is easier for us", the excuse I hear so often from so many programmers.

    If I am understanding correctly (realize that Universities don't even seem to go into JUnit and such, there seems to be some sorta of stigma attached to practical learning. ;) ), this mostly applies for cases when you do not have the original source code correct?

  226. P.S.... the parent AC was me by IBitOBear · · Score: 1

    But I was having login problems at work...

    ah, technology... /sigh

    --
    Innocent people shouldn't be forced to pay for inferior software development.
    --"Code Complete" Microsoft Press
  227. Re:Counter arguments by sulam · · Score: 1

    It's certainly older than my Athlon 4800+, and it's older than G5's they sell today. I didn't say "old", I said "older." English, whadda language!

  228. Re:Counter arguments by Money+for+Nothin' · · Score: 1

    It's certainly older than my Athlon 4800+, and it's older than G5's they sell today.

    True.

    I didn't say "old", I said "older." English, whadda language!


    No, you said "older". Go re-read:

    I can go from Tomcat not running to it being completely started up and serving requests in 4s on my PC, and 11s on my older G5.

    (emphasis mine)

    What a language indeed!
  229. Re:Counter arguments by maraist · · Score: 1

    Um, except for the whole operator part.
    Operators are pure syntactic sugar. There are an enormous number of meta-languages around java; bean-sh, groovy and others which alter the syntactic sugar.
    Moreoever, Java has demonstrated that best-practices eventually get syntactic sugar enhancements in later versions.
    Look at auto-boxing, for example.
    Integer bar(..) { .. }
    int foo(..) { return bar(..); }
    int Integer are auto converted as pure syntactic sugar.
    So now
    Map map;
    map.put(1 + map.get(key));
    is feasible (increment value in map).
    To favor your point and disfavor mine, "toString" IS an operator in Java.. Namely it overloads the "+" symbol.
    Integer i;
    Bar b;
    String s;
    File f;
    return s + i + b + f;
    This is syntactic sugar for:
    return new StringBuffer().append(s).append(i).append(b.toStri ng()).append(f.toString()).toString();
    Probably just calls toString on s and i as well; it's compiler specific.
    ---
    The point is that operators are visual queues.. They can be nice, but they have to be balanced against abuse.
    Java specifically looked at the level of operator overloading available to C++ and decided against them, with the one exception of defining the plus operator.
    No, then there'd be a method called add.
    Again, syntactic sugar. Functionally identical. The two forms of operation are dramatically different:
    printf("[%i]\n", val);
    cout.print(val.toString());
    But the latter is functionally identical to "cout I sure as heck would like to be able to say a + b instead of a.add(b), especially as the latter to me seems more like a += b than returning the sum without a side effect.
    Agreed. Java isn't very consistent in it's core API method naming conventions. map.add(.) mutates the object which stringBuffer.add(.) returns an immutable value-object. This is SUNs fault and hasn't been corrected yet. Though Java-Bean specification does a very nice job of this with get/set prefixes though "verb" methods are a mixed bag. Same w/ any language.
    You can't write an equivalent to printf in Java because you can't have a variable length parameter list.
    Sorry, dated.
    System.out.printf("[%i,%s]\n",var1, var2);
    has worked since verion 1.5. In fact you have an i18n version:
    Locale l;
    System.out.printf(l, "%i", var);
    You now have a much more powerful version of the "..." parameter.. Namely type safe:
    void foo(Integer ... args)
    void bar(Foo ... arrgs)
    PLUS the multi-parameter autoboxes arrays, multi-parameters, and collections.
    Integer[] ints;
    foo(ints);
    foo(1,2,new Integer(3));
    Set sints;
    foo(sints);
    all works just fine.
    std::max
    class Util
    {
    public static Number max(Comparable ... comparables)
    {
    if (comparables == null || comparables.length == 0)
    { throw new InvalidArgumentException("empty set"); }
    Comparable maxComparable = comparables[0];
    for (Comparable c : comparables)
    {
    if (maxComparable.compareTo(c) > 0) { maxComparable = c; }
    }
    return maxComparable;
    }
    Done! And thanks to auto-boxing, works with ALL primitives.. And even if it didn't.. If you were doing this in Java 1.4
    Util.max(new Character(c1), new Character(c2));
    Thanks to the foresite of java 1.0, the need for generics has not existed until only recently.. And that was only for type-safety, not for generalization.. Namely all collections take generic Objects.. Something that was severely lacking in C++ (due to multi-inheretance). Any specific capabilities use interfaces or interface markers (like clone or serializable).
    Moreo

    --
    -Michael
  230. Re:Counter arguments by Raven15 · · Score: 1

    We just removed everything on that list that we didn't need. I think the only thing we kept was the JCE jar. It all compresses down to about 18MB (Nullsoft installer, LZMA compression). Also, you can put any of your jars into jre/lib/ext, and the VM will pick them up automatically without you having to add them to the classpath.

  231. Re:Counter arguments by EvanED · · Score: 1

    Operators are pure syntactic sugar.

    Yes, I know. You'll notice I said that.

    But I'd argue they are an important bit of syntactic sugar for writing nice code. Again, a+b (to me) is A LOT nicer than add(a,b).

    Java isn't very consistent in it's core API method naming conventions. map.add(.) mutates the object which stringBuffer.add(.) returns an immutable value-object. This is SUNs fault and hasn't been corrected yet.

    Not to mention the ways of getting the size of a collection. Collections have a size() method, Strings a length() method, and arrays a length read-only property. Go consistancy!

    Sorry, dated.
    System.out.printf("[%i,%s]\n",var1, var2);
    has worked since verion 1.5


    Very interesting. I don't think I ran into that when I was reading about 1.5. Thanks for the correction.

    (My experience with Java has been exclusively with 1.4. I've now done two projects with it; one was started before Java 5 was released, and one was written for a platform that hasn't yet had the Java 5 SDK ported to it. I have seen some things about 1.5 and have liked what I see, but I wasn't aware of this.)

    Done! And thanks to auto-boxing, works with ALL primitives

    See above with my (lack of) Java 5 experience. I was aware of autoboxing, I just didn't put it together to be used in that way.

    Thanks to the foresite of java 1.0, the need for generics has not existed until only recently

    In what manner? I haven't seen any benefits besides the lack of a need now to cast.

    (And I'd say that it WAS needed before, because having to cast from object on every get or whatever leads to sloppy code and errors that can't be detected until runtime if you screw up the type. It was just that Sun took their time to get the implementation right and probably do higher priority things first.)

    Something that was severely lacking in C++ (due to multi-inheretance)

    Multiple inheritance shouldn't have anything to do with it.

    (Oh, and MI is another thing I miss in Java. I have almost never used it, but when I have it's been a Godsend. I'd have really liked to have had it for my second project; there was one place it would have saved a couple hundred lines at least of duplicated code. (It wouldn't have been a good use from an OO design standpoint, but I'm reminded of the error-handling idiom of using gotos in the Linux kernel. Not good from an acedemic standpoint, but it gives much cleaner code and is good from an engineering standpoint.)

    Any specific capabilities use interfaces or interface markers (like clone or serializable)

    Stuff that C++ mostly doesn't need because of templates.

    Moreover, the Collections is INSANELY useful.. Pretty much providing an open-source hand-book to almost all computer science class problems. The bane to any CISC teacher. sort, binarySearch, shuffle, min,max, reverse and others.

    Most of which is in the STL. The only major thing in Java.Util that's missing (which, admittedly, is a pretty big omission) is a hash table. Other things that are missing (e.g. regular expressions, threads) are available in other free, high quality libraries like Boost. (With a BSD style, not copyleft license.)

    Sorry, my opinion is that Java is one of the most pleasant languages to program in for just about any sized project. I grew up on C++ and C.. Later in perl

    To each his own. I don't really like programming in Java because I feel like the language is boxing me in, preventing me from doing things that I think I should be able to coming from a C++ background.

    It's getting better, but I still prefer C++.

    (I'm not trying to dis you by the way, it really is a personal preference.)

    Similarily, I think the debate over operator overloading comes down to preference. I think the readibility benefits gained outweigh the potential for abuse. You feel that the problems of abuse outweigh the readability benefits. Whatever.

  232. UTF-8 by dolmen.fr · · Score: 1
    ... I've never seen Unicode outside 2 bytes in use...

    Si it's time for you to read about UTF-8:
    • It is the common encoding of Unicode used on Unix/Linux platforms.
    • A variant of UTF-8 is used for the internal representation of strings in the Java Virtual Machine.
    • UTF-8 will be the default encoding of source files for Perl6.

  233. Re:Counter arguments by maraist · · Score: 1

    First I noticed that some of my code was cut-off due to less-thans.. bugger.


    Thanks to the foresite of java 1.0, the need for generics has not existed until only recently

    In what manner? I haven't seen any benefits besides the lack of a need now to cast.


    Well, I admit that Java 1.5 generics was a more of a show than a real implementation. The only thing it does is generate really wierd exceptions when you pull from a generalized class. For example.

    List foo = new ArrayList();
    foo.add(null);
    List bar = foo;
    int 5 = bar.get(0);

    I've scratched my head on that one. Hibernate can return List but contain a single row w/ a null.. So I have to perform
    if (foo == null || foo.get(0) == null) { return 0; }
    return ((Integer)foo.get(0));

    The Collections class has lots of type-checkers, but they ONLY work if you are the one that instantes the collections.. I haven't found any 3'rd party tools which do post-facto validation of type-safety in a collection. I've had to roll my own.

    Other than this specific issue w/ accessing external libraries, I really love the type-safety enforcement w/in my own internal libraries thanks to generics.


    Something that was severely lacking in C++ (due to multi-inheretance)

    Multiple inheritance shouldn't have anything to do with it.


    Shouldn't, but due to performance, does. Perl makes use of hierarchical arrays of package names to implement MI. This can be an analysis nightmare as you have to know the order in which the super-classes were defined (in a subclass) in order to determine which conflicting super method will be invoked. It's also a performance nightmare. Method calls become linear nested traversals of array-lists. Additionally most implementations of OO in Perl make use of a hash-map.. Essentially all fields are virtual (potentially conflicting between alternate class definitions).

    In C++ you have to fiddle w/ virtual inheretance and can't make arbitrary inheretance.. If you get a 3'rd party library, it's possible that you physically can't composite multiple classes (due to collisions and lack of declared virtual inheretance). The requirement to declare a method as virtual is both a positive and negative.. Great for explicit definition of an OO heirarchy, horrible for extending classes beyond what the original author conceived (e.g. 3'rd party libraries). I don't recall if C++ has the equivalent of Java's final modifier.. I've found it to be incredibly frustrating (in terms of preventing prevention of code-reuse). In Java "final" is useless except on 1'st class objects like "String" which have JVM optimizations. A good JVM can determine the "final" attribute at runtime based on whether anything actually overloads the method or not. In C++ such an optimization isn't possible, so there is a serious performance advantage to not declaring a method as virtual. It's the difference between a c-style direct function call and an indirection-table lookup (or two).

    In Java, MI is ommited purely for OO elegance. Thanks to heavy use of interfaces (and runtime optimizations of interfaces into static method invocations where possible) you get all the advantages of MI w/ none of the complexities and limitations. The ONLY thing MI provides (and you correctly pointed out) is the lack of code-reuse. BUT, this is actually a blessing in disguise. Take the following example:

    class BaseWebPage
    {
    Foo utilityA(...);
    Bar utilityB(...);
    abstract void drawPage(...);
    }

    OO here is purely for utilitarian purposes. But how about
    class PageA
    {
    UtilityA utilityA; void setUtilityA(UtilityA ua) { utilityA = ua; }
    UtilityB utilityB; void setUtilityB(UtilityB ub) { utilityB = ub; }
    void drawPage(...) { utilityA.doA(...); utilityB.doB(...); }
    }

    This latter code is MORE OO than the foremore. Here you can swap out what utility A actually is.

    --
    -Michael
  234. C is the problem; Java is not the solution by idlake · · Score: 1

    Yes, you are absolutely right that memory leaks and pointer problems in C suck, and that dealing with them is a colossal waste of time. And Java's garbage collection is, in some ways, better than Perl's.

    However, Java is neither the only, nor the first, nor the best language to offer garbage collection and runtime safety. Java's type system sucks, its implementation of generics is awful, its native code interface is slow and cumbersome, its libraries are bloated and saddled by backwards compatibility issues, and the platform is being designed by huge committees of self-appointed experts.

    Do yourself a favor and use some other language. There are many choices; my personal favorites are Python, C#, and OCaml.

    1. Re:C is the problem; Java is not the solution by Doc+Ruby · · Score: 1

      Python, C#, and OCaml were also designed by committees and self-appointed experts. Who else produces languages?

      I want out of the entire structured lexical programming paradigm. I want to compile flowcharts, zooming in on schema objects until I'm looking at primitives, even if they're lexical. I want to use topological analysis for debugging, optimization, and interface definitions. I want to show the sourcecode to the marketer, and have them able to ask meaningful questions about how it works, by looking at flowcharts. And I want to compile that flowchart all the way down to CPU instructions, or even better, packet networks among FPGA gate arrays. Until we get there, Java and Perl are mostly good enough for me. If I'm switching, I'm switching big, and leaving all that structured lexical behind, for the compiler to worry about.

      --

      --
      make install -not war

    2. Re:C is the problem; Java is not the solution by idlake · · Score: 1

      Python, C#, and OCaml were also designed by [huge committees of self-appointed experts.]

      The "also" is false. The Python, Mono, and OCaml platforms are driven by market choice: some people develop libraries, others choose. That's why there are half a dozen XML libraries for Python, for example, with end users making the choice. For Java, the JCP decides, and when they make a bad choice (as they do more often than not), the Java world is effectively stuck with it; any non-JCP alternative is going to be a second class citizen.

      I want out of the entire structured lexical programming paradigm.

      Have a look at Smalltalk. Even the 1980 version of Smalltalk is still far ahead of Java and Java IDEs. If the industry had unified behind Smalltalk 25 years ago, we'd be much futher along than we are now. Among other things, in Smalltalk, all implementations, all code, and all documentation is always available, there is no separate compilation step, and you can inspect and modify running applications. Also, its syntax encourages highly readable code; even people with no programming experience can generally at least get the gist of what Smalltalk code is doing by reading it.

    3. Re:C is the problem; Java is not the solution by Doc+Ruby · · Score: 1

      I said: "designed by committees and self-appointed experts"

      You quoted me as: "designed by [huge committees of self-appointed experts.]".

      The languages you cited, as you further detailed, were designed either by committes or "experts", or "committes of experts". Misquoting me to suit your argument doesn't support it.

      As for Smalltalk, I've been looking at it since I first read about it in 1980. But it's the lexical part that I want out of, not just the structured programming. I'm tired of describing code paths in human languages which communicate 4D spatiotemporal material phenomena. I want to draw schematics of logical components, using my geometric/topological intuition to specify programs, which can be optimized by the machine. Sure, I want to import all the current lexical code into primitives with IO to the rest of the programs. And I'd love the holy grail of free interconversion between flowchart and text - so I can also reuse lexical tools to improve the flowcharts. But I'm tired of reading so much code, just to decide "where this goes" and "how that can be factored" and "this data is touched by that". And I'm tired of spending time explaining programs to people who can't read the code, like managers, marketers, customers, and the reverse: explaining them to the machine in code I can't check with the people I'm explaining. Smalltalk doesn't do any of that. So I'm still waiting. I'm also working on it, but I'm just one of the many people who haven't delivered it.

      When I get it, I'll stop whining about it - and start whining about something else, like how 3 dimensions isn't enough to model the complexity of some automatable systems. My complaining is NP-complete.

      --

      --
      make install -not war

  235. Re:Counter arguments by EvanED · · Score: 1

    The only thing it does is generate really wierd exceptions when you pull from a generalized class. For example.

    In Java's defense here, I don't see any real way around that. Not allowing you to implicitly cast an Integer to an int breaks the autounboxing bit of sugar, and prohibiting you from putting null in a container is just wrong.

    I'd say that Java has the best option here, with the possible exception that it might be nice to have a little nicer exception type or message.

    In C++ you have to fiddle w/ virtual inheretance and can't make arbitrary inheretance.. If you get a 3'rd party library, it's possible that you physically can't composite multiple classes (due to collisions and lack of declared virtual inheretance).

    Is this what you're talking about:

    struct B1 { int foo() { return 0; } };

    struct B2 { int foo() { return 1; } };

    struct D: public B1, public B2 {};


    Because if it is, that doesn't really present a problem; you just have to specify which foo D should use.

    The requirement to declare a method as virtual is both a positive and negative.. Great for explicit definition of an OO heirarchy

    I think from a pure OO standpoint, I like methods to be implicitly virtual rather than implicitly non-virtual, but that's just me.

    I don't recall if C++ has the equivalent of Java's final modifier

    No, it doesn't.

    But, if you have a class that isn't in a heirarchy of your own, you can go along ways toward preventing effective reuse by making a public, non-virtual constructor. Deriving from such a class can open up a can of worms for anyone who does it without being careful.

    Thanks to heavy use of interfaces ... you get all the advantages ... . The ONLY thing MI provides (and you correctly pointed out) is the lack of code-reuse.

    Seems you contradict yourself there a bit. ;-)

    Also, it can in some sense lead to cleaner code and cleaner design. Look at all the places in Java where there is a class you can extend to get some functionality OR an interface you can use in case you're subclassing something else. Like if you want to make a thread, you can subclass Thread or implement Runnable. If you're writing Swing you can extend DefaultWindowListener or implement WindowListener. (I don't know if those are actual names, but you get the idea.)

    Finally, the prevention of code-reuse can, in some cases, be a decent drawback.

    I think I already mentioned this, but MI prevents you from defining a top-level Object class.

    And again, I don't understand why. You might have to sort out if it inherits virtually or not (though if the object doesn't have state I think that's a meaningless bit anyway!), but I see no reason it can't be done.

    If you want to have a function that accepts any type of data, you are forced to accept a void*.

    In what case would you want to do this? I can only think of two. The first is if you're writing something like the sort of thread start methods you see in some languages where you can pass a void* parameter with information for the thread about what it should do. (Java doesn't do this for threads as you can store stuff in the Thread object's fields beforehand, but such a situation is certainly concievable.) The second is if you were writing something to deal with, say, JavaBeans and were using the reflection API to figure out what the methods are in the object.

    In the former case, Java's method is admittedly a lot superior because it typechecks instead of causing massive explosions. In the latter situation you just flat out can't write something like that in C++ because of the lack of reflection.

    (And reflection is perhaps at the top of my wish list for C++.)

    I'm very confused as to how you could say this.. java.util.Hashtable is a java 1.0 feature.

    Sorry, I worded my original statement pretty poorly. It should have said

  236. Re:Counter arguments by sulam · · Score: 1

    sulam> I didn't say "old", I said "older." English, whadda language! MFN> No, you said "older". Go re-read: Violent agreement? I said I said "older". You quote me saying I said "older." What am I supposed to be disagreeing with? Why are you telling me what I said? ;)

  237. Re:Counter arguments by Money+for+Nothin' · · Score: 1

    Dammit... OK, you got me on that one. :P

    I'm going to go back to preschool and learn to read now...

  238. Ugh. Not this again by Heretik · · Score: 1

    I'm so sick of this recurring "Java is as fast (or faster!) than C++" absolute nonsense. Java is provably slower than C (in other words, Java has overhead as compared to C). Consider an operation X.

    My C++ program, doing operation X, has to perform the following actions, at the machine level:

    X

    An equivalent Java program, doing operation X, must perform the following actions at the machine level:

    **A Bunch Of Stuff**
    X

    The part varies depending on the case. Heck, sometimes it's not even there (JIT and all that). But it is there, and it's not free.

    Honestly, this is the most brutally, painfully, hit-you-over-the-head-with-a-sledgehammer obvious thing ever.

    Yes, a given Java program can be much faster than a given C++ program... a given shell script can be much faster than an assembly program, too.

    Clearly this implies that shell scripts are faster than hand coded assembly! ... if you're an idiot.