digitalmars.D.learn - Is it possible to write some class members in another module ?
- Vinod K Chandran (5/5) May 19 2020 Hi all,
- Adam D. Ruppe (3/4) May 19 2020 You can make some of members be other structs that you aggregate
- Vinod K Chandran (21/25) May 20 2020 That's a good idea but there is a problem.
- welkam (11/18) May 20 2020 Then you want alias this.
- Vinod K Chandran (8/28) May 20 2020 Wow !!!
- welkam (4/6) May 20 2020 Walter(creator of this language) said that redundant grammar is a
- Boris Carvajal (4/9) May 19 2020 You can use Template Mixins to add variable declarations in
- Vinod K Chandran (2/11) May 20 2020 Thank you for the reply. Let me check. :)
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.
May 19 2020
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.
May 19 2020
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: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; ```Is it possible to write some class members in another module ?You can make some of members be other structs that you aggregate together.
May 20 2020
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
May 20 2020
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: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.// 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
May 20 2020
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.
May 20 2020
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
May 19 2020
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:Thank you for the reply. Let me check. :)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
May 20 2020