Re: Is it possible to write some class members in another module ?

2020-05-20 Thread welkam via Digitalmars-d-learn

On Wednesday, 20 May 2020 at 17:29:47 UTC, Vinod K Chandran wrote:
I am very sad that i delayed to start learning D only because 
of semicolons and curly braces.
Walter(creator of this language) said that redundant grammar is a 
good thing because it allows compiler to emit better error 
messages.


Re: Is it possible to write some class members in another module ?

2020-05-20 Thread Vinod K Chandran via Digitalmars-d-learn

On Wednesday, 20 May 2020 at 15:01:36 UTC, welkam wrote:
On Wednesday, 20 May 2020 at 09:45:48 UTC, Vinod K Chandran 
wrote:

// Now, we need to use like this
auto form= new Window();
form.event.click = bla_bla;

// I really want to use like this
auto form= new Window();
form.click = bla_bla;
```


Then you want alias this.

class Window : Control{
   Events event;
   alias event this
   .
}

and now when you write
form.click = bla_bla;
Compiler first checks if form.click compiles and if it doesnt 
it then it tries form.event.click


Wow !!!
What a perfect solution ! That is what i wanted. Thanks a lot 
friend. :)
The more i practice D, the more i am loving it. I am very sad 
that i delayed to start learning D only because of semicolons and 
curly braces. But now i recognizes that how beautiful this 
language is.


Re: Is it possible to write some class members in another module ?

2020-05-20 Thread welkam via Digitalmars-d-learn

On Wednesday, 20 May 2020 at 09:45:48 UTC, Vinod K Chandran wrote:

// Now, we need to use like this
auto form= new Window();
form.event.click = bla_bla;

// I really want to use like this
auto form= new Window();
form.click = bla_bla;
```


Then you want alias this.

class Window : Control{
   Events event;
   alias event this
   .
}

and now when you write
form.click = bla_bla;
Compiler first checks if form.click compiles and if it doesnt it 
then it tries form.event.click


Re: Is it possible to write some class members in another module ?

2020-05-20 Thread Vinod K Chandran via Digitalmars-d-learn

On Tuesday, 19 May 2020 at 23:51:45 UTC, Boris Carvajal wrote:

On Tuesday, 19 May 2020 at 22:01:03 UTC, Vinod K Chandran wrote:

Hi all,
Is it possible to write some class members in another module ? 
I have class with a lot of member variables.(probably 50+) I 
would like to write them (Not all, but some of them) in a 
special module for the sake of maintenance.


You can use Template Mixins to add variable declarations in 
others scope.


https://dlang.org/spec/template-mixin.html


Thank you for the reply. Let me check. :)


Re: Is it possible to write some class members in another module ?

2020-05-20 Thread Vinod K Chandran via Digitalmars-d-learn

On Tuesday, 19 May 2020 at 22:10:25 UTC, Adam D. Ruppe wrote:

On Tuesday, 19 May 2020 at 22:01:03 UTC, Vinod K Chandran wrote:

Is it possible to write some class members in another module ?


You can make some of members be other structs that you 
aggregate together.


That's a good idea but there is a problem.
As per your idea--
```
struct Events{
uint click;
uint shown;
uint move;

}
class Window : Control{
   Events event;
   .
}
// Now, we need to use like this
auto form= new Window();
form.event.click = bla_bla;

// I really want to use like this
auto form= new Window();
form.click = bla_bla;
```


Re: Is it possible to write some class members in another module ?

2020-05-19 Thread Boris Carvajal via Digitalmars-d-learn

On Tuesday, 19 May 2020 at 22:01:03 UTC, Vinod K Chandran wrote:

Hi all,
Is it possible to write some class members in another module ? 
I have class with a lot of member variables.(probably 50+) I 
would like to write them (Not all, but some of them) in a 
special module for the sake of maintenance.


You can use Template Mixins to add variable declarations in 
others scope.


https://dlang.org/spec/template-mixin.html


Re: Is it possible to write some class members in another module ?

2020-05-19 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 19 May 2020 at 22:01:03 UTC, Vinod K Chandran wrote:

Is it possible to write some class members in another module ?


You can make some of members be other structs that you aggregate 
together.