dancing about architecture
DESCRIPTION
Agile has democratized software architecture, taking it out of the hands of the few and putting it into the hands of the many. But architecture is a complex thing, and there are lots of mines in the meadow. This presentation provides some key things to keep in mind as you contribute to the evolution of your Rails application.TRANSCRIPT
The idiomatic approach embodied in Railsenables rapid development.
• Built in discrete layers• Models, views, and controllers• Controllers implement CRUD• Routes are RESTful• /lib = whatever doesn’t fit MVC
IdiomaticRails
But rapid development comes at a cost.
• Business logic leaking through the layers
• Raw SQL in models
• Complex object dependencies
• Conditional logic everywhere
• Controllers with non-CRUD methods
• Route exceptions become the norm
• Slow test suite execution
• /lib overflow
symptoms of a mature rails application
“Most software eventually degrades to the point where someone will declare the design to be unsound.”-- Uncle Bob
• Rigidity
• Fragility
• Immobility
• Feature friction
warning signs of adegraded design
Bad design happens one line of code at a time.
• Duplicated code
• Long methods
• God objects
• Feature envy
• Class intimacy
• Contrived complexity
• Übercallbacks
commoncode smells
• Reek
• Flog
• RSpec
• Bug reports
• Feature requests
• Intuition
refactoringtoolkit
• TDD until it doesn’t hurt anymore
• Build the interface you want to have
• Hexagonal architecture
• Verbs as nouns
refactoringpatterns
• Let the test suite tell you where the pain points are
• Test only what you’re testing
• Stub everything else
• If you can’t stub it, it’s supposed to be a method
• Avoid factories
• Refactor until your methods are shorter than your tests
test-drivendevelopment
• Build a new object
• Add the methods you wish you had
• Wrap the methods that you do have
• Refactor until it’s symmetrical
interface-drivendesign
• Layered architectures are a convenient metaphor but break down quickly in a real app
• Build a Ruby application and integrate it with Rails, not the other way around
• Allow your application to be driven by users, programs, automated tests, batch scripts, ...
• Don't think in layers, think in ports
• Everything is an API
hexagonalarchitecture
hexagonalarchitecture
WebBrowser
RakeTask
APIClient
TestingFramework
APIServer
Database
Mocks
iOSApplication
CommandLine
Domain ObjectsPersistence
HTTP
Com
man
d Lin
eM
essaging
DefaultLogger
ExternalMonitoring
Service
EmailService
• Classes don’t have to represent business objects
• Classes can represent processes
• Classes can represent interactions
• Classes can represent workflows
• Do you need a run method, or a running class?
gerunds:the verb-as-noun
Agile development has democratized architecture.
.: we are all architects.
Be the best architect you can be.