Upload
smartlogic
View
233
Download
9
Embed Size (px)
DESCRIPTION
A short view into the language of abstraction in software development.
Citation preview
The Language of Abstraction
Sam Goldman@nontrivialzeros
Tuesday, July 23, 13
Software is Big
• 400 page book: ~20,000 LOC
• MS Vista: ~120,000,000 LOC (6,000 books)
• MS Apps: ~140,000,000 LOC (7,000 books)
Kay, Alan. “Programming and Scaling.” HPI Colloquium. Hasso-Plattner-Institut Postdam. 2011.http://www.tele-task.de/archive/video/flash/14029/
Tuesday, July 23, 13
Layers of Abstraction
Electronic Switches
Logic Gates
Binary
Machine Language
High-Level Language
Your Application
Tuesday, July 23, 13
Switches to Gates
Primitives Combination Abstraction
Tuesday, July 23, 13
Gates to Binary
Primitives Combination Abstraction
1 1 1 1 1 (carried digits) 0 1 1 0 1+ 1 0 1 1 1-------------= 1 0 0 1 0 0 = 36
Tuesday, July 23, 13
Primitive Obsession
• Using a primitive from the wrong layer of abstraction
• Particularly primitives provided by your programming language, e.g., dictionaries
• Create useful primitives in a new language
• Provide a means of combination and a means of abstraction
Tuesday, July 23, 13
Framework Obsession
• We use frameworks that provide lots of functionality: routing, ORM, templating
• Express your application in the language of the domain, not the language of the framework.
Tuesday, July 23, 13
Linguistic Abstraction
• Simpler mental models of software
• Self-documenting code
• Complexity where it matters
Tuesday, July 23, 13
TCP/IP
Tuesday, July 23, 13
Tell, Don’t Ask
• Depending on collaborators’ states breaks encapsulation
• Depend on behaviors, not state
• Law of Demeter
Tuesday, July 23, 13
AskingQuestionnaire = Struct.new(:questions) do def render(html) html.form questions.each do |question| html.fieldset { case question when ShortAnswerQuestion html.label(:for => question.id) { html.text question.prompt } html.input(:type => "text", :id => question.id, :name => question.id) when MultipleChoiceQuestion html.label { html.text question.prompt } html.ul { question.choices.each do |choice| html.li { html.label(:for => choice.id) { html.text choice.title } html.input(:type => "radio", :id => choice.id, :name => choice.id) } end } end } end end endend
Tuesday, July 23, 13
Telling
Questionnaire = Struct.new(:questions) do def render(html) html.form do questions.each do |question| html.fieldset { question.render(html) } end end endend
Tuesday, July 23, 13
TellingShortAnswerQuestion = Struct.new(:id, :prompt) do def render(html) html.label(:for => id) { html.text prompt } html.input(:type => "text", :id => id, :name => id) endend
MultipleChoiceQuestion = Struct.new(:id, :prompt, :choices) do def render(html) html.label { html.text prompt } html.ul { choices.each do |choice| html.li { choice.render(html) } end } endend
Choice = Struct.new(:id, :title) do def render(html) html.label(:for => id) { html.text title } html.input(:type => "radio", :id => id, :name => id) endend
Tuesday, July 23, 13
Encapsulation
• Limits the number of components affected by change
• Allows for extension
Tuesday, July 23, 13
Virtual Memory
Tuesday, July 23, 13
Services
• Fulfill needs determined though wishful thinking
• Hide concrete implementation details
Tuesday, July 23, 13
Thank you
@smartlogic
facebook.com/smartlogic
github.com/smartlogic
Tuesday, July 23, 13