Numerical Computing in Java?
Nightshade queries: "I work for a department in a big financial company that uses equal amounts of C++ and Java. For a variety of reasons, we've decided that Java is the future of the group because of all the benefits of the language (it's so easy to use compared to C++, we can use Eclipse, Ant, jUnit, etc). The problem is that we do a lot of numerical computing and Java has no operator overloading! Languages like C# have operator overloading and because of this company's like CenterSpace have popped up with some nice looking numerical libraries. Try to find numerical packages for Java and it'll be pretty tough. What have people done in terms of numerical computing in Java? We currently use the Jama and Colt libraries for matrices and complex numbers, but these have awkward interfaces without operator overloading and are incomplete (no support for things like symmetric matrices) so we're looking for better solutions. So should we bite the bullet and switch to C#? Should we use a pre-processor like JFront? What have other people done?"
All it does is make us have to type more and take a few hundred milliseconds more time to look at a line of code like
CrazyObjectNumber a = new CrazyObjectNumber(...);
CrazyObjectNumber b = new CrazyObjectNumber(...);
CrazyObjectNumber c = (a * b) + 53;
Which line 3 ends up being:
CrazyObjectNumber c = ((a = a.multiply(b)).add(53)).clone();
Which one is easier to read?
1;
Sure it might be easier on the administration side to use just one tool. But in the end a language is just that, a tool. You don't see carpenters throwing away all their tools except the hammer just to keep their tool-shed clean...
I hate operator overloading because if hides what's actually happening - a function call. When you are actually debugging code its difficult to see what is going on.
I also dislike "virtual" inheritance for the same reason.
I just don't think OO programming is the greatest thing since sliced bread. That's a very unpopular view.
Check out the writings of Dr William Kahan. One of the men behind the IEEE floating-point standard.
Read "How JAVA's Floating-Point Hurts Everyone Everywhere".
http://www.cs.berkeley.edu/~wkahan/
For speed, Fortran is still best. Most enginering codes are in Fortran.
Step away from the "one language fits all" mentality. The type of problem you're trying to solve has already been solved, so you can forget about Java and C++.
Go get Matlab (or Mathematica or Mathcad/Maple). Matlab has a powerful scripting language that does exactly what you need, and you can download thousands of functions written for it. Or just hire me and I'll write a translator from Matlab to your favorite language. Oh wait: translators already exist, so nevermind.
Also, why are you trying to confuse yourself (and future maintainers) with operator overloading in C++? It's just a Bad Idea (TM). Don't do it.
You might want to try Jython and the Numerical Python for Jython.
I have not used either for a long time, but use plain Python and Numerical Python a lot; sure beats Matlab and Mathematica for most things. Right now for solving optimization problems with 10k+ s.t. constraints.
What I'd suggest is BOTH. I am a huge C# fan, and am very inexperienced when it comes to Java. I never got into Java because the code seemed very akward and cumbersome to me (event handling, etc).
.NET, since each dev house will use their platform of choice. If you write a .NET version, then it can be used by any lanugage supported by .NET (C#,VB,C++,Java.NET,Cobol,Python, etc). But it will not be usable from native Java.
The dev teams working with java are used to the quirks of the language, thus should be very familiar with how to use the library, even though it might not be the best it could be.
However, If you are looking to provide a tool for companies to use for development, I would recommend both. There is a need for this in both Java AND
Perhaps looking into a way to use the same code base, but compile it in both Java, and Java.NET would be the best option here, and give more choice to the customers!
Consider the following:Now when you s/crazy_mul/operator*/ and s/crazy_add_int/operator+/, you can simply type:Guess what happens in the background when you use operator overloading? It turns back into the equivalent of crazy_add_int and crazy_mul! So when you use operator overloading, all you buy yourself is a false sense of confidence in some operators that are commonly understood to have no side effects. However, in your f**k'd up example, you show us why C++ is dangerous: we end up with people using class specific overloads to do braindead things like mutating the object in place (why else would you feel the need to specify clone()?).
On Windows, you can use either MS Visual J# to compile Java for .NET and then use the numeric libraries, or on Linux (and Windows) you can use ikvm ( http://www.ivm.net ) to statically compile java bytes-codes into MSIL code and run it (with .NET on windows, or mono ( http://www.mono-project.com ) on Linux & Windows).
/..sig file not found - permission denied.
how about) ));
a = sqrt(abs((b + c) * (d / e)));
vs
a = Math.sqrt(Math.abs((b.add(c).multiply(d.divide(e)
for the small cases (such as this one) it doesn't make as much difference, but for complex equations it adds up quickly.
As somebody said, there's the "famous" paper by dr. Kahan.t ent/sf2002/conf/sessions/pdfs/1079.pdf)
But Sun pulled out of the JCP regarding IEEE fp, didn't it?
One of the authors of the "Java Floating Point's Hurt Everyone" paper now works for Sun and says (in http://servlet.java.sun.com/javaone/resources/con
that "Java's floating point follow rules, just not the rules you are used to!:-)"
It's all confusing. Apparently, the information just isn't out there in the open and hasn't been ventilated enough. A lot of Java programmers apparently have never even *heard* of the issue.
Makes me shiver to know some banks use Java...!
My take: do *not* use Java for numerical computation, as "Java Specification Request for Floating-Point Extensions has been withdrawn due to difficulties in setting up an expert group" (from http://math.nist.gov/javanumerics/ ).
Hopefully there might be a better future, after Java. Despite the many popular features (garbage collection first and foremost), Java is widely regarded as a half-baked language.
Hmmmm..
And without C, where would Java be?
Nowhere!
Who is general failure, and why is he reading my hard drive?
That's really sad. You have all the functionality you want but can't progress because your favourite syntactical sugar isn't there?
... END" and I just can't live without them.
That's pathetic.
That's like saying, I've got this *great* idea but I can't code it up because I'm using C and it has brackets and not "BEGIN
It's a different language - get used to it.
Even for simple case such as yours, I'd avoid trying to pack it all on one line. Misplaced parentheses are easy mistakes to make and extemely difficult to debug.
It's simple: I demand prosecution for torture.
1. try to do everything in one environment
.NET/Java using bytecode-IL translators such as IKVM.
.NET, ...).
...)
This seems like low short-term risk because you reduce the number of technologies that have to work together, but you incur more long-term risk because of technology churn.
2. Combine libraries
A library implemented in Java/.NET can call a library implemented in
Another way is to develop bindings, like we used to do to call C++ libraries from Ada, and such.
3. 'On the wire' integration
This is similar to (2) except that you have more processes.
Using something like CORBA, you can implement a service in, say FORTRAN, that calls the FORTRAN libraries. You can then implement your client in whatever (Java, PERL, C/C++,
There are CORBA/.NET solutions, both OS and commercial, available (Borland Janeva, IIOP.NET,
Matlab may be slower than C++, but then so is Java, and Java is what the original question is asking about.
I've never seen a side-by-side comparison of Java to Matlab, but if forced to guess I'd definitely really Java to be faster. However, Java is definitely not designed for any kind of mathematical work, so coding and maintenance would end up being a pain. (Trust me, I've been there.)
If you want ease of coding for mathematics, do what this post's grandparent said, and get yourself a dedicated mathematical package. If you want raw execution speed, write in C++ or C or assembler, depending on how much you value speed over maintainability.
Don't get me wrong, I like Java, but in this situation it's the wrong compromise. It doesn't have enough coder-friendliness (for math applications) to make up for its lack of speed, nor enough speed to make it worth the trouble.
And that proves what?
"I think this line is mostly filler"
If C / C++ is so last week, and Java is the future, then how can it be that Java wouldn't exist without C.
From Java's perspective, the two are tied together.
You (currently) can't have Java without C, while you can have C, without Java.
It's safe to assume that until another language comes around that can do things as well as C/C++, that Java will continue to be written in C.
So to say that Java is the future, while condemning C/C++ to the past is short-sighted at best, and ignorant at worst.
Where would all your lovely new "Java" versions come from, if not from dedicated, hard working C/C++ programmers?
Who is general failure, and why is he reading my hard drive?
That's kind of the point, isn't it? Interpreting a line that looks like an actual equation, where all the parentheses are mathematically meaningful, is easy.
When all the operations are turned into function calls, it gets much harder to debug. That's partly because of all the extra parens, and also partly because your brain has to interpret mathematics and English words at the same time. (That kind of thing tends to be harder than working with one or the other.) If you then split the equation out onto multiple lines it gets a little easier, but is still not as straightforward as the plain-looking math.
Of course there may be behind-the-scenes problems either way, because "a + b" or a.add(b) can represent a function of arbitrary complexity. But if your operators are hiding really complicated stuff, or especially if they have side effects, that's a strong sign that your design needs to be reworked.
My f**k'd up example was in Java not C++. The problems you bring up aren't present in Java. We are discussing Java, not C++. You do not seem to be knowledgable in Java, hence your statement, '...do braindead things like mutating objects in place...need to specify clone()'. Clone does not mutate any object. The need for it is to make a copy so that c won't be modified when someone modifies a.
I'm not going to get into another religious debate over something that has been argued since the dawn of time.
1;
[Disclaimer: Until recently I was a quant, and among other things was responsible for the coding quality of Bank One's quantitative libraries. I am no longer there, and do not speak for JPMorgan, who now owns the business.]
There are two main considerations you have with respect to libraries of numerical routines:
(1) Having access to quick, accurate, and reliable numerical analytic routines such as singular value decompositions, FFTs, and optimizers.
(2) Having convenient and standard ways within your organization of defining vectors and matrices, as well as simple operations (e.g. dot products) on them.
To address the first problem, I think you have to look first to the quality of the numerical routines you plan to use. Paying attention to their native language or available interfaces is foolish. Would you really trust a 5-year-old SVD written in Java over something from LAPACK or NAG? I sure wouldn't, and I would never guarantee a model calibration based on it!
Thus, your numerical analytic routines will come in some hoary library, and you will have to interface to it as best you can. In many cases you could use JNI or, if that makes you nervous, have the Java portion communicate with the library wrapped in a separate process using sockets or something. But the point is, quality is more important than interface here.
The other issue is standardization of vector and matrix encapsulations etc. Here I am less opinionated, but my thoughts are roughly as follows: there are probably lots of vector/matrix implementations out there, some of which must be good. You might as well just choose one with an API and implementation you are impressed with...it's not as though you will be expecting it to do your numerical math. Sure you won't get operator overloading (if you're in Java) but having done financial mathematics in C, C++ and MatLab, I can say with a fair degree of certainty that you will use overloading far less often than you might think.
You now have a convenient standard for manipulating objects, and a quality library. Write the glue and you're done.
Oh, and for those people recommending MatLab/Octave/Mathematica etc., let me just say that most of us in finance know about them and many use them for prototyping. Python, and (ugh) VB too. But ultimately one is often asked to create a library that gets handed off to internal developers for use in one or more custom apps, which are then distributed to anywhere from 5 to a couple hundred users, and run on portfolios of thousands of securities. Even if, say, your MatLab routine didn't need licensing for each workstation and took just a couple milliseconds to run, you're still looking at perceptible delays before the user sees results.
Modern financial applications are one of those few remaining arenas in which computers are Not Yet Fast Enough.
When choosing a language, choose one that does what you need. Don't choose a language because it's easy or pretty if it doesn't do what you need. Moreover, if you really are limited to a single language, you are forgoing the huge swaths of comp. sci. goodness whatever language you're limiting yourself to doesn't support.
Any competent group generally needs to be able to handle a mix of languages, from C/C++/Java, Perl/Python/Ruby/etc, and the myriad of narrow languages (SQL, templating, shell & batch, HTML, lua, etc., etc.).
Perhaps you should use C, C++ or FORTRAN for the numerical portions and native Java for the general purpose portions.
- Barrie
Operator over loading is a redherring. I would think using a math markup language to handle the User interface part would be a nice way to go. Then you can simply write a parser to convert the markup to execution code. that way, you can easily change the parser to generate more optimized code. just a thought. then it wouldn't matter if the actual library is written in C/C++/Java/C# or some other language.
I have just the opposite opinion. Interpreting a line (or multiple lines) with method calls is no more or less difficult than interpreting lines with overloaded operators. I think the OP has the opposite opinion and I was trying to understand why they felt that way.
It's simple: I demand prosecution for torture.
a = Math.sqrt (
Math.abs ( b . add ( c )
. multiply ( d . divide ( e ) )
)
);
Is bulkier. But you can see exactly what is happening... Contrast with:
a = sqrt(abs((b + c) * (d / e)));
And try to figure out why FOO::BAR::BAZ(char*) is being invoked with a const string.
Also: You may want your add/multiply routines to modify the object rather than creating unnecessary new objects. To avoid unnecessary replication costs when each object is measured in megabytes...
a . copy ( b )
. add ( c )
. multiply ( d )
. divide ( e )
. abs ( )
. sqrt ( );
Which works provided each method returns the current object.
But dude, have you ever programmed in C++? Used STL? Blech! Blech^2! I know there are people who love these things, but the readability is unforgivable. Only a Perl code could make it look good. Operator overloading brings out the worst in developers, encourages them to be waaaay to clever for anybody's good. In C++, the evil started with (what the hell were they thinking?!) and went downhill from there. Once you open the door to crap like that, the crap will come.
Years ago, I was at a forum with Josh Bloch and Gilad Bracha where a Java numerics guy berated them for not having overloading and asked them to add it. Bracha basically said "over my cold, dead body." I'm with him on that. The greater cause of readable Java trumps the minor benefits of overloading.
I think his problem is elsewhere: without overloading he would end up with something like:
a = Math.sqrt(Math.abs((b + c)multiply((d/e)) ))
That is, a mix of "native" operators and adhoc methods. With overloading you would be able to forget about the type of the variable or the return value and let the VM figure it all out.
"In our tactical decisions, we are operating contrary to our strategic interest."
but it won't drill holes, what do I have to do to my hammer to make it drill holes?
---
object-oriented design is the roman numerals of computing.
-- Rob Pike
other witicisms
There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
I am a quant who uses Fortran 95 for the things you mentioned -- it has built-in multidimensional arrays, including arrays with complex elements and operator overloading, and it's cross-platform if you write standard Fortran 95 and have compilers for needed platforms. You can compile code to DLLs for use in Excel etc.
Since you've said that your department has experience with both C++ and Java, have you thought about using the Java Native Interface. JNI basically allows you to use some native methods that you can write in C++ in your java application. Sun has some good good articles on their website about it, and after spending a couple hours with it, it's pretty easy.
This will allow you to make use of a lot of pre-existing C++ code, and to write code in C++ when it turns out to be better at a particular problem, while still using Java for the majority of your application.
I've used JNI extensively for graphics applications (which are heavy on math), where it's either much faster in C++ (yes yes, java is much faster than it used to be, but sometimes much faster still isn't quite fast enough), or just much easier to solve a given problem in C++, even though Java is the best choice for most of the application.
Famous Last Words: "hmm...wikipedia says it's edible"
I agree with AC! Another benefit would be that you'd be separating data from processing, which would allow easy formula manipulation without needing a programmer (assuming that you'd have some sort of nice formula editor that can spit out the XML for you).
"In our tactical decisions, we are operating contrary to our strategic interest."
There is a list of several packages here: http://math.nist.gov/javanumerics
But don't expect much. Usually you'll have to convert your c++ or whatever code to java yourself. That's what I do. We build our own Java numerical library and use others as well. We use numerics for air flow simulations not finance so our old code is in fortran. I'd suspect there are more commercial java packages directed at finance.
Take a look at J.A.D.E. Java Addition to Default Environment.
It seems to have some nice math and physics packages.
You can also use Eclipse, JUnit and Ant with Nice. Don't hesitate to ask for help on the nice-info mailing list.
Watch great movie opening scenes!
Actually, it would seem that YOU'RE the one that doesn't know about Java. The operations you perform with A mutates A, and after the mutations, you clone it. In your example, you'll end up with
c.equals(a) == true
presuming that you have implemented equals correctly, of course
Gee, I wish you had logged in. You need some negative mod points.
You didn't realize FOO::BAR::BAZ(char*) will never be called unless you attempt a *unary* math operation on a string of const char*. (Why would you implement that??!?!?)
Also, C++ operator overloading can modify objects instead of returning new ones -- (How pre-increment, etc)?? Also, if you return by reference, a decent compiler should be smart enough to figure out what is going on....
and templates (generics) are the other half.
Every modern C++ financial library employs templates. Not only do they save time in writing code - the high quality C++ optimizing compilers these days crunch that template code down into very small and fast code. I don't think Java generics are mature enough to provide the same quality code. To my knowledge there are no financial libraries that make use of Java generics either. I'd wait a couple of years before embracing Java for heavy math crunching.
You might be better off with.
CrazyObjectNumber c=a;
c*=b;
c+=53;
This reduces the number of temporaries required. I use c++ and I hate object overloading because people hijack operators to mean silly things. For example, operator~ means surface integration and operator! means volume integration in this code I work in.
If something is commonly expected not to produce side-effects, then the coder should write it so that it will not produce side-effects.
How hard is that?
Marxist evolution is just N generations away!
We use MathML.
:= a/b; a method with name quotient and parameters a and b is created. If the term a/b gets more complicated like a sum or a integral, it is mapped to library functions.
You can use editors in most Word processing environments to write formulars in MathML. E.g google for "MathType".
We then use a generator to map MathML on java methods. If methods are mising we write them.
For a MathML equation like: quotient
As I said above, if such a function is missing a programmer writes it.
angel'o'sphere
Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
If you find yourself doing MI where the same base class gets inherited there's a very good chance you're doing something wrong.
Marxist evolution is just N generations away!
What you describe is a classic example of "mommy" thinking -- absolutely preventing the use of a feature which might be immensely valuable (or essential!) 10% of the time, because there is a chance that someone, somewhere will misuse it. It's the computational equivalent of forcing everyone to use safety scissors -- after all, someone might hurt themselves!
I do program in C++, and I know that it's one of the most flexible, expressive, and efficient programming languages that you'll ever find. It is a language for professional programmers who do not wish to be told how they must do something, in favor of being allowed to just do whatever it is that they're trying to do. So-called "ugly" languages (like Perl) share this philosophy. It's part of the reason that they're so widely used.
Coding in Java is a bit like trying to go through your life wearing nothing on your hands but Big Fluffy Mittens. There's nothing wrong with Big Fluffy Mittens, per se, and Big Fluffy Mittens are undeniably wonderful when you're making a snowman. Still, they kind of suck for brain surgery.
Let's try not to let fact interfere with our speculation here, OK?
Could we please try lo list why "operator overloading" is such a troublesome feature?
:-)
//ok, concatenation of the 2 vectors //what the hell does that mean?
:-) can't find such a way, or is not justified by the advantages (cleaner syntax in economics and mathematical expression) then we would not ask for it...
d =4905919
The statement "since it is so easy to misuse" doesn't count: I'd like to know WHY it is so easy to misuses.
The statement "you'd better use other languages for mathematical calculus" doesn't apply either: I'm in a financial project and we use Java, and there are some pretty complicate expression even in economics.
The statement "I used it in C++ and it was a mess" is also not appropriate as an answer to my question: if Java will ever consider this feature, there's no reason why it should copy the C++ style.
On the other side (the operator overloading fans):
the statement "I'm not going to" doesn't apply; your colleague could do and you would kill him after tracing a bug
The statement "The expressive power of this feature is more important than the possible misuses" doesn't apply either: Java tries to avoid misuses by forcing programmers to behave properly and we should respect this philosophy (not meaning I'm against the feature.. only I'd like to have it without the major cons)
My opinion:
"Why it is so easy to misuse and mantain?"
1) At first glance you could not realize if the symbol "+" is a simple primitive "sum" or a more elaborate object operator
2) sometimes the notation is simply "out of this world" (ehm... meaning "not natural"
Example: (let me write in pseudo-Java)
Vector v1=new Vector();
Vector v2=new Vector();
Vector v3=v1+v2;
Vector v4=v2-v1;
3) if we choose a C++-like implementation we could have a "operator+" (-/*) method that has its own implementation (possibly different from add() or any other method in the class)
4) if we choose a C++-like implementation we wouldn't have just one place to look at to understand the meaning of operators (they could be overloaded twice or more times in the class hierarchy)
Any other reason in your opinion?
Then when we have all the reasons listed we could consider if there could be a way (compatible with "Java guidelines") to add this feature without incurring in all this misuse problems.
If we (or Sun
Last thing:
you can vote for this feature (or stand against it ) at this URL (registration needed) http://bugs.sun.com/bugdatabase/view_bug.do?bug_i
This message doesn't need a sig
There's a serious question here as to how much performance you're willing to sacrifice just to be able to live solely under the JVM, though.
Are you adequate?
If you have to say the same thing twice in a program, you're probably doing something wrong.
Are you adequate?
1) I noticed I went slightly offtopic.. (sorry)
The original question was "what can I use to make numerical analysys?" while I followed the track "Operator overloading is good/evil"
2) the sentence "I'm not going to" was "I'm not going to misuse this feature"
This message doesn't need a sig
If your expected use is constrained enough, you can probably get away with writing some sort of simple code generator. You parse algebraic expressions, generate an abstract syntax tree, and use that tree to spit out appropriate java code.
Are you adequate?
There are schools of thought that would argue any use of MI that doesn't involve common base classes is probably doing something wrong. In practice, either view is rather absolute, no?
There are useful idioms using mix-ins, and there are times when combining two separate hierarchies is justified. There aren't many of either -- hence the unpopularity of any sort of multiple inheritance of implementation in some quarters -- but IME both have their uses, and when the time is right, it's much simpler to use the appropriate MI-based design than to work around it.
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
Here are a few reasons not to do it.
We use high level languages instead of assembler because they let us work at varying levels of abstraction, keeping what we're doing relatively simple at each level and delegating the details to the levels below. That makes for more readable, less error-prone code. What you're advocating is the very antithesis of this approach; if you're going to be that clumsy, you might as well write in assembler. In fact, on reflection, that would be neater...
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
The problem with using << for C++ I/O streams isn't really the use of operator overloading, it's the fact that it puts into code what should be data: the order of the terms to be output. As anyone who's worked with internationalised code much can tell you, that's a "D'oh!" mistake.
As for readability, I write serious maths software using C++. We already use complex matrix multiplication expressions and the like, which are hard enough to read already when you're constrained to a textual representation. From a numerical programmer's perspective, you can have my overloaded (and highly readable) operators over my code, dead body.
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
While many of your points (for either side) have merit, I think it's important to remember that programming is a skill. It is not something just anyone can do, and doing it well requires a sufficient level of knowledge and ability. If you're working with people who Just Don't Get It(TM) so badly that they write misleading operator overloads, then you have far bigger problems than the presence of operator overloading in your language.
Languages can protect against careless errors: everyone knows you shouldn't dereference a NULL pointer, but in some languages, you have the option to do so by mistake. But languages cannot protect against a lack of understanding of how to use your tools, no matter how restrictive they may be.
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
From the standpoint of a language, Matlab is, gee, I don't know where to begin. It really has this cobbled-together lets-figure-out-how-to-graft-on-objects feel to it like Visual Basic only more so. The really simple is simple, and the somewhat complicated gets to be rats' nest really fast.
Sure, it can make your classes look like part of the core libraries, but it is only a simple redirection of function calls. It is really just a change in syntax that doesn't really add any new functionality to the language. To me, I'd rather add a toString() method to my Java class so I can use it with print() or println(). If I wanted to do it the c++ way, I would probably make a toString() method anyway and just call that from the overloaded operator. Same idea just different ways of going about it.
SIGFAULT
I see comments as complementary.
;) ).
Unit tests might sometimes not work (or give useful results) when the program isn't working - e.g. badly broken. Whereas the comments could still be useful in those cases (maybe even more so
And if you are looking at the code, means you are going to be spending time with the code anyway, so the comments are a nice and handy reference.
I don't think you'd need comments everywhere - at least for most code - since most code is just run of the mill. Comments would be useful if you are doing something exceptional, or something important. e.g. "This weird stuff is to work-around bug #1467 in version x.y.z of software ABC".
Sure you should write documentation for that and refer to the documentation. But it is handier to have the comments around as well.
"Why it is so easy to misuse and mantain?"
was
"Why it is so easy to misuse and hard to mantain?"
This message doesn't need a sig
The problems you bring up aren't present in Java. We are discussing Java, not C++. You do not seem to be knowledgable in Java, hence your statement, '...do braindead things like mutating objects in place...need to specify clone()'. Clone does not mutate any object. The need for it is to make a copy so that c won't be modified when someone modifies a.
The other AC was pointing out that your second "equivalent" example revealed that your overloaded operators were mutating the objects when they shouldn't (a = a.multiply(b) is the same as a*b?!?!), which actually presents the case against operator overloading: people sometimes feel free to change their meanings.
First, you might be interested in Jakarta Commons Math, which is about to release version 1.0 : http://jakarta.apache.org/commons/math/index.html
...) in a human-readable format.
Secondly, I'd probably consider isolating all the formulas and then put them aside somewhere (XML, database,
Then make a parser that can read that format (i.e. using the libraries you mentioned), substitute variables, and calculate a result. The advantages that I see:
1) you centralize all numerical stuff
2) in a readable format
3) so operator overloading (or the lack of) will only bother you in the parser
4) it will be easy to change or add formulas without having to recompile everything
5) easy to write tests (junit)
6) easier to change underlying math-libraries without affecting the rest of your code.
FYI, java compilers and environment are coded with Java, not with C.
importing static methods in java 1.5 should clean that syntax up a bit since you won't need to have the "Math." everywhere. Or straight from Sun: http://java.sun.com/j2se/1.5.0/docs/guide/language /static-import.html
Your CPU is not doing anything else, at least do something.
The problem with using << for C++ I/O streams isn't really the use of operator overloading, it's the fact that it puts into code what should be data: the order of the terms to be output. As anyone who's worked with internationalised code much can tell you, that's a "D'oh!" mistake.
It's not a "D'oh!" mistake. Almost every basic I/O library, from C's printf() to Java's System.out.println() to Perl's print(), forces you to specify the order that the arguments are displayed. That has nothing to do with operator overloading. If you want code that allows you to change the order of the arguments in some sort of data file, then you need to use a more complicated library, like Java's java.text.MessageFormat. If you don't, then the basic functionality is perfectly fine.
In addition to the lack of operator overloading, there are other problems with Java for numerical computing. For example, it doesn't have "complex" and similar data types, and it has no means by which you can define them yourself efficiently either. Also, Java does not have true multidimensional arrays.
The C# language is considerably better for numerical computing than Java. However, C# implementations are still a bit behind Java implementations (although they seem to be catching up fast).
I would recommend sticking with C++ for now and waiting another year to switch to something else. C# will probably mature to the point where it is a reasonable choice.
Here's something that's potentially useful.
Jakarta's Commons Math library (http://jakarta.apache.org/commons/math/) has some interesting classes (including handling of complex numbers and lots of statistical stuff). I haven't used it in anger and hence do not know the extent of their support for the features you are looking for, but it is a good start. It is also designed to be a lot faster than Sun's math APIs.
And yes, they're all objects and there is no operator overloading. And I reflect sentiment earlier about how this is a Good Thing in general.
-- Manik Surtani
If something is commonly expected not to produce side-effects, then the coder should write it so that it will not produce side-effects.
How hard is that?
Harder than you think.
The problem is that side-effects are not always obvious. In a language without operator redefinition, you can look at "+" and know it has no side-effects. In C++, you have to read the code for the class in question and reason about it yourself, if you want to know. Let's hope you're not using a closed-source library, eh? And even if you have the code and read it, you might well get lost in a maze of twisty little constructors, all alike, and draw the wrong conclusion.
Overloaded operators are unquestionably useful - it's nice to be able to use + for floats and strings as well as ints, for example. But overloading should be left to people who know what they're doing. I trust language designers, I don't trust random programmers, so I don't like C++ libraries that overload operators.
Maybe you do trust random programmers -- but if you do, please post a list of projects you have worked on, so I can avoid them for the safety of my data.
Sparc assembler, you mean, of course.
That's only true for a language that doesn't allow dynamic binding or proxying: ie it's a work-around not a fundamentally requirement. The reason I'd call it a work around is because it uses nheritance for implementation (the same as private inheritance: something that real ;-) OO languages don't have).
Bad analogies are like waxing a monkey with a rainbow.
Protozoa can exist without you, too.
"Little does he know, but there is no 'I' in 'Idiot'!"
Don't focus too much on what is in the box. If you really want the operator overloading you can get it from JFront as you mention yourself. So add that to the mix in a gentle way.
Here's what I would do:
1. Modulize all the heavy math stuff you do into a couple of well defined modules (or subprojects if you like that term better).
2. Have all other modules interact with the computation modules on a logical level where you work in terms of getBigResult(arg1, arg2).
3. On the math modules use ant: http://jakarta.apache.org/ant to preprocess the code on those modules with JFront before compiling.
That approach would allow you to use JFront and the sugar that provides without getting too painful for the rest of the project.
In the current case, we want to use the more convenient notation for these computations (the plain old mathematical notiation) as the canonical one, and somehow get from it to the executable code. The best solution is to have it happen automatically, i.e., to have some program that will convert "a + b / c" into the program you want. This can be done directly (use a computer language with appropriate features), or indirectly (use a preprocessor to automatically convert the good notation into the java code, and then compile the latter).
Your solution involves (a) writing the same thing twice manually, (b) having the easy, desired notation be a comment, and thus not be the one that's converted into executable code; (c) have the process of translating the friendly notation to the unfriendly one be done manually, one time after the other.
Yeah, but nowhere did I suggest duplicating the code.
But my point is that in this case the comment should be the code. If what's written in your comment needs to be translated manually into something else, then you should write code to translate it automatically.
Are you adequate?
From a mathematical point of view, the prefix notation represented by a function with arguments makes much more sense than the infix notation represented by operator overloading.
Operator overloading only makes sense in a small number of cases where the class you are developing only provides binary and unary operations. There are many more cases where a function should be tertiary or more. In these cases, you have to abandon operator overloading and use the same functional notation anyway. Also, sometimes operator overloading doesn't even make sense. E.g. How do I overload the * operator for vectors?
In the end, when developing a library like that using operator overloading is going to have to use inconsistent representation for operations - which is just ugly - imo.
And have you ever tried to run Java sans shared libraries?
All those lovely libxyz.so type files...
Those aren't java my friend.
Those are lovely shared objects courtesy of C/C++
Very few languages can be used to compile themselves...
And I do not belive that Java is one of them...
Who is general failure, and why is he reading my hard drive?
"Dislike virtual" .. Mwahaha .. give me a break.
How is that a problem? Is it a problem because maybe a date in one country has the year in a difference place than the date in another country? If it's something like that, hey you're in luck! The C++ iostreams library was designed with just such a possibility in mind.
The answer is that you've got to define your own datatype for handling "date" information and deciding on how it's to be output (which elements and in which order). This allows you to *simplify* the code that writes the actual data. For example:
MyDateClass MyDate(1, 1, 2004);
cout << "Today is " << MyDate << endl;
So what's wrong with that?
___
The ends are ape-chosen, only the means are man's. -- Aldous Huxley
Actually, quite a few languages can be used to compile themselves, or, properly speaking, quite a few compilers (for various languages) can be (and are) used to compile themselves (or, for that matter, other compilers for the same language). And most languages could be used to develop a compiler for the same language (though it may not be worthwhile) -- say, any Turing-complete language with appropriate storage capacity and I/O facilities. After all, what is a compiler, other than a fancy data conversion application? Naturally, you need to bootstrap a compiler for a new language using tools written in other languages (possibly building up to a subset of the target language, but that's still another language), but that's necessarily true for all compiled langauges, as well as assembly.
If I'm not mistaken, javac is implemented in Java. To wit:
Of course, the back-end of javac emits Java bytecode, but there's no reason a compiler for Java, written in Java, with a native back-end couldn't be written.
huh?
Java is a turing complete language. It can be used to implement any other turing complete language.
Where do yu think C first came from? It did not burst forth, fully formed, from the loins of Kernigan and Ritche... it was originally written in some other language. As it became turing complete, it could be re-written in itself.
-db
http://jakarta.apache.org/commons/math/
You may also want to take a look at:
http://math.nist.gov/jnt/
http://www.vni.com/products/imsl/jmsl.html
http://www.mathtools.net/Java/Libraries/
there's a reason why ppl invented those operators (in real math) and continue use it.
according to the easy to misuse theory, gun is bad. it's so easy to kill ppl using a gun.
For example with C++ you can make any streamable object persistant by inheritace. You count on streaming operator overloading to make you save and restore functions work.
But the Java zelots don't like multiple inheritance eather. I'd say its lack groups Java with VB as a pseudo OO language.
John McAfee 'It was like that time I hired that Bangkok prostitute; to do my taxes, while I fucked my accountant'
I also dislike non-plotter output for the same reason.
I just don't think high level language programming is the greatest thing since sliced bread. That's a very unpopular view.
John McAfee 'It was like that time I hired that Bangkok prostitute; to do my taxes, while I fucked my accountant'
In Fortran 77 all variables are static. Saves allocate time and allows for more efficent machine code from the compiler. I've never seen a FORTRAN To C translator that translated all FORTRAN variables into Static C variables (haven't looked in some time). That might produce interesting benchmarks.
Of course the static array demension restriction brings on many problems of it's own.
John McAfee 'It was like that time I hired that Bangkok prostitute; to do my taxes, while I fucked my accountant'
In the context of mathematics (this thread), vector addition and subtraction should be scalar operations; therefore, your example of concatenation is counterintuitive.
Furthermore, these operations should only be defined for vectors of equal dimension (and that's going to require runtime checking unless you use a typedef for each vector size).
And finally, note that vector multiplication is also troubling since you'd have to pick if you want a scalar (dot product) or vector product (cross product). And once you pick one over the other, you're left with no way to express the other using standard overloadable operators.
These are examples why Java and C++ operator overloading are not suitable for mathematics.
It seems I mixed contexts... (sorry)
I meant Vector as in Java libraries, that is "a Collection". I should have used "List" instead.
I wanted to say that sometimes "operator overload" is used out of maths/economics context and this is sometimes confusing
This message doesn't need a sig