Your SlideShare is downloading. ×
  • Like
Writing Code That Writes Code
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Writing Code That Writes Code

  • 3,816 views
Published

The best developers are fundamentally very lazy. What if there was a way to write a fraction of the volume of code you currently write without losing any functionality, and massively increasing code …

The best developers are fundamentally very lazy. What if there was a way to write a fraction of the volume of code you currently write without losing any functionality, and massively increasing code quality (can you say '100% test coverage')?

Code generation allows us to do exactly that: we can write less code that does more. Imagine a world where all your code is unit-tested, fully documented, clearly commented, fully optimised, is a joy to maintain, and /still/ meets all the requirements. That world is exactly what code generation offers.

Why outsource code to someone halfway around the world when you can outsource it to the little goblins inside the magic box on your desk? Steve Marshall will show you the how, the why, and the 'what's that warm feeling inside?'

Published in Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Great demonstration about the require to innovate company models; tips on how to represent them succinctly; along with the need to make development initiatives actionable. Superb use of photographs along with easy to understand illustrative examples.
    Sharika
    http://financeadded.com http://traveltreble.com
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
3,816
On SlideShare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
31
Comments
1
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • 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
  • 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
  • Type of codegen…



    - Munging
    - Code expansion
    - Mixed codegen
    - Partial class gen
    - Tier gen
    - FDL
  • Type of codegen…



    - Munging
    - Code expansion
    - Mixed codegen
    - Partial class gen
    - Tier gen
    - FDL
  • Type of codegen…



    - Munging
    - Code expansion
    - Mixed codegen
    - Partial class gen
    - Tier gen
    - FDL
  • Type of codegen…



    - Munging
    - Code expansion
    - Mixed codegen
    - Partial class gen
    - Tier gen
    - FDL
  • Type of codegen…



    - Munging
    - Code expansion
    - Mixed codegen
    - Partial class gen
    - Tier gen
    - FDL
  • Type of codegen…



    - Munging
    - Code expansion
    - Mixed codegen
    - Partial class gen
    - Tier gen
    - FDL
  • Parses source code
    Produces some non-source output



    See documentation, linting, … Also: build header files, web service layers
  • Parses source for special keywords
    Replaces with production code



    eg. Embedding SQL in source à la Pro*C/SQLJ
  • 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
  • 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
  • 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)

Transcript

  • 1. WRITING CODE that WRITES CODE STEVE MARSHALL
  • 2. But why?
  • 3. Code munging
  • 4. Inline code expansion Code munging
  • 5. Mixed code generation Inline code expansion Code munging
  • 6. Partial class generation Mixed code generation Inline code expansion Code munging
  • 7. Tier generation Partial class generation Mixed code generation Inline code expansion Code munging
  • 8. Full domain language Tier generation Partial class generation Mixed code generation Inline code expansion Code munging
  • 9. Full domain language Tier generation Partial class generation Mixed code generation Inline code expansion Code munging
  • 10. Source code Code munger Output file
  • 11. Full domain language Tier generation Partial class generation Mixed code generation Inline code expansion Code munging
  • 12. Source code Inline code expander Output source code Compiler
  • 13. Full domain language Tier generation Partial class generation Mixed code generation Inline code expansion Code munging
  • 14. Source code Mixed code generator Output source code Compiler
  • 15. Full domain language Tier generation Partial class generation Mixed code generation Inline code expansion Code munging
  • 16. Definition file Partial class Templates generator Output base Custom derived class code class code Compiler
  • 17. Full domain language Tier generation Partial class generation Mixed code generation Inline code expansion Code munging
  • 18. Definition file Templates Tier generator Output source code Compiler
  • 19. Full domain language Tier generation Partial class generation Mixed code generation Inline code expansion Code munging
  • 20. What should I use?
  • 21. Let me tell you a story…
  • 22. One for the team.
  • 23. 1. Respect (and loathe) hand-coding.
  • 24. 2. Hand-code first.
  • 25. 3. Control your source.
  • 26. 4. Consider the generator’s language.
  • 27. 5. Integrate the generator into your workflow.
  • 28. 6. Include warnings.
  • 29. 7. Play nice with others.
  • 30. 8. Document well.
  • 31. 9. Consider the cultural impact.
  • 32. 10. Keep it maintained.
  • 33. icanhaz.com/codegen-book icanhaz.com/codegen @stevemarshall steve@nascentguruism.com Stephen Wolfram photo: flickr.com/photos/hybernaut/87907765/