2. Software is Big
• 400 page book: ~20,000 LOC
• MSVista: ~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
3. Layers of Abstraction
Electronic Switches
Logic Gates
Binary
Machine Language
High-Level Language
Your Application
Tuesday, July 23, 13
6. 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
7. 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
8. Linguistic Abstraction
• Simpler mental models of software
• Self-documenting code
• Complexity where it matters
Tuesday, July 23, 13
10. Tell, Don’t Ask
• Depending on collaborators’ states breaks
encapsulation
• Depend on behaviors, not state
• Law of Demeter
Tuesday, July 23, 13
11. 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
end
end
Tuesday, July 23, 13
12. Telling
Questionnaire = Struct.new(:questions) do
def render(html)
html.form do
questions.each do |question|
html.fieldset { question.render(html) }
end
end
end
end
Tuesday, July 23, 13
13. Telling
ShortAnswerQuestion = Struct.new(:id, :prompt) do
def render(html)
html.label(:for => id) { html.text prompt }
html.input(:type => "text", :id => id, :name => id)
end
end
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
}
end
end
Choice = Struct.new(:id, :title) do
def render(html)
html.label(:for => id) { html.text title }
html.input(:type => "radio", :id => id, :name => id)
end
end
Tuesday, July 23, 13
14. Encapsulation
• Limits the number of components affected
by change
• Allows for extension
Tuesday, July 23, 13