SlideShare une entreprise Scribd logo
1  sur  39
The Taming of the Code Alan Stevens A tale of the first principles of software development presented in three acts
Who is Alan Stevens? Microsoft Most Valuable Professional ASP Insider Occasional Blogger http://netcave.org Senior Software Developer 	Interactive Intelligence Incorporated An Enthusiast NOT an expert!
PLAYBILL Act I: The Goal Act II: The Guidelines Act III: The Practice
Let’s Talk About Code
Act I: The Goal
The rest of a developer's career is spent pursuing better and better answers to the question "where should this code go?" Jeremy Miller “On Writing Maintainable Code” http://codebetter.com/blogs/jeremy.miller/archive/2006/12/06/On-Writing-Maintainable-Code.aspx
Once you get your systems to work, you still have to go back and clean up the wreckage left behind by the victorious battle. You are not done until the victorious code has been cleaned, polished, and oiled. “Uncle” Bob Martin “The Rush” http://blog.objectmentor.com/articles/2009/06/26/the-rush
How do we balance building the right thingwith building it well?
Building the right thing is always a higher priority!
I'm never in favor of writing code poorly, but I am in favor of writing code to reflect your current understanding of a problem even if that understanding is partial. Ward Cunningham “Ward Explains Debt Metaphor” http://c2.com/cgi/wiki?WardExplainsDebtMetaphor
Building it right has a minimum acceptable thresholdwhich must be met
Do the simplest thing that could possibly work
Enable Change
Build Architectural Seams
At least build fault lines
Manage Debt
Manage Technical Debt
I thought that rushing software out the door to get some experience with it was a good idea, but that of course, you would eventually go back and as you learned things about that software you would repay that loan by refactoring the program to reflect your experience as you acquired it. Ward Cunningham “Ward Explains Debt Metaphor” http://c2.com/cgi/wiki?WardExplainsDebtMetaphor
By the same token, if you develop a program for a long period of time by only adding features and never reorganizing it to reflect your understanding of those features, then eventually that program simply does not contain any understanding and all efforts to work on it take longer and longer. In other words, the interest is total -- you'll make zero progress.
You know, if you want to be able to go into debt that way by developing software that you don't completely understand, you are wise to make that software reflect your understanding as best as you can, so that when it does come time to refactor, it's clear what you were thinking when you wrote it, making it easier to refactor it into what your current thinking is now.
Enable The *ILITIES Coined by KevlinHenney Agility Testability Readability Reversibility Changeability Flexibility Maintainability
Act II: The Guidelines
Don’t Repeat Yourself&Separation of Concerns
DRY Don’t Repeat Yourself
The Rule of Three See it once: do it See it twice: notice it See it a third time: abstract it!
Separation of Concerns
Separation Of Concerns Break the system into distinct, cohesive modules that don’t overlap in responsibilities Examples: MVC, MVP, MVVM etc. UI, Service, DAL HTML, CSS, JavaScript
Cohesion The degree to which the responsibilities within a given class are strongly related Highly cohesive code is: More readable and easier to understand Easier to manage, maintain, and test More likely to be reused Less complex
protected void btnSubmit_click(object sender, EventArgs e) {     if ( this.IsValid(this.txtUserName.Text, this.txtPassword.Text) )      { // do stuff here } } private boolIsValid(string userName, string password) { boolisValid = false;     using ( SqlConnectionconn = new SqlConnection(_connString) )     {         using ( SqlCommandcmd = conn.CreateCommand() )         {             // query on User Name and Password isValid = cmd.ExecuteScalar();         }    }    return isValid; }
SOLID Principles Single Responsibility Principle Open Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle
The Single Responsibility Principle  A class should have one, and only one, reason to change. Granularity Have many small classes that are easy to understand
The Open Closed Principle You should be able to extend a classes behavior, without modifying it. Sealed classes are evil! Make classes virtual by default.
The Liskov Substitution Principle  Derived classes must be substitutable for their base classes. Preserve polymorphism.
The Interface Segregation Principle  Clients should not be forced to depend on interfaces that they do not use. No God objects!
The Dependency Inversion Principle  Depend on abstractions, not on concretions. User interfaces and/or abstract base classes
Act III: The Practice
How do we guarantee baseline design without impeding productivity?

Contenu connexe

Similaire à The Taming Of The Code

2015.01.09 - Writing Modern Applications for Mobile and Web
2015.01.09 - Writing Modern Applications for Mobile and Web2015.01.09 - Writing Modern Applications for Mobile and Web
2015.01.09 - Writing Modern Applications for Mobile and WebMarco Parenzan
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistMark Fayngersh
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortalscgack
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernizationdevObjective
 
A report on mvc using the information
A report on mvc using the informationA report on mvc using the information
A report on mvc using the informationToushik Paul
 
WordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPressWordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPressmtoppa
 
Top 5 performance problems in .net applications application performance mon...
Top 5 performance problems in .net applications   application performance mon...Top 5 performance problems in .net applications   application performance mon...
Top 5 performance problems in .net applications application performance mon...KennaaTol
 
We continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellPVS-Studio
 
The Rest of the Best
The Rest of the BestThe Rest of the Best
The Rest of the BestKevlin Henney
 
5a329780735625624 ch10
5a329780735625624 ch105a329780735625624 ch10
5a329780735625624 ch10harkesh singh
 
Lublin Startup Festival - Mobile Architecture Design Patterns
Lublin Startup Festival - Mobile Architecture Design PatternsLublin Startup Festival - Mobile Architecture Design Patterns
Lublin Startup Festival - Mobile Architecture Design PatternsKarol Szmaj
 
Lessons Learned in a Continuously Developing Service-Oriented Architecture
Lessons Learned in a Continuously Developing Service-Oriented ArchitectureLessons Learned in a Continuously Developing Service-Oriented Architecture
Lessons Learned in a Continuously Developing Service-Oriented Architecturemdwheele
 
learn mvc project in 7 day
learn mvc project in 7 daylearn mvc project in 7 day
learn mvc project in 7 dayQuach Long
 
A Developer's Guide to CQRS Using .NET Core and MediatR
A Developer's Guide to CQRS Using .NET Core and MediatRA Developer's Guide to CQRS Using .NET Core and MediatR
A Developer's Guide to CQRS Using .NET Core and MediatRBình Trọng Án
 
Cinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsCinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsSteven Smith
 
Maintainable Javascript carsonified
Maintainable Javascript carsonifiedMaintainable Javascript carsonified
Maintainable Javascript carsonifiedChristian Heilmann
 
The Testing Planet Issue 2
The Testing Planet Issue 2The Testing Planet Issue 2
The Testing Planet Issue 2Rosie Sherry
 

Similaire à The Taming Of The Code (20)

2015.01.09 - Writing Modern Applications for Mobile and Web
2015.01.09 - Writing Modern Applications for Mobile and Web2015.01.09 - Writing Modern Applications for Mobile and Web
2015.01.09 - Writing Modern Applications for Mobile and Web
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwist
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortals
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
A report on mvc using the information
A report on mvc using the informationA report on mvc using the information
A report on mvc using the information
 
WordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPressWordCamp Nashville: Clean Code for WordPress
WordCamp Nashville: Clean Code for WordPress
 
Top 5 performance problems in .net applications application performance mon...
Top 5 performance problems in .net applications   application performance mon...Top 5 performance problems in .net applications   application performance mon...
Top 5 performance problems in .net applications application performance mon...
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
We continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShell
 
The Rest of the Best
The Rest of the BestThe Rest of the Best
The Rest of the Best
 
5a329780735625624 ch10
5a329780735625624 ch105a329780735625624 ch10
5a329780735625624 ch10
 
Lublin Startup Festival - Mobile Architecture Design Patterns
Lublin Startup Festival - Mobile Architecture Design PatternsLublin Startup Festival - Mobile Architecture Design Patterns
Lublin Startup Festival - Mobile Architecture Design Patterns
 
Lessons Learned in a Continuously Developing Service-Oriented Architecture
Lessons Learned in a Continuously Developing Service-Oriented ArchitectureLessons Learned in a Continuously Developing Service-Oriented Architecture
Lessons Learned in a Continuously Developing Service-Oriented Architecture
 
learn mvc project in 7 day
learn mvc project in 7 daylearn mvc project in 7 day
learn mvc project in 7 day
 
A Developer's Guide to CQRS Using .NET Core and MediatR
A Developer's Guide to CQRS Using .NET Core and MediatRA Developer's Guide to CQRS Using .NET Core and MediatR
A Developer's Guide to CQRS Using .NET Core and MediatR
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
Cinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsCinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patterns
 
Maintainable Javascript carsonified
Maintainable Javascript carsonifiedMaintainable Javascript carsonified
Maintainable Javascript carsonified
 
The Testing Planet Issue 2
The Testing Planet Issue 2The Testing Planet Issue 2
The Testing Planet Issue 2
 

Plus de Alan Stevens

My Prayer As I Leave You
My Prayer As I Leave YouMy Prayer As I Leave You
My Prayer As I Leave YouAlan Stevens
 
Making a Difference
Making a DifferenceMaking a Difference
Making a DifferenceAlan Stevens
 
Beyond Fast Good and Cheap
Beyond Fast Good and CheapBeyond Fast Good and Cheap
Beyond Fast Good and CheapAlan Stevens
 
You Are Not a Craftsman
You Are Not a CraftsmanYou Are Not a Craftsman
You Are Not a CraftsmanAlan Stevens
 
Better Is the Only Way Forward
Better Is the Only Way ForwardBetter Is the Only Way Forward
Better Is the Only Way ForwardAlan Stevens
 
Distributed Version Control Systems: A Guide For The Perplexed
Distributed Version Control Systems: A Guide For The PerplexedDistributed Version Control Systems: A Guide For The Perplexed
Distributed Version Control Systems: A Guide For The PerplexedAlan Stevens
 
Seven Lessons in Personal Marketing I Learned From Pickup Artists
Seven Lessons in Personal Marketing I Learned From Pickup ArtistsSeven Lessons in Personal Marketing I Learned From Pickup Artists
Seven Lessons in Personal Marketing I Learned From Pickup ArtistsAlan Stevens
 
Does Your Code Tell A Story
Does  Your  Code  Tell  A  StoryDoes  Your  Code  Tell  A  Story
Does Your Code Tell A StoryAlan Stevens
 

Plus de Alan Stevens (11)

My Prayer As I Leave You
My Prayer As I Leave YouMy Prayer As I Leave You
My Prayer As I Leave You
 
My Creed
My CreedMy Creed
My Creed
 
Leveling Up
Leveling UpLeveling Up
Leveling Up
 
Making a Difference
Making a DifferenceMaking a Difference
Making a Difference
 
Beyond Fast Good and Cheap
Beyond Fast Good and CheapBeyond Fast Good and Cheap
Beyond Fast Good and Cheap
 
You Are Not a Craftsman
You Are Not a CraftsmanYou Are Not a Craftsman
You Are Not a Craftsman
 
Better Is the Only Way Forward
Better Is the Only Way ForwardBetter Is the Only Way Forward
Better Is the Only Way Forward
 
Distributed Version Control Systems: A Guide For The Perplexed
Distributed Version Control Systems: A Guide For The PerplexedDistributed Version Control Systems: A Guide For The Perplexed
Distributed Version Control Systems: A Guide For The Perplexed
 
Seven Lessons in Personal Marketing I Learned From Pickup Artists
Seven Lessons in Personal Marketing I Learned From Pickup ArtistsSeven Lessons in Personal Marketing I Learned From Pickup Artists
Seven Lessons in Personal Marketing I Learned From Pickup Artists
 
Does Your Code Tell A Story
Does  Your  Code  Tell  A  StoryDoes  Your  Code  Tell  A  Story
Does Your Code Tell A Story
 
Coding In Public
Coding In PublicCoding In Public
Coding In Public
 

Dernier

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Dernier (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

The Taming Of The Code

  • 1. The Taming of the Code Alan Stevens A tale of the first principles of software development presented in three acts
  • 2. Who is Alan Stevens? Microsoft Most Valuable Professional ASP Insider Occasional Blogger http://netcave.org Senior Software Developer Interactive Intelligence Incorporated An Enthusiast NOT an expert!
  • 3. PLAYBILL Act I: The Goal Act II: The Guidelines Act III: The Practice
  • 5. Act I: The Goal
  • 6. The rest of a developer's career is spent pursuing better and better answers to the question "where should this code go?" Jeremy Miller “On Writing Maintainable Code” http://codebetter.com/blogs/jeremy.miller/archive/2006/12/06/On-Writing-Maintainable-Code.aspx
  • 7. Once you get your systems to work, you still have to go back and clean up the wreckage left behind by the victorious battle. You are not done until the victorious code has been cleaned, polished, and oiled. “Uncle” Bob Martin “The Rush” http://blog.objectmentor.com/articles/2009/06/26/the-rush
  • 8. How do we balance building the right thingwith building it well?
  • 9. Building the right thing is always a higher priority!
  • 10. I'm never in favor of writing code poorly, but I am in favor of writing code to reflect your current understanding of a problem even if that understanding is partial. Ward Cunningham “Ward Explains Debt Metaphor” http://c2.com/cgi/wiki?WardExplainsDebtMetaphor
  • 11. Building it right has a minimum acceptable thresholdwhich must be met
  • 12. Do the simplest thing that could possibly work
  • 15. At least build fault lines
  • 18. I thought that rushing software out the door to get some experience with it was a good idea, but that of course, you would eventually go back and as you learned things about that software you would repay that loan by refactoring the program to reflect your experience as you acquired it. Ward Cunningham “Ward Explains Debt Metaphor” http://c2.com/cgi/wiki?WardExplainsDebtMetaphor
  • 19. By the same token, if you develop a program for a long period of time by only adding features and never reorganizing it to reflect your understanding of those features, then eventually that program simply does not contain any understanding and all efforts to work on it take longer and longer. In other words, the interest is total -- you'll make zero progress.
  • 20. You know, if you want to be able to go into debt that way by developing software that you don't completely understand, you are wise to make that software reflect your understanding as best as you can, so that when it does come time to refactor, it's clear what you were thinking when you wrote it, making it easier to refactor it into what your current thinking is now.
  • 21. Enable The *ILITIES Coined by KevlinHenney Agility Testability Readability Reversibility Changeability Flexibility Maintainability
  • 22. Act II: The Guidelines
  • 24. DRY Don’t Repeat Yourself
  • 25. The Rule of Three See it once: do it See it twice: notice it See it a third time: abstract it!
  • 27.
  • 28.
  • 29. Separation Of Concerns Break the system into distinct, cohesive modules that don’t overlap in responsibilities Examples: MVC, MVP, MVVM etc. UI, Service, DAL HTML, CSS, JavaScript
  • 30. Cohesion The degree to which the responsibilities within a given class are strongly related Highly cohesive code is: More readable and easier to understand Easier to manage, maintain, and test More likely to be reused Less complex
  • 31. protected void btnSubmit_click(object sender, EventArgs e) { if ( this.IsValid(this.txtUserName.Text, this.txtPassword.Text) ) { // do stuff here } } private boolIsValid(string userName, string password) { boolisValid = false; using ( SqlConnectionconn = new SqlConnection(_connString) ) { using ( SqlCommandcmd = conn.CreateCommand() ) { // query on User Name and Password isValid = cmd.ExecuteScalar(); } } return isValid; }
  • 32. SOLID Principles Single Responsibility Principle Open Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle
  • 33. The Single Responsibility Principle A class should have one, and only one, reason to change. Granularity Have many small classes that are easy to understand
  • 34. The Open Closed Principle You should be able to extend a classes behavior, without modifying it. Sealed classes are evil! Make classes virtual by default.
  • 35. The Liskov Substitution Principle Derived classes must be substitutable for their base classes. Preserve polymorphism.
  • 36. The Interface Segregation Principle Clients should not be forced to depend on interfaces that they do not use. No God objects!
  • 37. The Dependency Inversion Principle Depend on abstractions, not on concretions. User interfaces and/or abstract base classes
  • 38. Act III: The Practice
  • 39. How do we guarantee baseline design without impeding productivity?
  • 40. Can we verify that we are building the right thing?
  • 41. The tests specify requirements in a way that does not require human interpretation to indicate success or failure. Jim Newkirk Test Driven Development in Microsoft .NET
  • 44. When you finally realize what your program is doing, you have to go back and make it look like you knew that all along. Make it look like it was easy to write this program, even if it wasn’t. Ward Cunningham “Mastering the Craft of Programming” http://railslab.newrelic.com/2009/09/15/ward-cunningham-aboutus-org
  • 45. Prevention is the best cure
  • 47. As applications mature, they should become more maintainable, not less.
  • 48. “With every mistake, I must surely be learning” George Harrison
  • 50. Thanks For Listening! Email/IM: alanstevens@gmail.com Blog: http://netcave.org Twitter: @alanstevens

Notes de l'éditeur

  1. The Taming of the Code:A tale of the first principles of software development presented in three actsHow do we balance building the right thingwith building it well? In this presentation we will examine this question at three levels of focus looking at I The Goal, II The Guidlines and III The Practice. This will be an interactive discussion of the values, compromises and practices of successful software development.
  2. Drafts when writing
  3. Enable isolationFault lines
  4. SRP The Single Responsibility Principle A class should have one, and only one, reason to change.OCP The Open Closed Principle You should be able to extend a classes behavior, without modifying it.LSP The Liskov Substitution Principle Derived classes must be substitutable for their base classes.ISP The Interface Segregation Principle Clients should not be forced to depend on interfaces that they do not use.DIP The Dependency Inversion Principle Depend on abstractions, not on concretions.