Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

83
Asynchronous Single Page Applications without a Line of HTML or Javascript. Or why D is just awesome Robert ”burner” Schadek May 5, 2016 DConf

Transcript of Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Page 1: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Asynchronous Single Page Applicationswithout a Line of HTML or Javascript.Or why D is just awesome

Robert ”burner” SchadekMay 5, 2016

DConf

Page 2: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Javascript and HTML are awesome

• No explicit types• Variables may be undefined• Repetition repetition repetition• No templates• No compile time function execution• No compile time

1

Page 3: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome
Page 4: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Goals

• Retain type-information of data from DB to Client’sBrowser

• Keeping things DRY• Performance• Get things done

3

Page 5: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Goals

• Retain type-information of data from DB to Client’sBrowser

• Keeping things DRY

• Performance• Get things done

3

Page 6: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Goals

• Retain type-information of data from DB to Client’sBrowser

• Keeping things DRY• Performance

• Get things done

3

Page 7: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Goals

• Retain type-information of data from DB to Client’sBrowser

• Keeping things DRY• Performance• Get things done

3

Page 8: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Vibe.d and Diet

Page 9: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Vibe.d

• Powerful asynchronous I/O and web toolkit for D• Uses Fibers and Threads

• n→ m mapping• yield()• async IO

• async DB connectivity for MongoDB, Redis, MySQL• You don’t need to care about async• Web interface generator• REST interface generator

4

Page 10: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Vibe.d

• Powerful asynchronous I/O and web toolkit for D• Uses Fibers and Threads

• n→ m mapping• yield()• async IO

• async DB connectivity for MongoDB, Redis, MySQL• You don’t need to care about async• Web interface generator• REST interface generator

4

Page 11: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Vibe.d

• Powerful asynchronous I/O and web toolkit for D• Uses Fibers and Threads

• n→ m mapping• yield()• async IO

• async DB connectivity for MongoDB, Redis, MySQL• You don’t need to care about async• Web interface generator• REST interface generator

4

Page 12: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

REST Interface Generator

i n t e r f a c e MyAPI {// GET / weather −> responds {” text ” : ” . . . ” , ”

↪→ temperature ” : . . . }Weather getWeather ( ) ;

}

c l a s s MyAPIImplementation : MyAPI {auto weather = [ ” sunny” , ” ra iny ” , ” ca t s and dogs ”

↪→ , ”snow” ] ;

Weather getWeather ( ) {re turn Weather (

weather [ uniform (0 , weather . l ength ) ] ,uniform (−10 ,30)

) ;}

}

5

Page 13: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

REST Interface Generator

i n t e r f a c e MyAPI {// GET / weather −> responds {” text ” : ” . . . ” , ”

↪→ temperature ” : . . . }Weather getWeather ( ) ;

}

c l a s s MyAPIImplementation : MyAPI {auto weather = [ ” sunny” , ” ra iny ” , ” ca t s and dogs ”

↪→ , ”snow” ] ;

Weather getWeather ( ) {re turn Weather (

weather [ uniform (0 , weather . l ength ) ] ,uniform (−10 ,30)

) ;}

} 5

Page 14: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

REST Interface Generator

auto route r = new URLRouter ;r out e r . get ( ”/” , s tat i cTemplate ! ” index . dt ” ) ;r out e r . get ( ”/main . html” , s tat i cTemplate ! ”main . dt ” ) ;

r out e r . r e g i s t e r R e s t I n t e r f a c e !MyAPI(new↪→ MyAPIImplementation , r e s t s e t t i n g s ) ;

s t r u c t Weather {s t r i n g text ;double temperature ;

}

6

Page 15: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

REST Interface Generator

auto route r = new URLRouter ;r out e r . get ( ”/” , s tat i cTemplate ! ” index . dt ” ) ;r out e r . get ( ”/main . html” , s tat i cTemplate ! ”main . dt ” ) ;

r out e r . r e g i s t e r R e s t I n t e r f a c e !MyAPI(new↪→ MyAPIImplementation , r e s t s e t t i n g s ) ;

s t r u c t Weather {s t r i n g text ;double temperature ;

}

6

Page 16: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

AngularJS Typescript

i n t e r f a c e Weather {text : s t r i ng ,temperature : number

}

i n t e r f a c e MainScope extends ng . IScope {weather : Weather

}

c l a s s MainCtrl {pub l i c s t a t i c $ i n j e c t = [ ’ $scope ’ , ’ $http ’ ] ;

c on s t ruc to r ( p r i va t e $scope : MainScope ,p r i va t e $http : ng . IHttpServ i c e )

{t h i s . weather ( ) ;

}

7

Page 17: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

AngularJS Typescript

i n t e r f a c e Weather {text : s t r i ng ,temperature : number

}

i n t e r f a c e MainScope extends ng . IScope {weather : Weather

}

c l a s s MainCtrl {pub l i c s t a t i c $ i n j e c t = [ ’ $scope ’ , ’ $http ’ ] ;

c on s t ruc to r ( p r i va t e $scope : MainScope ,p r i va t e $http : ng . IHttpServ i c e )

{t h i s . weather ( ) ;

}

7

Page 18: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

AngularJS Typescript

i n t e r f a c e Weather {text : s t r i ng ,temperature : number

}

i n t e r f a c e MainScope extends ng . IScope {weather : Weather

}

c l a s s MainCtrl {pub l i c s t a t i c $ i n j e c t = [ ’ $scope ’ , ’ $http ’ ] ;

c on s t ruc to r ( p r i va t e $scope : MainScope ,p r i va t e $http : ng . IHttpServ i c e )

{t h i s . weather ( ) ;

}7

Page 19: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

AngularJS Typescript

weather ( ) : void {var s = ’ / weather ’ ;t h i s . $http . get ( s ) . s u c c e s s ( ( data : Weather ) => {

t h i s . $scope . weather = data ;}) ;

}

8

Page 20: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Diet

doctype htmlhtml ( ng−app=”myapp”)

headt i t l e DConf 2016 Weather− j a v a s c r i p t ( ” . / angular . j s ”) ;− j a v a s c r i p t ( ” . / angular−route . j s ”) ;− j a v a s c r i p t ( ” . / myapp . j s ”) ;

bodydiv ( ng−view )

− void j a v a s c r i p t ( s t r i n g name)s c r i p t ( s r c=”#{name}”)

9

Page 21: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Diet

doctype htmlhtml ( ng−app=”myapp”)

headt i t l e DConf 2016 Weather− j a v a s c r i p t ( ” . / angular . j s ”) ;− j a v a s c r i p t ( ” . / angular−route . j s ”) ;− j a v a s c r i p t ( ” . / myapp . j s ”) ;

bodydiv ( ng−view )

− void j a v a s c r i p t ( s t r i n g name)s c r i p t ( s r c=”#{name}”)

9

Page 22: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Diet

. c on ta ine rp {{ weather . t ex t }}p {{ weather . temperature }}

button ( type=”submit ” , ng−c l i c k =” c t r l . weather ( ) ; ” )↪→ Get Weather

10

Page 23: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Live Demo

Page 24: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Dataflow from the Server to theFrontend and back again

Page 25: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Dataflow from the Server to the Frontend and back again

s t r u c t Weather {s t r i n g text ;double temperature ;

}

Dlang

i n t e r f a c e Weather {text : s t r i ng ,tempereture : number

}

Typescript

11

Page 26: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Dataflow from the Server to the Frontend and back again

s t r u c t Weather {s t r i n g text ;double temperature ;

}

Dlang

i n t e r f a c e Weather {text : s t r i ng ,tempereture : number

}

Typescript

11

Page 27: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

dstructtotypescript

dstructtotypescript -i weather.d -p weather.ts -s↪→ Weather

s t ruct Weather {s t r ing text ;double temperature ;

}

import std . format ;

foreach ( i t ; __traits ( allMembers , Weather) )

i n t e r f a c e Weather {text : str ing ,temperature : number

}

12

Page 28: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

dstructtotypescript

dstructtotypescript -i weather.d -p weather.ts -s↪→ Weather

s t ruct Weather {s t r ing text ;double temperature ;

}

import std . format ;

foreach ( i t ; __traits ( allMembers , Weather) )

i n t e r f a c e Weather {text : str ing ,temperature : number

}

12

Page 29: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

dstructtotypescript

dstructtotypescript -i weather.d -p weather.ts -s↪→ Weather

s t ruct Weather {s t r ing text ;double temperature ;

}

import std . format ;

foreach ( i t ; __traits ( allMembers , Weather) )

i n t e r f a c e Weather {text : str ing ,temperature : number

}

12

Page 30: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

dstructtotypescript

dstructtotypescript -i weather.d -p weather.ts -s↪→ Weather

s t ruct Weather {s t r ing text ;double temperature ;

}

import std . format ;

foreach ( i t ; __traits ( allMembers , Weather) )

i n t e r f a c e Weather {text : str ing ,temperature : number

}

12

Page 31: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is wrong

Page 32: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

13

Page 33: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is wrong

• All we solved was a tiny specific problem• What about server to database• What if we would use Dart instead of Typescript• How do we communicate the overall architecture• How do we keep the architecture in sync with the code• How do we communicate with non-developer• ...

• How do we deal with change?

14

Page 34: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is wrong

• All we solved was a tiny specific problem• What about server to database• What if we would use Dart instead of Typescript• How do we communicate the overall architecture• How do we keep the architecture in sync with the code• How do we communicate with non-developer• ...• How do we deal with change?

14

Page 35: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is still wrong

• Waterfall Model

← no change, never• UML ← just kill me already

• Agile Methods ← just hacking, with fancy names• Hacking ← no plan to speak of, just change

15

Page 36: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is still wrong

• Waterfall Model ← no change, never

• UML ← just kill me already

• Agile Methods ← just hacking, with fancy names• Hacking ← no plan to speak of, just change

15

Page 37: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is still wrong

• Waterfall Model ← no change, never

• UML ← just kill me already

• Agile Methods ← just hacking, with fancy names

• Hacking

← no plan to speak of, just change

15

Page 38: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is still wrong

• Waterfall Model ← no change, never

• UML ← just kill me already

• Agile Methods ← just hacking, with fancy names

• Hacking ← no plan to speak of, just change

15

Page 39: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is still wrong

• Waterfall Model ← no change, never

• UML ← just kill me already

• Agile Methods

← just hacking, with fancy names

• Hacking ← no plan to speak of, just change

15

Page 40: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is still wrong

• Waterfall Model ← no change, never

• UML ← just kill me already

• Agile Methods ← just hacking, with fancy names• Hacking ← no plan to speak of, just change

15

Page 41: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is still wrong

• Waterfall Model ← no change, never• UML

← just kill me already

• Agile Methods ← just hacking, with fancy names• Hacking ← no plan to speak of, just change

15

Page 42: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is still wrong

• Waterfall Model ← no change, never• UML ← just kill me already

• Agile Methods ← just hacking, with fancy names• Hacking ← no plan to speak of, just change

15

Page 43: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is still wrong

• Waterfall Model ← no change, never• UML ← just kill me already

• Agile Methods ← just hacking, with fancy names• Hacking ← no plan to speak of, just change

15

Page 44: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Everything is still wrong

• Waterfall Model ← no change, never• UML ← just kill me already

• Agile Methods ← just hacking, with fancy names• Hacking ← no plan to speak of, just change

15

Page 45: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

What do we want

• Speak about the system at different levels of detailwith different people

• Quickly introduce people to the system• Keep data classes (Model) synchronized across

• Frontend• Server• Database

• Write only one model for everything, to keep stuff in sync• Have description line based, because git• Generate everything possible from the model

16

Page 46: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Introducing the C4 Architecture

Page 47: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome
Page 48: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome
Page 49: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome
Page 50: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome
Page 51: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Structurizr

• Implements C4 Architecture Model• Java library to build the model

• Its code, its fits into git

• Structurizr generates code

• Only Java and .net

21

Page 52: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Structurizr

• Implements C4 Architecture Model• Java library to build the model

• Its code, its fits into git

• Structurizr generates code

• Only Java and .net

21

Page 53: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Structurizr

• Implements C4 Architecture Model• Java library to build the model

• Its code, its fits into git

• Structurizr generates code

• Only Java and .net

21

Page 54: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Structurizr

• Implements C4 Architecture Model• Java library to build the model

• Its code, its fits into git

• Structurizr generates code

• Only Java and .net

21

Page 55: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome
Page 56: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

How hard can it be

Page 57: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

How do we approach the development

• We’re not gonne create a new language

, at first, most likely• The model (ast) is pretty simple

• The world• The world has• Actors, software/hardware systems• A software systems has• Containers (everything with a unique pid)• A container has• Components (think module) and classes• A component has• Components and classes• Classes have members

• Connections between the above• UML Association, Aggregation, Composition, Dependency,

. . .

• Additional informations, names, descriptions

23

Page 58: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

How do we approach the development

• We’re not gonne create a new language, at first

, most likely• The model (ast) is pretty simple

• The world• The world has• Actors, software/hardware systems• A software systems has• Containers (everything with a unique pid)• A container has• Components (think module) and classes• A component has• Components and classes• Classes have members

• Connections between the above• UML Association, Aggregation, Composition, Dependency,

. . .

• Additional informations, names, descriptions

23

Page 59: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

How do we approach the development

• We’re not gonne create a new language, at first, most likely

• The model (ast) is pretty simple• The world• The world has• Actors, software/hardware systems• A software systems has• Containers (everything with a unique pid)• A container has• Components (think module) and classes• A component has• Components and classes• Classes have members

• Connections between the above• UML Association, Aggregation, Composition, Dependency,

. . .

• Additional informations, names, descriptions

23

Page 60: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

How do we approach the development

• We’re not gonne create a new language, at first, most likely• The model (ast) is pretty simple

• The world• The world has• Actors, software/hardware systems• A software systems has• Containers (everything with a unique pid)• A container has• Components (think module) and classes• A component has• Components and classes• Classes have members

• Connections between the above• UML Association, Aggregation, Composition, Dependency,

. . .

• Additional informations, names, descriptions

23

Page 61: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

How do we approach the development

• We’re not gonne create a new language, at first, most likely• The model (ast) is pretty simple

• The world• The world has• Actors, software/hardware systems• A software systems has• Containers (everything with a unique pid)• A container has• Components (think module) and classes• A component has• Components and classes• Classes have members

• Connections between the above• UML Association, Aggregation, Composition, Dependency,

. . .

• Additional informations, names, descriptions 23

Page 62: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Using Degenerator 1/2

auto world = new TheWorld ( ”TheWorld” ) ;Actor u s e r s = world . getOrNewActor ( ”The Users ” ) ;u s e r s . d e s c r i p t i o n = ” This i s a way to long

↪→ d e s c r i p t i o n f o r something ”~ ” that should be obvious . ” ;

auto system = world . getOrNewSoftwareSystem ( ”↪→ AwesomeSoftware” ) ;

Container f rontend = system . getOrNewContainer ( ”↪→ Frontend ” ) ;

f rontend . techno logy = ” Angular ” ;auto f rontendUserCtr l = frontend . getOrNewComponent (

↪→ ” f r on tUse rCt r l ” ) ;

24

Page 63: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Using Degenerator 1/2

auto world = new TheWorld ( ”TheWorld” ) ;Actor u s e r s = world . getOrNewActor ( ”The Users ” ) ;u s e r s . d e s c r i p t i o n = ” This i s a way to long

↪→ d e s c r i p t i o n f o r something ”~ ” that should be obvious . ” ;

auto system = world . getOrNewSoftwareSystem ( ”↪→ AwesomeSoftware” ) ;

Container f rontend = system . getOrNewContainer ( ”↪→ Frontend ” ) ;

f rontend . techno logy = ” Angular ” ;auto f rontendUserCtr l = frontend . getOrNewComponent (

↪→ ” f r on tUse rCt r l ” ) ;

24

Page 64: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Using Degenerator 2/4

auto database = system . getOrNewContainer ( ” Database ”↪→ ) ;

database . techno logy = ”MySQL” ;world . getOrNew ! Dependency ( ” serverDatabase ” ,

s e rver , database) . d e s c r i p t i o n = ”CRUD” ;

Class user = getOrNewClass ( ” User ” ,f rontendUserCtr l , s e rve rUserCtr l , database

) ;

25

Page 65: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Using Degenerator 2/4

auto database = system . getOrNewContainer ( ” Database ”↪→ ) ;

database . techno logy = ”MySQL” ;world . getOrNew ! Dependency ( ” serverDatabase ” ,

s e rver , database) . d e s c r i p t i o n = ”CRUD” ;

Class user = getOrNewClass ( ” User ” ,f rontendUserCtr l , s e rve rUserCtr l , database

) ;

25

Page 66: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Using Degenerator 3/4

Class user = getOrNewClass ( ” User ” ,f rontendUserCtr l , s e rve rUserCtr l , database

) ;

MemberVariable use r Id = user . getOrNew !↪→ MemberVariable ( ” id ” ) ;

use r Id . type = i n t e g e r ;use r Id . addLandSpec i f i cAtt r ibute ( ”MySQL” , ”PRIMARY

↪→ KEY” ) ;use r Id . addLandSpec i f i cAtt r ibute ( ”MySQL” , ”AUTO

↪→ INCREMENT” ) ;

26

Page 67: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Using Degenerator 3/4

Class user = getOrNewClass ( ” User ” ,f rontendUserCtr l , s e rve rUserCtr l , database

) ;

MemberVariable use r Id = user . getOrNew !↪→ MemberVariable ( ” id ” ) ;

use r Id . type = i n t e g e r ;use r Id . addLandSpec i f i cAtt r ibute ( ”MySQL” , ”PRIMARY

↪→ KEY” ) ;use r Id . addLandSpec i f i cAtt r ibute ( ”MySQL” , ”AUTO

↪→ INCREMENT” ) ;

26

Page 68: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Using Degenerator 4/4

Class address = getOrNewClass ( ” Address ” ,f rontendUserCtr l , s e rve rUserCtr l , database

) ;

Aggregation userAddress = world . getOrNew !↪→ Aggregat ion ( ” addressUser ” ,address , user

) ;

27

Page 69: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Using Degenerator 4/4

Class address = getOrNewClass ( ” Address ” ,f rontendUserCtr l , s e rve rUserCtr l , database

) ;

Aggregation userAddress = world . getOrNew !↪→ Aggregat ion ( ” addressUser ” ,address , user

) ;

27

Page 70: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Types in Degenerator

• Types

e.g. strings are not always strings• D string• MySQL text• C++ std::string

s t r u c t Type {s t r i n g name ;s t r i n g [ s t r i n g ] typeMapping ;

}

auto pwdHash = Type( ” PasswordStr ing ” ) ;pwdHash . typeMappings [ ”D” ] = ” s t r i n g ” ;pwdHash . typeMappings [ ”MySQL” ] = ”VARCHAR(128) ” ;

28

Page 71: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Types in Degenerator

• Types e.g. strings are not always strings

• D string• MySQL text• C++ std::string

s t r u c t Type {s t r i n g name ;s t r i n g [ s t r i n g ] typeMapping ;

}

auto pwdHash = Type( ” PasswordStr ing ” ) ;pwdHash . typeMappings [ ”D” ] = ” s t r i n g ” ;pwdHash . typeMappings [ ”MySQL” ] = ”VARCHAR(128) ” ;

28

Page 72: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Types in Degenerator

• Types e.g. strings are not always strings• D string• MySQL text• C++ std::string

s t r u c t Type {s t r i n g name ;s t r i n g [ s t r i n g ] typeMapping ;

}

auto pwdHash = Type( ” PasswordStr ing ” ) ;pwdHash . typeMappings [ ”D” ] = ” s t r i n g ” ;pwdHash . typeMappings [ ”MySQL” ] = ”VARCHAR(128) ” ;

28

Page 73: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Types in Degenerator

• Types e.g. strings are not always strings• D string• MySQL text• C++ std::string

s t r u c t Type {s t r i n g name ;s t r i n g [ s t r i n g ] typeMapping ;

}

auto pwdHash = Type( ” PasswordStr ing ” ) ;

pwdHash . typeMappings [ ”D” ] = ” s t r i n g ” ;pwdHash . typeMappings [ ”MySQL” ] = ”VARCHAR(128) ” ;

28

Page 74: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Types in Degenerator

• Types e.g. strings are not always strings• D string• MySQL text• C++ std::string

s t r u c t Type {s t r i n g name ;s t r i n g [ s t r i n g ] typeMapping ;

}

auto pwdHash = Type( ” PasswordStr ing ” ) ;pwdHash . typeMappings [ ”D” ] = ” s t r i n g ” ;pwdHash . typeMappings [ ”MySQL” ] = ”VARCHAR(128) ” ;

28

Page 75: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Generating

Graphvic gv = new Graphvic ( world , ” GraphvizOutput ” ) ;gv . generate ( ) ;

MySQL mysql = new MySQL( world , ”MySQL” ) ;mysql . generate ( database ) ;

29

Page 76: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

The World

30

Page 77: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

The World and Containers

31

Page 78: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Awesome Software System

32

Page 79: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

Generating the Database CREATE TABLE Statements

CREATE TABLE Address {id LONG PRIMARY KEY

};

CREATE TABLE Address_User {User_id LONGFOREIGN KEY( User_id )

↪→ REFERENCES User ( id ) ON↪→ UPDATE CASCADE ON↪→ DELETE CASCADE,

Address_id LONGFOREIGN KEY( Address_id )

↪→ REFERENCES Address ( id )↪→ ON UPDATE CASCADE ON↪→ DELETE CASCADE

}

CREATE TABLE User {id LONG PRIMARY KEY AUTO

↪→ INCREMENT,lastname TEXT,firstname TEXT

};

CREATE TABLE PostelCode {id LONG PRIMARY KEY AUTO

↪→ INCREMENT,code LONG,Address_id LONGFOREIGN KEY( Address_id )

↪→ REFERENCES Address ( id )↪→ ON UPDATE CASCADE ON↪→ DELETE CASCADE

};

33

Page 80: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

What can we generate

• Diagrams describing the project at different levels of detail• Database schema• phpmyadmin clones• Database access code• Data objects (D struct/class, Typescript interface/class, . . .• Server skeletons• Frontend skeletons

• Graphviz mostly done, MySQL is getting there, Vibe.d andAngular2 next

34

Page 81: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

What can we generate

• Diagrams describing the project at different levels of detail• Database schema• phpmyadmin clones• Database access code• Data objects (D struct/class, Typescript interface/class, . . .• Server skeletons• Frontend skeletons• Graphviz mostly done, MySQL is getting there, Vibe.d and

Angular2 next

34

Page 82: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome
Page 83: Asynchronous single page applications without a line of HTML or Javascript, or why D is just awesome

The End

• vibe.d https://vibed.org

• typescript https://www.typescriptlang.org/

• dstructtotypescripthttps://github.com/burner/dstructtotypescript

• C4 Architecture (Simon Brown)http://www.codingthearchitecture.com

• Structurizr https://structurizr.com/

• Degenerator https://github.com/burner/Degenerator

36