SlideShare a Scribd company logo
Visual Studio 2010Effective Code Generation TechniquesDoug Hollanddoug.holland@microsoft.comblogs.msdn.com/dohollan
Doug HollandSr. Architect Evangelist, Microsoft CorporationMSc Software Engineering, Oxford University             @doughollandhttp://blogs.msdn.com/dohollan
Code generation
AgendaStringBuilderSystem.CodeDomCode SnippetsXSLTVisual Studio 2010 Project & Item TemplatesText Template Transformation Toolkit (T4)Entity Framework 4.0 & T4 TemplatesUML & T4 TemplatesSQL Server 2008 R2 Management Objects (SMO)Unit Testing
StringBuilderAdvantagesAlmost all .net developers should feel comfortable using the StringBuilder class so it requires no additional languages / tools to learn.Even with the disadvantages, the StringBuilder can be an excellent choice if you need to generate code quickly. Especially if you don’t need to maintain the “template” long term.DisadvantagesUnable to truly see the “template” within the control logic.Requires a recompile if the “template” should be changed.
System.CodeDomAdvantagesAllows  a single “template” to generate code within several target languages, such as VB and C#.Additional language providers  can be written to support other languages.Proven technology, used by Microsoft for code generation in all versions of Visual Studio since .net was released.DisadvantagesUnable to truly see the “template” within the control logic.Requires a recompile if the “template” should be changed.Very few developers have experience using the CodeDom even though it has been with us since the .net framework 1.0.
Code SnippetsAdvantagesSimple Xml based template with numerous samples provided within Visual Studio.Several open source code snippet libraries available.DisadvantagesLimited snippet functions and at the present time developers are unable to author additional snippet functions! Tell the Visual Studio team you want to be able to author snippet functions, tell your Congressman too if you think it would help!
XSLTAdvantagesXml based template.Simple code generation technique for those developers comfortable with XSLT transformations.DisadvantagesWhile Xml is a relatively simple technology, XSLT has been known to bring grown men to tears!XSLT can be difficult to debug.
Visual Studio Project / Item TemplatesAdvantagesTarget language used to write the templates. (e.g. C# or VB).Simple Xml *.vstemplate file tells Visual Studio what to do with the template.Templates are stored within .zip file which is a standard file format we’re all familiar with.DisadvantagesTemplates are stored within  .zip file which can complicate editing templates.
T4 TemplatesAdvantagesAbility to embed C# control logic within the template.Syntax that will be somewhat familiar to classic ASP developers..Preferred code generation technique for Entity Framework 4.0 and the Visual Studio 2010 modeling tools., which means lots of samples on MSDN, etc.Templates can be precompiled.DisadvantagesWhile third parties have written language support for Visual Studio no built in support for editing T4 templates exists in Visual Studio today. Tell the Visual Studio product team and your congressman about this too!Relatively new technology, therefore not many developers have experience with T4 templates.
Unit TestingShould we use unit testing for generated code?
Thank youdoug.holland@microsoft.comblogs.msdn.com/dohollan© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation.  Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.  MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related Content

PPT
MTaulty_DevWeek_VS2010
PPT
Write once... Take Less Time to Deploy
PPT
Developing for a world wide audience
PDF
What Do Developers Discuss about Code Comments?
PDF
Tips to Comment the Code
ODP
A Brief Introduction to Zend_Form
PDF
Speculative analysis for comment quality assessment
PPT
Why test with flex unit
MTaulty_DevWeek_VS2010
Write once... Take Less Time to Deploy
Developing for a world wide audience
What Do Developers Discuss about Code Comments?
Tips to Comment the Code
A Brief Introduction to Zend_Form
Speculative analysis for comment quality assessment
Why test with flex unit

What's hot (19)

ODP
TDD in PHP - Memphis PHP 2011-08-25
PPT
PHP Documentor
PDF
Let linguistics guide software analysis
PDF
Software Analysis using Natural Language Queries
ODP
Zero to Zend Framework in 10 minutes
PPT
Whay QA- engineers should know how to code
PDF
Public Training RPG IV (free format) Programming Workshop for System i from B...
PDF
PhD defense presenation
PDF
How to Identify Class Comment Types? A Multi-language Approach for Class Com...
PPT
C# Introduction brief
PPTX
NET Event - Migrating WinForm
PPTX
Python certification
PDF
PHP, Java EE & .NET Comparison
PDF
PRG/420 ENTIRE CLASS UOP TUTORIALS
PDF
Comment soup with a pinch of types, served in a leaky bowl
PPTX
Why is cold fusion better than c#
PDF
PRG/420 ENTIRE CLASS UOP TUTORIALS
PPTX
Comparison of Programming Platforms
PPTX
Java Tutorial: Part 2. IntelliJ IDEA
TDD in PHP - Memphis PHP 2011-08-25
PHP Documentor
Let linguistics guide software analysis
Software Analysis using Natural Language Queries
Zero to Zend Framework in 10 minutes
Whay QA- engineers should know how to code
Public Training RPG IV (free format) Programming Workshop for System i from B...
PhD defense presenation
How to Identify Class Comment Types? A Multi-language Approach for Class Com...
C# Introduction brief
NET Event - Migrating WinForm
Python certification
PHP, Java EE & .NET Comparison
PRG/420 ENTIRE CLASS UOP TUTORIALS
Comment soup with a pinch of types, served in a leaky bowl
Why is cold fusion better than c#
PRG/420 ENTIRE CLASS UOP TUTORIALS
Comparison of Programming Platforms
Java Tutorial: Part 2. IntelliJ IDEA
Ad

Similar to Code generation (20)

PPTX
What's New in Visual Studio 2010
PPTX
T4 presentation
DOCX
The advantages and disadvantages of .net framework programming
PPTX
Why is .Net Technology Recognised for Software Development?
PPT
PDF
Why is .Net Technology Recognised for Software Development?
PPTX
VS TFS 2010 - Part1
PDF
NetWork - 15.10.2011 - Applied code generation in .NET
PPTX
(150324) Everything you ever wanted to know about Studio!
PDF
CLR_via_CSharp_(Jeffrey_Richter_4th_Edition).pdf
PPT
Intro To AOP
PDF
Choosing the Right Demo Environment (Salesforce Partners)
PDF
Как да станем софтуерни инженери и да стартираме ИТ бизнес?
PPT
MTaulty_DevWeek_VS2010
PDF
Mobile development with Flutter
PPTX
microsoft visual studio .net introduction from ids team
PDF
Visual Studio 2008 Overview
PDF
The Best Python IDEs and Code Editors.pdf
PPTX
Visual Studio 2012 introduction
PDF
Top Ten Reasons to Upgrade from Delphi 7
What's New in Visual Studio 2010
T4 presentation
The advantages and disadvantages of .net framework programming
Why is .Net Technology Recognised for Software Development?
Why is .Net Technology Recognised for Software Development?
VS TFS 2010 - Part1
NetWork - 15.10.2011 - Applied code generation in .NET
(150324) Everything you ever wanted to know about Studio!
CLR_via_CSharp_(Jeffrey_Richter_4th_Edition).pdf
Intro To AOP
Choosing the Right Demo Environment (Salesforce Partners)
Как да станем софтуерни инженери и да стартираме ИТ бизнес?
MTaulty_DevWeek_VS2010
Mobile development with Flutter
microsoft visual studio .net introduction from ids team
Visual Studio 2008 Overview
The Best Python IDEs and Code Editors.pdf
Visual Studio 2012 introduction
Top Ten Reasons to Upgrade from Delphi 7
Ad

Code generation

  • 1. Visual Studio 2010Effective Code Generation TechniquesDoug [email protected]/dohollan
  • 2. Doug HollandSr. Architect Evangelist, Microsoft CorporationMSc Software Engineering, Oxford University @doughollandhttp://blogs.msdn.com/dohollan
  • 4. AgendaStringBuilderSystem.CodeDomCode SnippetsXSLTVisual Studio 2010 Project & Item TemplatesText Template Transformation Toolkit (T4)Entity Framework 4.0 & T4 TemplatesUML & T4 TemplatesSQL Server 2008 R2 Management Objects (SMO)Unit Testing
  • 5. StringBuilderAdvantagesAlmost all .net developers should feel comfortable using the StringBuilder class so it requires no additional languages / tools to learn.Even with the disadvantages, the StringBuilder can be an excellent choice if you need to generate code quickly. Especially if you don’t need to maintain the “template” long term.DisadvantagesUnable to truly see the “template” within the control logic.Requires a recompile if the “template” should be changed.
  • 6. System.CodeDomAdvantagesAllows a single “template” to generate code within several target languages, such as VB and C#.Additional language providers can be written to support other languages.Proven technology, used by Microsoft for code generation in all versions of Visual Studio since .net was released.DisadvantagesUnable to truly see the “template” within the control logic.Requires a recompile if the “template” should be changed.Very few developers have experience using the CodeDom even though it has been with us since the .net framework 1.0.
  • 7. Code SnippetsAdvantagesSimple Xml based template with numerous samples provided within Visual Studio.Several open source code snippet libraries available.DisadvantagesLimited snippet functions and at the present time developers are unable to author additional snippet functions! Tell the Visual Studio team you want to be able to author snippet functions, tell your Congressman too if you think it would help!
  • 8. XSLTAdvantagesXml based template.Simple code generation technique for those developers comfortable with XSLT transformations.DisadvantagesWhile Xml is a relatively simple technology, XSLT has been known to bring grown men to tears!XSLT can be difficult to debug.
  • 9. Visual Studio Project / Item TemplatesAdvantagesTarget language used to write the templates. (e.g. C# or VB).Simple Xml *.vstemplate file tells Visual Studio what to do with the template.Templates are stored within .zip file which is a standard file format we’re all familiar with.DisadvantagesTemplates are stored within .zip file which can complicate editing templates.
  • 10. T4 TemplatesAdvantagesAbility to embed C# control logic within the template.Syntax that will be somewhat familiar to classic ASP developers..Preferred code generation technique for Entity Framework 4.0 and the Visual Studio 2010 modeling tools., which means lots of samples on MSDN, etc.Templates can be precompiled.DisadvantagesWhile third parties have written language support for Visual Studio no built in support for editing T4 templates exists in Visual Studio today. Tell the Visual Studio product team and your congressman about this too!Relatively new technology, therefore not many developers have experience with T4 templates.
  • 11. Unit TestingShould we use unit testing for generated code?
  • 12. Thank [email protected]/dohollan© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.