Jump to page: 1 2
Thread overview
It's a dead horse but I still need it to go... (opAssign)
Nov 19, 2005
Traveler Hauptman
Nov 20, 2005
Factory
Nov 20, 2005
Derek Parnell
Nov 20, 2005
Oskar Linde
Nov 21, 2005
Ben Phillips
Nov 21, 2005
Derek Parnell
Nov 22, 2005
Ben Phillips
Nov 22, 2005
traveler hauptman
Nov 22, 2005
Georg Wrede
Nov 20, 2005
Manfred Nowak
Nov 20, 2005
Traveler Hauptman
Nov 20, 2005
JT
Nov 20, 2005
Manfred Nowak
Nov 21, 2005
Derek Parnell
Nov 21, 2005
Traveler Hauptman
opSliceAssign (was Re: It's a dead horse...)
Nov 20, 2005
Nick
November 19, 2005
I do embedded/real-time programming for robotics. I like the D language and have been playing with a vector/matrix math class. With vanilla code (no assembler) and standard optimization it is 5 times faster than equivalent vanilla C++ code and 3 times faster than C. It does not use the built in garbage collector, rather what walter calls a fast-stack. It's everything I wished I had...

Except my code reads:
{
  Vect a = new Vect(6);
  Vect b = new Vect(6);

  a.fill(1.0);
  b.fill(2.0);

  b.assign( c + 2.0 * a + a * b + 10.0);
}

To be so close to nirvana and without an opAssign()... I want to cry.


Just wanted to share my misery...

Traveler
November 20, 2005
In article <dlo5mc$17oh$1@digitaldaemon.com>, th@barrett.com says...
> Except my code reads:
> {
>    Vect a = new Vect(6);
>    Vect b = new Vect(6);
> 
>    a.fill(1.0);
>    b.fill(2.0);
> 
>    b.assign( c + 2.0 * a + a * b + 10.0);
> }
> 
> To be so close to nirvana and without an opAssign()... I want to cry.

  Hmm I just use a static function called ctor(). ie

struct Vect
{
	static Vect ctor( int _x, int _y )
	{
		Vect v;
		v.x= _x;
		v.y= _y;
		return v;
	}
	...
};

  Which isn't perfect, but it's pretty close.

Vect v= Vect.ctor( 0,0 ) + Vect.ctor( 1,1 )

compared to

Vect v= Vect( 0,0 ) + Vect( 1,1 )

  (But then again I merge all my .d files into one
before compiling to get around the (IMHO unusable)
module system, so I'm no guru :) )

  - Factory
November 20, 2005
On Sat, 19 Nov 2005 16:34:44 -0500, Traveler Hauptman wrote:


> Just wanted to share my misery...

Thanks. Its like having $300 customized running shoes that do the perfect job, but constantly finding little pebbles in them.

Not have an 'op'_something_or_other_name that gets called when the form

  classinstance = something;

is so frustrating. I still fail to see the overriding, blinding obvious, reason for not having it.

-- 
Derek Parnell
Melbourne, Australia
20/11/2005 5:29:08 PM
November 20, 2005
In article <1ol6gofhwkngq.18oz5jfsrgka$.dlg@40tude.net>, Derek Parnell says...
>
>On Sat, 19 Nov 2005 16:34:44 -0500, Traveler Hauptman wrote:
>
> 
>> Just wanted to share my misery...
>
>Thanks. Its like having $300 customized running shoes that do the perfect job, but constantly finding little pebbles in them.
>
>Not have an 'op'_something_or_other_name that gets called when the form
>
>  classinstance = something;
>
>is so frustrating. I still fail to see the overriding, blinding obvious, reason for not having it.

I fully agree that not having assignment overloading is severely limiting. One reason may be that classes are reference types. If classes started overriding opAssign, you would have to resort to pointers to classes to make pure references.

There is one middle road though: Allow copy/assignment overloading for structs. Considering the value based nature of structs, this feels very natural. If this was possible, you could even wrap the class reference in a struct if you needed custom assignment semantics.

/Oskar


November 20, 2005
Traveler Hauptman wrote:

> but I still need it to go... (opAssign)

Where is the need?

Or more detailed: why a class instead of a struct?

-manfred
November 20, 2005
In article <dlo5mc$17oh$1@digitaldaemon.com>, Traveler Hauptman says...
>
>Except my code reads:
>{
>   Vect a = new Vect(6);
>   Vect b = new Vect(6);
>
>   a.fill(1.0);
>   b.fill(2.0);
>
>   b.assign( c + 2.0 * a + a * b + 10.0);
>}
>
>To be so close to nirvana and without an opAssign()... I want to cry.

Why isn't there an opSliceAssign operator? Seems to fit naturally with the opIndex/opIndexAssign operators. It would at least allow you to write

b[] = c + 2.0*a + a*b + 10.0;

which IMO would make MORE sense than opAssign in your case, since you are not simply overwriting the b reference but doing something to the contents of b. (Just like the difference between "a = ..." and "a[] = ..." in normal D arrays.)

Nick

PS: As a crude hack you could always make an

void opIndexAssign(Vect v, int dummy) { assign(v); }

and write b[0] = c + ..., but it's not terribly nice :)


November 20, 2005
Manfred Nowak wrote:
> Traveler Hauptman wrote:
> 
> 
>>but I still need it to go... (opAssign)
> 
> 
> Where is the need?
> 
> Or more detailed: why a class instead of a struct?
> 
> -manfred

I am not looking for a "copy contents on assign"; Because I cannot use the garbage collector and malloc is too slow; I have a specialized memory manager for my Vector/Matrix class.

On "assignment" I clean up the calculation stack. In debug/profile mode I also collect calculation statistics.

-traveler



November 20, 2005
In article <dlq9ge$2sq3$1@digitaldaemon.com>, Traveler Hauptman says...
>
>Manfred Nowak wrote:
>> Traveler Hauptman wrote:
>> 
>> 
>>>but I still need it to go... (opAssign)
>> 
>> 
>> Where is the need?
>> 
>> Or more detailed: why a class instead of a struct?
>> 
>> -manfred
>
>I am not looking for a "copy contents on assign"; Because I cannot use the garbage collector and malloc is too slow; I have a specialized memory manager for my Vector/Matrix class.
>
>On "assignment" I clean up the calculation stack. In debug/profile mode I also collect calculation statistics.
>
>-traveler
>
>
>

Maybe you could use one of the other ops you arent using like the ~= cat op. Wouldnt it be ironic if in walters desire to make the code less obfuscated people worked around his limitations and in fact made it more obfuscated. Im afraid that in some cases this will be the result. I would love an opAssign, and Im hoping to just implment one via a compile time metaobject protocol, where a modified D front end will simply replace all instances of x = y with x.opAssign(y) and sends it to the DMD compiler. So in the end I dont really mind. Walter has made the language so easy to parse that extending the laguage is fairly simple.


November 20, 2005
Traveler Hauptman wrote:

[...]
> On "assignment" I clean up the calculation stack. In debug/profile mode I also collect calculation statistics.
[...]

I see. Now please explain, what should happen with expressions like

x= y= b= c= c + 2.0 * a + a * b + 10.0;

Especially if x and y are of types derived from your vector class?

Are you able to present a homogene solution under all aspects?

-manfred
November 21, 2005
On Sun, 20 Nov 2005 23:00:30 +0000 (UTC), Manfred Nowak wrote:

> Traveler Hauptman wrote:
> 
> [...]
>> On "assignment" I clean up the calculation stack. In debug/profile mode I also collect calculation statistics.
> [...]
> 
> I see. Now please explain, what should happen with expressions like
> 
> x= y= b= c= c + 2.0 * a + a * b + 10.0;
> 
> Especially if x and y are of types derived from your vector class?
> 
> Are you able to present a homogene solution under all aspects?
> 

Yes. Assuming that 'homogene solution' in this context means 'solution that works as expected'.

-- 
Derek Parnell
Melbourne, Australia
21/11/2005 1:00:46 PM
« First   ‹ Prev
1 2