Re: struct inheritance need?

2008-12-25 Thread Weed

Kagamin пишет:

Weed Wrote:

If you do not want to initialize repeatedly matrix inside the sub, which 
often cause each other, must be static matrices or declared as global 
(in relation to these procedures). You agree with that?


What's problem? If you want static or global variables, you have them in D.


Do you propose through mixin divide the code into parts?


Well, why mixin? Just create different modules and place code according to its 
purpose to these modules.

You do not think that it is better to add to language that would give 
100% to use the opportunity of calculations at compile time. This 
greatly simplify the code and perfectly and logically fit into the language.


Compile-time evaluation is just an optimization technique, which may or may not 
be applied without any change to source code, so it doesn't affect source code 
in any way, it just can't. In C++ you can't tell whether the code executes at 
compile time, as as of standard, it's completely up to the compiler to optimize 
code generation.


Yeah, right.

I propose that it be expanded to optimize the static arrays and classes.


Re: struct inheritance need?

2008-12-25 Thread Weed
Kagamin пишет:
 Weed Wrote:
 
 If you do not want to initialize repeatedly matrix inside the sub, which 
 often cause each other, must be static matrices or declared as global 
 (in relation to these procedures). You agree with that?
 
 What's problem? If you want static or global variables, you have them in D.
 
 Do you propose through mixin divide the code into parts?
 
 Well, why mixin? Just create different modules and place code according to 
 its purpose to these modules.
 
 You do not think that it is better to add to language that would give 
 100% to use the opportunity of calculations at compile time. This 
 greatly simplify the code and perfectly and logically fit into the language.
 
 Compile-time evaluation is just an optimization technique, which may or may 
 not be applied without any change to source code,

Incidentally, this is incorrect.

In the event that it is impossible to calculate the static expression
compiler immediately gives an error rather than moves calculation to
run-time.


Re: struct inheritance need?

2008-12-23 Thread Kagamin
Weed Wrote:

 The problem is not in use templates.
 
 Templates are implementing some of the functionality of 2 types of 
 structures matrices (normal and dynamic). But the structures do not 
 inherit, then to add functionality matrix to other entities ( pixel, 
 image etc) sites will have their list in a template return type.

If structs don't suit you, don't use them. Classes are better suited for OOP as 
I said long ago and continue repeating it over and over.

 It contain list of all types (MatrixT and VectorT) for return. Will it 
 add types of image and pixel and still others if needed. This is as 
 good as manually implement a new object model.

I'm sure any properly formalized problem is solvable. All you need is proper 
formalization and some design work.

 It is not necessary to suggest to wrap up pixel in a class - then it 
 too cannot be initialized in a compile time.

Sure it can't. Does it cause that big problems?


Re: struct inheritance need?

2008-12-23 Thread Weed

Kagamin пишет:

Weed Wrote:


The problem is not in use templates.

Templates are implementing some of the functionality of 2 types of 
structures matrices (normal and dynamic). But the structures do not 
inherit, then to add functionality matrix to other entities ( pixel, 
image etc) sites will have their list in a template return type.


If structs don't suit you, don't use them. Classes are better suited for OOP as 
I said long ago and continue repeating it over and over.

It contain list of all types (MatrixT and VectorT) for return. Will it 
add types of image and pixel and still others if needed. This is as 
good as manually implement a new object model.


I'm sure any properly formalized problem is solvable. All you need is proper 
formalization and some design work.

It is not necessary to suggest to wrap up pixel in a class - then it 
too cannot be initialized in a compile time.


Sure it can't. Does it cause that big problems?


Sometimes it is the only way to avoid a large number of global ad


Re: struct inheritance need?

2008-12-22 Thread Weed

Kagamin пишет:

Weed Wrote:


that is, suppose that after some action should get a matrix matrix3x1


Well... if you want to template every piece of your code, this can
cause disaster, so I think, this is not very good design. For
example, multiplication method will be duplicated N*N*N times for all
possible matrix size combinations.


Only for really used combinations (i am using duck typing inside 
templates).


In any case, unused functions in the resulting file is not included.


I'd prefer run-time checks, though
templates can be used for sure.


This problem would help solve the availability of inheritance for 
structs or compile-time creation of class instances.


But now the compiler can identify duplicate parts of the code, working 
with the same types


Re: struct inheritance need?

2008-12-18 Thread Derek Parnell
On Thu, 18 Dec 2008 07:24:34 -0500, Kagamin wrote:

 Static constructor can execute any valid D statements including construction 
 of objects.

A static constructor (also known as the Module constructor) executes at
program run-time and not at program compile-time. I think Weed wants the
ability to have the compiler build class objects at compile-time such that
when a program first starts running, the objects are already fully formed
in RAM just waiting to be used.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell


Re: struct inheritance need?

2008-12-17 Thread Kagamin
Weed Wrote:

 I agree.
 In my case I chose to structure rather than a class because it can be 
 initialized at compile time.
 
 But now I thing must be allowed to deploy class in the default data 
 segment. And add the possibility of creating a object of class at 
 compile time.

If you want to use full blown OOP, class is your choise. There are static 
constructors for static initialization.


Re: struct inheritance need?

2008-12-17 Thread Janderson

Weed wrote:

I should explain why it's important for me:

For example, I am making a matrix object(s)

It should be:
- any size
- with ability of making matrix instance of a given size in compile time.
- ability of creating matrix instance in runtime.

I have decided to make it struct because I need to create matrix
object in compile time. in real program I'll need matricies of
variable size and 3х1, 3х3, 6х6, 3х6 sizes (and may be other).

I want to make matrix template and insert in it with mixin operator
several structures of different sizes (and this structs are not store 
his dimensions in each instance, of course: variables width and height 
declared as invariant). By doing this I'll get several different 
structures  (matrix_dynamic, matrix3x3, matrix6x6 etc)


question is how those matricies can interoperate? They does not have
common parent (structures does not have inheritance) , so I can't
make common function for matricies of different sizes opAdd for
example, and have to do functions for all types of matricies.

How should I implement such a class In D properly? 
It possible in C++, but I like some of the language D


The classical approach is to have helper template functions. 
Essentially:


void doOpearation(mymatrix)(...)
{

}


Note this is compiletime polymorphisms.

Now if you want to add runtime polymorphism it is impossible to get away 
from a cost.  You can use a wrapper class like so:


interface CommonMatrix
{
operation()...
}

class PolymorphicMatrix(mymatrix) : CommonMatrix
{
operation()...
}

You'll probably find though that PolymorphicMartix should be some higher 
level concept, like car, or entity.


The great thing about these techniques is that they give a whole load 
more power then just using inheritance alone because you can essentially 
attach many different behaviors to that struct.


I hope that was helpful.

-Joel


Re: struct inheritance need?

2008-12-16 Thread bearophile
Weed:
 Planned in the future to implement inheritance of structs or the static 
 creation of classes?

Inheritance of structs: I think it's not planned. Structs in D are meant to be 
used for different things than classes.
Yet, as time passes structs are gaining more power: you can't believe that very 
recently they have gained constructors/destructors too in D2. Probably in a 
system language conceptual purity isn't much appreciated :-)

Static creation of classes (I think you mean creation of objects): it sounds 
like an interesting thing, I know of a system language that allows the creation 
of objects only at compile-time, and at compile-time it also performs several 
space optimizations among such objects (and such space optimizations often 
improve running speed a little).

Bye,
bearophile


Re: struct inheritance need?

2008-12-16 Thread Weed

bearophile пишет:
 Weed:
 Planned in the future to implement inheritance of structs or the 
static creation of classes?


 Inheritance of structs: I think it's not planned. Structs in D are
meant to be used for different things than classes.
 Yet, as time passes structs are gaining more power: you can't believe

that very recently they have gained constructors/destructors too in D2.
Probably in a system language conceptual purity isn't much appreciated :-)


I believe that the opportunity to place an object in memory, stack or 
heap is more important than the struggle against splicing.


I think not worth taking structs and classes from C#. May be bytecode 
interpreter C# does not show the difference in speed between the 
allocation of memory by a small object + its using and the use of a 
static object, so developers C# decided to do so as done. (but I am not 
a specialist in the design of compilers :))


 Static creation of classes (I think you mean creation of objects): it
 sounds like an interesting thing, I know of a system language that
 allows the creation of objects only at compile-time, and at
 compile-time it also performs several space optimizations among such
 objects (and such space optimizations often improve running speed a
 little).

And in fact we come to making structs and classes similar except that 
classes can not be assigned by value.


Such an option I like.


Re: struct inheritance need?

2008-12-16 Thread Weed

Bill Baxter пишет:

2008/12/16 Weed resume...@mail.ru:

I should explain why it's important for me:

For example, I am making a matrix object(s)

It should be:
- any size
- with ability of making matrix instance of a given size in compile time.
- ability of creating matrix instance in runtime.

I have decided to make it struct because I need to create matrix
object in compile time. in real program I'll need matricies of
variable size and 3х1, 3х3, 6х6, 3х6 sizes (and may be other).

I want to make matrix template and insert in it with mixin operator
several structures of different sizes (and this structs are not store his
dimensions in each instance, of course: variables width and height declared
as invariant). By doing this I'll get several different structures
 (matrix_dynamic, matrix3x3, matrix6x6 etc)

question is how those matricies can interoperate? They does not have
common parent (structures does not have inheritance) , so I can't
make common function for matricies of different sizes opAdd for
example, and have to do functions for all types of matricies.

How should I implement such a class In D properly?
It possible in C++, but I like some of the language D



Here's one way:
http://www.dsource.org/projects/openmeshd/browser/trunk/LinAlg/linalg/MatrixT.d

--bb



necessarily need the ability to change the size of the matrix

together with a static matrix it can be done using two types of matrices 
with a common parent.


Re: struct inheritance need?

2008-12-16 Thread Weed

Bill Baxter пишет:

2008/12/16 Weed resume...@mail.ru:

I should explain why it's important for me:

For example, I am making a matrix object(s)

It should be:
- any size
- with ability of making matrix instance of a given size in compile time.
- ability of creating matrix instance in runtime.

I have decided to make it struct because I need to create matrix
object in compile time. in real program I'll need matricies of
variable size and 3х1, 3х3, 6х6, 3х6 sizes (and may be other).

I want to make matrix template and insert in it with mixin operator
several structures of different sizes (and this structs are not store his
dimensions in each instance, of course: variables width and height declared
as invariant). By doing this I'll get several different structures
 (matrix_dynamic, matrix3x3, matrix6x6 etc)

question is how those matricies can interoperate? They does not have
common parent (structures does not have inheritance) , so I can't
make common function for matricies of different sizes opAdd for
example, and have to do functions for all types of matricies.

How should I implement such a class In D properly?
It possible in C++, but I like some of the language D



Here's one way:
http://www.dsource.org/projects/openmeshd/browser/trunk/LinAlg/linalg/MatrixT.d

--bb


necessarily need the ability to change the size of the matrix

together with a static matrix it can be done using two types of matrices 
with a single parent.