Version française
Home     About     Download     Resources     Contact us    
Browse thread
RE: [Caml-list] Operator overloading
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Robert Fischer <RFischer@R...>
Subject: RE: [Caml-list] Operator overloading
> For example, I often define +| for vectors, +|| for matrices, *| for 
> scalar-matrix multiplication, *|| for vector-matrix and *||| for 
> matrix-matrix. I also want to support complex numbers and symbolic 
> expressions and I don't particularly want to remember and document 50 numeric 
> operators, nor explain their existence to my customers...
>
Which is exactly my point.  You should have to document all that, because they are genuinely different operations.  You have these operations, so why shouldn't you document them?  Or, better yet, abstract them and organize them.  By using operator overloading, you're sweeping under the rug genuine complexity -- something that my surprise later developers!

When I see "+", I want to know what that means.  With operator overloading, I don't know.  An IDE might help me out there, but that's just polishing a genuine ding on code readbility and maintainability.  Why should I have to rely on an IDE to make sense of my code?

If I have a typing issue in my code, I want the compiler balk at where the problem is.  The best I can hope for with operator overloading is that the result type is caught through a failure of duck typing shortly down the pipeline -- but that very safety would is undermined if "down the pipeline" also uses lots of operator overloading.

I'm very sure that you can code with operator overloading and be productive.  The person writing the code probably even feels like it's a productivity and readability boon.  But I see maintainability as a big problem here.  As far as I'm concerned, if two things do different things, they should have different names.  You can give them funny names like "+|", but it should still be different names.

~~ Robert.

-----Original Message-----
From: caml-list-bounces@yquem.inria.fr
[mailto:caml-list-bounces@yquem.inria.fr]On Behalf Of Jon Harrop
Sent: Thursday, March 08, 2007 1:41 PM
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Operator overloading


On Thursday 08 March 2007 17:54, Brian Hurt wrote:
> Roland Zumkeller wrote:
> > Wasn't there a more or less good reason for OCaml *not* to support
> > operator overloading?
>
> Yes.  Ocaml has modules and functors.  IMHO, any time you thing "boy,
> it'd be really nice to use operator overloading here", you should use a
> module and a functor instead.
> ...

For me, operator overloading is about clarity. In the absence of operator 
overloading, you cannot regain the lost clarity using modules and functors.

This is one of the two things I missed when I moved from C++ to OCaml: 
operator overloading and template metaprogramming for low-dimensional vector 
and matrix operations. The latter can be addressed by autogenerating code. 
The former cannot be addressed in the current OCaml.

For example, I often define +| for vectors, +|| for matrices, *| for 
scalar-matrix multiplication, *|| for vector-matrix and *||| for 
matrix-matrix. I also want to support complex numbers and symbolic 
expressions and I don't particularly want to remember and document 50 numeric 
operators, nor explain their existence to my customers and I certainly don't 
appreciate reading expressions written in this syntax.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs