SlideShare uma empresa Scribd logo
1 de 11
Design by Contract for Mainstream .NET Code Contracts AshicMahtabhttp://www.heartysoft.com@ashic
Static Languages Why do we code in C#? So type errors don’t manifest at runtime? Intellisense? Fear of learning Ruby?
Contract A promise that something will behave in a certain way. (Sounds like an interface, right?)
A joint account can be opened only if the number of holders is greater than two. public void OpenJointAccount(AccountHolder[] holders) An account holder’s balance may never fall below -100. Go ahead…try writing interfaces for them.
Design by Contract Based on the work of Alan Turing, Tony Hoare, EdsgerDijkstra, David Gries Popularized / advocated by Bertrand Meyer and originally implemented in Eiffel. Works on the basis of constraints like preconditions, post conditions and invariants which the supplier provides.
Preconditions: I require this to be true before I execute. Post condition: I ensure this to be true when I am done executing. Invariant: A condition that holds true during the lifetime of an object. It may not hold during the execution of a method but will do so before and after the method executes.
Demo Basics Preconditions, Post conditions, Invariants Subtle edge case violations Contract Blocks, [Pure] Contracts on Interfaces and Abstract Classes [ContractArgumentValidator], [ContractAbbreviator]
Integrating into legacy apps [ContractVerification(false)] Baseline
Drawbacks Slower build with static checking Public properties  Interface contracts have weird syntax Currently no contracts on delegates Static checker can’t understand collections Algorithmic performance may be compromised IL mangling…no edit and continue Must have buy in – something whole team uses or nobody does
Resources http://research.microsoft.com/en-us/projects/contracts/

Mais conteúdo relacionado

Destaque

ribbit..inc_portfolio 2017©
ribbit..inc_portfolio 2017©ribbit..inc_portfolio 2017©
ribbit..inc_portfolio 2017©
ribbitrocks
 
Nogelmini 2
Nogelmini 2Nogelmini 2
Nogelmini 2
Olijohn
 
Ch.2
Ch.2Ch.2
Ch.2
jespi
 
RCP Company Information,
RCP Company Information,RCP Company Information,
RCP Company Information,
johnyboy7
 
9c21f702517c42b94bbbab1c2dc84adb
9c21f702517c42b94bbbab1c2dc84adb9c21f702517c42b94bbbab1c2dc84adb
9c21f702517c42b94bbbab1c2dc84adb
guest29574b
 
Aan de slag met social media
Aan de slag met social mediaAan de slag met social media
Aan de slag met social media
hallofryslan
 
Kitchen evolution
Kitchen evolutionKitchen evolution
Kitchen evolution
NatashaRDH
 

Destaque (20)

Rome for Beginners
Rome for BeginnersRome for Beginners
Rome for Beginners
 
Marjoriepp
MarjorieppMarjoriepp
Marjoriepp
 
ribbit..inc_portfolio 2017©
ribbit..inc_portfolio 2017©ribbit..inc_portfolio 2017©
ribbit..inc_portfolio 2017©
 
Nogelmini 2
Nogelmini 2Nogelmini 2
Nogelmini 2
 
ZeroMQ at Oredev 2013
ZeroMQ at Oredev 2013ZeroMQ at Oredev 2013
ZeroMQ at Oredev 2013
 
Bágyi Péter: CT protokollok, dózis-csökkentés lehetőségei. MRAE Országos Radi...
Bágyi Péter: CT protokollok, dózis-csökkentés lehetőségei. MRAE Országos Radi...Bágyi Péter: CT protokollok, dózis-csökkentés lehetőségei. MRAE Országos Radi...
Bágyi Péter: CT protokollok, dózis-csökkentés lehetőségei. MRAE Országos Radi...
 
Ch.2
Ch.2Ch.2
Ch.2
 
The Museum of Tomorrow
The Museum of TomorrowThe Museum of Tomorrow
The Museum of Tomorrow
 
Swpbs Change Process
Swpbs Change ProcessSwpbs Change Process
Swpbs Change Process
 
Week 1 Copyright
Week 1 CopyrightWeek 1 Copyright
Week 1 Copyright
 
Augmented Reality Presentation at Leadership Forum 2012 Randwick
Augmented Reality Presentation at Leadership Forum 2012 RandwickAugmented Reality Presentation at Leadership Forum 2012 Randwick
Augmented Reality Presentation at Leadership Forum 2012 Randwick
 
Adjectives
AdjectivesAdjectives
Adjectives
 
Wk 1 Intro Text Types
Wk 1 Intro Text TypesWk 1 Intro Text Types
Wk 1 Intro Text Types
 
RCP Company Information,
RCP Company Information,RCP Company Information,
RCP Company Information,
 
9c21f702517c42b94bbbab1c2dc84adb
9c21f702517c42b94bbbab1c2dc84adb9c21f702517c42b94bbbab1c2dc84adb
9c21f702517c42b94bbbab1c2dc84adb
 
Belinda Wright
Belinda WrightBelinda Wright
Belinda Wright
 
Aan de slag met social media
Aan de slag met social mediaAan de slag met social media
Aan de slag met social media
 
Logarska Valley (Logarska dolina), Slovenia images
Logarska Valley (Logarska dolina), Slovenia imagesLogarska Valley (Logarska dolina), Slovenia images
Logarska Valley (Logarska dolina), Slovenia images
 
The Buckboard
The BuckboardThe Buckboard
The Buckboard
 
Kitchen evolution
Kitchen evolutionKitchen evolution
Kitchen evolution
 

Semelhante a Code contracts

London F-Sharp User Group : Don Syme on F# - 09/09/2010
London F-Sharp User Group : Don Syme on F# - 09/09/2010London F-Sharp User Group : Don Syme on F# - 09/09/2010
London F-Sharp User Group : Don Syme on F# - 09/09/2010
Skills Matter
 

Semelhante a Code contracts (20)

Tips to Comment the Code
Tips to Comment the CodeTips to Comment the Code
Tips to Comment the Code
 
Workshop: .NET Code Contracts
Workshop: .NET Code ContractsWorkshop: .NET Code Contracts
Workshop: .NET Code Contracts
 
How to not Destroy Millions in Smart Contracts
How to not Destroy Millions in Smart ContractsHow to not Destroy Millions in Smart Contracts
How to not Destroy Millions in Smart Contracts
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Designing Modules in Python
Designing Modules in PythonDesigning Modules in Python
Designing Modules in Python
 
Attacking and Exploiting Ethereum Smart Contracts: Auditing 101
Attacking and Exploiting Ethereum Smart Contracts: Auditing 101Attacking and Exploiting Ethereum Smart Contracts: Auditing 101
Attacking and Exploiting Ethereum Smart Contracts: Auditing 101
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
OAuth for QuickBooks Online REST Services
OAuth for QuickBooks Online REST ServicesOAuth for QuickBooks Online REST Services
OAuth for QuickBooks Online REST Services
 
Tdd in practice
Tdd in practiceTdd in practice
Tdd in practice
 
Code Contracts
Code ContractsCode Contracts
Code Contracts
 
Iot hub agent
Iot hub agentIot hub agent
Iot hub agent
 
When e-commerce meets Symfony
When e-commerce meets SymfonyWhen e-commerce meets Symfony
When e-commerce meets Symfony
 
Making PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptx
 
Safetty systems intro_embedded_c
Safetty systems intro_embedded_cSafetty systems intro_embedded_c
Safetty systems intro_embedded_c
 
Coding Naked 2023
Coding Naked 2023Coding Naked 2023
Coding Naked 2023
 
London F-Sharp User Group : Don Syme on F# - 09/09/2010
London F-Sharp User Group : Don Syme on F# - 09/09/2010London F-Sharp User Group : Don Syme on F# - 09/09/2010
London F-Sharp User Group : Don Syme on F# - 09/09/2010
 
RTP Bluemix Meetup April 20th 2016
RTP Bluemix Meetup April 20th 2016RTP Bluemix Meetup April 20th 2016
RTP Bluemix Meetup April 20th 2016
 
Part i
Part iPart i
Part i
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

Code contracts

  • 1. Design by Contract for Mainstream .NET Code Contracts AshicMahtabhttp://www.heartysoft.com@ashic
  • 2.
  • 3. Static Languages Why do we code in C#? So type errors don’t manifest at runtime? Intellisense? Fear of learning Ruby?
  • 4. Contract A promise that something will behave in a certain way. (Sounds like an interface, right?)
  • 5. A joint account can be opened only if the number of holders is greater than two. public void OpenJointAccount(AccountHolder[] holders) An account holder’s balance may never fall below -100. Go ahead…try writing interfaces for them.
  • 6. Design by Contract Based on the work of Alan Turing, Tony Hoare, EdsgerDijkstra, David Gries Popularized / advocated by Bertrand Meyer and originally implemented in Eiffel. Works on the basis of constraints like preconditions, post conditions and invariants which the supplier provides.
  • 7. Preconditions: I require this to be true before I execute. Post condition: I ensure this to be true when I am done executing. Invariant: A condition that holds true during the lifetime of an object. It may not hold during the execution of a method but will do so before and after the method executes.
  • 8. Demo Basics Preconditions, Post conditions, Invariants Subtle edge case violations Contract Blocks, [Pure] Contracts on Interfaces and Abstract Classes [ContractArgumentValidator], [ContractAbbreviator]
  • 9. Integrating into legacy apps [ContractVerification(false)] Baseline
  • 10. Drawbacks Slower build with static checking Public properties  Interface contracts have weird syntax Currently no contracts on delegates Static checker can’t understand collections Algorithmic performance may be compromised IL mangling…no edit and continue Must have buy in – something whole team uses or nobody does