Nice readable code with initializer

Виталий Фадеев vital.fadeev at gmail.com
Thu Mar 5 06:48:53 UTC 2020


Searching for beauty code implementation.

Goal is: Create new object with "custom initializer".

"custom initializer" - is function, executed in _ctor, in object 
scope.

Main Goal is: "clean readable beauty code".

Like this and better:


class DataGrid : Base
{
     this()
     {
         super();

         CR!VBoxLayout({
             sizeWidthMode  = SIZE_MODE.PARENT;
             sizeHeightMode = SIZE_MODE.PARENT;

             CR!GridLayout({
                 id             = "grid";
                 sizeWidthMode  = SIZE_MODE.PARENT;
                 sizeHeightMode = SIZE_MODE.FIXED;
                 h              = 400;
             });

             CR!HCenterLayout({
                 CR!(Pager!TextButton) ({
                    id = "pager";
                 });
             });
         });
     }
}


class Base
{
     T CR( T, F )( F func )
     {
         auto c = new T();
         c.Apply( func );
         return c;
     }

     void Apply( F )( F func )
     {
         func();
     }
}

In code above created tree and configured nodes.

Trouble in code above is: "custom initializer" - executed in 
DataGrid context.

How to execute "custom initializer" in VBoxLayout context and 
keep readable beauty ?




More information about the Digitalmars-d-learn mailing list