“By now, Windows and Unix are functionally more similar than different. They both support the same major programming metaphors, from command lines to GUIs to web servers; they are organized around virtually the same panoply of system resources, from nearly identical file systems to memory to sockets and processes and threads. There’s not much about the core set of services provided by each operating system to limit the kinds of applications you can create. What’s left is cultural differences.” Read the article by JoelOnSoftware.
“You should move your programs to Java because the Win32API is only going to be narrowly accessible in Longhorn. There have been numerous articles on this already here on OSNews. The API will only be about 20% of what it was in XP.”
I am moving towards Java. It makes more sense for me because I can a lot more done in the same amount of time. It also allows me to be ready to switch platforms if I have to. (Like I said, there’s a real possibility that Linux could take root in my field).
The main reason I haven’t used Java in the past is because of budget constraints, we often use some pretty antiquated hardware, and Java simply didn’t run well on it. But the hardware was so antiquiated, that we have pretty much been forced to upgrade. So Java performance isn’t a big issue anymore.
“You should move your programs to Java because the Win32API is only going to be narrowly accessible in Longhorn.”
Java is not the only option. wxWindows and Qt are both very nice, cross-platform toolkits that have bindings to several languages. Qt, for example, only needs a limited number of functions from the win32 api and they will do anything they can to make sure their stuff will work on Longhorn.
And there is no way MS would make this impossible, because that would also make 99% of all current software obsolete which would cost them a *lot* of customers.
I am getting more and more convinced that the future is not .net and not java, too. I think the future is cross-platform toolkits written in C++ with bindings to several languages like python, which will make the whole OS issue basically irrelevant.
Oh, as for 28 header files? Its called modularity!
Not really, the C library still globs all the code together that assorted headers provide an interface to. While breaking the headers apart may speed up compile times, they can create a large headache for both programmers and software users. One notable example is all Dan Bernstein software such as qmail 1.03, whose standard distribution doesn’t build on modern Linux systems because it fails to include errno.h
Modularity means something that is *not* like Windows’s giant “windows.h” POS. Windows is the only system I’ve seen that does something that stupid in its API.
I now begin to wonder why I’m responding to this post, as clearly you have some very misconceived ideas about programming. The only disadvantage to placing everything in a single header file is the time required for the compiler to parse it every time.
Oh, and if you’re having trouble finding something in the UNIX API, you call “man <symbol>”. Way easier than digging around in a single giant header file.
Why would Windows programmers dig around windows.h when there’s http://msdn.microsoft.com ?
“Qt, for example, only needs a limited number of functions from the win32 api and they will do anything they can to make sure their stuff will work on Longhorn.”
Qt isn’t really an option because the Windows version is about $2,000 per license. That’s way out of my price range.
I’ve had problems getting wxWindows to work with mingw, which is the compiler I usually use on Windows. It has to do with getting a ton of error messages in the wxWindows header files about attempts to redefine constants and such. I haven’t figured out what the problem is.
Some open source people want to eliminate closed source, and some closed source companties want to make non Microsoft products illegal.
I think that vendors should be able to charge money and that Linux is only the platform. The idea of having an open source platform means that no single competitor has control over the entire direction of the platform, because than it wouldn’t be a platform, it’s a product like (Solaris, Windows, Mac, etc). So I defend Linux because I want to have a platform there because maybe I want to code in C still or maybe I want to implement a system rather than a specialized vendor solution.
Yes, XML is one of the key technologies for generic data, so are the framework objects, but it’s curious that the vendors focus on data and not ‘the code’ :+)
I’d like to see Linux expose the research and development of the core operating sytem libraries, and than build a knowledge base and challenge those systems. I want a more organic platform, kind of like an organism. Maybe a scientist like you can relate. Which is stronger, the plant we like to have or the weeds.
“Why would Windows programmers dig around windows.h when there’s http://msdn.microsoft.com ?”
Well, there you have the culture difference again. I, for example, like to grep tough header files and look inside how it really works. Usually, that solves my problems much faster then browsing the web.
On windows, however, this is much more difficult. The api is really coming at age and is full of macro’s which are difficult to read and grasp. So, then I also refer to google and the web. I usually need to see an example before I can understand how I should use it.
On the other hand, I use the online Qt documentation also a lot. This has been written using a documentation tool ( like doxygen: http://doxygen.org ) which results in a very nice, cross linked online documentation system.
“I want a more organic platform, kind of like an organism. Maybe a scientist like you can relate. Which is stronger, the plant we like to have or the weeds.”
I don’t know. An organic platform that behaves like an organism sounds a little to much like we could end with The Matrix becoming a reality. :p
Its not just the fact that the compiler needs to reparse it each time. Its also the fact that anytime any of the sub-headers changes, all files must be relinked and recompiled. Also, its terrible from a code maintainence standpoint — pretty much every book on programming tells you not to make monolithic files. Headers should be modular, with each one collecting closely related interfaces. Look at the BeOS or Qt APIs for how it should be done. The Windows APIs are just not good examples of interface design, no matter how you slice it.
Why would you go looking around in “28 headers” looking for the type of a variable? My point was in response to Anonymous, you missed the context. Of course, that piques my interest. Why shouldn’t programmers dig around in windows.h? Maybe because its nearly unreadable? With all the hungarian notation, weird typedefs, non-standard calling conventions, etc. UNIX programmers have no problem digging around in the standard headers — after all, they’re the definitive reference of the API. Its not just windows.h, either. Windows programming (especially MFC) is just full of opaque code. Have you ever actually tried to read some of the files Visual Studio generates for you?
If you choose Java to write your solutions, than it must have been a stretch going from Win32 to Java.
Someone basing a product line on Linux could implement a software layer (rather than a wrapper) virtual machine that interprets an intermediate language compiled from Standard c++ and a supporting framework. Than Standard c++ would be back in business and it would have similar infrastructure as Java. I’d like to see it happen. It would be interesting to lay out all of the classes that you would want to support in the framework. You could learn from Java and .Net but focus on a slightly different library architecture.
Java/C# people make me laugh. Yes, they can be very productive languages, but only because they basically do everything for you. Most Java/C# programs are a matter of stringing together library components. The languages themselves are nowhere near competitive with C++.
Also, I’ve seen a number of competitions of coding productivity in alternative languages vs C/C++/Java. Rarely does Java beat C++ in amount of code required.
Check out a study done by a guy at the JPL. It shows that when the language itself (rather than a library) is tested, Java is not only more verbose than C++, but slower than Lisp (hi Roy!)
http://www.flownet.com/gat/papers/lisp-java.pdf
There are languages much more productive than C++, but Java ain’t it. Python is probably the most mainstream one that fits the bill.
I just hope that Linux doesn’t end like the Matrix. Just from what I heard, I haven’t seen revolutions yet.
“Qt isn’t really an option because the Windows version is about $2,000 per license.”
If you dig a little, you can still download the Qt/free version 2.?? for Windows for free.
Provided you don’t distribute your code outside your company or distribute your software with source code, it is still a very nice toolkit and very useable.
With respect to MinGW, you have a little less luck. V3.1 and up compile out of the box with MinGW, but the older versions do not officially support MinGW.
This would mean that you’d have to backport the MinGW makefiles to V2.x, which could easily take you a week or so, _if_ you’re more or less familiar with Qt’s make system.
Another option would be to develop under cygwin for the time being because that supports the free X version of Qt, _but_ requires an X server to run your program. See: http://kde-cygwin.sourceforge.net/
As you can see, these guys are also working on a native port of the free Qt version, but no one knows when this will be available.
Objective C, while not generally more powerful than C++, is very nice in the specific domain of GUI programming. I hear Cocoa programming on OS X is really fun.
“If you choose Java to write your solutions, than it must have been a stretch going from Win32 to Java.”
Well, it involved some relearning. But the speed of development more than makes up for it. For example, it takes about 100 lines of Win32 code using the native API to do what can be done in 5 lines of Java code.
I still envy the performance I can get from C and the Win32 API directly though. Fully funtional GUI applications that can fit on a floppy, use less than 10Mb of RAM, and load so fast, they feel like they were already resident, is pretty cool.
Oh, and as far as the Win32 API, it’s being replaced by the WinFX API, which will be more powerful, and also safer.
“Also, I’ve seen a number of competitions of coding productivity in alternative languages vs C/C++/Java. Rarely does Java beat C++ in amount of code required.”
I would love for you to show me some of those competitions and their results.
I have seen plenty of studies that show Java programs are on average, 5 to 10 times shorter than the same program in C++
Can you write a minimally functional Web browser in C++ with less than 50 lines of code? I can in Java
“Can you write a minimally functional Web browser in C++ with less than 50 lines of code? I can in Java”
This has much more to do with the libraries you use then with the langage itself.
I don’t know if I could write it in 50 lines using Qt, but I could get very close.
I just pointed you to one! And yes, you can write a minimally functional web-browser in C++ with less than 50 lines of code. Just embed KHTML. There is a tutorial on IBM’s DeveloperWorks. But that’s comparing the library, not the language!
It takes 100 lines to do in Win32 what it takes 5 lines to do in any other API not designed by people while they were high. It takes screenfulls of code to just create a damn window in Win32!
“It takes 100 lines to do in Win32 what it takes 5 lines to do in any other API not designed by people while they were high. It takes screenfulls of code to just create a damn window in Win32!”
It takes 100 lines because the API is the lowest level of Windows programming (And I suggest you try it in XForms and I think you will find it takes even more code).
It takes 100 lines because scrollbars, for example, don’t do anything in the API. You have to program the scrollbar logic.
And embedding KHTTP is cheating. Now do it without embedding an application that handles all of the work for you.
The library is whats important unless you plan on reinventing all the wheels.
“Check out a study done by a guy at the JPL. It shows that when the language itself (rather than a library) is tested, Java is not only more verbose than C++, but slower than Lisp (hi Roy!) http://www.flownet.com/gat/papers/lisp-java.pdf“
By the way… This is what makes me laugh. Because the comparision was done with Java 1.2!
In case you didn’t realize Java 1.2 did not use JIT. So this comparision is quite unfair. Compare it with Java 1.3 or 1.4 and you are going to get quite different results.
But this is what most people do when complaining that Java is slow. They compare it with an old and outdated version of the Java runtime engine.
and one who has no real “preferred” development platform, as my projects are developed on Linux, FreeBSD, Solaris, and MacOS X interchangably, I think much of the scorn “POSIX native” programmers feel towards Win32 comes from a lack of experience. I really enjoy the degree of control given by the Win32 API, and the level of cleanliness my code enjoys through having an integrated messaging system. I’ve developed a number of thread pool-based transactional servers, and no interface on any platform, including kqueues, /dev/poll, and epoll (and let’s not even mention atrocious O(n) mechanisms such as poll, or worse, select) rivals the code cleanliness that comes from using completion ports. Sure, the syntax may be ugly, and you may have some bizarre ideological problems with using primarily one header file, but ultimately when it comes down to it Win32 makes a programmer’s life (at least, one who isn’t doing GUI design from scratch without a nice wrapper) a lot easier than what POSIX has to offer.
Arend (IP: —.almel1.ov.home.nl)
“Why would Windows programmers dig around windows.h when there’s http://msdn.microsoft.com ?”
Well, there you have the culture difference again. I, for example, like to grep tough header files and look inside how it really works. Usually, that solves my problems much faster then browsing the web. On windows, however, this is much more difficult. The api is really coming at age and is full of macro’s which are difficult to read and grasp. So, then I also refer to google and the web. I usually need to see an example before I can understand how I should use it.
I find myself doing the same thing on POSIX systems, but my reasons for doing so rarely carry over to Windows. Some of these include problems with the order of headers, or incomplete documentation within the manpages (some C libraries do a particularly bad job of documenting themselves in manpages… glibc, I’m looking in your direction, a lot of us really detest info) On MSDN, this really isn’t a problem. As for using a “web page”, you can install a local copy of MSDN when you install MSVS. I find MSDN to provide much more extensive documentation than the manpages bundled with most C libraries, and consequently I’ve never really had a need to dig around inside windows.h itself.
Rayiner Hashem (IP: —.dc.dc.cox.net)
Its not just the fact that the compiler needs to reparse it each time. Its also the fact that anytime any of the sub-headers changes, all files must be relinked and recompiled.
Are you referring to the headers included by windows.h itself? These don’t exactly change often… only when I’ve upgraded the Platform SDK, which occurs about once every few years. I modify and recompile my code several thousand times a day… this really isn’t a problem.
Also, its terrible from a code maintainence standpoint — pretty much every book on programming tells you not to make monolithic files.
Take a look inside windows.h; it’s highly modular. It’s really just a meta-include which gives you access to the entire Win32 application layer. Windows maintains a fairly stringent header file -> library mapping… the standard libraries are covered by windows.h, whereas a separate library such as Winsock 2 has its own header, winsock2.h. This really isn’t possible on POSIX due to different ways in which different platforms compartmentalize functionality. FreeBSD throws everything including the dynamic linker and threads into libc_r, whereas Linux compartmentalizes the dynamic linker into libdl, and Solaris compartmentalizes sockets and hostname resolution into separate libraries from the standard C library.
Headers should be modular, with each one collecting closely related interfaces.
Again, there’s no reason why modular headers must force the programmer to manually include each of them by hand. On all of my cross-platform Win32/POSIX projects, I end up creating a single meta-include header for POSIX as well. The impact on compile time, even on the 500MHz K6-2 which is my primary development machine, is negligable, and meanwhile I’ve already solved any header ordering problems which I’ve encountered on a variety of platforms. Someone not taking this approach may find when they try to move their code to another platform that that particular platform does not like both sys/time.h and time.h included, and an appropriate #ifdef for that platform must be placed in every .c file which includes both, if they don’t prefer header consolidation.
The real reason why I believe the POSIX side hasn’t moved to unified header files has to do with its legacy. On Linux, linking with glibc gives you access to sockets and libresolv. However, on Solaris for example, you must link with separate libraries to provide this functionality. Because the compartmentalization of features on a library level varies from platform to platform, it does make sense to have a header system that accounts for this. On the Windows side, a cross-platform API is not an issue, and consequently the programmer’s life may be greatly simplified by providing a single header file which represents the entire API of the standard libraries.
Standard C++ should be used to reinvent the wheels, but it can also be used in the same way that Java is used but somone has to write a new VM, and an intermediate langauge compatible with the instruction set architecture, and the interpreter. I like the idea though of C++ as a low level systems langauge.
I wouldn’t mind though designing a middleware framework, just collecting all the ideas into UML and than describing all of the classes. No coding involved. Same with the X protocol and Xfree86. I’d like to expose the ideas behind those systems.
Let me quote two things you said:
“And embedding KHTML (ed.) is cheating. Now do it without embedding an application that handles all of the work for you.”
— and —
“The library is whats important unless you plan on reinventing all the wheels.”
So which is it? Make up your mind!
It takes 100 lines to do in Win32 what it takes 5 lines to do in any other API not designed by people while they were high. It takes screenfulls of code to just create a damn window in Win32!
The Win32 API is extremely low level, primarily due to its legacy. This has many disadvantages in that unless programmers begin from the start by writing a nice wrapper which adds object orientation and centralizing message processing/event handling, the code will become a mess and a complete nightmare to maintain. What it does afford however, is a degree of control not really present on any other platform except MacOS (X) with Carbon. Unlike most GUI APIs, which impose a single layout model, the choice is really left to the programmer as to what layout model they use. Would you prefer to implement a packbox/table style layouts such as Swing, GTK, and Qt provide? This certainly makes internationalization easy, as widgets “know” how to resize themselves and consequently you can throw whatever size text you want into the labels throughout the window and the widgets will react intelligently. Or would you prefer traditional Visual Basic/Cocoa-style pixel-precise layouts which don’t require hackish spacer elements to get the look you’re trying for. With Win32, it really affords an enormous degree of power to the programmer. Looking at Win32 for the first time without having written a nice C++ wrapper to handle messaging/events, widget resizing/hiding, etc. it really can be intimidating due to its low level nature. However, having written such a wrapper for my own use, I can safely say that I like the interface I have written for myself much better than any other GUI API I have ever tried, and that includes GTK (oh god, object orientation in C is the ugliest thing I’ve ever seen), Qt (having system native event objects which work in conjunction with the C library is better than signals/slots any day), Swing (I hate the Swing layout model, and inner classes are so ugly compared to callbacks), and a number of others.
I think of Java as a software layer (supported by the VM) that is integrated into a product line and directed by a sales strategy.
The C++ library efforts are dependent on the operating systems native interface(s), rather than the instruction set layer of the processor family.
In part Java is dependent on the native interfaces, for example AWT, and any threading is handed off to the implementation. Yet Java needs to do this only in areas of high complexity.
It appears that middleware is a step in the right direction for a vendor who wants a flexible product line.
What the user wants is fine on Linux, and if he pursues C++ than it will run fine on Linux, but he might have problems in the future running his solutions on Windows. So that’s when things will evolve. I just wish that more C++ libraries supported Standard C++ and the Standard Library.
I can’t possible understand how anybody would find Win32 *clean*! Its an API where its impossible to do anything useful without filling out structures full of parameters. Where even the simplest functions need two lines to call because they have so many arguments. Where nothing or orthogonal, and you get entire sub-APIs to do what you need a single POSIX call to do. Maybe its just cultural differences, but I learned Win32 before POSIX, and I’d never want to go back.
@Anonymous: Even with a JIT, Java would’ve been slower, unless, of course, Java code is regularly faster than C++ code? But that’s not the point of the article. In the general case, C++ is faster than Lisp is faster than Java. But just look at those develoment times! That’s the meat of the article. Peter Norvig, a big AI guy and other of PAIP, wrote in response to the study:
“I did not participate in the study, but after I saw it, I wrote my version in Lisp. It took me about 2 hours (compared to a range of 2 to 8.5 hours for the other Lisp programmers in the study, 3 to 25 for C/C++ and 4 to 63 for Java) and I ended up with 45 non-comment non-blank lines (compared with a range of 51 to 182 for Lisp, and 107 to 614 for the other languages). (That means that some Java programmer was spending 13 lines and 84 minutes to provide the functionality of each line of my Lisp program.)”
There was a C++ programmer, also, who using templates got in the same playing field as Norvig’s Lisp program. You’re welcome to do a Java version that does the same
Why can’t we have BOTH modular, reusable, command-line runnable code AND a well-designed gui as an alternative run interface?
Look, I’m not trying to be a C++/Lisp evangelist here. Just think before trying to spread to gospel of Java…
Yeah but if some company came out with a new OS, that ran on Intel X86, than you could get most of Java’s functionality over there even if you had no knowledge of that systems native API, but with C++ you would be dead in the water (even though you already know that C++ has nothing to do with any specific library, i’m just talking about how existing C++ libraries are implemented with wrappers on different platforms…as far as I know anyway). Java can run interpreted from a VM for the Intel instruction set (not the whole library). So that is damn flexible if you ask me.
I can’t possible understand how anybody would find Win32 *clean*!
Apparently you misunderstood. I’ve written my own wrapper for the Win32 API in C++ which I use for developing GUI applications on Windows. Because I designed its API, it suits my tastes much better than any other GUI API I’ve used. Because the interface exposed by Win32 is so low level, writing such a wrapper is much easier that it would be for a higher level GUI API. Consequently, I have a wonderful programming experience when developing Win32 applications, which is rivaled only by a visual interface builder, but eliminates the ensuing cruft.
I’m curious, how could you program on Win32 without abstracting it with a nice object oriented wrapper. I’m not even asking how you could tolerate it… I’m wondering how it’s even possible. Using the Win32 API directly from a traditional structured programming perspective without adding a management layer would result in a massively bloated, overly redundant, and unmaintainable codebase. Writing a wrapper is just sensible design, and Win32 fits nicely into an object oriented paradigm, as all “windows” (which may be read as controls or widgets by those not versed with Microsoft’s odd sematnics) have very OOP-esque properties which fit nicely into the canonical OOP inheritance model. Event handling can be done recursively with the parent object propagating all relevant events to its children. With sufficient knowledge of the operation of Win32, it’s possible to throw a very nice face on it, one custom tailored to your own personal taste.
The only other choice is MFC, which while more usable than raw Win32 without a wrapper, is horribly ugly…
“Even with a JIT, Java would’ve been slower, unless, of course, Java code is regularly faster than C++ code?”
On average, JIT code benchmarks as fast as native C++ code.
“I did not participate in the study, but after I saw it, I wrote my version in Lisp. It took me about 2 hours (compared to a range of 2 to 8.5 hours for the other Lisp programmers in the study, 3 to 25 for C/C++ and 4 to 63 for Java) and I ended up with 45 non-comment non-blank lines (compared with a range of 51 to 182 for Lisp, and 107 to 614 for the other languages). (That means that some Java programmer was spending 13 lines and 84 minutes to provide the functionality of each line of my Lisp program.)”
This doesn’t really say how long the resulting programs ended up being in Java compared to C. It also doesn’t state how well the programmers knew the language in question, so nothing can be said from this study.
I’m also not going to buy the results of one study (that doesn’t even state how it was controlled), when many other studies suggest that Java development time is on average, 10 times shorter than C++ development time.
But as far as LISP, there are plenty of reasons why LISP isn’t being used for major development projects
“I can’t possible understand how anybody would find Win32 *clean*! Its an API where its impossible to do anything useful without filling out structures full of parameters.”
It’s not. It’s old, it’s outdated, and MFC only made things worse. (MFC is horribly designed). The only thing the WinAPI has going for it is that it is fast.
But that’s one major reason that the Win32 API is being replaced by WinFX, which is completely object oriented. The Win32 API will still be available for support of legacy applications however.
Oh, I see. That makes sense. Sounds like a lot of work, but to each his own.
As for how you can use Win32 without a wrapper: when there is a will, there is a way. There was a time when people wrote raw Xlib-apps, after all. You just have to be really careful and factor things out into reusable functions. In a way, you do create a partial abstraction layer, but I’ve never considered it a wrapper as such.
Oh, and there is always WTL. Along with DirectX, its one of the few reasonably nice APIs to come out of Redmond.
On average, JIT code benchmarks as fast as native C++ code.
>>>>>>>>>>>>>>
That’s what Sun says. On Doug Bagley’s Great Language shootout (which uses J2SDK 1.3.1) its in 14th place overall in the speed department. The only “benchmarks’ that show Java performing as fast as C++ are numeric microbenchmarks, where the JIT can just compile down to a tight native-code loop, and is never involved in the rest of the test.
This doesn’t really say how long the resulting programs ended up being in Java compared to C.
>>>>>>>>>>>>>>>>
Look at the deveopment times. They are seperate for Java and C.
It also doesn’t state how well the programmers knew the language in question, so nothing can be said from this study.
>>>>>>>>>>>>>>>>>&g t;>
Read the PDF! On average, the Lisp programmers had something like 6.2 years of experience with the language, the C/C++ programmers 9.6 years with the language, and the Java programmers 7.7.
when many other studies suggest that Java development time is on average, 10 times shorter than C++ development time.
>>>>>>>>>>>>>>>
Only studies that test the libraries rather than the language. This study had a challenging problem that really didn’t have canned solutions in the libraries.
But as far as LISP, there are plenty of reasons why LISP isn’t being used for major development projects
>>>>>>>>>>>>>>>>>
Eh, not very many people are familiar with it, and it doesn’t get a lot of hype. There also aren’t pretty GUI tools like Visual Studio, and 3rd party libraries are less widely available.
But it *is* used for some major commercial development.
http://www.franz.com/success/
But the same is true for a number of languages that are more productive than Java: Python (used at Google), Erlang (used at Ericsson, Motorola, and T-Mobile), Ocaml (used at INRIA), etc. These languages are still used rather often in academia, science, and CS research. Also, the Europeans seem to be a bit ahead of the ball-game, they’re much more willing to use and teach alternate languages than Americans.
Speed and flexibility are counter productive. The library frameworks that are decouple by a VM are more flexible than wrappers, and there are some new applciation domains being discovered by flexible distributed computing. Those tasks can be handled by a wrapper library, but than they are tied to the platform and they are not as integrated with other software if they are not supported by a major vendor and not part of a product line.
The situation of designing wrappers for Win32 is illogical because you don’t own Win32, the vendor Microsoft does, so you just have to use whatever they tell you to use, that’s the only way to succeed because they will come along with a bulldozer and plow you over, the Win32 API is cordoned off for construction, you are supposed to be using .Net because the whole thing (Windows) is a product.
On Linux I could benefit from having a fully documented Xlib because it’s not the property of a vendor, it’s my property. I want to understand the fine details because it’s such an important library. Most of my applications, if you generalize them, they end up using Xlib, so I have a situation where 90% of my programs are dependent on this library, I want to know more about it.
Than I might want to do the one thing in Linux that you can’t do in MS Windows. I might want to make some changes and recompile my platform.
Every benchmark I have seen in which Java is demostrated to be “as fast or faster” than C++ has been very visibly rigged. Perhaps the most notable was one where a Fast Fourier Transform was implemented in a completely object oriented manner, so values fed into the transform had to be given in the form of objects, and virtual methods were used to access the values inside the container objects, as the transform took values from a pure virtual base class and the actual objects passed to the transform were inherited from that class.
THIS IS NOT HOW C++ WAS MEANT TO BE USED. Please see this interview with Bjarne Stroustrup: http://www.artima.com/intv/goldilocks2.html
Objects in C++ should be used as a state management tool. In the case of values being fed into a Fourier transform, this is clearly a job that can be done efficiently and effectively with arrays. There is no state to manage, no invariant to establish, and absolutely no need to use inheritance.
Even if there were a need to pass different types of objects to some complex portion of code, this is an ideal job for templates. Rather than using a pure virtual base class and inheriting from it, simply write the transformation engine as a template.
In the case of the FFT example, it was obviously the work of Java zealots who chose to implement the code in a manner designed explicitly to take advantage of the only notable optimization feature Java employs which isn’t possible on C++, namely automatic inlining of virtual methods.
C++ code can be optimized at run-time through the use of profile guided optimization. While profile guided optimization isn’t “automatic” and does require developer intervention, it ensures that any optimizations applied to the code are persistent, whereas with the Java JIT/HotSpot approach all optimizations are done at run-time each time the program is started.
If you continue to insist that a JIT can bring Java’s performance on par with native code, I implore you to provide me with a benchmark in which the language features of Java and C++ are properly utilized in a real world manner, and where the C++ code has been optimized through profile guided optimization.
And don’t kid yourself, in the majority of cases C++ will be faster. In the small number of cases where Java is exhibiting similar (or better) performance than C++ profile guided optimization can be used to tune the C++ code’s resulting executable, and in extreme cases virtual methods may need to be eliminated through the use of templates.
“Look at the deveopment times. They are seperate for Java and C.”
Development time and number of code lines aren’t the same thing. I can spend 20 hours writing 5 lines of code if I dilly dally a lot, or if I am trying to do something complex that I don’t know how to do, so I have to resort to the API documentation a lot.
“Only studies that test the libraries rather than the language. This study had a challenging problem that really didn’t have canned solutions in the libraries.”
Using the libraries is generally more important for most programming. Example, produce a scrollable JPEG image in a frame in C++ using only 2 lines of code. Can you do it? I can in Java.
“Eh, not very many people are familiar with it (LISP), and it doesn’t get a lot of hype”.
And it’s notation is downright annoying. No thanks, I’d rather not spend all day trying to code my hausdorff metrics in reverse polish notation.
“But the same is true for a number of languages that are more productive than Java: Python (used at Google)”
Python is also slower than Java by quite a bit because it doesn’t optimize anything down to native code.
BTW, none of these take into account debugging time.. ie: the time you spend in C++ trying to find that memory leak, or trying to track down the pointer problem that is causing that occasional and ellusive illegal operation error.
You simply don’t have problems like this with Java.
“C++ code can be optimized at run-time through the use of profile guided optimization. While profile guided optimization isn’t “automatic” and does require developer intervention, it ensures that any optimizations applied to the code are persistent, whereas with the Java JIT/HotSpot approach all optimizations are done at run-time each time the program is started.”
Yes. Guided optimization… as I watch that C++ development time get longer and longer because of things like guided optimization…
Now you see where the 10x time savings comes from in Java (that’s just one example).
Now tell me. If there are no speed of development advantages to Java and such, than why is it more popular than C++ today? Certainly the cross-platform nature cannot explain all of it.
BTW, none of these take into account debugging time.. ie: the time you spend in C++ trying to find that memory leak, or trying to track down the pointer problem that is causing that occasional and ellusive illegal operation error.
With modern memory debuggers (such as GlowCode on Windows, or valgrind on Linux, an OSS application) solving these problems is as easy as figuring out the cause of a particular segment violation. They can not only point out what memory was leaked but give you a complete backtrace as to how it was allocated, including line numbers. It can also show reads from/writes to unallocated memory, and also the location of the nearest allocated block. Couple this with proper unit and overall system testing and memory problems really aren’t an issue.
You simply don’t have problems like this with Java.
No, instead your end users have problems like this:
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
www 43642 53.8 16.0 101960 83520 p0 R 5:18PM 0:02.88 /usr/local/jdk1.3.1/bin/i386/green_threads/java -classic -jar -Dcata
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
www 43642 53.8 16.0 101960 83520 p0 R 5:18PM 0:02.88 /usr/local/jdk1.3.1/bin/i386/green_threads/java -classic -jar -Dcata
Your point being what? That it is using 53.8% of the CPU time?
I’d have to see a running list to see if that was bad or not. For all I know, that was taken at a time the app was doing something particularily intensive.
Java byte code that is compiled to the operating system binary level is fast, however the operating sytem layer is a hybrid layer, and metrics probably have to made for each individual operating system. The binary might also be optimized by the compiler for lower layer interpretation so the compiler will make a difference too.
Java might perform better on Solaris than on Intel.
I meant Sparc vs Intel.
“Java might perform better on Solaris than on Intel.”
Java performs quite well on Intel if using a JIT. The JIT generates native machine code.
In fact, my experience has been that Java performs better on Windows than .NET does.
I think I am done with this discussion, since it seems like we aren’t going to get any further than we have gotten. And we are just going to be stuck at.
“Java development is faster than C++ development”
“No it’s not”
“Yes it is”
“No it’s not”
“Yes it is”
“No it’s not”
….
That needs to be answered is…
Does unmanaged C++ have any future on Windows? After all, the WinFX API is a managed API.
And if unmanaged C++ does not have any future on Windows, than these discussions are not really relavent, because it’s not going to matter whether you use managed C++, C#, VB, or whatever. They are all going to perform equivalently.
You mean like the IE core, which you can use in your own apps? There are far more IE-based browsers than Gecko browsers out there, so what exactly is your point?
I think you hit the nail on the here, I can only assume that a large proportion of the Linux community left Windows as newbies because all of these elitist abilities I keep hearing about are equally available in Windows.
I quite liked the analogy i read earlier about mechano vs toy helicopter? but cant help but feel it’s a little blinkered, the way I see(lol great pun but unintended)it Windows users have Mechano & a toy helicopter, linux only the mechano
But a native machine binary is than interpreted. So the JIT compiler has to optimize the binary for the underlying layers to interpret. And it’s a question of the compilers knowledge of the architecture.
“But a native machine binary is than interpreted. So the JIT compiler has to optimize the binary for the underlying layers to interpret. And it’s a question of the compilers knowledge of the architecture.”
True. But the JIT can actually make optimizations that a C or C++ compiler can’t even think about making. Why? Because Java profiles code as it is running, and looks for bottlenecks, and looks for the best ways to optimize those bottlenecks. The next time you start the application, the JRE will optimize those portions that are causing slowdowns.
And it’s only going to get better. Tiger (Java 1.5) is going to have some major performance improvements over current JREs.
Combine Tiger with the Java Desktop System, and Longhorn has some serious competition on its hands.
I’m sure Microsoft took notice when Sun got a contract to deliver 200 million Java desktop systems to China… Yes, that’s 200 million. 200 million desktop systems running Linux. That has to put a subtantial dent in Microsoft’s share of the desktop OS market.
Yeah, I guess what I’m saying is that on SPARC, Sun Microsystems has control over the micro architecture and the instruction set architecture, so they can build the low level architecture to support a more sophisticated Java Virtual Machine, but on Intel, they don’t have as much control.
China is the fastest growing economy in the world. I think that MS might try to get their hands in on the deal if they buy AMD.
I mean take a hardware JVM chip, it can directly execute JVM binary programs without the need for a layer of software interpetation or JIT compilation.
Here is where speed and cost are at odds in a multiprocessing computer architecture, but feasible for embedded systems. The only difference between hardware and software is that hardware is ‘fixed’ software, but if cost was not prohibitive, you would never even need a JIT compiler or interpreter to run your Java programs, only the javac compiler to produce the byte code, and the hardware would directly execute it without interpretation.
“China is the fastest growing economy in the world. I think that MS might try to get their hands in on the deal if they buy AMD.”
I don’t think the government would let Microsoft buy AMD.
As far as hardware based JVMs, yeah, I would love to see something like that on Intel boxes.
“Yes. Guided optimization… as I watch that C++ development time get longer and longer because of things like guided optimization…”
Apparently your time is more important to you than the end user experience. At least you aren’t claiming anymore that Java’s performance is equivalent to or better than native code…
“Now tell me. If there are no speed of development advantages to Java and such, than why is it more popular than C++ today? Certainly the cross-platform nature cannot explain all of it.”
The second case of argument ad populum I’ve seen on OSnews today! Not only is this a logical fallacy, but there is no method by which popularity of a programming language can be effectively quantified.
“Your point being what? That it is using 53.8% of the CPU time?
I’d have to see a running list to see if that was bad or not. For all I know, that was taken at a time the app was doing something particularily intensive.”
My point being that, in general, languages with runtimes consume significantly more system resources, both CPU and memory, than native code applications. Most have event loops which don’t block on I/O, and constantly drag down your available CPU.
Again, it’s an issue of the best end user experience…
@Anonymous: Those things are more theoretical than practical. In practice, the Java JIT is severely limited in what it can do because it has to generate code quickly to avoid stalling the application. Since a lot of advaned analysis are time-consuming, JIT’s don’t achieve the kind of performance in real life that they do in theory. Of course, the most advanced compilers in existence are, for Lisp and other functional languages. Basically, the “Lisp is slow” or “ML is slow” stereotype spurred literally decades of compiler optimization research for those languages. For example, in Dylan (Apple’s infix version of Lisp) there are no native types. Even integers and floating-point numbers are full classes. Their compiler guys realized that the int primitive vs. Integer class distinction was unnecessary, because the compiler could just figure out itself when an object didn’t need to be boxed. Of course, this is a tremendously intensive analysis, and it wouldn’t be feasible to do it at runtime.
“Apparently your time is more important to you than the end user experience.”
The end user experience is just fine with Java. And my time is more important when we need an app now, and not later.
“At least you aren’t claiming anymore that Java’s performance is equivalent to or better than native code…”
I am still claiming that JIT code is on a par with native code.
“Not only is this a logical fallacy, but there is no method by which popularity of a programming language can be effectively quantified.”
Sure there is. You can do surveys and find out what languages people are using to develop applications. The number of “help wanted” adds that require Java experience comapred to the number that require C++ experience is also useful.
“My point being that, in general, languages with runtimes consume significantly more system resources, both CPU and memory, than native code applications. Most have event loops which don’t block on I/O, and constantly drag down your available CPU.”
If you’d like, I can post ps output from a C application using 80% of the CPU time and 40Mb of memory. In other words, your ps output paste doesn’t prove anything.
“Again, it’s an issue of the best end user experience…”
So tell me. Are you one of those people who never got past “Java is only useful for putting animations on Web pages”?
If Java can’t handle mainstream programming tasks, why don’t you tell that to the people at NASA that are designing a system to manage shuttle payloads in Java, or the people using Java to track global weather patterns, or the people using Java to sequence and analyize human DNA, or the people using Java to study seizmic vibrations in the Earth?
Apparently, they never got the message that Java is too slow for such very computation intensive tasks.
“@Anonymous: Those things are more theoretical than practical. In practice, the Java JIT is severely limited in what it can do because it has to generate code quickly to avoid stalling the application.”
Your application spends 95% of its time executing 5% of its code. That’s the only part that really needs to be optimized. So no, Java is not limited in what it can do, because it only has to do it to a small part of the code. So yes, Java can make runtime optimizations that C and C++ can’t, and it is not strictly theoretical.
“My point being that, in general, languages with runtimes consume significantly more system resources, both CPU and memory”
Image Name: java.exe
CPU: 00
Mem Usage: 2,300 K
See? I can process information too.
Companies have built hardware JVM chips to execute Java binary code directly. This is the case with cell phone technology and other embedded systems where there is not enough memory for compilation and an interpreter is too slow. The telephone user can download an applet or web service that allows him to perform a certain task that his phone was not able to do previously. Java binary code is the native code of this hardware.
If Java can keep up to a network connection data rate, which apparently it can, even while performing computationally intensive tasks, than it doesn’t matter if C++ is faster.
Sun has created a successful product in Java and they are not expanding the product line to include Linux as an endpoint.
Linux C++ and C developers would be better off using their knowledge to expose the source code of low level libraries and systems infrastruture. C and C++ are languages used to build systems, they are not appropriate for writing specialized solutions. Start to generalize instead of trying to specialize.
not = now
I didn’t say it was strictly theoretical. I said it was mostly theoretical. HotSpot doesn’t a fraction of the optimizations it could theoretically do because it must operate under a time limitation.
Also, while some (mainly scientific computing) apps might spend most of their time in 5% of their code, that’s not true for other types of apps. Being able to do good optimizations on the whole codebase is less important for a low-level language like Java, but it is still a factor.
“Not only is this a logical fallacy, but there is no method by which popularity of a programming language can be effectively quantified.”
Sure there is. You can do surveys and find out what languages people are using to develop applications.
Then by all means, do surveys. As soon as your surveys have the same degree of authority that Gartner and IDC surveys do perhaps I’ll listen to you. However, thus far you have failed to post any source for your audacious claim. Were you to say, post a survey of programmers for the top 100 software firms in the world asking which language they prefered, that would be acceptable.
The number of “help wanted” adds that require Java experience comapred to the number that require C++ experience is also useful.
This can speak of any number of things, most notably the high rate of turnover in Java related jobs, which is currently dominated by JSP development. Like all web development, JSP jobs are quite tummoltuous compared to the traditional C/C++ applications market.
Your application spends 95% of its time executing 5% of its code.
Most of my applications spend 99.9% of their time blocking on I/O, as compared to Java which is constantly chewing CPU.
That’s the only part that really needs to be optimized.
The system calls… good luck getting a JIT to optimize those.
So yes, Java can make runtime optimizations that C and C++ can’t, and it is not strictly theoretical.
Like I mentioned earlier, runtime optimizations may be made in C and C++ code through profile guided optimization if performance is an issue.
“Most of my applications spend 99.9% of their time blocking on I/O, as compared to Java which is constantly chewing CPU.”
Java does not chew CPU.
Image Name: java.exe
CPU: 00
Mem Usage: 2,225 K
“Like I mentioned earlier, runtime optimizations may be made in C and C++ code through profile guided optimization if performance is an issue.”
And like I said, watch that development time get longer… and longer…
BTW, you wouldn’t happen to be friends with Gerald Bauer would you? I’m just wondering because you seem to have some kind of major axe to grind with Java.
There used to be a problem with Java threading on Linux because Java would let the implementation handle threading even though the threading API was the same for all Java applications. Linux didn’t support the creation of hundreds of threads efficiently and some Java applications used that many threads. That has changed with Linux’s new thread implementation which is able to handle hundreds or thousands of threads efficiently, but something like that does give Java a bad reputation. I think that the good outweighs the bad though and C++ developers should concentrate more on systems implementation where many ideas are not being realized.
Sun’s Java interpreter ‘java’ is implemented in C. I imagine that the JVM is as well, but I’ve only read about the interpreter.
or i guess that would be ‘javac’
maybe not
“Linux didn’t support the creation of hundreds of threads efficiently and some Java applications used that many threads.”
Ah yes. I remember that now too. Linux kernel versions prior to 2.4 did have problems managing large numbers of threads. I think most of that has been fixed with 2.4 though.
“Sun’s Java interpreter ‘java’ is implemented in C. I imagine that the JVM is as well, but I’ve only read about the interpreter.”
The java virtual machine (java) is written in C. The java compiler itself (javac) is written in Java itself.
Why wasn’t the the java virtual machine written in Java?
Bascule wrote:
However, having written such a wrapper for my own use, I can safely say that I like the interface I have written for myself much better than any other GUI API I have ever tried, and that includes GTK (oh god, object orientation in C is the ugliest thing I’ve ever seen), Qt (having system native event objects which work in conjunction with the C library is better than signals/slots any day), Swing (I hate the Swing layout model, and inner classes are so ugly compared to callbacks), and a number of others.
This is really interesting, having that kind of experience would surely have a good type of messaging and event handling system implemented at a fairly clean way. Personally, my preferences closely match a Win32 looper coupled with a BeOS-like message handler. That way, those dreaded macros are eliminated from the equation.
Other than that, it is nice to see posts like these.
Rayiner wrote
When you circumvent the type system, you’re going to get type errors. Unfortunately, printf() circumvents the type system, but a *NIX compiler would have caught that because they usually do type-checking for printf(). In the end, its best to make sure your C code typechecks properly in a C++ compiler. That’ll get you compiler-enforced type safety without any silly naming conventions.
Doing type checking in *nix C is considered anathema. And I don’t know exactly why would anyone use C for that purpose, though. There are other languages out there that can do pretty much most of the hard work better than C.
Personally, I use C to get away with type checking and just use a different language like Java or C++ when I want to go back to a typed-checked environment.
Because that would involve a chiken and the egg problem. You can’t run the Java Virtual Machine on a system if it is written in Java since the system can’t understand Java yet. It has to have the Java Virtual Machine running before it can understand Java. That’s why the compiler can be written in Java, because it can run under the JVM.
The other reason is performance. The JVM is written in a native language and fully optimized, and translates Java API calls into native calls on the platform.