Upload
alan-stevens
View
10
Download
2
Embed Size (px)
DESCRIPTION
Citation preview
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 threshold which must be met
Do the simplest thing that could possibly work
Enable Change
Build Architectural
Seams
At least build fault lines
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
Enable The *ILITIES• Agility• Testability• Readability• Reversibility• Changeability• Flexibility• Maintainability
Coined by Kevlin Henney
Act II: The Guidelines
Don’t Repeat Yourself&
Separation of Concerns
DRYDon’t Repeat
Yourself
The Rule of ThreeSee it once: do itSee it twice: notice itSee it a third time: abstract it!
Separation of Concerns
Separation Of ConcernsBreak the system into distinct, cohesive modules that don’t overlap in responsibilities
Examples:MVC, MVP, MVVM etc.UI, Service, DALHTML, CSS, JavaScript
protected void btnSubmit_click(object sender, EventArgs e){ if ( this.IsValid(this.txtUserName.Text, this.txtPassword.Text) ) { // do stuff here }}
private bool IsValid(string userName, string password){ bool isValid = false; using ( SqlConnection conn = new SqlConnection(_connString) ) { using ( SqlCommand cmd = 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
Act III: The Practice
How do we guarantee baseline design without impeding productivity?
Can we verify that we are building the right thing?
The tests specify requirements in a way that does not require human interpretation to indicate success or failure.
Jim NewkirkTest Driven Development in Microsoft .NET
Let’s write some code!
Closing Thoughts
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
Prevention is the best cure
Continuous Improvement
Avoid Complacency