Thin controllers - fat models (Proper code structure for MVC)
Code quality in MVC systems - BENEVOL 2016
-
Upload
mauricio-aniche -
Category
Technology
-
view
200 -
download
2
Transcript of Code quality in MVC systems - BENEVOL 2016
![Page 1: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/1.jpg)
CodequalityinMVCsystems
Maurício Aniche@mauricioaniche
![Page 2: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/2.jpg)
![Page 3: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/3.jpg)
60kand110klinesofJavacode!
![Page 4: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/4.jpg)
Me beautifulcode
![Page 5: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/5.jpg)
5
Sugarlevel150[70,120]
![Page 6: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/6.jpg)
6
Coupling10<15
Howtofindthisnumber?
![Page 7: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/7.jpg)
7
Benchmarking
![Page 8: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/8.jpg)
Benchmarkin Controllers
8
![Page 9: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/9.jpg)
Why? theirownconcernseachpartofthearchitecture
has!
![Page 10: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/10.jpg)
10
Quantiles
Coup
ling(CBO
)
Aniche, M., Treude, C., Zaidman, A., van Deursen, A., Gerosa, M.A., “SATT: Tailoring Code Metric Thresholds for Different Software Architectures”. 16th IEEE International Working Conference on Source Code Analysis and Manipulation, 2016.
![Page 11: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/11.jpg)
11
Expertsexplained to us
![Page 12: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/12.jpg)
SATT for the rescue12
![Page 13: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/13.jpg)
13
![Page 14: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/14.jpg)
14
Talktodevelopersyoushould,youngpadawan!
![Page 15: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/15.jpg)
A catalogueof smells
specific to MVC(after talking to 50 developers)
15
Grrrrrr…Controllers that offer many
servicesGrrrr…
Repositories that deal with many Entities
Grrrrr…
Aniche, Maurício, Bavota, Gabriele, Treude, Christoph, van Deursen, Arie, Gerosa, Marco.“A Validated Set of Smells in Model-View-Controller Architecture”. Software Maintenance and Evolution (ICSME), 2016, 32th International Conference, IEEE, 2016.
![Page 16: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/16.jpg)
16
Theyareindeedbad…(pronetochangeandtodefects)
![Page 17: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/17.jpg)
Itindeedbecameatool!
17
![Page 18: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/18.jpg)
Bettercodehub likeit!J
![Page 19: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/19.jpg)
Database-centriccodeBecauseinthewrong
place,theyare!It’sveryhardtofindsomeSQLqueriesinmycodebase…
![Page 20: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/20.jpg)
Project #ofclasses
#ofcommits
#ofDAOs #ofmethods
Gnarus 924 10451 39 233
Caelumweb 1321 12077 81 590
There aremany queries!
![Page 21: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/21.jpg)
Queriescan get complicated!SELECT
p.name as project,c.id as commitId,a.name as artifactName,a.path as artifactPath
FROMProjects p
JOIN Commits c ON c.project_id = p.id
JOIN Artifacts a ON a.commit_id = c.id
WHEREp.repository = ’Apache’;
WhereshouldIput
it?
![Page 22: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/22.jpg)
public class InvoiceDAO {public Invoice findById(int id) { … }public ShoppingCart find(User u) { … })public List<Invoice> getAll() { … }public void save(Invoice inv) { ...}
}
Bythemethodsignatureswe
should!
Whereshouldwestart?
![Page 23: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/23.jpg)
Project #ofDAOmethods
#of”correct”methods
#of”wrong”methods
%ofwrongmethods
Caelumweb 590 511 79 13.38%
Gnarus 233 200 33 14.16%
Project #ofinspectedmethods
#ofagreement
%ofagreement
Caelumweb 79 59 74.68%
Gnarus 33 16 48.48%
Aniche, Maurício F., Gustavo A. Oliva, and Marco A. Gerosa. “Are the Methods in Your Data Access Objects (DAOs) in the Right Place? A Preliminary Study.”. 6th Workshop on Managing Technical Debt, in conjunction with ICSME2014, Canada. Short paper.
![Page 24: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/24.jpg)
PhilCalçado just(re-)bloggedaboutit!
http://philcalcado.com/2010/12/23/how_to_write_a_repository.html
![Page 25: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/25.jpg)
TestcodestabilityNothappenitshould!
Wehatesystemtestingbecausewehavetorewritethem
often!
![Page 26: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/26.jpg)
Largeseleniumcodeis!
![Page 27: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/27.jpg)
A catalogueof patterns
27
Fixture APIID in HTML
Move Fast, Move Slow…
Aniche, M., Guerra, E., Gerosa, M. “A Set of Patterns to Improve Code Quality of Automated Functional Tests of Web Applications”. 21th Conference on Pattern Languages of Programs. 2014.
![Page 28: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/28.jpg)
![Page 29: Code quality in MVC systems - BENEVOL 2016](https://reader034.fdocuments.in/reader034/viewer/2022051523/586f74581a28ab10258b5b3f/html5/thumbnails/29.jpg)
Thanks!@mauricioaniche
YoungmeworkingonalowqualitycodethatIwrotemyselfat
myfirstinternationalproject(DominicanRepublic,2006).
Sorryaboutmyhair.
Mybossesdoingpeerpress…oops,pairprogramming!