Practical Code Generation

22
http://europe.cfunited.com/ March 12 & 13, 2007 Practical Code Generation Peter Bell SystemsForge

description

Practical Code Generation. Peter Bell SystemsForge. Overview. Who am I? Why Listen? Problems to solve Potential solutions Domain Specific Languages Software Product Lines Code Gen/Frameworks Next Steps. Who Am I?. Programmer - 30-40 projects/yr. - PowerPoint PPT Presentation

Transcript of Practical Code Generation

Page 1: Practical Code Generation

http://europe.cfunited.com/ March 12 & 13, 2007

Practical Code GenerationPractical Code Generation

Peter BellSystemsForge

Page 2: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

OverviewOverviewWho am I?

Why Listen?

Problems to solve

Potential solutions

Domain Specific Languages

Software Product Lines

Code Gen/Frameworks

Next Steps

Page 3: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Who Am I?Who Am I?Programmer - 30-40 projects/yr.

Researcher - Published academic papers DSM forum/ooPSLA

Entrepreneur - Profitable/practical

SystemsForge - 10,000 custom apps/yr.

Writer - CFDJ, Fusion Authority Quarterly

Presenter - cf.objective(), CF United, Frameworks, Code Generation 2007, ooPSLA, Domain Specific Modeling Forum, CFCamp . . .

Page 4: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Why Listen?Why Listen?

Companies are reporting 5-10x faster development using Domain Specific Languages and Software Product Lines

You’re already doing these things

A few concepts will help you to do them better

Page 5: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

CalibrationCalibration

Have you:

Written OO code?

Heard of DSLs?

Written a DSL?

Heard of SPLs

Created a SPL?

Page 6: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

ProblemsProblems

OO coding is slow

Changes are painful

Reuse is difficult

Page 7: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

OO Coding is SlowOO Coding is Slow

ProductService.cfc

ProductDAO.cfc

Product.cfc

tbl_Product

ColdSpring/Lightwire config

Admin controller/views

Front end controller

Catalog.cfc

Front end views

ProductList.cfm, ProductDetail.cfm

Add Products to site . . .

Page 8: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Changes are PainfulChanges are Painful

Add services from tbl_Service to product catalog

Products -> multiple categories

Change form error handling (error list to in-form display)

Page 9: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Re-use is DifficultRe-use is DifficultLibraries/utility components/cut and paste/snippets - usually OK

Problem with cfc reuse is usually cross cutting concerns:

Logging

Error handlers

Notification services

Other dependencies . . .

Page 10: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Solving Same ProblemsSolving Same Problems

Solutions

Content management

Workflow

Shopping carts

Techniques

Form processing

DB access

Paginated lists

Reporting

Imports/Exports

Page 11: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Potential SolutionsPotential Solutions

Code quicker - DSL

Maintain easier - DSL

Re-use better - SPL

Page 12: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Domain Specific LanguageDomain Specific Language

“An executable language targeted to a specific problem domain”

Specific - can’t do everything

Executable - not just conceptual

Raising level of abstraction

Page 13: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Types of DSLsTypes of DSLsHorizontal (tech focused)

SQL

RegEx

Import description language

General workflow language

Vertical (business focused)

Insurance policy language

Product configuration language

Academic requirements language

Page 14: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Types of DSLs - InternalTypes of DSLs - Internal

Custom tag

<cf_import filename="test.csv" record-delimiter="," field-name-list="FirstName,LastName,Email" source="tbl_User" method="update">

API

UserService.import("test.csv", ",", "FirstName,LastName,Email", "tbl_User", "update");

Method Chaining

User.IsValid.FirstName()

Page 15: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Types of DSL - ExternalTypes of DSL - ExternalComma delimited

"test.csv", ",", "FirstName,LastName,Email", "tbl_User", "update"

XML

<import filename="test.csv" record-delimiter="," field-name-list="FirstName,LastName,Email" source="tbl_User" method="update" />

Databased

“Little Language”

Import test.csv using commas update tbl_User with FirstName,LastName,Email

Visual

Page 16: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

DSL Key ConceptDSL Key ConceptAbstract Grammar vs. Concrete Syntax

What you say vs. How you say it

User@FirstName

<cfset Objects.User.Title = “User”><cfset Objects.User.Attributes.Name = “FirstName”>

<Object title=”User”> <Name>FirstName</Name></Object>

Page 17: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Example DSLExample DSLProduct extends: BaseObject tableName: tbl_ProductIdentity: ProductID

Properties: Title title required Price money optional default:0 Description WYSIWYG optional

ClassMethods: AdminList: Title,Price OrderBy Title DefaultAdd: Title,Price,Description QuickAdd: Title,Price multiple:5 DefaultEdit: ID, Title,Price,Description

Relationship has-many Category associated optional

Page 18: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Benefits of DSLsBenefits of DSLs

More concise (less to write/edit)

Can add constraints

MAY be end user editable

Page 19: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Software Product LinesSoftware Product LinesDesign a collection of applications

Bounded and unbounded variability

Bounded: feature model/configuration

Unbounded: DSLs

Extension points

Page 20: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Code Gen/FrameworkCode Gen/Framework

Both use DSLs

Compiled/interpreted

Late bound decision

Page 21: Practical Code Generation

March 12 & 13, 2007http://europe.cfunited.com/

Next StepsNext StepsMultiple Applications?

Plan variability

Feature model

Configuration options

DSLs

Generators/framework

Single Application?

Reusable services

Raise abstraction levels

DSLs: Custom tags, APIs, external config files, CMSs, visual editors (Eclipse EMF)

Page 22: Practical Code Generation

March 12 & 13, 2007 22

http://europe.cfunited.com/

Questions?Questions?

Blog: www.pbell.com

Email: [email protected]

Yahoo: freshstartsw

AIM: appgeneration