Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The scary fairy tale about MVC or How to stop w...
Search
Andrey Savchenko
May 31, 2013
Programming
3
260
The scary fairy tale about MVC or How to stop worrying and start to write ruby code
Hotcode conference, 5 May 2013
Andrey Savchenko
May 31, 2013
Tweet
Share
More Decks by Andrey Savchenko
See All by Andrey Savchenko
Building web-API without Rails, registration or sms
ptico
3
850
The big, the small and the Redis
ptico
1
220
Zen TDD
ptico
2
180
The Application: An Unexpected Journey
ptico
1
290
How to f*ck up the refactoring
ptico
11
450
Practical SOLID with Rails
ptico
5
600
Redis - little helper for big applications (rus)
ptico
3
150
Other Decks in Programming
See All in Programming
watsonx.ai Dojo #6 継続的なAIアプリ開発と展開
oniak3ibm
PRO
0
270
カンファレンス動画鑑賞会のススメ / Osaka.swift #1
hironytic
0
200
Оптимизируем производительность блока Казначейство
lamodatech
0
990
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
1
500
functionalなアプローチで動的要素を排除する
ryopeko
1
930
[JAWS-UG横浜 #79] re:Invent 2024 の DB アップデートは Multi-Region!
maroon1st
0
130
SRE、開発、QAが協業して挑んだリリースプロセス改革@SRE Kaigi 2025
nealle
1
3.3k
Внедряем бюджетирование, или Как сделать хорошо?
lamodatech
0
980
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.3k
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
240
Linux && Docker 研修/Linux && Docker training
forrep
22
4.1k
Java Webフレームワークの現状 / java web framework at burikaigi
kishida
9
2k
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
20
2.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
39
1.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
YesSQL, Process and Tooling at Scale
rocio
171
14k
Designing Experiences People Love
moore
139
23k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Statistics for Hackers
jakevdp
797
220k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Optimizing for Happiness
mojombo
376
70k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Transcript
The scary fairy tale about MVC How to stop worrying
and start to write ruby code or
Andrey Savchenko @ptico @ptico_eng Aejis
Cast • Little Red Riding Hood - developer • Grandmother
- customers • The map - MVC • Compass - Rails And others…
nce upon a time, a little girl goes trough the
scary wood to deliver pies to her grandmother. O
here she met the Damn Horrible Human nicknamed «The Wolf»
T
here you are going, little girl? he asked. I’m going
to deliver pies to my grandma – she answered. W –
have a present for you – wolf said. Take this
map and this compass: it works very well for me. I
None
he girl took gifts and moved on. And have lost
in the wood. Because the compass was point to the wolf’s grandmother and map defines the ways not applicable for little girls. T
THE END
Moral: the tools which works for other person may doesn’t
work for you
MVC is a good example
What’s wrong with MVC?
It has only three letters MVC
One of them superfluous MVC
Application should know nothing about representation
Another one means a little bit more than nothing MVC
The controller should delegate the work that needs to be
done to other objects; it coordinates or controls the activity. It should not do much work itself. GRASP controller definition
So, what’s left?
The model M
M
M
M
None
Please, rise your hand if you have this kind of
models
So, this is a moment when we should start writing
the Ruby code
What does it mean?
Lets take a look at our daily gems
carrierwave
state_machine
resque
Ok, i catch the idea, lets start!
Wait a minute - we need some weapons
Metrics
Metrics • WPM - WTFs per minute
Metrics • WPM - WTFs per minute • SLOC/M -
Source lines of code per method
Metrics • WPM - WTFs per minute • SLOC/M -
Source lines of code per method • SLOC/C - Source lines of code per class
Overall complexity ((AVG(SLOC/M) + SLOC/C)^WPM)/100
Overall complexity If you have > 10 – i have
a bad news for you
Principles • SOLID
Principles • SOLID • YAGNI
Principles • SOLID • YAGNI • KISS
Secret weapon: Testability
The simpler your objects to test - the easier they
can be changed and reused
The more complex your objects is - the harder to
test them
Got it! What about strategy?
Strategies:
Use-case strategy
Use-case strategy • Doesn’t work with Rails • Requires to
build your own stack • But once you build this – its bullet-proof
Onion strategy
None
Onion strategy • Do work with Rails • Layer can
be just Plain Old Ruby Object • Layers is hard to naming
Onion strategy Model Controller View
Onion strategy Model Controller View Presenter
Onion strategy Model Controller View Presenter Form object
Onion strategy Model Controller View Presenter Form object Repository
Onion strategy Model Controller View Presenter Form object Repository Service
Onion strategy Model Controller View Presenter Form object Repository Service
Validator
Attribution: http://www.flickr.com/photos/42255449@N00/7177978063/ http://www.flickr.com/photos/normanbleventhalmapcenter/2674605704/ Thank you!
Questions? Andrey Savchenko Aejis* * we are hiring** ** if
you understand the problem described in talk