220 likes | 337 Views
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.
E N D
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. • 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 . . .
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
Calibration • Have you: • Written OO code? • Heard of DSLs? • Written a DSL? • Heard of SPLs • Created a SPL?
Problems • OO coding is slow • Changes are painful • Reuse is difficult
OO Coding is Slow Add Products to site . . . • Admin controller/views • Front end controller • Catalog.cfc • Front end views • ProductList.cfm, ProductDetail.cfm • ProductService.cfc • ProductDAO.cfc • Product.cfc • tbl_Product • ColdSpring/Lightwire config
Changes are Painful • Add services from tbl_Service to product catalog • Products -> multiple categories • Change form error handling (error list to in-form display)
Re-use is Difficult • Libraries/utility components/cut and paste/snippets - usually OK • Problem with cfc reuse is usually cross cutting concerns: • Logging • Error handlers • Notification services • Other dependencies . . .
Solving Same Problems • Techniques • Form processing • DB access • Paginated lists • Reporting • Imports/Exports • Solutions • Content management • Workflow • Shopping carts
Potential Solutions • Code quicker - DSL • Maintain easier - DSL • Re-use better - SPL
Domain Specific Language “An executable language targeted to a specific problem domain” • Specific - can’t do everything • Executable - not just conceptual • Raising level of abstraction
Types of DSLs • Vertical (business focused) • Insurance policy language • Product configuration language • Academic requirements language • Horizontal (tech focused) • SQL • RegEx • Import description language • General workflow language
Types 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()
Types of DSL - External • Comma 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
DSL Key Concept • Abstract Grammar vs. Concrete Syntax • What you say vs. How you say it <cfset Objects.User.Title = “User”> <cfset Objects.User.Attributes.Name = “FirstName”> <Object title=”User”> <Name>FirstName</Name> </Object> User @FirstName
Example DSL Product extends: BaseObject tableName: tbl_Product Identity: 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
Benefits of DSLs • More concise (less to write/edit) • Can add constraints • MAY be end user editable
Software Product Lines • Design a collection of applications • Bounded and unbounded variability • Bounded: feature model/configuration • Unbounded: DSLs • Extension points
Code Gen/Framework • Both use DSLs • Compiled/interpreted • Late bound decision
Next Steps • Single Application? • Reusable services • Raise abstraction levels • DSLs: Custom tags, APIs, external config files, CMSs, visual editors (Eclipse EMF) • Multiple Applications? • Plan variability • Feature model • Configuration options • DSLs • Generators/framework
Questions? • Blog: • www.pbell.com • Email: • peter@pbell.com • Yahoo: • freshstartsw • AIM: • appgeneration