SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Better Contracts. Better Code. An Introduction to Microsoft Code Contracts in the .NET 4.0 Framework August 2010 W. Kevin Hazzard, C# MVP
What is code? Intent Assumption Binding Promise Guarantee Obligation http://www.asu.edu/clas/shs/aald/
A Simple Illustration public int[] ApplyDiscounts( intmaxPercentageAllowed, 	Customer[] customers, 	Promotion[][] promotions ) { // apply the promotions here // and return the results }
C# Does OK with Types & Structure Customer int int int public int[] ApplyDiscounts( intmaxPercentageAllowed, 	Customer[] customers, 	Promotion[][] promotions ) {} Customer int Customer Promotion Promotion Promotion Promotion Promotion Promotion
Questions Left Unanswered What is the acceptable range for the integer maxPercentageAllowed parameter? Can the customers or promotions arrays references be null or contain nulls? The promotions array is jagged. If an associated customer has no promotions, should the second-dimension array be null or empty? What range will the integers in the array result have?
Microsoft Code Contracts Static code verification Runtime checking, too Cross-language support Enhances documentation Works with .NET Fx 3.5; built into 4.0 Supports pre/post-conditions & invariants Helper classes for iteration, assertion, etc.
Samples Survey Let's take a look at the Code Contract samples which are excellent for learning how this stuff works.
Contract Reference Assemblies Something like "buddy classes" for contracts Contain visible interface and contracts but no code bodies ccrefgen.exe tool can be used to generate Some have been pre-built and ship with the Code Contracts installer Silverlight 3.0 and 4.0 .NET Framework 3.5 and 4.0
Patching Sandcastle Open the SandCastle zip file in the Code Contracts installation directory Copy the templates into your installed SandCastle folder Now help builds from XML comment documentation will include contract information A future release of SandCastle should remove the need for patching
Useful URLs MSDN Forum for Code Contractssocial.msdn.microsoft.com/Forums/en-IE/codecontracts Microsoft Code Contractsresearch.microsoft.com/en-us/projects/contracts Kevin's Blogdevjourney.com
Demos

Weitere ähnliche Inhalte

Ähnlich wie Better contracts better code - august 2010

Wooing the Best Bank Deposit Customers
Wooing the Best Bank Deposit CustomersWooing the Best Bank Deposit Customers
Wooing the Best Bank Deposit CustomersLucinda Linde
 
Smu mba is- spring 2016 - solved assignments
Smu mba   is- spring 2016 - solved  assignmentsSmu mba   is- spring 2016 - solved  assignments
Smu mba is- spring 2016 - solved assignmentssmumbahelp
 
Cisco 810-403 Selling Business Outcomes
Cisco 810-403 Selling Business OutcomesCisco 810-403 Selling Business Outcomes
Cisco 810-403 Selling Business OutcomesExamscollectionvce
 
Lesson_04_ist402_google_adwords_02
Lesson_04_ist402_google_adwords_02Lesson_04_ist402_google_adwords_02
Lesson_04_ist402_google_adwords_02Jim Jansen
 
Segmentation white paper_final_111505
Segmentation white paper_final_111505Segmentation white paper_final_111505
Segmentation white paper_final_111505mhine1212
 
Customer Experience Mastery Level 1 Visualization CxC Matrix
Customer Experience Mastery Level 1 Visualization CxC MatrixCustomer Experience Mastery Level 1 Visualization CxC Matrix
Customer Experience Mastery Level 1 Visualization CxC MatrixClient X Client
 
SA Google Ads Search Project part 2
SA Google Ads Search Project part 2SA Google Ads Search Project part 2
SA Google Ads Search Project part 2Shahid Afridi
 
Microsoft az-900 Dumps
Microsoft az-900 DumpsMicrosoft az-900 Dumps
Microsoft az-900 DumpsArmstrongsmith
 
V4C - Lean Business Model Canvas.pptx
V4C - Lean Business Model Canvas.pptxV4C - Lean Business Model Canvas.pptx
V4C - Lean Business Model Canvas.pptxScott Meyers
 
mb-210 prüfungsfragen, mb-210 Prüfungsvorbereitung
mb-210 prüfungsfragen, mb-210 Prüfungsvorbereitungmb-210 prüfungsfragen, mb-210 Prüfungsvorbereitung
mb-210 prüfungsfragen, mb-210 Prüfungsvorbereitungjackbob1787
 
Class 06: Search Engine Marketing
Class 06: Search Engine MarketingClass 06: Search Engine Marketing
Class 06: Search Engine MarketingJon Chang
 
DM-MICA_TELTEK_Tahir_Ashraf gg g g g..pdf
DM-MICA_TELTEK_Tahir_Ashraf gg g g g..pdfDM-MICA_TELTEK_Tahir_Ashraf gg g g g..pdf
DM-MICA_TELTEK_Tahir_Ashraf gg g g g..pdfSayedtahirAshraf
 
Bt8902, e commerce
Bt8902, e commerceBt8902, e commerce
Bt8902, e commercesmumbahelp
 
[Sample Questions] Salesforce B2C Solution Architect Exam
[Sample Questions] Salesforce B2C Solution Architect Exam[Sample Questions] Salesforce B2C Solution Architect Exam
[Sample Questions] Salesforce B2C Solution Architect ExamAdinaCoyle
 
Lesson 11 Writing Good Ads
Lesson 11 Writing Good AdsLesson 11 Writing Good Ads
Lesson 11 Writing Good AdsJim Jansen
 
Bt8902 e-commerce-de
Bt8902 e-commerce-deBt8902 e-commerce-de
Bt8902 e-commerce-desmumbahelp
 
Bt8902 e-commerce-de
Bt8902 e-commerce-deBt8902 e-commerce-de
Bt8902 e-commerce-desmumbahelp
 
Digital Marketing Training In Bangalore1
Digital Marketing Training In Bangalore1Digital Marketing Training In Bangalore1
Digital Marketing Training In Bangalore1saitarun12500
 

Ähnlich wie Better contracts better code - august 2010 (20)

Wooing the Best Bank Deposit Customers
Wooing the Best Bank Deposit CustomersWooing the Best Bank Deposit Customers
Wooing the Best Bank Deposit Customers
 
Smu mba is- spring 2016 - solved assignments
Smu mba   is- spring 2016 - solved  assignmentsSmu mba   is- spring 2016 - solved  assignments
Smu mba is- spring 2016 - solved assignments
 
Cisco 810-403 Selling Business Outcomes
Cisco 810-403 Selling Business OutcomesCisco 810-403 Selling Business Outcomes
Cisco 810-403 Selling Business Outcomes
 
Lesson_04_ist402_google_adwords_02
Lesson_04_ist402_google_adwords_02Lesson_04_ist402_google_adwords_02
Lesson_04_ist402_google_adwords_02
 
Segmentation white paper_final_111505
Segmentation white paper_final_111505Segmentation white paper_final_111505
Segmentation white paper_final_111505
 
Customer Experience Mastery Level 1 Visualization CxC Matrix
Customer Experience Mastery Level 1 Visualization CxC MatrixCustomer Experience Mastery Level 1 Visualization CxC Matrix
Customer Experience Mastery Level 1 Visualization CxC Matrix
 
SA Google Ads Search Project part 2
SA Google Ads Search Project part 2SA Google Ads Search Project part 2
SA Google Ads Search Project part 2
 
Microsoft az-900 Dumps
Microsoft az-900 DumpsMicrosoft az-900 Dumps
Microsoft az-900 Dumps
 
V4C - Lean Business Model Canvas.pptx
V4C - Lean Business Model Canvas.pptxV4C - Lean Business Model Canvas.pptx
V4C - Lean Business Model Canvas.pptx
 
mb-210 prüfungsfragen, mb-210 Prüfungsvorbereitung
mb-210 prüfungsfragen, mb-210 Prüfungsvorbereitungmb-210 prüfungsfragen, mb-210 Prüfungsvorbereitung
mb-210 prüfungsfragen, mb-210 Prüfungsvorbereitung
 
Class 06: Search Engine Marketing
Class 06: Search Engine MarketingClass 06: Search Engine Marketing
Class 06: Search Engine Marketing
 
Service Provider
Service Provider Service Provider
Service Provider
 
DM-MICA_TELTEK_Tahir_Ashraf gg g g g..pdf
DM-MICA_TELTEK_Tahir_Ashraf gg g g g..pdfDM-MICA_TELTEK_Tahir_Ashraf gg g g g..pdf
DM-MICA_TELTEK_Tahir_Ashraf gg g g g..pdf
 
Bt8902, e commerce
Bt8902, e commerceBt8902, e commerce
Bt8902, e commerce
 
Bis 375 final exam
Bis 375 final examBis 375 final exam
Bis 375 final exam
 
[Sample Questions] Salesforce B2C Solution Architect Exam
[Sample Questions] Salesforce B2C Solution Architect Exam[Sample Questions] Salesforce B2C Solution Architect Exam
[Sample Questions] Salesforce B2C Solution Architect Exam
 
Lesson 11 Writing Good Ads
Lesson 11 Writing Good AdsLesson 11 Writing Good Ads
Lesson 11 Writing Good Ads
 
Bt8902 e-commerce-de
Bt8902 e-commerce-deBt8902 e-commerce-de
Bt8902 e-commerce-de
 
Bt8902 e-commerce-de
Bt8902 e-commerce-deBt8902 e-commerce-de
Bt8902 e-commerce-de
 
Digital Marketing Training In Bangalore1
Digital Marketing Training In Bangalore1Digital Marketing Training In Bangalore1
Digital Marketing Training In Bangalore1
 

Mehr von Kevin Hazzard

C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607Kevin Hazzard
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIKevin Hazzard
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersKevin Hazzard
 
Introduction to SQL Azure
Introduction to SQL AzureIntroduction to SQL Azure
Introduction to SQL AzureKevin Hazzard
 
Enterprise Data Validation
Enterprise Data ValidationEnterprise Data Validation
Enterprise Data ValidationKevin Hazzard
 
Dynamic Language Performance
Dynamic Language PerformanceDynamic Language Performance
Dynamic Language PerformanceKevin Hazzard
 

Mehr von Kevin Hazzard (6)

C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for Beginners
 
Introduction to SQL Azure
Introduction to SQL AzureIntroduction to SQL Azure
Introduction to SQL Azure
 
Enterprise Data Validation
Enterprise Data ValidationEnterprise Data Validation
Enterprise Data Validation
 
Dynamic Language Performance
Dynamic Language PerformanceDynamic Language Performance
Dynamic Language Performance
 

Better contracts better code - august 2010

  • 1. Better Contracts. Better Code. An Introduction to Microsoft Code Contracts in the .NET 4.0 Framework August 2010 W. Kevin Hazzard, C# MVP
  • 2. What is code? Intent Assumption Binding Promise Guarantee Obligation http://www.asu.edu/clas/shs/aald/
  • 3. A Simple Illustration public int[] ApplyDiscounts( intmaxPercentageAllowed, Customer[] customers, Promotion[][] promotions ) { // apply the promotions here // and return the results }
  • 4. C# Does OK with Types & Structure Customer int int int public int[] ApplyDiscounts( intmaxPercentageAllowed, Customer[] customers, Promotion[][] promotions ) {} Customer int Customer Promotion Promotion Promotion Promotion Promotion Promotion
  • 5. Questions Left Unanswered What is the acceptable range for the integer maxPercentageAllowed parameter? Can the customers or promotions arrays references be null or contain nulls? The promotions array is jagged. If an associated customer has no promotions, should the second-dimension array be null or empty? What range will the integers in the array result have?
  • 6. Microsoft Code Contracts Static code verification Runtime checking, too Cross-language support Enhances documentation Works with .NET Fx 3.5; built into 4.0 Supports pre/post-conditions & invariants Helper classes for iteration, assertion, etc.
  • 7. Samples Survey Let's take a look at the Code Contract samples which are excellent for learning how this stuff works.
  • 8. Contract Reference Assemblies Something like "buddy classes" for contracts Contain visible interface and contracts but no code bodies ccrefgen.exe tool can be used to generate Some have been pre-built and ship with the Code Contracts installer Silverlight 3.0 and 4.0 .NET Framework 3.5 and 4.0
  • 9. Patching Sandcastle Open the SandCastle zip file in the Code Contracts installation directory Copy the templates into your installed SandCastle folder Now help builds from XML comment documentation will include contract information A future release of SandCastle should remove the need for patching
  • 10. Useful URLs MSDN Forum for Code Contractssocial.msdn.microsoft.com/Forums/en-IE/codecontracts Microsoft Code Contractsresearch.microsoft.com/en-us/projects/contracts Kevin's Blogdevjourney.com
  • 11. Demos
  • 12. Useful URLs MSDN Forum for Code Contractssocial.msdn.microsoft.com/Forums/en-IE/codecontracts Microsoft Code Contractsresearch.microsoft.com/en-us/projects/contracts Kevin's Blogdevjourney.com

Hinweis der Redaktion

  1. What is the acceptable range for the integer maxPercentageAllowed parameter?Can the customers or promotions arrays references be null or contain nulls?The promotions array is jagged. If an associated customer has no promotions, should the second-dimension array be null or empty?What range will the integers in the array result have?