Re: [Vala] Operator overloading



Yu Feng wrote:
On Sun, 2009-03-22 at 15:27 +0000, pancake wrote:
Are there any plans to implement operator overloading in Vala?


We can also use the operator overloading to wrap access to optimize
paralelized operations to be done in a while by using external APIs
like OpemMPI or any liboil to optimize code with MMX/SSE stuff.
On this point:

Getting parallel is more related to loops than to operators.
A family of [OpenMP (... = ...)] implementing the OpenMP specification
would be sufficient for implicit parallelism.

OpenMPI(and its predecessors - lam/mpich) are not designed for automatic
parallelism; they are for explicit parallelism.

Yep, mono has added something like this using MMX/SSE and
multimedia arm extensions with classes using these instructions
to operate over 4 packed integers at a time or so. It's not a
full abstraction, but the underlaying implementation can provide
the cpu detection and proper optimization for such operations.

At the end its just to ease the task of the end compiler to detect
such loops and optimize them using SIMD instructions (but gcc
doesn't support this), only ICC afaik.
Another nice feature would be to add an 'auto-cast' capability using
code attributes over the class definitions to simplify the code writing
when a cast is necessary to be done. for example:

   string str = obj.to_string();

This can be simplified and defined as:

.. Object definition (or any other class) ..
 [[CCode (autocast="string")]
 string to_string();

So we can now do:
  Object obj = new Object();
  string str = obj;
This is flexible in writing, but unreadable for the reader. To
understand string str = obj, the reader has to find the definition of
Object, search for all autocast annotations, then guess which is which.

Yes, I agree on this point, it was just a proposal to simplify code
and make it more 'dynamic' boxing friendly.
This is a not very complex situation, but we can for example serialize
data types into xml strings in a simple way with this concepts.
The more complex the situation gets, the more difficult for the reader
to understand the code. Verbosity is not always bad, given that our
brains are not compilers.

Does java support operator overriding? Python? C#?
c# does. Here's a sample syntax:

public static Complex operator +(Complex c1,Complex c2)
{
 Complex temp = new Complex();
 temp.x = c1.x+c2.x;
 temp.y = c1.y+c2.y;
 return temp;
}



--pancake



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]