- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Have you never used software with logging? With logging turned off, there will be no log. Otherwise they would have just used System.out.println() instead of a logging framework.
Admin
That's just another thing anonymous subroutines are good for:
Perl, for example:
Python can do about the same (untested):Or Ruby:
Admin
The WTF to me has been the attitudes and prejudices regarding performance. Qoute benchmarks, but if you really think worrying about perfromance starightaway rules out Java, you've not done enough lately to deserve staying in the software industry.
Admin
This reminds me of a project I was given, to figure out where it was taking so long.
One of the problems was in fact, a debug statement inside a loop, something innocuous like:
log("message" + object);
The problem was the object had a horribly long operation to convert itself into a string, and inside a tight loop, too!
Admin
The whole whack of HotSpot VM options for tuning are available at http://java.sun.com/docs/hotspot/VMOptions.html and they can all be specified on the command line when starting the VM.
Admin
Why does everyone think this is a premature optimization?? We're just talking about good coding practice. Sure, building a string doesn't use that many clock cycles, but if he can convince his programmers to always do an if(DebugIsEnabled()) as a coding practice, there's no downside to that. Put a trace statement in a for-loop and we're talking a pretty big performance boost.
Where I work, these things are usually inlined something similar to this-
if (trace.isEnabled()) trace.println( ... );
And then for our C++ code the trace function is a macro that always checks if the trace is enabled first, so we don't have to worry about it....
Admin
Here is some more info that I've found very useful: http://java.sun.com/docs/hotspot/gc1.4.2/ and http://www.petefreitag.com/articles/gctuning/
Admin
While premature optimization is the root of all evil, it's premature pessimization that leads to flamewars about it :) Adding thousands of text maniipulations to every level of algorithm no matter how nested and throwing the results away is premature pessimization. The solution (check for trace flag) is obvious, but yea, it warts the code. That's the pain felt from java leaving us no mechanism for late binding of parameters, which can sometimes be done with the C++ preprocessor, but not always. IIRC it's impossible to implement operators &&, ||, and ?: correctly in C++ also because of this same issue.
I can think of a few ways to limit the warting, but they aren't obvious to future coders, eg..
isDebug() && debugLog("log message here");
Admin
Come on now! Any true programmer knows that if you want to keep your servers running fast you need to push everything over to the client side. Drop C/C++ and Java and try using JavaScript or VBScript. You'll be amazed at the reduced load on your core processors.
\Format this!
Admin
The one thing that needs to be talked about in the Java vs C++ discussion when you are talking about the garbage collector, is the delete operator in C++. To delete objects in java it costs (from what I've heard) about 0 system calls since the JVM handles the memory, whereas deleting in C++ takes significantly more since you're married to the hardware. I haven't done any research into that area because premature optimization isn't really something that I care about, but I thought it was interesting, and if anyone else has any information on it that would be quasi interesting to read about.
Admin
Java may have adequete performance, but anytime I use a Java desktop app I groan to myself. The UI insists on looking different and acting funny (not all access keys are implemented, whereas with native controls you get them for free) for no reason. Then there's the GC being lazy about releasing chunks of memory, to the point where people tell me I shouldn't leave Eclipse open after I go home from work because it takes longer to un-minimize the sucker than to simply launch it again the next day.
Admin
Thought your comments on lazy GC are valid, Eclipse is written using SWT, not Swing.
Admin
I'm not sure what kind of benchmark you would accept, but I can show you a hundred thousand Java applets that suck in terms of performance and/or kill the browser.
Admin
Admin
Who the hell uses applets? :)
Admin
You do realize that they are either extremely narrow in scope or written by people who are absolutely clueless about C++ and who have a grudge to settle?
Admin
Cute. I suppose you could also create a DebugMessage class and have the expensive stuff in the toString method (anonyouse inner class?) and pass the DebugMessage to the logging framework. Then the if check could be done before calling toString(). Though that brings in other warts though.
One technique that seems to work well is to put the most of the logging in the catch block of an exception. If you find this a problem because it gets called too much or not enough, then you often have a design problem with the code itself.
Admin
After it starts up. Garbage collection is actually quite efficient, and if you add that to a JIT compiler (which the latest Sun JVM are) on a statically typed language (allows more easy optimisations than dynamically typed) and code that compiles well to native, you have performances that can reach at or beyond compiled C++ code level (usually not C level though, and there are languages that are faster than C, SML+the MLTon compiler often is for example).
The memory consumption, on the other hand, is a whole 'nother problem ;)
Admin
I'm not sure if there is a benchmark I would accept, since everyone that invests the time and $ into the research has some vested interest in the results.
I have said many times on this board that Swing/AWT sucks in terms of performance. I don't use them and have seen only 3 applets offered as a product/service in my 8+ year career.
Terrible performance of applets is always the case people make against Java but I assure you, not many companies on this side of the industry use them for any significant product or service offering.
Since this is a non-issue, care to complain about anything in Java with which you are knowledgable?
Admin
Could you please refer me to the paragraph in the C++ standard that says that C++ is statically compiled to native code?
Admin
I'm not a fan of Eclipse myself. And I have to admit that most Java GUIs aren't too hot. I develop middleware applications, so it isn't an issue for me. I ought to download Eclipse some day and see if I can tune the JVM to make the GUI perform respectably.
Anyway, real men don't use fancy schmancy IDEs. Real men use vim to code and to write their ant scripts, then run the whole thing from the command line.
Admin
If dynamically compiled code is faster in this regard, it's typically because the statically compiling guys don't know what to do with a profiler.
Admin
I pondered the same question.... Generally when I think of a high performance, hardware taxing application (not for servers) I think of 3D games. Maybe it has to do with the libraries available, but I don't hear much about the next hot first-person-shooter being developed in Java.
Admin
Could you please refer me to a C++ implementation in common use which is not?
Admin
Hmmm, Alexis, I never would have taken you for a conspiracy theorist. See my earlier post....I have yet to see a benchmark that wasn't slanted one way or the other. What's worse is the morons here, most of which likely have never read one, passing judgement regardless of whether they know anything about the "other language".
Admin
Yeah I agree...I prefer to waste time doing all the things in VIM that an IDE can do for me. Like refactoring, automatic compilation as I type, automatic package importing...etc.
Admin
Isn't that syntactic sugar for:
log(LogLevel.INFO, new Object() { public String toString() { return expensiveStringMakingCall();}
That being said, syntactic sugar is sometimes a good thing and this may be one of those times.
Admin
Neither C++ nor Java issues a syscall for every deallocation. A thoroughly brain-dead implementation of either might, but I'm not aware of any.
Admin
<sarcasm>
You are all missing the point. The real WTF is that they are using a high level language at all. Everyone knows if an application is coded in assembly it will positively scream.
</sarcasm>
Admin
Care to explain why application start-up times aren't relevant for performance? As a command-line freak I beg to differ.
PS: Ad hominems won't buy you much in this discussion.
Admin
Let me put it like this - my work computer isn't the fastest one in the world, but besides taking it's time to start up, the GUI works perfectly, and as far as I'm concerned works even better than that Visual Studio .Net crap that I'm forced to use from time to time.
But that's just me...
Admin
With the proper VM, you will have incredibly fast startup times, godly memory management, rock-solid stability, lightning fast performance rivaling the best hand-tuned ASM code. You just need to find the right VM.[:D]
Admin
There is more to it than that. The optimizations might be different for a Pentium, a Power, or a Sparc chip. Furthermore the optimizations may be different for, say, a Pentium 4, a Xeon, an Opteron, and an AthlonXP. And the optimizations can even be tweaked for each model in each family. The dynamically compiled code can take advantage of this. The guys with profilers typically won't tweak for every conceivable chip model. The dynamically compiled code can.
This is the same argument that was fought 15 years ago when optimizing compilers started coming out. A wizard could always write something a little faster than the compiler, but at what cost? There aren't that many wizards around and when you have one you usually want him working on something more that squeezing a few percent of performance out of something. Optimizing compilers allowed good competent programmers to write code that executed very nearly as well as a wizard's.
A real wizard using C or C++ will pretty much always be able to write something better than Java. But why, and at what cost? Realisticly, for a wide class of applications (typically long running server apps), a good competent team using Java will be able to develop better applications than a similarly talented team using C++. If performance is the final word then we'd all be writing assembly. We're not because programmer productivity and time to market is important too.
Admin
Eclipse isn't bad but VS .NET isn't bad either. You Java fan boys have to remember that some of us started using Java IDEs for serious projects way before Eclipse was around and it left a real bad taste in our mouths.
Admin
I didn't say it wasn't relevant. My problem with Java is that you're forced to take Swing, even if you don't use it. Slow classloading and start-up time is the result. They continue to add more sub-par apis (e.g. logging) to the core language and it becomes bloated. I'm a huge proponent of modularizing the language, as it used to be, so I can pick and choose what is loaded at start-up time.
That's your problem, not Java's. If you're a Java developer, chances are you're not a command line freak, since most shops make use of widely available development tools.
It wasn't an ad hominem, and I gather that your argument is ad hominem for the language of your choice (C++?). Your initial argument about Java (applets) happens to be a seldom used feature/defect. If you have any legitimate issues with Java, let's hear them.
Admin
I've read and performed some benchmarks comparing various C++ and Java implementations, and in most of them, C++ was slightly to dramatically faster (though D won some ahead of both others) even when taking JVM startup time into account. The others were typically biased against C++ by means of utter cluelessness (e.g. strdup'ing a string only to discard the result), whether malicious or not.
There are numerous theoretical reasons why C++ cannot be slower than Java in certain respects, not the least of which being that everything the JVM does can be done in C++ as well. Java implementations have become surprisingly fast given that at one time they executed many programs dozens of times slower than equivalent C++ programs, but Java still is almost never faster than a good C++ program run through a state of the art compiler, as some people like to claim (on this board and elsewhere). It's simply a myth. There are many good reasons to use Java for long-running applications, and even some short-running applications if you're smart enough to use GCJ for that purpose instead of that JVM bloatware. But, sorry, "because it's faster than C++" just isn't among.
BTW, I've used both languages extensively, in numerous implementations, so it must be someone else you are talking about in the last sentence.
Admin
We're using C++ with garbage collection, thank you. C++ certainly is not my first choice for a language, but with suitable libraries it can be fairly nice (nice, not safe).
Selecting software developers by the languages they know is like selecting mechanics by asking whether they use a 1/8" wrench or 3/8" wrench. One should choose the tools (i.e. the language) according to the problem.
Admin
For the record, I wasn't grouping you with the morons. It was a general statement.
Admin
Amen. If I told one of my developers not to concatenate strings because she's wasting clock cycles, I'd expect a knife in my belly. I'd rather work help desk than tap code for someone like Josh...
Admin
That's not true at all. If you know how to use a specific type of wrench, you can learn how to use a different type within a split second. The same is not true for programming languages. You cannot make an immediate and/or sognificant contribution to a Perl application if you're expert only in C++. I'd venture a guess that you were denied a job at some point because you didn't know a specific language........but you know other languages and you're a "quick learner."
Admin
Ok, they typically won't (most C++ programmers probably don't even use a profiler regularily). But they could. You can make an installation disc with different binaries depending on the processor model. Virtually nobody does, but it can be done. I was more interested in pointing out that the theoretical advantage of dynamic compilation over static compilation with profiling information is smaller than some assert. The practical advantage is much larger because almost no one wants to jump through these hoops just to get the last few percents of performance out of his/her statically compiled app. Gentoo users notwithstanding.
I strongly suspect that, if application start-up times are taken into account, dynamic compilation that occurs every time the program is run is inferior to properly performed static compilation with realistic profiling information, or dynamic compilation that includes a caching scheme. I don't quite buy the argument that dynamical compilation is by necessity superior since it can handle differences in execution behavior that occur per application run. This is because
a) Most often the execution behavior doesn't change a lot
and
b) If it does, it also changes per execution of a given function, which is too fine-grained even for dynamic compilers.
I agree 100%. A lot of relatively simple code takes too long to write in C++, mostly because of the source code model which is still based on translation units, and too long to debug because C++ not only offers many more ways to solve a problem, but also many more ways to shoot yourself in the foot.
Admin
Have you never used a program with log levels? The debug message is printed at level "debug", and the "debugging is disabled" message is printed at level "info". IIRC, "debug" is normally the more verbose of the two, so presumably if the maximum log level is set to "info" you'd get a load of messages saying that no message has been printed in the log...
Admin
Real Men collect their own garbage. :) Anyway, real men code in binary.
Admin
Even more to the point: Real Men do:
copy con program.zip
'nuff said!
Admin
You're goddamned right you weren't. Otherwise he will bust your face in! He knows karater after all.
Sincerely,
Richard Nixon
Admin
Nice reach, asshole.
Admin
Haha, that's f*ckin funny!
Admin
He wasn't talking about software in general. He was talking about this particular WTF.
To be precise, he was pointing out that either logInfo() is going to fill up the disk
or it won't do anything . . . in either case, why call it?
ok
dpm
Admin
disclaimer: I'm not saying anything about the validity of other statements made here
I'm just adding the info that in the case of our workplace - our code only ever runs on our own server so we only ever have to optimise to our own chip. We run a combination of Java and C (they don't interact with one another) and I've already tried submitting some of the horrendous code to this site... but anyway.
OOC is there a code profiler available for C? I'd love to run some of our crud through it...
Admin
I apologize for being late to the Java/C/C++ war, but I have to respond to that earliest of comments, as quoted above.
Push everything onto the stack in order to run the function ???? WTF? Just where do you think "everything" is sitting, that it's going to be pushed onto the stack when you make a function call? Are you talking about saving all the register contents?
Here's a hint: if your compiler doesn't "inform" calling applications what registers get modified in a procedure call (thereby limiting the list of registers that need to be saved before making the call), you need to get a better compiler.
And readjusting the stack pointer (once in each direction), loading a register from a memory location, and executing a branch isn't nearly as expensive as even looking up the length of a string to be concatenated.
As for the Java/C/C++ war, the question is this: how fast is the CPU that you're running on, that the performance difference between today's Java and today's alternative languages are making the difference between success and failure for you? How fast was the CPU when you started the project? How fast is your memory? Your I/O? Do you even know where your performance boundaries actually are?