How to Build Successful DSL s Jos Warmer Leendert Versluijs
Jos Warmer Expert in Model Driven Development One of the authors of the UML standard Author of books Praktisch UML MDA Explained Object Constraint Language Partner at Ordina
Leendert Versluijs 20 years of specialization in latest Microsoft Technology Solution Architect at Ordina Software Factory
SMART-Microsoft
Agenda Introduction Process What Define Build Test Use Best Practices Summary
Introduction: Choose Your Environment Microsoft's answer to MDA and UML is their own flexible (meta-) modeling environment: Domain Specific Language Tools Solves the problems with UML Available as tools Create your own modeling languages Generation of visual editor within Visual Studio Part of the Microsoft Software Factory initiative
Introduction: DSL Workbench DSL Developer Domain Model Designer Templates DSL Setup Installation In IDE of application developers Manual code Application Models In DSL Generated code Application developers Working Application Domain Specific Framework
What: The Goal Modeling must be less work than coding Generate code that runs Being able to always re-generate Code always conform a reference architecture Only for reoccurring patterns Useable for junior developers
What: The Product Define type of similar applications Decide on the target architecture Write the code that needs to be generated by hand using a reference application Test and review the reference application
What: SMART-Microsoft Domain Medium to large scale administrative systems Based on Microsoft architecture Latest available Microsoft technology Service oriented Open standards Microsoft & open source components Clear, explicit choices
What: Application architecture Users Utilities Presentation layer User Interface components Communication Operational Management Security Ordina Core Framework Ordina DSL Specific Frameworks User Processes Business layer Service Interfaces Business Processes Business Workflows Business Classes Service Agents Data contract DTO View DTO Data Access Logic Components Data layer Data Service Agents Data sources Services
What: Framework selection Utilities Communication Operational Management Security Ordina Core Framework Log4Net Ordina DSL Specific Frameworks Users User Interface components User Processes Application Building Block Business Process (Validation) Microsoft (AJAX) UI Process (Translation for DTO s) Business Class Business Processes (Base classes) (Translation) Business Classes Controls (Business rules handling) Presentation layer Validation WCF (Custom (Behaviours) Business attributes) layer Service Interfaces Business Workflows Service Agents Data contract DTO View DTO NHibernate Data Access Logic Components Data layer Data Service Agents Data sources Services
What: The proof is in the eating
Define: Analyze the Code Static code is put into framework Re-occuring patterns are generated from a DSL The rest: keep writing the code by hand Tradeoffs : the division between putting something in the framework or generating code is iteratively being adjusted.
Define: Rules of the Game Define the concepts that you need in your DSL to generate the required code Focus on concepts above programming language level Keep a DSL small and simple Keep models for a DSL small Assume that you will need multiple DSLs Storyboard the models
Define: The Models Users Utilities Communication Operational Management Security Ordina Core Framework Ordina DSL Specific Frameworks Service DSL Web-Scenario User Interface components User Processes Service Interfaces Business Processes Business Classes DSL DSL Presentation layer Business layer View DTO Business Workflows Service Agents Data layer Data contract Data Contract DSL Workflow Foundation Sequential workflows DTO Data Access Logic Components Data Service Agents Data sources Services
Define: Business Class Model
Define: Data Contract Model
Define: Service Interface Model
Define: Web Scenario Model
Build: Usability Domain model Presentation and tool model Need Intellisense Need ease of use Need smart code generation Etc. etc.
Build: Code Generation Code generation templates (T4) Never change generated code, extend it Design extension points in generated code Code generation patterns Abstract Base Class GENERATED Partial Concrete SubClass GENERATED HAND WRITTEN Partial SubClass Extension
Build: Model Integration & Validation <@Page /> <HTML> <BODY> Hello World </BODY> </HTML> Class MyClass { public string Hello() { return Hello world ; } } DSL Specifiek Framework Class MyClass { public string Hello() { return Hello world ; } } DSL Specifiek Framework Generiek Framework Class MyClass { public string Hello() { return Hello world ; } } <Mapping> <Class> <Table> </Mapping> DSL Specifiek Framework CREATE TABLE MyTable FIELD1 int FIELD2 varchar(50)
Build: NDIP Ordina NDIP Code generation support Cross model validation DSL Intellisense support Propagate model changes Ordina Web Scenario Designer Ordina DTO Designer Ordina Service Designer Ordina Business Class Designer Output Output Output Output
Build: Visual Studio.NET Instant action on save Validation Generation Popups for complex editing tasks Generation of multiple files Cross project generation Files under model
Build: Validation & Generation Validation Only existing model Relations within and from model Properties T4 templates Helperfunctions for T4 Provided as embedded resource, not in client project Xml merging Need partial XML files (a la partial C# classes) Configurable Controls Unique identifiers
Test Rebuild the reference application with the DSLs and test them Test coverage: ensure all DSL concepts are used If necessary change reference application Just big enough Do this iteratively for each DSL Gradually rewrite reference application
Test: Best Practices Lotus massage salon sample app Business class relation types All types of DTO s Services all method types Web scenario all types and events
Test: Demo?
Use: Create Fertile Environment Workshops developed Underlying architecture, framework & components The DSL s Development process with DSLs Project support Life Wiki for how-to's Q&A Release management Keep technology up to date Add new functionality Release new versions of DSL s regularly
Use: Development Process Web-Scenario model Business Class model Data Contract model Maintenance functions Service model Scenario s Business functions Data Contract model Scenario Web-Scenario model Service model
Use: Projects First 3 successful commercial projects High volume transaction system Public internet application for large customer Extranet application for government 11937 Generated code 32926 Manual code
Use: Project Experience Version control / Team work Keep models small Consistency between models Manual changes Web pages after first generation Business processes & business rules Side effects Guidance how to use new technology
DSL Developer Domain Model Designer Templates DSL Setup Installation In IDE of application developer Define DSLs Application developers Test: rewrite reference application using DSLs Application Models In DSL Reference application is divided it into Generated code Domain Specific Framework Manual code Working Application Define your domain: decide on the reference architecture Write a reference application
Take Away s Keep DSLs small A DSL doesn t live standalone, you need an NDIP Model is the unit of version control, multiuser access, etc. Everything in a model is used for code generation Models are leading: never touch the generated code Don t aim for 100% code generation The success lies in the usage of your DSL