Shalloway s Law. excerpted from Essential Skills for the Agile Developer by Alan Shalloway, Scott Bain, Ken Pugh, and Amir Kolsky

Similar documents
Our Approach to the Scaled Agile Framework (SAFe )

An Introduction to Commonality-Variablity Analysis

Introduction to Acceptance Test-Driven Development

An Overview of Guiderails: Keeping Aligned and on Track

Net Objectives Approach for Fast Growth and Mid-Scale Organizations

An Overview of Lean-Agile Methods

Becoming Lean: Why, What, and How

Aligning Multiple Teams with Lean-Agile Thinking

The Business Case for Agility

Aligning Multiple Teams with Lean-Agile Thinking

Why We Need More Than MVPs

The Business Case for Agility

ESSENTIAL WHITE PAPERS. Demystifying Kanban. by Al Shalloway

ISTOCKPHOTO.

Lean. Agile. Trim Tabs. and Pickup Sticks. White Papers. essential. by Alan Shalloway

An Introduction to Leanban. A Net Objectives White Paper

Agile at Mid-Scale. Al Shalloway. Introducing FLow for Enterprise Transformations (FLEX)

THE PRODUCT MASTERY ROADMAP. from Product Manager to Product Master

How to go agile enterprise-wide: An interview with Scott Richardson

IT Service Management

Why Achieving Agile at Scale Requires More Than Team & Evolutionary-based

Introduction to Agile Life Cycles. CSCI 5828: Foundations of Software Engineering Lecture 07 09/13/2016

Welcome to this IBM Rational podcast, The. Scaled Agile Framework in Agile Foundation for DevOps. I'm

Advice on Conducting Agile Project Kickoff. Meetings

Scaling Agile: Fractals of Innovation. An excerpt from Agile Business by Bob Gower and CA Technologies

HOW YOUR CAREER BACKGROUND CAN HELP YOU BECOME A BUSINESS ANALYST

developer.* The Independent Magazine for Software Professionals Automating Software Development Processes by Tim Kitchens

Create Your Successful Agile Project

HOW ALGORITHMS RULE THE WORLD

What You Must Attend to to Achieve Agile at Scale (and how SAFe

Before getting into the details of our engagement, I d like to ask, what does your company do?

Drive Predictability with Visual Studio Team System 2008

Review. The Radtac Key to Change

Kanban kick- start (v2)

/smlcodes /smlcodes /smlcodes. Small Codes. Programming Simplified. A SmlCodes.Com Small presentation. In Association with Idleposts.

The PMO Lifecycle: Building, Running, and Shutting Down The PMO Lifecycle: Building, Running, and Shutting Down

How can we get more value out of software development? An introduction to value visualization

Demystify the Dynamics AX JumpStart

Introduction to the Testing Maturity Model Enhanced TM (TMMe)

Changing Customers Expectations in the Water Industry by Scott J. Rubin. Good morning. It s a pleasure to be here with you this morning.

Integrated Safety Management System

How I Fired My Boss & Made More Money

Estimation as Hypothesis. Alan Shalloway BJECTIVES. Copyright, 2001, Net Objectives. Page 1-1. Copyright 2001 by Net Objectives

What Is Coaching? Overview Guiding Church Leaders

WORKING WITH TEST DOCUMENTATION

The Business Case for Dragon1

Claus von Riegen. Innovating at SAP the Delicate Balance between Incremental and Radical Innovation. An interview with

Agile versus? Architecture

TUNING AGILE TO YOUR BUSINESS OBJECTIVES

An Oracle White Paper May A Strategy for Governing IT Projects, Programs and Portfolios Throughout the Enterprise

Communicate business value to your stakeholders

AGILE SALES ONBOARDING METHODOLOGY

Holding Accountability Conversations

Brief. For the Modern Marketer, Hearing (Market) Voices Is a Good Thing

IN-HOUSE. By Margaret Steen

Shattering the Myths about CMMI and Extra- Small Companies

NEW! What to Expect for the Needs Assessment, Planning, Analysis, Traceability and Monitoring, and Evaluation Domains

AGILE TEST MANAGEMENT WITH VISUAL STUDIO

Management And Operations 593: Organizational Politics. Managerial Leadership and Productivity: Lecture 6. [Ken Butterfield]

GETTING STARTED IN PERSONAL AND EXECUTIVE COACHING

Managing Your Backlog

4 Steps To Scaling Agile Across The Enterprise. The Guide To Agile At Scale

IBM Software Services for Lotus To support your business objectives. Maximize your portal solution through a rapid, low-risk deployment.

Seven Key Success Factors for Identity Governance

Enhanced Employee Health, Well-Being, and Engagement through Dependent Care Supports

We are Product Support following Kanban (ScrumBan), yet pulling in small features (stories), room for scope creep.

Automating Your Way to Simplified Application Management

Communicate and Collaborate with Visual Studio Team System 2008

The Transformation of Transformation Maturity Assessment Workshop.

Website Content Creation Worksheet

Survive Your Alberta Transportation Audit:

Getting Started. Chapter 1

David Linthicum, Managing Director, Chief Cloud Strategy Officer, Deloitte Consulting LLP

Spotlight on Success. July Brendan Howe

Does the organization play together? BY: Collin Quiring. The Concept (Part 1)

YOUR GUIDED TRANSFORMATION

30 Course Bundle: Year 1. Vado Course Bundle. Year 1

Types of Process Methodologies

The Single, Easiest Branding Thing To Do On The Internet for Financial Practices. A free report provided by USA Financial

A philosophy first and methodology second

An Introduction to Hoshin Kanri, a.k.a. Strategic Goal Deployment How to Use this Process to Deploy Your Strategic Goals

AGILE SOLUTIONS. Agile Basics

The Metadata Handbook An interview with Renee Register & Patricia Payton. For podcast release Monday, February 11, 2013

JANUARY 2017 $ State of DevOps

Make sure to listen to this audio: as you go through this handout, to get maximum value.

Agile Portfolio Management for a Fast- Paced World. Are you ready? Are you ready?

Succeed with Agile at Scale

Scrum Alliance Certified Team Coach SM (CTC) Application SAMPLE

Certification Exam: DASA DevOps Fundamentals

Changing a culture with lean management

AHGILE A N D B O O K

At This Education Nonprofit, A Is for Analytics Social services agencies are turning to data to find the practices that get the best results.

The Impact of Agile. Quantified.

Communication. Understanding

The Meaningful Hospitality Smart Hiring Guide

Capacity Management Maturity Assessing and Improving the Effectiveness

A package full of change: An interview with Ian Andrews of Commonwealth Bank of Australia

The #1 Financial Mistake Made by Small-Business Owners

Seven Areas of Improvement in the Business

Pulse surveys are becoming popular as

Transcription:

ESSENTIAL WHITE PAPERS Shalloway s Law excerpted from Essential Skills for the Agile Developer by Alan Shalloway, Scott Bain, Ken Pugh, and Amir Kolsky

Shalloway s Law by Alan Shalloway, Scott Bain, Ken Pugh, and Amir Kolsky A Net Objectives Essential White Paper Net Objectives Press, a division of Net Objectives 1037 NE 65th Street Suite #362 Seattle, WA 98115-6655 404-593-8375 Find us on the Web at: www.netobjectives.com To report errors, please send a note to info@netobjectives.com Copyright Net Objectives, Inc. All Rights Reserved. Published by Net Objectives, Inc. Net Objectives and the Net Objectives logo are registered trademark of Net Objectives, Inc. Notice of Rights No part of this publication may be reproduced, or stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise without the written consent of Net Objectives, Inc. Notice of Liabilities The information in this book is distributed on an As Is basis without warranty. While every precaution has been taken in the preparation of this book, neither the authors nor Net Objectives shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the instructions contained in this book or by the computer or hardware products described in it. 10 9 8 7 6 5 4 3 2 Printed in the United States of America

Shalloway's Law 1 This article is excerpted from Essential Skills for the Agile Developer: A Guide to Better Programming and Design by Alan Shalloway, Scott Bain, Ken Pugh, Amir Kolsky. Addison-Wesley Professional: 2011. CHAPTER 4: SHALLOWAY S LAW A few years ago someone in one of my Design Patterns classes mentioned I should name something after myself since I had written a successful book on design patterns. I, of course, liked this person and his idea immediately. So I went about thinking about what would be appropriate. The best I could come up with was: When N things need to change and N>1, Shalloway will find at most N-1 of these things. While I had hoped to find something complimentary, this was the most appropriate thing I could come up with. I point out that I didn t ask for this when I was born I was given this ability. Most people also have this trait. In other words, this isn t choice it s how we are. This means we had better pay attention to it. Otherwise, we ll find that if we write code that requires finding more than 1 thing, we won t find them all, but our customers (or if we re lucky, someone else on our team) will. While I am not particularly proud of Shalloway s Law I am proud of Shalloway s Principle which I came up with to deal with it. Shalloway s Principle states: Avoid situations where Shalloway s Law applies. Kent Beck s famous once and only once rule is one approach to this in other words, keep N at 1 but not the only one. While avoiding redundancy is perhaps the best way to follow Shalloway s Principle, it is not always possible. Let s begin by looking at different types of redundancy and see how we might avoid them, or if not, how we can still follow Shalloway s Principle. TYPES OF REDUNDANCY Copy and Paste This is the most obvious type of redundancy and probably easiest to avoid. Using functions is a common way to avoid this. Magic Numbers COPYRIGHT NET OBJECTIVES, INC. This is not quite as obvious as redundancy, but it is. Basically the redundancy is that what the magic number means must be known everywhere the magic number is used. How to avoid magic numbers is well known just use #defines or consts or their equivalent depending upon your language of choice. WHAT IS REDUNDANCY? Redundancy can be much more intricate than what people initially think. The definition of redundancy I am referring to here is characterized by similarity or repetition. I would suggest redundancy can be fairly subtle and to define it as duplication or repetition is not sufficient. Defining it as similarity, unfortunately, can be a bit vague so perhaps it isn t that useful either. I propose a definition of redundancy in code that I believe is very useful Redundancy is present if when you make a change in one place in your code, you must make a corresponding change in another place. Alan Shalloway is the founder and CEO of Net Objectives. With over 40 years of experience, Alan is an industry thought leader in Lean, Kanban, product portfolio management, Scrum and agile design. He helps companies transition to Lean and Agile methods enterprisewide as well teaches courses in these areas. Alan has developed training and coaching methods for Lean- Agile that have helped Net Objectives clients achieve long-term, sustainable productivity gains. He is a popular speaker at prestigious conferences worldwide. He is the primary author of Design Patterns Explained: A New Perspective on Object-Oriented Design, Lean-Agile Pocket Guide for Scrum Teams, Lean-Agile Software Development: Achieving Enterprise Agility and Essential Skills for the Agile Developer. Alan has worked in literally dozens of industries over his career. He is a cofounder and board member for the Lean Software and Systems Consortium. He has a Masters in Computer Science from M.I.T. as well as a Masters in Mathematics from Emory University. You can follow Alan on twitter @alshalloway

2 NET OBJECTIVES ESSENTIAL WHITE PAPERS A little reflection will tell us that redundancy, at least defined this way, is almost impossible to avoid. For example, a function call has redundancy in it. Both the calling and defined statement must be changed if either change. From this we can also see the relationship between redundancy and coupling. And, as with coupling, not all redundancy is bad or even avoidable. I would say the type of redundancy you must avoid is that redundancy that violates Shalloway s Principle. Redundancy that doesn t violate Shalloway s Principle is likely to be a nuisance at most. For example, in the case above, I can have a function called from any number of places. Doing so has my system have a significant amount of redundancy. However, this doesn t violate Shalloway s Principle? Why? Because if I change the defining statement, the compiler will generate a to do list for me to change my calling statements. I still, of course, have work to make my changes, but that is considerably different from the dangerous situation I would be in if I had to also find the changes that were required. OTHER TYPES OF REDUNDANCY Given our new definition of redundancy, what are other common forms of it (and how do we avoid them)? Implementations are often redundant even if the code making them up are not duplicates of each other. For example, if a developer takes a function and copies it (clearly redundant at this point) but then changes all the code (presumably removing the redundancy) because the implementation of the new function is different do you still have redundancy? I would suggest you do. Not of the implementation, but most likely the algorithm you are implementing. The second function was copied from the first one presumably because the flow of both algorithms were the same - only their implementations were different. How do you remove this type of redundancy? I ll refer to Design Patterns Explained: A New Perspective on Object-Oriented Design s The Template Method Pattern. Basically, it involves putting the algorithm in a base (abstract) class and having the implementations of each step be in derived (extended) classes. THE ROLE OF DESIGN PATTERNS IN REDUCING REDUNDANCY We often talk about the purpose of design patterns is to handle variation. Many patterns are readily identified as doing this: Strategy handles multiple algorithms Bridge handles multiple implementations Template Method handles multiple implementations of a process Decorator allows for various additional steps in a process Most of the design patterns in the seminal work Design Patterns: Elements of Reusable Object- Oriented Software are about either directly handling variations or support handling variations. Another way to think of the use of design patterns is that they also eliminate the redundancy of having to know which implementation is being used. Because design patterns handle variations in a common manner, they can often be used to eliminate redundant relationships that often exist in a problem domain. For example, a purchasing/selling system will have several types of documents and payment types. Each document type may have a special payment type but the relationship between them is probably similar to the relationship between any other pair. This sets up redundant relationships. By using abstract classes and interfaces, redundancies can be made explicit and allow the compiler to find things for you. For example, when an interface is used, the compiler will ensure that any new method be defined in all cases you won t have to go looking for them. FEW DEVELOPERS SPEND A LOT OF TIME FIXING BUGS A common misconception amongst software developers is that they spend a lot of time fixing bugs. But on reflection, most realize that most of their time is spent in finding the bugs. Actually fixing them takes relatively little time. One of the reasons people spend a lot of time finding bugs is that they have violated Shalloway s Principle. If you can t find the cases easily, bugs will result. A key to avoiding this problem is to be aware of COPYRIGHT NET OBJECTIVES, INC.

Shalloway's Law 3 when you are violating Shalloway s Principle. Here s an interesting case. Let s say you ve been using an Encrypter class in your code. If you ve been following our suggestion of separating use from construction you may have code that looks something like this: public class BusinessObject { } public void actionmethod() { } AnotherObject aanotherobject= AnotherObject.getInstance() String astring; String astring2; Other things Encrypter myencrypter= Encrypter.getEncrypter(); myencrypter.doyourstuff( astring); aanotherobject( myencrypter); myencrypter.doyourstuff( astring2); public class AnotherBusinessObject { } public void actionmethod( Encrypter encryptertouse) { } Other things encryptertouse.doyourstuff( astring); Now let s say there become a case where we don t need to use the Encrypter. We might change the code from: Other things to Encrypter myencrypter= Encrypter. getencrypter(); Encrypter myencrypter; If (<<need an encrypter>>) myencrypter= Encrypter. getencrypter(); Then, of course, we have to go through our code and see when we don t have an encrypter: if (myencrypter!= null) myencrypter.doyourstuff( astring); At some point we ll hit the second case of this. This means Shalloway s Law is in effect. By the way, a corollary to Shalloway s Law is If you find two cases, know you won t find all of the cases. At this point, we should figure out a way not to have to test for the null case. An easy way is to put the logic in the getencrypter method in the first place. In other words, have Encrypter s getencrypter method have: NullEncrypter derives from Encrypter but does no encryption If (<<don t need an encrypter>>) return new NullEncypter(); This first of all, keeps all the knowledge about the construction of the encrypter out of the calling class. It also eliminates the need for checking in the null condition both avoiding Shalloway s Law and de-coupling the client code from the Encrypter object. This, by the way, is the Null Object Pattern. I would suggest that anytime you find you are doing a test for null more than once, you should see if you can use this properly. I suspect that many readers will think this example somewhat contrived because with a factoring making the Encrypter object it is pretty clear that the test for a null case should be handled in there. COPYRIGHT NET OBJECTIVES, INC.

4 NET OBJECTIVES ESSENTIAL WHITE PAPERS But this is also my point when you separate use from construction you are more likely to make better decisions later on. If a getencrypter wasn t being used, and the client code had the rules of construction, never setting the myencrypter reference would likely occur. REDUNDANCY AND OTHER CODE QUALITIES It s useful to note how redundancy is related to other code qualities. In particular, coupling and testability. Anytime you have redundancy, it is likely that if one of the occurrences change, the other one will need to change. If this is the case, these two cases are coupled. Coupling and redundancy are often different flavors of the same thing. Note that redundancy also raises the cost of testing. Test cases can often be reduced if redundant relationships are avoided. Let s consider the following case. Note that each of the service objects are doing conceptually the same thing, but are doing it in different ways (e.g., different kinds of encrypting). Figure 4.1. Testing in a 1 to many relationship Note that we need to have the following for a full set of tests: Test of Service1 Test of Service2 Test of Service3 Client using Service1 Client using Service2 Client using Service3 The need for testing Client using the services is because we have no assurance that we ve abstracted out the service code. There may be coupling taking place especially since each service interface may be different. Notice what happens when more clients become involved this gets worse and worse. Now, consider what happens if we make sure that all of the service objects work in the same way. In this case, we basically abstract out the service objects. If we put in an abstraction layer (either an abstract class or an interface that the services implement) we get what is shown in figure 4-2. Figure 4.2. Creating a 1 to 1 relationship While we still need to test each Service, we now only need to test the Client to Service relationship. Note that as we get more client objects the savings are even greater. SUMMARY Shalloway s Law is both humorous attempt at saying avoid redundancy while giving developers some guidance in how to do so or at least to make it less costly not to do so. Understanding redundancy is key to Shalloway s Law and avoiding the cost of it is the essence of Shalloway s Principle. A powerful question when programming that can be deduced from all of this is if this changes, how many places will I have to change things and can the compiler find those for me? If you can t see a way to make it so the answer is either 1 or yes then you have to acknowledge that you have a less than ideal design. At this point you should consider an alternative or, heaven help you ask someone else to suggest an alternative. OTHER ARTICLES OF INTEREST Go to www.netobjectives.com/articles to see the following articles: The Business Case for Agility Can Patterns be Harmful? Check out the Net Objectives Portal at portal. netobjectives.com where an extensive amount of online self-study is available. COPYRIGHT NET OBJECTIVES, INC.

Drive from Business Value BUSINESS-DRIVEN SOFTWARE DEVELOPMENT Business-Driven Software Development is Net Objectives proprietary integration of Lean-Thinking with Agile methods across the business, management and development teams to maximize the value delivered from a software development organization. This approach has a consistent track record of delivering higher quality products faster and with lower cost than other methods. Business-Driven Software Development goes beyond the first generation of Agile methods such as Scrum and XP by viewing the entire value stream of development. Lean-Thinking enables product portfolio management, release planning and critical metrics to create a top-down vision while still promoting a bottom-up implementation. Our approach integrates business, management and teams. Popular Agile methods, such as Scrum, tend to isolate teams from the business side and seem to have forgotten management s role altogether. These are critical aspects of all successful organizations. Here are some key elements: Business provides the vision and direction; properly selecting, sizing and prioritizing those products and enhancements that will maximize your investment. Teams self-organize and do the work; consistently delivering value quickly while reducing the risk of developing what is not needed. Management bridges the two; providing the right environment for successful development by creating an organizational structure that removes impediments to the production of value. This increases productivity, lowers cost and improves quality. BECOME A LEAN-AGILE ENTERPRISE Involve all levels. All levels of your organization will experience impacts and require change management. We help prepare executive, mid-management and the front-line with the competencies required to successfully change the culture to a Lean-Agile enterprise. Prioritization is only half the problem. Learn how to both prioritize and size your initiatives to enable your teams to implement them quickly. Learn to come from business need not just system capability. There is a disconnect between the business side and development side in many organizations. Learn how BDSD can bridge this gap by providing the practices for managing the flow of work. WHY NET OBJECTIVES While many organizations are having success with Agile methods, many more are not. Much of this is due to organizations either starting in the wrong place, such as focusing on the team when that is not the main problem, or using the wrong method, such as using Scrum or kanban because they are popular. Net Objectives is experienced in all of the Agile team methods (Scrum, XP, Kanban) and integrates business, management and teams. This lets us help you select the right method for you. info@netobjectives.com www.netobjectives.com 1.888.LEAN-244 (1.888.532.6244)

LEARN TO DRIVE DEVELOPMENT FROM THE DELIVERY OF BUSINESS VALUE What really matters to any organization? The delivery of value to customers. Most development organizations, both large and small, are not organized to optimize the delivery of value. By focusing the system within which your people are working and by aligning your people by giving them clear visibility into the value they are creating, any development organization can deliver far more value, lower friction, and do it with fewer acts of self-destructive heroism on the part of the teams. THE NET OBJECTIVES TRANSFORMATION MODEL Our approach is to start where you are and then set out a roadmap to get you to where you want to be, with concrete actionable steps to make immediate progress at a rate your people and organization can absorb. We do this by guiding executive leadership, middle management, and the teams at the working surface. The coordination of all three is required to make change that will stick. OUR EXPERTS Net Objectives consultants are actually a team. Some are well known thought leaders. Most of them are authors. All of them are contributors to our approach. Al Shalloway Scott Bain Alan Chedalawada Max Guernsey Guy Beaver Luniel de Beer SELECTED COURSES Executive Leadership and Management Lean-Agile Executive Briefing Preparing Leadership for a Lean-Agile/SAFe Transformation Product Manager & Product Owner Lean-Agile Product Roadmaps PM/PO Essentials Lean-Agile at the Team Acceptance Test-Driven Development Implementing Team Agility Team Agility Coaching Certification Lean-Agile Story Writing with Tests Technical Agility Advanced Software Design Design Patterns Lab Effective Object-Oriented Analysis and Design Emergent Design Sustainable Test-Driven Development DevOps DevOps for Leaders and Managers DevOps Roadmap Overview SAFe -Related Implementing SAFe with SPC4 Certification Leading SAFe 4.0 Using ATDD/BDD in the Agile Release Train (workshop) Architecting in a SAFe Environment Implement the Built-in Quality of SAFe Taking Agile at Scale to the Next Level OUR BOOKS AND RESOURCES CONTACT US info@netobjectives.com 1.888.LEAN-244 (1.888.532.6244) LEARN MORE www.netobjectives.com portal.netobjectives.com Copyright Net Objectives, Inc.