SlideShare a Scribd company logo
Code generation: Going all the way Rafael Chaves [email_address] http://alphasimple.com
Defining "code generation"
Code generation is everywhere IDE wizards Web Frameworks (RoR, Grails, Spring Roo, Django...)   JSP -> Servlet compiler   ORM tools (HQL -> SQL, LINQ -> SQL) XML tools (JAXB)   Any compiler (object code)  Modeling tools <<< this will be our focus
Step 1: basic code generation from models
 
package banking; public class Account {     private Double balance;      public Double getBalance() {         return this.balance;     }      public void setBalance(Double balance) {         assert balance != null;         this.balance = balance;      }      public void deposit(Double amount) {         /* FILL ME IN */     }     public void withdraw(Double amount) {         /* FILL ME IN */     }  }
Step 1 Good: generates boilerplate (example: getters/setters) can take advantage of richer modeling features (multiplicity) into account   Bad: empty methods need to be filled in manually regenerating will destroy manual changes generate once and take it from there?  Solution: protected regions
Step 2: using protected regions
package banking; public class Account {     private Double balance;      public Double getBalance() {         return this.balance;     }      public void setBalance(Double balance) {         assert balance != null;         this.balance = balance;      }      public void deposit(Double amount) {         //BEGIN-USER-CODE          this.balance = this.balance + amount;          //END-USER-CODE           }    ... }
Step 2: Protected regions Good: Can regenerate whenever model changes  Manual changes are preserved   Bad: Not supported by all code generation tools Generated artifact or manual artifact? no gains w.r.t. cognitive load SCM   Solution: &quot; generation gap &quot; pattern [Vlissides]    
Step 3: applying the Generation Gap pattern
Source:  IBM Research
// GENERATED - DO NOT MODIFY  package banking; public class AccountCore {     protected Double balance;      public Double getBalance() {         return this.balance;     }      public void setBalance(Double balance) {         assert balance != null;         this.balance = balance;      }      public void deposit(Double amount) {         // override me      }      public void withdraw(Double amount) {         // override me      }  }
package banking; public class Account extends AccountCore {      public void deposit(Double amount) {         this.balance = this.balance + amount;      }      public void withdraw(Double amount) {         this.balance = this.balance - amount;      }  }
Step 3: generation gap Good: tool support not required clean separation between generated and hand-written code  cognitive load win only handwritten code (and models) in SCM Bad: domain behavior still has to be written by hand ugly duality: structure in models, behavior in code  how much are we really gaining? Solution: ?
What problem are we trying to solve again?
Enterprise software is  much  harder than it should be Problem domains are typically not very complex (information management + business rules) How come? Secondary concerns abound   persistence, concurrency, (a)synchronism, distribution, transactions, security, caching, replication, logging, ...
Two dimensions of enterprise software Completely different beasts change rate abstraction level  tools skills reuse         Why do we treat them the same? Business Technical processes  entities  attributes and relationships constraints actions queries technical architecture design patterns programming idioms best practices
Problem hypothesis: lack of separation between technical and domain concerns is the root of all evil
Solutions Using ordinary 3GL + reflection/AOP   Model-driven development with DSLs   Model-driven development with a GPL (like UML)
Using ordinary 3GL + reflection/AOP Examples: Ruby On Rails, Grails, Django, Spring Roo, EJB Pros you can model using your existing programming language when done at runtime, avoids generation step Cons you can model using your existing programming language not meant for conceptual modeling ties development time to deployment time too much magic?
Model-driven development (with DSL or GPL) Examples: MetaEdit+, Xtext, MPS, WebRatio, Mendix, Bridgepoint UML,  AlphaSimple   Pros Can use the best tool for the job: language optimized for conceptual modeling  platform independence* Cons DSL: need to build/maintain the language  GPL: may need to extend language (a bit like 3GLs) Significant change in mindset/workflow
Solution hypothesis: Model-driven development with a GPL and full code generation
Models in software brainstorming communicating documenting understanding (rev. eng.) That is  not  what MDD is about
Models in MDD are the central artifacts in software (re: source vs. object code)  are well-formed are precise are complete are  executable  (directly/code generation) while still technology-independent
Demo: Executable modeling and full code generation with AlphaSimple
Validating hypotheses
How disappointed would you be if AlphaSimple 1.0 didn't allow you to: write your own templates generate JPA code out-of-the-box generate the entire code (back to partial code gen) model behavior  run a prototype off of your model   visualize your model as a class diagram run code generation using Maven  add your own!    Alternatives very disappointed somewhat disappointed not disappointed
Model-driven development is not about taking work (or fun) away from developers, but making their work more meaningful and valuable
Code generation: Going all the way Rafael Chaves [email_address] http://alphasimple.com

More Related Content

PDF
AlphaSimple product pitch
PPTX
Modern software architect post the agile wave
PPS
Ideal 2007 BEAM Overview
PDF
The Modern Software Architect
PPT
Doors Analyst
PPTX
Software Engineering - Spiral Model
PDF
A Lightweight MDD Process Applied in Small Projects
PPT
Spiral model explanation
AlphaSimple product pitch
Modern software architect post the agile wave
Ideal 2007 BEAM Overview
The Modern Software Architect
Doors Analyst
Software Engineering - Spiral Model
A Lightweight MDD Process Applied in Small Projects
Spiral model explanation

What's hot (20)

PPTX
The Spiral Model
DOCX
Assignment
PPT
Software development life cycle
PDF
[2015/2016] Software development process
PPTX
Evolutionary models
PPTX
RAD Model
PDF
Interactive sketching for the early stages of user interface design
PPT
The software management and engineering in the AI-oriented projects tutorial
PPT
Slides chapter 3
PPSX
Sohrab Waterfall Vs Rad
PPT
50500113 spiral-model
PPT
Iterative Development: Breaking from the Waterfall
PPTX
PROTOTYPE MODEL
PPT
Software Engineering Lec 2
PPTX
Prototyping
PPTX
Spiral model : System analysis and design
PDF
3. ch 2-process model
DOCX
Spiral Model & Requirement Validation
PPT
Software development slides
The Spiral Model
Assignment
Software development life cycle
[2015/2016] Software development process
Evolutionary models
RAD Model
Interactive sketching for the early stages of user interface design
The software management and engineering in the AI-oriented projects tutorial
Slides chapter 3
Sohrab Waterfall Vs Rad
50500113 spiral-model
Iterative Development: Breaking from the Waterfall
PROTOTYPE MODEL
Software Engineering Lec 2
Prototyping
Spiral model : System analysis and design
3. ch 2-process model
Spiral Model & Requirement Validation
Software development slides
Ad

Viewers also liked (11)

PDF
11 Dogmas of model driven development
PDF
Model Driven Prototyping
PDF
TDC SP 2016 - Dos requisitos à implantação em uma palestra
PDF
Modernização de Sistemas de Gestão
PDF
Cloudfier business pitch deck
PPTX
TDC Floripa 2015 Desenvolvendo Sistemas de Gestão a partir de Modelos Execut...
PDF
Refatorando o software corporativo
PDF
Separando arquitetura e negócios em sistemas de gestão
PDF
TDC SP 2016 - Construindo um microserviço Java 100% funcional em 30 minutos
PDF
MDD with Executable UML Models
PDF
TextUML Toolkit
11 Dogmas of model driven development
Model Driven Prototyping
TDC SP 2016 - Dos requisitos à implantação em uma palestra
Modernização de Sistemas de Gestão
Cloudfier business pitch deck
TDC Floripa 2015 Desenvolvendo Sistemas de Gestão a partir de Modelos Execut...
Refatorando o software corporativo
Separando arquitetura e negócios em sistemas de gestão
TDC SP 2016 - Construindo um microserviço Java 100% funcional em 30 minutos
MDD with Executable UML Models
TextUML Toolkit
Ad

Similar to Code generation (20)

PDF
Software Automation with Eclipse Modeling
PPTX
Agile MDD
ODP
RailswayCon 2010 - Command Your Domain
PPTX
Software Development: Beyond Training wheels
PDF
Odessa .NET User Group - 10.11.2011 - Applied Code Generation
PPTX
Domain Driven Design
PDF
Model driven software engineering in practice book - Chapter 9 - Model to tex...
PPT
Agile and Modeling / MDE : friends or foes? (Agile Tour Nantes 2010)
PDF
10 Things You Should Know About MDD
PDF
Why there is no future for Model Driven Development
PPT
P Training Presentation
PDF
4 agile modeldevelopement-danielleroux
 
PDF
Agile Model Developement- Daniel Leroux
PDF
Domain Driven Design
PPT
Relentless Refactoring
PDF
Introduction to MDE
PPT
Importance Of Being Driven
PDF
Software Development Practices
PDF
10 Ways To Improve Your Code
Software Automation with Eclipse Modeling
Agile MDD
RailswayCon 2010 - Command Your Domain
Software Development: Beyond Training wheels
Odessa .NET User Group - 10.11.2011 - Applied Code Generation
Domain Driven Design
Model driven software engineering in practice book - Chapter 9 - Model to tex...
Agile and Modeling / MDE : friends or foes? (Agile Tour Nantes 2010)
10 Things You Should Know About MDD
Why there is no future for Model Driven Development
P Training Presentation
4 agile modeldevelopement-danielleroux
 
Agile Model Developement- Daniel Leroux
Domain Driven Design
Relentless Refactoring
Introduction to MDE
Importance Of Being Driven
Software Development Practices
10 Ways To Improve Your Code

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Encapsulation theory and applications.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
KodekX | Application Modernization Development
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPT
Teaching material agriculture food technology
PDF
Modernizing your data center with Dell and AMD
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Encapsulation_ Review paper, used for researhc scholars
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Encapsulation theory and applications.pdf
A Presentation on Artificial Intelligence
KodekX | Application Modernization Development
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Teaching material agriculture food technology
Modernizing your data center with Dell and AMD
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Big Data Technologies - Introduction.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
NewMind AI Monthly Chronicles - July 2025
Encapsulation_ Review paper, used for researhc scholars

Code generation

  • 1. Code generation: Going all the way Rafael Chaves [email_address] http://alphasimple.com
  • 3. Code generation is everywhere IDE wizards Web Frameworks (RoR, Grails, Spring Roo, Django...)   JSP -> Servlet compiler   ORM tools (HQL -> SQL, LINQ -> SQL) XML tools (JAXB)   Any compiler (object code) Modeling tools <<< this will be our focus
  • 4. Step 1: basic code generation from models
  • 5.  
  • 6. package banking; public class Account {     private Double balance;     public Double getBalance() {         return this.balance;     }     public void setBalance(Double balance) {         assert balance != null;         this.balance = balance;     }     public void deposit(Double amount) {         /* FILL ME IN */     }     public void withdraw(Double amount) {         /* FILL ME IN */     } }
  • 7. Step 1 Good: generates boilerplate (example: getters/setters) can take advantage of richer modeling features (multiplicity) into account   Bad: empty methods need to be filled in manually regenerating will destroy manual changes generate once and take it from there? Solution: protected regions
  • 8. Step 2: using protected regions
  • 9. package banking; public class Account {     private Double balance;     public Double getBalance() {         return this.balance;     }     public void setBalance(Double balance) {         assert balance != null;         this.balance = balance;     }     public void deposit(Double amount) {         //BEGIN-USER-CODE         this.balance = this.balance + amount;         //END-USER-CODE         }    ... }
  • 10. Step 2: Protected regions Good: Can regenerate whenever model changes Manual changes are preserved   Bad: Not supported by all code generation tools Generated artifact or manual artifact? no gains w.r.t. cognitive load SCM   Solution: &quot; generation gap &quot; pattern [Vlissides]    
  • 11. Step 3: applying the Generation Gap pattern
  • 12. Source: IBM Research
  • 13. // GENERATED - DO NOT MODIFY package banking; public class AccountCore {     protected Double balance;     public Double getBalance() {         return this.balance;     }     public void setBalance(Double balance) {         assert balance != null;         this.balance = balance;     }     public void deposit(Double amount) {         // override me     }     public void withdraw(Double amount) {         // override me     } }
  • 14. package banking; public class Account extends AccountCore {     public void deposit(Double amount) {         this.balance = this.balance + amount;     }     public void withdraw(Double amount) {         this.balance = this.balance - amount;     } }
  • 15. Step 3: generation gap Good: tool support not required clean separation between generated and hand-written code cognitive load win only handwritten code (and models) in SCM Bad: domain behavior still has to be written by hand ugly duality: structure in models, behavior in code how much are we really gaining? Solution: ?
  • 16. What problem are we trying to solve again?
  • 17. Enterprise software is much harder than it should be Problem domains are typically not very complex (information management + business rules) How come? Secondary concerns abound persistence, concurrency, (a)synchronism, distribution, transactions, security, caching, replication, logging, ...
  • 18. Two dimensions of enterprise software Completely different beasts change rate abstraction level tools skills reuse         Why do we treat them the same? Business Technical processes entities  attributes and relationships constraints actions queries technical architecture design patterns programming idioms best practices
  • 19. Problem hypothesis: lack of separation between technical and domain concerns is the root of all evil
  • 20. Solutions Using ordinary 3GL + reflection/AOP   Model-driven development with DSLs   Model-driven development with a GPL (like UML)
  • 21. Using ordinary 3GL + reflection/AOP Examples: Ruby On Rails, Grails, Django, Spring Roo, EJB Pros you can model using your existing programming language when done at runtime, avoids generation step Cons you can model using your existing programming language not meant for conceptual modeling ties development time to deployment time too much magic?
  • 22. Model-driven development (with DSL or GPL) Examples: MetaEdit+, Xtext, MPS, WebRatio, Mendix, Bridgepoint UML, AlphaSimple Pros Can use the best tool for the job: language optimized for conceptual modeling platform independence* Cons DSL: need to build/maintain the language GPL: may need to extend language (a bit like 3GLs) Significant change in mindset/workflow
  • 23. Solution hypothesis: Model-driven development with a GPL and full code generation
  • 24. Models in software brainstorming communicating documenting understanding (rev. eng.) That is not what MDD is about
  • 25. Models in MDD are the central artifacts in software (re: source vs. object code) are well-formed are precise are complete are executable (directly/code generation) while still technology-independent
  • 26. Demo: Executable modeling and full code generation with AlphaSimple
  • 28. How disappointed would you be if AlphaSimple 1.0 didn't allow you to: write your own templates generate JPA code out-of-the-box generate the entire code (back to partial code gen) model behavior run a prototype off of your model  visualize your model as a class diagram run code generation using Maven  add your own!   Alternatives very disappointed somewhat disappointed not disappointed
  • 29. Model-driven development is not about taking work (or fun) away from developers, but making their work more meaningful and valuable
  • 30. Code generation: Going all the way Rafael Chaves [email_address] http://alphasimple.com

Editor's Notes

  • #3: code generator = a program that produces other programs
  • #17: Code generation is just a tool   Productivity   Automate what can be automated    What problem does it solve?   To extract architectural decisions as reusable artifacts   To reduce time to market   To ensure consistency (developers like to pretend they are robots)
  • #24: Code generation is just a tool   Productivity   Automate what can be automated    What problem does it solve?   To extract architectural decisions as reusable artifacts   To reduce time to market   To ensure consistency (developers like to pretend they are robots)