39
The Taming of the Code Alan Stevens A tale of the first principles of software development presented in three acts

The Taming Of The Code

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: The Taming Of The Code

The Taming of the Code

Alan Stevens

A tale of the first principles of software development presented in three acts

Page 2: The Taming Of The Code

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!

Page 3: The Taming Of The Code

PLAYBILL

• Act I: The Goal• Act II: The Guidelines• Act III: The Practice

Page 4: The Taming Of The Code

Let’s Talk About Code

Page 5: The Taming Of The Code

Act I: The Goal

Page 6: The Taming Of The Code

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

Page 7: The Taming Of The Code

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

Page 8: The Taming Of The Code

How do we balance building the right thingwith building it well?

Page 9: The Taming Of The Code

Building the right thing is always a higher priority!

Page 10: The Taming Of The Code

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

Page 11: The Taming Of The Code

Building it right has a minimum acceptable threshold which must be met

Page 12: The Taming Of The Code

Do the simplest thing that could possibly work

Page 13: The Taming Of The Code

Enable Change

Page 14: The Taming Of The Code

Build Architectural

Seams

Page 15: The Taming Of The Code

At least build fault lines

Page 16: The Taming Of The Code

Manage Technical Debt

Page 17: The Taming Of The Code

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

Page 18: The Taming Of The Code

Enable The *ILITIES• Agility• Testability• Readability• Reversibility• Changeability• Flexibility• Maintainability

Coined by Kevlin Henney

Page 19: The Taming Of The Code

Act II: The Guidelines

Page 20: The Taming Of The Code

Don’t Repeat Yourself&

Separation of Concerns

Page 21: The Taming Of The Code

DRYDon’t Repeat

Yourself

Page 22: The Taming Of The Code

The Rule of ThreeSee it once: do itSee it twice: notice itSee it a third time: abstract it!

Page 23: The Taming Of The Code

Separation of Concerns

Page 24: The Taming Of The Code
Page 25: The Taming Of The Code
Page 26: The Taming Of The Code

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

Page 27: The Taming Of The Code

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;}

Page 28: The Taming Of The Code

SOLID Principles

• Single Responsibility Principle

• Open Closed Principle

• Liskov Substitution Principle

• Interface Segregation Principle

• Dependency Inversion Principle

Page 29: The Taming Of The Code

Act III: The Practice

Page 30: The Taming Of The Code

How do we guarantee baseline design without impeding productivity?

Page 31: The Taming Of The Code

Can we verify that we are building the right thing?

Page 32: The Taming Of The Code

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

Page 33: The Taming Of The Code

Let’s write some code!

Page 34: The Taming Of The Code

Closing Thoughts

Page 35: The Taming Of The Code

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

Page 36: The Taming Of The Code

Prevention is the best cure

Page 37: The Taming Of The Code

Continuous Improvement

Page 38: The Taming Of The Code

Avoid Complacency

Page 39: The Taming Of The Code

Thanks For Listening!

Email/IM: [email protected]

Blog: http://netcave.org

Twitter: @alanstevens