Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson,...

36
Love your architecture II SATURN 2017 Paulo Merson Denver Art Museum. Photo by Danielle Webster

Transcript of Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson,...

Page 1: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Love your architecture II SATURN 2017Paulo Merson

Denver Art Museum. Photo by Danielle Webster

Page 2: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

A not so uncommon story…

Page 3: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

A software architecture was carefully defined based on• architecture and design patterns• experience with similar design problems• discussions with several stakeholders

Page 4: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

The architecture was incrementally refined and implementedSprint after sprint, code became the main artifact

Page 5: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Development and maintenance• spanned several years• involved tens of people

Page 6: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

The end of the story…

Page 7: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Actual architecture != intended architecture

Page 8: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout
Page 9: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout
Page 10: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Lack of architecture conformance• makes the code hard to understand and change, mainly

because of undesired dependencies• may affect portability, performance, interoperability,

security and other qualities

Page 11: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

How to avoid code and architecture disparity?

Page 12: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

1) Communicate the architecture to developers• Not the focus of this presentation

Page 13: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

2) Automate architecture conformance analysis• Often done with static analysis tools

Page 14: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Two limitations of static analysis tools, as commonly used…

Page 15: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

1) Many people just enable built-in checks, which• are oblivious to your architecture design constraints

2) Developers can ignore reported violations• There’s no time to “clean the house”• There may be no accountability for

adding violations

Page 16: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

How did we overcome limitation 1?

Page 17: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

We created custom checks

Page 18: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

How did we overcome limitation 2?

Page 19: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Upon code commit a pre-commit hook• runs custom checks on each source file

If a custom check detects a violation• the commit operation is denied• developer sees a descriptive error message • architecture team is notified of the failed commit• developer gets email with further explanation

Page 20: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Custom checks at TCUBrazilian Federal Court of Accounts (tcu.gov.br)

Page 21: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

We’ve created 51 custom checks• 27 checks for architecture conformance• 14 checks for coding guidelines• 10 checks for application security

Page 22: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Architecture conformance checks enforce for example• the layered architecture• placement of data access logic• mandated generalizations• naming of software elements• design standards in

reference architectures

Page 23: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Some lessons learned…

Page 24: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Add to pre-commit hooks only the checks• with zero violations in the target codebase• that enforce mandatory rules

Page 25: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

But add all checks to sonarqube analysisAnd run analysis in your continuous integration

Page 26: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Adopt an architecturally-evident coding style

An architecturally-evidentcoding style encourages you to embed hints in the source code that makes the architecture evident to a developer who reads the code

Page 27: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Let developers know about the custom checks and suggest changes and improvementsLet architects understand the potential of the custom checks

Page 28: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

For more informationEmail: [email protected], P. Ultimate architecture enforcement: custom checks enforced at code-commit time. SPLASH Wavefront 2013. Merson, P., Yoder, J., Guerra, E. Continuous Inspection: A Pattern for Keeping your Code Healthy and Aligned to the Architecture. Asian PLoP 2014.

Page 29: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

The single best thing you can do for the long term health, quality and maintainability of a non-trivial software system is to

carefully manage and control the dependencies between its different elements and components by defining and enforcing an

architectural blueprint over its lifetime—Alexander Zitzewitz

Loving your architecture == defining and enforcing it

Page 30: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Backup slides

Page 31: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Some results…

Page 32: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

750+ commit attempts denied in the first 24 months Enhacements to the checkstyle and PMD APIs submitted to these open source projects~12,000 violations fixed in the codebase

The real value was• increased code quality • improved awareness of the architecture and coding guidelines

Page 33: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

More lessons learned…

Page 34: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Be careful not to become the “architecture police” Be the “architecture mentors”

Page 35: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Create a mechanism to easily trump a check in exceptional cases

Page 36: Love Your Architecture II - SEI Digital Library...Love Your Architecture II Author Paulo Merson, Brazilian Federal Court of Accounts (TCU) Subject Architecture requires attention throughout

Automate the email with further clarification about a denied commit attempt