SlideShare uma empresa Scribd logo
1 de 12
Visual Studio 2010Effective Code Generation Techniques Doug Holland doug.holland@microsoft.com blogs.msdn.com/dohollan
Doug Holland Sr. Architect Evangelist, Microsoft Corporation MSc Software Engineering, Oxford University              @dougholland http://blogs.msdn.com/dohollan
Agenda StringBuilder System.CodeDom Code Snippets XSLT Visual Studio 2010 Project & Item Templates Text Template Transformation Toolkit (T4) Entity Framework 4.0 & T4 Templates UML & T4 Templates SQL Server 2008 R2 Management Objects (SMO) Unit Testing
StringBuilder Advantages Almost 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. Disadvantages Unable to truly see the “template” within the control logic. Requires a recompile if the “template” should be changed.
System.CodeDom Advantages Allows  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. Disadvantages Unable 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 Snippets Advantages Simple Xml based template with numerous samples provided within Visual Studio. Several open source code snippet libraries available. Disadvantages Limited 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!
XSLT Advantages Xml based template. Simple code generation technique for those developers comfortable with XSLT transformations. Disadvantages While 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 Templates Advantages Target 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. Disadvantages Templates are stored within  .zip file which can complicate editing templates.
T4 Templates Advantages Ability 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. Disadvantages While 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 Testing Should we use unit testing for generated code?
Thank you doug.holland@microsoft.com blogs.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.

Mais conteúdo relacionado

Mais procurados

TDD in PHP - Memphis PHP 2011-08-25
TDD in PHP - Memphis PHP 2011-08-25TDD in PHP - Memphis PHP 2011-08-25
TDD in PHP - Memphis PHP 2011-08-25
Jeremy Kendall
 
Zero to Zend Framework in 10 minutes
Zero to Zend Framework in 10 minutesZero to Zend Framework in 10 minutes
Zero to Zend Framework in 10 minutes
Jeremy Kendall
 

Mais procurados (19)

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

Semelhante a Code generation

NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
Dmytro Mindra
 
microsoft visual studio .net introduction from ids team
microsoft visual studio .net introduction from ids teammicrosoft visual studio .net introduction from ids team
microsoft visual studio .net introduction from ids team
royaljaiitsolutions
 
Visual Studio 2008 Overview
Visual Studio 2008 OverviewVisual Studio 2008 Overview
Visual Studio 2008 Overview
Roman Okolovich
 

Semelhante a Code generation (20)

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

Code generation

  • 1. Visual Studio 2010Effective Code Generation Techniques Doug Holland doug.holland@microsoft.com blogs.msdn.com/dohollan
  • 2. Doug Holland Sr. Architect Evangelist, Microsoft Corporation MSc Software Engineering, Oxford University @dougholland http://blogs.msdn.com/dohollan
  • 3.
  • 4. Agenda StringBuilder System.CodeDom Code Snippets XSLT Visual Studio 2010 Project & Item Templates Text Template Transformation Toolkit (T4) Entity Framework 4.0 & T4 Templates UML & T4 Templates SQL Server 2008 R2 Management Objects (SMO) Unit Testing
  • 5. StringBuilder Advantages Almost 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. Disadvantages Unable to truly see the “template” within the control logic. Requires a recompile if the “template” should be changed.
  • 6. System.CodeDom Advantages Allows 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. Disadvantages Unable 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 Snippets Advantages Simple Xml based template with numerous samples provided within Visual Studio. Several open source code snippet libraries available. Disadvantages Limited 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. XSLT Advantages Xml based template. Simple code generation technique for those developers comfortable with XSLT transformations. Disadvantages While 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 Templates Advantages Target 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. Disadvantages Templates are stored within .zip file which can complicate editing templates.
  • 10. T4 Templates Advantages Ability 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. Disadvantages While 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 Testing Should we use unit testing for generated code?
  • 12. Thank you doug.holland@microsoft.com blogs.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.