- 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
Correct. As explained above, you have to have an immutable object or wrap it in an immutable container.
Practically, when confronted with this kind of problem, I do something like this:
As for the whole references / value: in Java, primitives are passed by value, and for everything else, a reference to the object is passed by value (meaning the object pointed to can be altered if possible, but not the memory location of the object).
Admin
I meant Collections.unmodifiableSet(...), but the rest is correct.
Admin
If you read it again, FooNorsk designed and was building the system, they needed ACME to develop parts of it. And of course, the platform was already chosen.
Admin
I once wrote an application in Java that spawned hundreds of threads to run perform concurrent tasks for several days. Although it was a memory hog, I find it hard to believe your application screwed up so badly. Either you coded it extremely bad, your teacher can't properly configure a server, or you're just trolling.
What do you mean by forking processes? Are you talking about processes or threads?
Admin
Admin
Fair enough with MyNumberClass, but it is a total WTF to assume that non-number classes need the ability to overload these.
Far less than 1% of classes are numbers and assuming that these corner cases need a universal feature of the language is a proof by example.
Admin
http://en.wikipedia.org/wiki/String_(computer_science)
Does that hold up for a method parameter?Admin
If my failing memory serves, the only place in compiled Java bytecode where a static final is referenced is the point where it was defined - every other occurrence would have been replaced by its value; the reference is only kept to maintain the interface. But this is the same behaviour as a C# const. So I'm curious, too.
It's C#'s static readonly members that are the fakes: the substitution isn't made until runtime (or at least jitting). Why the delay? It's not like the value will change in the meantime, is it?
A static readonly member might look and behave a lot like a const (except that a const is limited in what it can contain compared with a readonly), but if you change a const you have to recompile every module that references it, while changing the member only requires recompiling the module in which it's defined (all the others would obtain the new value at runtime).
Admin
A least with Dick & Rod being the protagonists, we can be confident that he didn't mean homophobe.
Admin
Which for those that don't know, would redirect stdout (i.e., 1) to append to a file named "bar".
Further, while you're free to implement operators any way you want in C++, best practice is to obviously not abuse it (documentation should explain what does occur and a reasonable developer should say WTF to something that doesn't make sense and look for an alternative). However, note there's nothing stopping you from implementing this in Java:
Basically, common sense always plays a factor. Sure, operators can be abused, but any language feature can be abused. That's where best practices play a role. You wouldn't likely use a framework that did something like this in Java, and similarly you wouldn't likely use something illogical in C++ (or C#, which also supports operator overloading).
The bitshift operators make excellent stream IO operators, IMHO. Some argue that operator+ (and I assume operator-) would make more sense, but those operators are much more likely to be put to use more often.
Honestly, I like the stream IO operators. I think they were the best choice.
Admin
Proof that in college you wrote crappy java programs. Bravo, sir. Sounds like you will soon be proud of many achievements noted here.
Admin
Well, it should be. Sometimes flashy new features are WAY WAY more important than performance, which is WAY WAY more important than stability, which is WAY WAY more important than maintainability.
Admin
No, Java classloading is far more screwed up than that.
If you define a static final field of a primitive type, the bytecode for the given class may (at the discretion of the compiler) replace the value in the bytecode. It can do that because the value doesn't have to be determined during linking.
However, if the final field is referenced outside that class (note that inner classes count as "outside that class"), then the final field is always compiled as a reference, since the value isn't known until runtime.
The JIT compiler is free to detect that something is a constant and then rewrite the code such that it's constant, but that's an additional process beyond the initial compile step. C#'s constants avoid that extra linkage penalty.
An even more screwy case is when you have a final primitive field where the value isn't set until runtime. These are always references, since the value isn't set until runtime - which means that even if it's a primitive type, it still has to be referenced.
Yes, you can make final static fields be determined at runtime, thanks to static initializer blocks. It ensures that the compiler can never inline the value.
Admin
A lot of interesting comments to read, although there are quite a few that are rather poorly corroborated.
At our place, we use Java almost exclusively. Why? Because it works best for us. We're a mobile phone company (in a rather small country), so we deal with large amounts of data. But this data is usually stored in a database, in which case a lot of the crunching takes place there.
If it comes to raw number crunching speed, C or C++ will indeed be faster, but since we don't do aircraft design or simulating nuclear explosions, that is not an issue: Java is fast enough for what we do.
We develop on Windows, and run on Solaris, Linux or the few Windows servers we have left. The maintenance people don't like Windows very much, because it's a bitch to administer remotely, what with all the limitations you have on number of users, and they're virtualising everything. Quite apart from the operational expenditure of Windows licences.
But the platform-independence is more a convenience than a deciding factor. Java's strength lies in its large standard library, the number of available third-party libraries, and the nice way it abstracts things from you like database access.
Yes, JDBC has plenty of weaknesses, but I'm yet to see a standard library for C++ that both compiler suppliers and database engine suppliers use. Oracle gives you ojdbc6.jar and you know it'll work on your system, whether it's Windows, Solaris, Linux or anything else that runs Java.
Another thing about Java is that it's a resource hog. Netbeans easily gobbles up hundreds of megabytes, and what for? But on the other hand, what's cheaper: a better kitted out computer, or paying a developer? We've found that C++ development takes a lot longer, because whilst you have all this power, it doesn't have a great deal of convenience, and as a result, applications take longer to develop.
Certain things, though, I wouldn't do in Java if my life depended on it. BER decoding, for example. Not having unsigned integers and not having mmap() is a major headache, so this I do with a combination of C and Perl.
C++ may be a Formula 1 car compared to Java being a family car, but very few people can drive a Formula 1 car without crashing it.
All in all, Java gives us the lowest capital and operational expenditure overall. That's what keeps our development section from being outsourced to India.
Admin
Yeah, I've also written software that bad in order to get people to stop bugging me...
Admin
COBOL Rulez
Admin
Does Java have some special magic that makes it easier to maintain...?
Admin
Indeed it's slow! Hate when I have to use any of Java software
Admin
I tried to run this benchmark with Haskell but it can't do loops.
Admin
Java vs. C benchmark:
http://www.stefankrause.net/wp/?p=9
Admin
Think of it the other way around: Why should there be a fixed set of "special" types? Java developers should have been honest and abolished every operator except "." if they thought this way lead to more expresiveness. They didn't, because obviously, it's ugly.
Take a look at Ada, which certainly is the essence of "write out what you mean": Allows operator overloading. Why? Because Ada strongly discourages (ab)using the built-in types for everything. (It allows you to e.g. declare two integer types that behave identical but are incompatible with each other.) So if operators couldn't be overloaded, it would be almost pointless to have them in the first place.
Operator overloading provides you with a great chance of extensibility and readability in arithmetic expressions. Of course only small parts of most programs deal with arithmetic, but these are usually also the most tricky ones.
Admin
The existence of const_cast<T> or similar methods to forcibly throw out const, ways to access private class members by using raw memory offsets, etc. all guarantee that C++ can't guarantee const correctness. It's a programmer's aid and that is all it is.
Admin
Admin
(Dennis Ritchie's first hand account, which specifically mentions the pipeline model.)
Admin
The reason "Java is slow" gets passed around so much is that so many things which display the java logo are so slow. Maybe there's something about the language which is secretly fast, but capabilities mean nothing to what is actually perceived if the end result is: Java logo next to something unusable.
To give a couple of examples:
Admin
Wrong! I know of at least one language that makes it impossible to write good code: Fortran 77. Malbolge, Intercal, whitespace, and brainfuck are also contenders.
Admin
True, but that's because the .Net platform is optimized for database and backoffice applications, not for games, where as C/C++ is optimized for nothing/everything. Functions on Vectors, Floats and Matricres are therefor not as fast in .Net as in C++, and a game uses allot of those. So yeah, for making full blown games C# and Java are not a good choise, however for (boring) database interacting applications (like say 99% of all the applications written). C#/JAVA/C++ are all valid candidates depending on the requirements.
Admin
Now that guy is the real Dick!
Admin
Homophobe???
Admin
(CAPTCHA: Abbas. Is that a political statement?)
Admin
Admin
Have you actually looked at a Java desktop application in the last, say, 10 years? Or maybe you still have a Pentium II based computer with 128 MB of memory?
The computers I use aren't exactly premier league (an AMD Athlon 2.2 GHz and a Core 1 Duo laptop), but to call the Java applications I use (mostly Netbeans) slow? No. Memory hogs, oh yes, but not slow. Just make sure you have 2 GB of memory.
Anyway, everybody knows that Java on the desktop is as good as dead, but that it's extensively used in back-end server applications for the reasons I pointed out a few posts up.
Admin
The magic of trying to hide this deadly weapon people call pointers manipulation. Let's face it, 2/3 or more of the so called "software professionals" have no idea how to correctly deal with memory. A language with which you can't do anything is a language with which you can't do any harm...
Admin
Admin
Agreed.
Admin
Java is poo.
Admin
For those unaware of Scala, it can use alla existing Java libs, compiles into class files and runs on the JVM. Also, it allows operator overloading, including using funny Unicode symbols. Mixed blessing?
See http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html for a hilarious progression of languages, with Scala at its apex.
Admin
Exactly, and that's what most people seem to be missing here. We're talking about backend processing, not a direct desktop application, so even if a desktop application such as Eclipse is pretty resource-hungry, that doesn't mean it's relevant for a server application.
If the application is built to be scalable e.g. for multiple cores, and you add in load-balancing and stuff, you can improve performance simply by adding hardware. You can't really do that with a desktop computer, not for a reasonable price anyway, but for server-side systems you can. If you can save a few man-months of development time by investing a few thousand dollars/euros/whatever more on hardware, it makes sense economically.
Admin
Of course carbon dating wouldn't give you her age accurately: Carbon dating tells you how long an object has been dead, so unless you were dating a zombie, it would always give 0.
Admin
Admin
You are right - I got a little bit hung up on the parameter thing... Really it applies everywhere. You can write a getter function that returns a const reference to an object and the caller cannot modify that object. There are ways to approximate this in Java/C# but they aren't anywhere near as clean.
What is up with the lack of unsigned value types in Java. That's just stupid!
Not that I have anything against Java - I'm programming in it right now....
Admin
Of course, the comparison isn't entirely fair, because in any case where common libraries are used, once they are installed for one app, they don't have to be for any additional apps that use them.
Admin
I would be more open to Java if it was compiled down to native code instead of byte-code. A release build of a particular version of a program is only going to be compiled once. I'm fine with compiling separate programs for each platform if it means I can get rid of the performance penalty of running an extra layer above the OS.
I mean, to me, JIT means "recompile every time you run the program" whereas it could be done once and you'd have a native build... :-/ Even if the byte-code concept was kept, but instead of JITing byte-code every time, compile the byte-code down to a native binary on the first run and cache it in a secure directory somewhere. Win. From there, re-running the program would consist of hashing it to identify the cache and running the native build.
Why not?
Admin
The reality is that that myth was de-bunked years ago. In some circumstances, Java has even been observed to out-perform the equivalent C++ code. It's true that for any trivial snippet of Java code, the equivalent C++ code will be quicker, but software isn't a trivial snippet of code, and the optimisations that, say, HotSpot, provides, blow this long-standing Java myth out out of the water.
Next
Admin
Not really. Java isn't merely a programming language, it's a platform. If an enterprise has decided on a specific platform, then so be it
Admin
Yeah, you're using C-sharp, and he's using C-pound.
Admin
Brainfuck anyone?
Admin
Actually, I think the core is C, not C++, but the rest is in LISP.
Still, it meets the spirit of the the request. Fast, multi-language, and doesn't hog resources. I have 40+ buffers open atm (Java, .NET, news, mail, shells, ...) and only using ~25MB of RAM.
Admin
Admin
Dynamically linked libraries are not even a C++ thing. They are an executable thing. Everything could be statically linked, but there are advantages to dynamically linking.
It is in no way the same thing as Java's VM. It's ridiculous to claim that it is. Java programs run a layer above native programs. You can't compare that. It's different. Until that layer is eliminated and you no longer need to run your program through a native program, STFU, KTHX.