var blog = new ThoughtStream(me); RSS 2.0
 Wednesday, September 24, 2008

I've seen this question a lot recently, and Scott Bellware asks it again in response to a post by Jimmy Bogard.

"Ok, but why are "contracts" important?  I can write concrete classes that interact with each other just fine without interfaces. And as Roy has already demonstrated, you don't need interfaces for test-focused SoC. To wit, any concrete class's signature is a contract with its user." -- Scott Bellware

First - a small psychology lesson in Cognitive Load theory and Chunking. A human brain can only hold so much information in it's short term memory. The "magic number" of 7 (+/- 2) has often been touted as the average number of concepts that a person can hold in short term memory, and still understand what's going on.

... and we need to recognize this in our code. If a developer who is reading the code has more than 7 (+/- 2) concepts, then that developer is not likely to understand the code they are reading. If you can't understand the code, you can't maintain the code. It's as simple as that. So why are contracts important? An intention-revealing interface, as a contract, can significantly reduce the cognitive load that is required to understand the code in question.

Abstraction and dependency inversion via interfaces help us achieve this understandability by letting a developer's mind chunk a process into what's really important - the "when" and "what" of the process, ignoring the "how". If you eliminated all abstractions and interfaces - even the interfaces that have only one implementation - you are telling a developer that they need to know the details of "how", not just the abstraction of "when" and "what". This puts an additional load on any persons' brain, and can quickly overload the person reading the code.

These theories go so far beyond just code, in software. When was the last time you saw a web site that had more than 8 or 9 buttons in it's navigation/menu, and you thought it was an intuitive and easy to use site? I'd be willing to bet that you thought the site was poorly organized and difficult to navigate. Interaction design is usually the first place that people apply cognitive load and chunking theories. Unfortunately, it's also usually the last. We need to break this cycle of overloading ourselves and our coworkers, and create proper abstractions in our code that fit easily within our own cognitive load, but more importantly in the cognitive load of other developers who have to read/maintain the code.

Wednesday, September 24, 2008 9:05:16 PM (Central Standard Time, UTC-06:00)  #    Comments [4]. Trackback 
Tags: .NET | Analysis and Design | Code Reviews | Design By Contract | Interaction Design | Principles and Patterns | Psychology Of Software
Tracked by:
"Dependency Inversion: 'Abstraction' Does Not Mean 'Interface'" (new ThoughtStre... [Trackback]
"Dependency Inversion: 'Abstraction' Does Not Mean 'Interface'" (Derick Bailey.c... [Trackback]
"http://www.chooseyourevent.com/MoreDetails.asp?ID=49911" (http://www.chooseyour... [Pingback]
"http://www.rlc.cc.il.us/pressroom/newsstory.php?id=2692" (http://www.rlc.cc.il.... [Pingback]
"http://www.google.com/search?q=tbahkowe" (http://www.google.com/search?q=tbahko... [Pingback]
"http://www.club14.com/page/club14/clubinfo_actuclub.asp?id=191" (http://www.clu... [Pingback]
"http://www.capgros.com/agenda/cicle.asp?id=377" (http://www.capgros.com/agenda/... [Pingback]
"http://www.zubiri.org/financial/profile.cfm?RecNum=416905198" (http://www.zubir... [Pingback]
"http://www.cosacnaify.com.br/loja/biografia.asp?IDAutor=525" (http://www.cosacn... [Pingback]
"http://www.fims.org/default.asp?PageID=540599787" (http://www.fims.org/default.... [Pingback]
"http://www.aiim.org.uk/news/db/newsmore.asp?id=561" (http://www.aiim.org.uk/new... [Pingback]
"http://intranet.asoex.cl/AsoexWeb/Menu.asp?Id_Menu=124" (http://intranet.asoex.... [Pingback]
"http://www.tips4me.com/forum/displayallmessagesNew.asp?messageid=997776664" (ht... [Pingback]
"Baby names search - Search for bailey" (Baby-Parenting.com) [Trackback]
"http://www.hhs-stat.net/bobby/scripts/notes.cfm?urlid=947597341" (http://www.hh... [Pingback]
"http://www.calis.edu.cn/CALIS/lhml/faqall.asp?id=100" (http://www.calis.edu.cn/... [Pingback]
"http://www.goleeflames.com/info/miscellaneous/box-score.asp?id=4628" (http://ww... [Pingback]
"http://www.arbetov.com/en/reply.asp?message_id=1883" (http://www.arbetov.com/en... [Pingback]

Navigation
About Me
View Derick Bailey's profile on LinkedIn

Send mail to the author(s) Contact Me
Archive
<September 2008>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Derick Bailey
Sign In
Statistics
Total Posts: 115
This Year: 0
This Month: 0
This Week: 0
Comments: 44
Themes
Pick a theme:
All Content © 2010, Derick Bailey
DasBlog theme 'Business' created by Christoph De Baene (delarou)