February 20, 2009
Weed Wrote:

> Good (I think) use cases have been in this thread

They may be good, but they don't show what can be done in C++ and can't be done in D. You were advised to use structs for value semantic.
February 20, 2009
2009/2/21 Weed <resume755@mail.ru>:
> Kagamin пишет:
>> Weed Wrote:
>>
>>> Good (I think) use cases have been in this thread
>>
>> They may be good, but they don't show what can be done in C++ and can't be done in D. You were advised to use structs for value semantic.
>
> We are beginning to repeat itself. Okay. :)
>
> On D you may write anything. Even without cycles! With only "if" and "goto" keywords. The question of the costs of such a code.  :)
>
> An example is unnecessarily complex code here: http://www.dsource.org/projects/openmeshd/browser/trunk/LinAlg/linalg/MatrixT.d
>
> See line 227, template MultReturnType(ArgT) {
>
> This template is necessary to receive by value a structures containing
> the vectors and matrices as mathematical operations results. Receiving
> the vectors and matrices by value in structures needed to increase
> performance.
> Try to add here another 3 or 4 types of the returned object to this
> template?

I think I answered this already, but here goes again:

1) D2 has auto return type deduction, so this whole template probably
isn't necessary in D2, you just use typeof(return) instead, IIRC.

2) A better way to manage the case where you are concerned about supporting any kind of user type is to have the caller supply a "traits" template that describes how the type implements the underlying concept, how to access an element in a generic way, etc.  I didn't do that in the above code because A) I hadn't figured that out yet, and B) I moved on to the next thing once I had something working, and the above was doing what I needed it to do.

> In C++ vector, matrix, and all other possible objects would have been the class derived from common base class and this problem does not occur.

I'm sure if you look you can also find many C++ matrix classes that are not written that way.  Probably fewer are written the way you suggest, actually.  But as always you're plenty vague about what you mean here.   Do you mean the mult function would return a generic Matrix type?  That function does a by-value return.  You'd have slicing if you did that with polymorphic classes.

Actually from what I've seen, most C++ matrix libraries that support generic types do so by heavy use of argument-dependent lookup (ADL) aka Koenig lookup.   Basically you just define your own mult<MyType> specialization in your own header (or maybe you use the generic mult template, but have a specialization GetElement<MyType> in your own header.  There are various ways to do it).   The way C++ works, these will get used by the generic template if they are the best match.

D doesn't have ADL, and I griped about it for a while because it makes porting those kinds of C++ code difficult.  But in the end I think that style of programming leads to maintenance headaches.   You see GetElement being called in some module you're reading and you want to see its definition -- it could be anywhere!   With the D/traits approach I mentioned above such code must be injected explicitly into the template via a parameter of some kind, which gives the maintenance programmer a little bit better chance of finding where it comes from. It may not be so much better, but anyway it seems to allow you to do the same kinds of things you could do with ADL.

If you want to go the polymorphic route with D you can.  As I think has been pointed out plenty.

Why don't you just show us the class in the way you would like to write it in C++, and we'll show you how to write it in D, or finally agree with you that it's not possible.   But as long as you continue to be hand-wavy about "common base classes" we're at a bit of an impasse.  So far everyone thinks D can do what you want it to do based on your vague descriptions.

--bb
February 21, 2009
Bill Baxter пишет:

> Why don't you just show us the class in the way you would like to write it in C++, and we'll show you how to write it in D, or finally agree with you that it's not possible.   But as long as you continue to be hand-wavy about "common base classes" we're at a bit of an impasse.  So far everyone thinks D can do what you want it to do based on your vague descriptions.

Yes, it's a good idea
February 21, 2009
Weed пишет:
> Bill Baxter пишет:
> 
>> Why don't you just show us the class in the way you would like to write it in C++, and we'll show you how to write it in D, or finally agree with you that it's not possible.   But as long as you continue to be hand-wavy about "common base classes" we're at a bit of an impasse.  So far everyone thinks D can do what you want it to do based on your vague descriptions.
> 

As I said, you can write everything using "goto" and "if".

...But why you do not like the original example of this thread?

> Yes, it's a good idea

February 21, 2009
2009/2/21 Weed <resume755@mail.ru>:
> Weed пишет:
>> Bill Baxter пишет:
>>
>>> Why don't you just show us the class in the way you would like to write it in C++, and we'll show you how to write it in D, or finally agree with you that it's not possible.   But as long as you continue to be hand-wavy about "common base classes" we're at a bit of an impasse.  So far everyone thinks D can do what you want it to do based on your vague descriptions.
>>
>
> As I said, you can write everything using "goto" and "if".
>
> ...But why you do not like the original example of this thread?

Please post again.  I don't seem to recall any detailed example.

--bb
February 21, 2009
Bill Baxter пишет:
> 2009/2/21 Weed <resume755@mail.ru>:
>> Weed пишет:
>>> Bill Baxter пишет:
>>>
>>>> Why don't you just show us the class in the way you would like to write it in C++, and we'll show you how to write it in D, or finally agree with you that it's not possible.   But as long as you continue to be hand-wavy about "common base classes" we're at a bit of an impasse.  So far everyone thinks D can do what you want it to do based on your vague descriptions.
>> As I said, you can write everything using "goto" and "if".
>>
>> ...But why you do not like the original example of this thread?
> 
> Please post again.  I don't seem to recall any detailed example.
> 
> --bb

http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=83506
February 21, 2009
On Sun, Feb 22, 2009 at 1:02 AM, Weed <resume755@mail.ru> wrote:
> Bill Baxter пишет:
>> 2009/2/21 Weed <resume755@mail.ru>:
>>> Weed пишет:
>>>> Bill Baxter пишет:
>>>>
>>>>> Why don't you just show us the class in the way you would like to write it in C++, and we'll show you how to write it in D, or finally agree with you that it's not possible.   But as long as you continue to be hand-wavy about "common base classes" we're at a bit of an impasse.  So far everyone thinks D can do what you want it to do based on your vague descriptions.
>>> As I said, you can write everything using "goto" and "if".
>>>
>>> ...But why you do not like the original example of this thread?
>>
>> Please post again.  I don't seem to recall any detailed example.
>>
>> --bb
>
> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=83506

You should use a struct there!   Your code does not show you doing
anything that would even remotely suggest using a class is worthwhile.
 You're doing value operations on value types.  That's what structs
are for.

--bb
February 21, 2009
On Sat, 21 Feb 2009 21:49:46 +0300, Bill Baxter <wbaxter@gmail.com> wrote:

> On Sun, Feb 22, 2009 at 1:02 AM, Weed <resume755@mail.ru> wrote:
>> Bill Baxter пишет:
>>> 2009/2/21 Weed <resume755@mail.ru>:
>>>> Weed пишет:
>>>>> Bill Baxter пишет:
>>>>>
>>>>>> Why don't you just show us the class in the way you would like to
>>>>>> write it in C++, and we'll show you how to write it in D, or finally
>>>>>> agree with you that it's not possible.   But as long as you continue
>>>>>> to be hand-wavy about "common base classes" we're at a bit of an
>>>>>> impasse.  So far everyone thinks D can do what you want it to do based
>>>>>> on your vague descriptions.
>>>> As I said, you can write everything using "goto" and "if".
>>>>
>>>> ...But why you do not like the original example of this thread?
>>>
>>> Please post again.  I don't seem to recall any detailed example.
>>>
>>> --bb
>>
>> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=83506
>
> You should use a struct there!   Your code does not show you doing
> anything that would even remotely suggest using a class is worthwhile.
>  You're doing value operations on value types.  That's what structs
> are for.
>
> --bb

That's what *everyone* tells him!

February 21, 2009
On Sun, Feb 22, 2009 at 5:10 AM, Denis Koroskin <2korden@gmail.com> wrote:
> On Sat, 21 Feb 2009 21:49:46 +0300, Bill Baxter <wbaxter@gmail.com> wrote:
>
>> On Sun, Feb 22, 2009 at 1:02 AM, Weed <resume755@mail.ru> wrote:
>>>
>>> Bill Baxter пишет:
>>>>
>>>> 2009/2/21 Weed <resume755@mail.ru>:
>>>>>
>>>>> Weed пишет:
>>>>>>
>>>>>> Bill Baxter пишет:
>>>>>>
>>>>>>> Why don't you just show us the class in the way you would like to
>>>>>>> write it in C++, and we'll show you how to write it in D, or finally
>>>>>>> agree with you that it's not possible.   But as long as you continue
>>>>>>> to be hand-wavy about "common base classes" we're at a bit of an
>>>>>>> impasse.  So far everyone thinks D can do what you want it to do
>>>>>>> based
>>>>>>> on your vague descriptions.
>>>>>
>>>>> As I said, you can write everything using "goto" and "if".
>>>>>
>>>>> ...But why you do not like the original example of this thread?
>>>>
>>>> Please post again.  I don't seem to recall any detailed example.
>>>>
>>>> --bb
>>>
>>>
>>> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=83506
>>
>> You should use a struct there!   Your code does not show you doing
>> anything that would even remotely suggest using a class is worthwhile.
>>  You're doing value operations on value types.  That's what structs
>> are for.
>>
>> --bb
>
> That's what *everyone* tells him!

I am vaguely open to the possibility that he has a point.  FLENS uses
inheritance, for instance.  But I don't recall what the intent of that
inheritance was in FLENS, exactly.  I more or less ported it to D
without that, though, so I guess I didn't find it to be essential.
See this:
  http://flens.cvs.sourceforge.net/viewvc/flens/FLENS/matvec/densevector.h?revision=1.36&view=markup
Versus this:
  http://www.dsource.org/projects/multiarray/browser/trunk/multiarray/dflat/DenseVector.d

Weed, if you want to make a real argument, that would be a good place to start.  Investigate why and how FLENS uses inheritance.

--bb
February 22, 2009
Bill Baxter пишет:
> On Sun, Feb 22, 2009 at 1:02 AM, Weed <resume755@mail.ru> wrote:
>> Bill Baxter пишет:
>>> 2009/2/21 Weed <resume755@mail.ru>:
>>>> Weed пишет:
>>>>> Bill Baxter пишет:
>>>>>
>>>>>> Why don't you just show us the class in the way you would like to write it in C++, and we'll show you how to write it in D, or finally agree with you that it's not possible.   But as long as you continue to be hand-wavy about "common base classes" we're at a bit of an impasse.  So far everyone thinks D can do what you want it to do based on your vague descriptions.
>>>> As I said, you can write everything using "goto" and "if".
>>>>
>>>> ...But why you do not like the original example of this thread?
>>> Please post again.  I don't seem to recall any detailed example.
>>>
>>> --bb
>> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=83506
> 
> You should use a struct there!   Your code does not show you doing
> anything that would even remotely suggest using a class is worthwhile.
>  You're doing value operations on value types.  That's what structs
> are for.

Why?

What if I have not substantiated the fact that c1 is a class I should use there a structure?

Used in D a model of placement classes only in heap have a rule "if you made the class and trying to pass it by value is somewhere in your code, there is a design error?
« First   ‹ Prev
1 2 3 4
Top | Discussion index | About this forum | D home