SlideShare a Scribd company logo
WRITING CODE
           that
 WRITES CODE
        STEVE MARSHALL
But why?
Writing Code That Writes Code
Code munging
Inline code expansion

Code munging
Mixed code generation

Inline code expansion

Code munging
Partial class generation

Mixed code generation

Inline code expansion

Code munging
Tier generation

Partial class generation

Mixed code generation

Inline code expansion

Code munging
Full domain language

Tier generation

Partial class generation

Mixed code generation

Inline code expansion

Code munging
Full domain language

Tier generation

Partial class generation

Mixed code generation

Inline code expansion

Code munging
Source code




Code munger




 Output file
Full domain language

Tier generation

Partial class generation

Mixed code generation

Inline code expansion

Code munging
Source code



 Inline code
  expander


Output source
    code



  Compiler
Full domain language

Tier generation

Partial class generation

Mixed code generation

Inline code expansion

Code munging
Source code



 Mixed code
 generator


Output source
    code



  Compiler
Full domain language

Tier generation

Partial class generation

Mixed code generation

Inline code expansion

Code munging
Definition file



 Partial class
                               Templates
  generator


Output base                  Custom derived
 class code                    class code



                  Compiler
Full domain language

Tier generation

Partial class generation

Mixed code generation

Inline code expansion

Code munging
Definition file                    Templates



                  Tier generator



                  Output source
                      code



                    Compiler
Full domain language

Tier generation

Partial class generation

Mixed code generation

Inline code expansion

Code munging
Writing Code That Writes Code
What should I use?
Let me tell you
a story…
One for the team.
1.

Respect (and loathe)
hand-coding.
2.

Hand-code first.
3.

Control your source.
4.

Consider the
generator’s language.
5.

Integrate the
generator into your
workflow.
6.

Include warnings.
7.

Play nice with others.
8.

Document well.
9.

Consider the
cultural impact.
10.

Keep it maintained.
Writing Code That Writes Code
icanhaz.com/codegen-book
icanhaz.com/codegen

@stevemarshall
steve@nascentguruism.com


Stephen Wolfram photo:
flickr.com/photos/hybernaut/87907765/

More Related Content

PPTX
Inside Dvm basics
PPTX
Interesting Facts About Flutter
PPTX
SETCON'18 - Yauheni Pakala - .NET Embedding
PDF
Google Developer Day 2010 Japan: 音声入力 API for Android (アレックス グランスタイン, 小西 祐介)
PPT
Mr. Ankur Sharma - PDE good practices
KEY
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
PPT
Using JavaScript for Mobile Development
PPT
Mobile Devolpment Slides
Inside Dvm basics
Interesting Facts About Flutter
SETCON'18 - Yauheni Pakala - .NET Embedding
Google Developer Day 2010 Japan: 音声入力 API for Android (アレックス グランスタイン, 小西 祐介)
Mr. Ankur Sharma - PDE good practices
Pragmatic DSL Design with Xtext, Xbase and Xtend 2
Using JavaScript for Mobile Development
Mobile Devolpment Slides

Viewers also liked (7)

PDF
HackU Barcelona 2011: YQL
PDF
HackU Dundee 2011: Tools to Hack With
PPSX
Reuters: Pictures of the Year 2016 (Part 2)
PDF
Open Source Creativity
PDF
The Six Highest Performing B2B Blog Post Formats
PDF
The Outcome Economy
PDF
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
HackU Barcelona 2011: YQL
HackU Dundee 2011: Tools to Hack With
Reuters: Pictures of the Year 2016 (Part 2)
Open Source Creativity
The Six Highest Performing B2B Blog Post Formats
The Outcome Economy
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
Ad

Similar to Writing Code That Writes Code (20)

PPTX
Intro to Reverse Engineering
PPTX
Lecture 1 introduction to language processors
PPTX
compiler and their types
PPT
Lecture 10 software development
ODP
Native client (Евгений Эльцин)
PPTX
Weekly Session with the local .NET Developer Community
PPT
Introduction to c_sharp
PPT
Introduction to c_sharp
PDF
Wondershare filmora crack FREE Download 2025
PDF
IObit Advanced SystemCare Pro Crack Download (Latest 2025)
PDF
[DSC Europe 24] Daniel Savenkov - Beyond Autocomplete: Local AI Code Completi...
PDF
Adobe Photoshop 2025 Free crack Download
PDF
Autodesk AutoCAD Architecture free crack
PDF
iTop VPN Free Download key (Latest 2025)
PDF
Ableton Live Suite Download (Latest 2025)
PDF
CorelDRAW Graphics Suite Download free
KEY
Development workflow
PPTX
aditya malkani compiler.pptx
PDF
NetWork - 15.10.2011 - Applied code generation in .NET
PDF
UnDeveloper Studio
Intro to Reverse Engineering
Lecture 1 introduction to language processors
compiler and their types
Lecture 10 software development
Native client (Евгений Эльцин)
Weekly Session with the local .NET Developer Community
Introduction to c_sharp
Introduction to c_sharp
Wondershare filmora crack FREE Download 2025
IObit Advanced SystemCare Pro Crack Download (Latest 2025)
[DSC Europe 24] Daniel Savenkov - Beyond Autocomplete: Local AI Code Completi...
Adobe Photoshop 2025 Free crack Download
Autodesk AutoCAD Architecture free crack
iTop VPN Free Download key (Latest 2025)
Ableton Live Suite Download (Latest 2025)
CorelDRAW Graphics Suite Download free
Development workflow
aditya malkani compiler.pptx
NetWork - 15.10.2011 - Applied code generation in .NET
UnDeveloper Studio
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation theory and applications.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Unlocking AI with Model Context Protocol (MCP)
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Spectroscopy.pptx food analysis technology
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Cloud computing and distributed systems.
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Spectral efficient network and resource selection model in 5G networks
Big Data Technologies - Introduction.pptx
MYSQL Presentation for SQL database connectivity
Encapsulation theory and applications.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Assigned Numbers - 2025 - Bluetooth® Document
Unlocking AI with Model Context Protocol (MCP)
The AUB Centre for AI in Media Proposal.docx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Spectroscopy.pptx food analysis technology
A Presentation on Artificial Intelligence
Encapsulation_ Review paper, used for researhc scholars
Cloud computing and distributed systems.
Network Security Unit 5.pdf for BCA BBA.
Programs and apps: productivity, graphics, security and other tools
Digital-Transformation-Roadmap-for-Companies.pptx
sap open course for s4hana steps from ECC to s4
Review of recent advances in non-invasive hemoglobin estimation
Spectral efficient network and resource selection model in 5G networks

Writing Code That Writes Code

Editor's Notes

  • #2: Gonna talk about codegen. Steve Marshall - Interested in everything - Want to be a pirate - Y! Ents Why codegen - Don’t like repetition - Don’t like repetition - Interesting problem of scale - Lack of resources => be creative
  • #3: Quality, consistency, single point of knowledge, eases bulk refactoring, improves architectural consistency, increases abstraction, increases morale. Quality Lots of code => inconsistencies Templates => consistent quality Consistency - Consistent naming - API style - No surprises Single Point of Knowledge Schema describes system simply Architecture documented, not embedded in code Facilitates Bulk Refactoring Faulty assumptions in hand coding mean refactoring lots of code Generation makes refactoring minimal Also: generation can compress project timelines => more time to design/prototype, less need to refactor Architectural Consistency - Generator encourages working within architecture - “generator doesn’t do that” can indicate that the feature doesn’t fit the architecture - Consistent, structured approach, regardless of team members joining/leaving Abstraction - Application logic is language-independent. Can easily port templates to other languages (eg. for performance, also: WSDL describing inputs/outputs) - Can easily review/validate abstract designs - Aids development of non-implementation code (tests, documentation, etc) High Morale Less gruntwork to do by hand More focus on interesting problems Higher morale Also: higher quality, consistent code => confidence and pride
  • #4: Type of codegen… - Munging - Code expansion - Mixed codegen - Partial class gen - Tier gen - FDL
  • #5: Type of codegen… - Munging - Code expansion - Mixed codegen - Partial class gen - Tier gen - FDL
  • #6: Type of codegen… - Munging - Code expansion - Mixed codegen - Partial class gen - Tier gen - FDL
  • #7: Type of codegen… - Munging - Code expansion - Mixed codegen - Partial class gen - Tier gen - FDL
  • #8: Type of codegen… - Munging - Code expansion - Mixed codegen - Partial class gen - Tier gen - FDL
  • #9: Type of codegen… - Munging - Code expansion - Mixed codegen - Partial class gen - Tier gen - FDL
  • #11: Parses source code Produces some non-source output See documentation, linting, … Also: build header files, web service layers
  • #13: Parses source for special keywords Replaces with production code eg. Embedding SQL in source à la Pro*C/SQLJ
  • #15: Like inline code expansion, but output can be used as input (replaces in-place) Looks for specially formatted comments, fills comment-wrapped area with new production source eg. Marshalling code
  • #17: Reads abstract definition with enough info to build classes Applies def’n to templates to output base classes Used with subclasses for custom behaviour Can be a stepping stone to tier generation
  • #19: Generator builds a complete tier of your app (eg ORM) eg. Model-driven generation takes definition file and applies to templates Like partial class, but without special cases (or are codified in templates) Partial class generation requires extra code, tier doesn’t (but may have it)