Showing posts with label Kanban. Show all posts
Showing posts with label Kanban. Show all posts

Sunday 5 April 2020

Protocol oriented programming




Protocol oriented programming(POP) is a paradigm that has come into the limelight with the advent of Swift. Different languages over different periods have had some flavor of POP in them, but there are some traits unique in the POP central to Swift, which gives them a measurable advantage over OOP. That is not to say that OOP is flawed and or POP is the knight in the shining armor. POP simply extends OOP with a few new additions that help in writing better code ergo, better systems
Contents
a. Existing system example
b. Problem with Inheritance
c. Enter protocols
d. Protocol Extensions
e. Protocols & Value types

1. Existing system example

Let’s take a simple example to see how OOP and POP work on the same problem. Consider that we are contracted to build a vehicle that can be driven. The requirement is we will be asked to build many vehicles that will have different colors, number of wheels, different engine capacity, etc. Coming from the OOP world, the core of the solution would be something like this


Everything works fine. SmallCarRaceCar both can be driven. They also can have their unique traits.(noOfSeats()nitroBoosterCapacity() etc). No paradigm maps the real world as efficiently as OOP, and hence we can apply principles of real-world like inheritance in object modeling. That’s the beauty of it.
However, the real world is far from perfect, and that seeps into its derivative like OOP. Consider the same example above. The customer has now contracted you to build the ability to have wipers for the existing category of vehicles. So now Vehicle can be modified to have the ability to wipe


Courtesy, inheritance, all the categories of vehicles created hitherto can wipe its screen. RaceCar or SmallCar can simply call wipe() and startDriving() safely in the rains! The customer is now happy and since you are so awesome in building systems he now asks for introducing a new class of vehicle, A two-wheeler known as a motorcycle. The first reaction would be to subclass Motorcycle from Vehicle. In this case, Vehicle would not be useful. Why? Semantically a motorcycle is a vehicle so we should be able to use the Vehicle class. But the problem is if a Motorcycle inherits from Vehicle it would also inherit the ability to wipe(). Needless and absurd as well! So if we don’t extend Motorcycle from Vehicle, all the complex logic and business rules which are available through Vehicle namely in startDriving() will not be available to a Motorcycle. We could simply argue that ignore the ability to wipe() in a Motorcycle, but that’s knowingly introducing an association in the system which is not required. So what’s wrong with our design?

OOPs, OOP has done it again!

A subclass may not need all the features from its parent class. A child who has a rich, alcoholic father will happily choose to inherit his wealth but would keep his distance from his father's drinking vice(hopefully!). Similarly, a subclass may not require all the traits of its superclass. Since most of the languages do not support multiple inheritances we cannot break the superclass features into multiple smaller classes and have the subclasses inherit from the required ones.


OOP does not do a great job when it comes to this.

2. Problem with Inheritance

Inheritance is a great mechanism to reuse code and build software, but it is not particularly great when it comes to a selective association. The class that gets inherited is imbibed in the DNA of the subclass whether it likes it or not. It’s like a mobile data plan which comes with a host of great features that you are interested in but also with a few meh! features which you would have rather not wanted if sold individually. But since it’s part of the package you can’t escape it.

3. Enter protocols

Protocols have been in existence since OOP itself and it offers another way of designing and modeling classes. Let’s consider the above example of vehicles and how we could design the same using protocols


As we can see, with protocols we have been able to break the dependency enforced by Inheritance on the class Motorcycle when it inherited Vehicle. Now any new category of Vehicle which does not require wipers won’t be burdened with the same. It simply does not conform to it. Don’t need it, don’t ask for it and so not burdened with it! For e.g. a scooter. The protocol used in Swift generally is implemented as an abstraction (virtual class, interface so on and so forth) in many other languages. Nothing really new there. Readers would have noticed here that the need to define the logic of driving is now on the concrete class which implements Vehicle i.e both RaceCar and SmallCar now has to define how to startDriving(). This can lead to the repetition of code and logic. Besides if protocols have been available in many other languages what’s so special about POP in Swift? The answer is Protocol extensions.

4. Protocol Extensions

The cornerstone for POP is protocol extension. Swift (v2.0 onwards) allows a protocol to have a generic behavior that can be overridden as well. This generic behavior allows every implementation to “inherit” this by default. If they don’t like the generic behavior, well, simple, change it i.e., override it.
For e.g. the above example can now be written as

This is exactly like inheritance with the extra association of startWiper() now broken down to a need basis. Every implementation of Vehicle now has the complex startDriving() logic available by default i.e it has “inherited” the same from the protocol. Plus motorcycle does not have any association with Wipers. Thus protocol extensions help implementation to have the ability to “inherit” from a protocol and keep the dependency to an atomic level. i.e A protocol should contain only those contracts which an implementation or concrete object has to implement. Otherwise, it exhibits a fat interface problem. For e.g., Vehicle was a fat interface because it contained startWiper() which was not required for all subclasses.
5. Protocols & Value types
Swift advocates using value types over reference types wherever applicable. The use cases, benefits of both are well documented and won’t be covered here in this post. Value types like structenum can extend Protocols as well thus extending the benefits of designing using Protocols to even value types. This is one of the main reasons why Apple evangelizes using protocols over classes.

Bottom Line

POP extends OOP to provide another level of abstraction which helps a developer to write better code and design reusable components. Everything has its place under the sun and OOP is certainly not to be totally replaced with POP. Only where required. The decision to use POP or OOP can be context-specific

Monday 30 March 2020

Scrum vs Kanban


Scrum is a project management framework based on the principles of agile methodology (https://agilemanifesto.org/) which emphasizes small production cycles over short sprints of 2–3 weeks. Since its an agile methodology It also stresses on feedback-driven incremental changes incorporated throughout.
Scrum is widely used in the software development process, but the principles of scrum are industry agnostic. It can be applied to any process or domain or business vertical.
“Agility is principally about mindset, not practices.”
― Jim Highsmith, Agile Project Management: Creating Innovative Products


Backlog

At the heart of a scrum is a project backlog. A project backlog is a well-authored list of tasks generally known as “Stories.” Stories are measured, or story pointed with some metricE.g., 1,3,5,8,13 or 5 hours, 10 hours. As a rule of thumb, a project backlog should have sufficient tasks/stories to last at least two sprints. A business analyst or product owner prepares project backlogs in close collaboration with the customer during a periodic event known as Sprint planning. Representatives from the engineering, designing, quality are also involved in providing inputs on feasibility, cost, and time factors.

Sprints

Sprints are the actual production cycle or development cycle. Usually, sprints run for 2 weeks. At the start of a sprint, the project manager/ product owner includes stories or tasks from the project backlog. The development/engineering team works on the same for the duration of the sprint. Teams determine beforehand what constitutes the completion of a task. Usually, a task is complete once it’s tested and verified by the QA or customer. The end of a sprint features a new addition to the state of the existing product. At the end of the sprint, the primary stakeholder reviews the product and gives feedback. This feedback is used as an input for the next set of backlogs. This iterative cycle of
planning->develop->test->review->planning
forms the backbone of the scrum framework. A project manager often doubles as a scrum master who conducts the day-to-day sprint meetings; known as a Standup.

Standup

Standups are conducted on a day to day basis and are strictly time-bound. The goal of standup is for the team members to give a status update on a day to day basis. Members give an update on
What they did yesterday?
What they will do today?
What are the challenges for the same if any.”
As the name suggests, standups are conducted standing up to put the focus on short time frames for providing updates

Retrospective

Scrum encourages a team to be self-motivated and drives continuous improvement. A “Sprint retrospective” is held to deliberate on the work accomplished in the previous sprint. The focus is on learning from past mistakes, improve efficiency, and share findings, which helps the team to improve and increase productivity.


Kanban

“In the beginning, it’s advisable to focus on the flow of your work and the idea that your work actually has a “shape.”
― Jim Benson, Personal Kanban: Mapping Work | Navigating Life
Kanban is a project management framework based on the principles of agile methodology with particular focus on the visualization of production flows. Kanban aims to improve productivity and reduce delays in the value chain by continuous monitoring, feedback and reduced waiting across the workflow.
Like its famous cousin “Scrum,” Kanban can be used across any domain or workflow. Any existing workflow can be expressed or represented using the Kanban board. There is no need to modify a workflow to include Kanban. An elementary Kanban board can be created with three lanes; “Todo,” “In progress,” “Done.” Depending on the workflow, these lanes can be more or less.

Visualization

Kanban places emphasis on visualization of workflows. On the kanban board, a workflow or its derivative is expressed in a naturally flowing order from left to right. For e.g., In the software development process, the workflow would be expressed with lanes as such
||Backlog|| — ||Progress|| — ||For review|| — ||For test|| -||For deploy||
Each task is expressed with cards, or color-coordinated. For e.g., In-progress tasks are expressed with green stickers or green colors. In-review tasks are expressed in Red color or red stickers. The tasks are moved to the adjacent lane, once it’s completed. Unlike a sprint, Kanban is not time-bound. Once a task is completed, it’s simply removed from the board.
By visualizing a workflow in such a manner, teams can obtain vital information about the work output. Useful metrics regarding the time taken to complete a task, where is a task getting held up, what is the dependency of one task over the other can be easily found out.
Kanban was first designed for the production lines of Toyota with emphasis on unused inventory. The Kanban board gives instant clarity to the team if a task is sitting idle on a lane for a long time. To overcome this, Kanban allows setting a limit on the input such that tasks are not lying idle in a lane because of the unavailability of any resource. This is generally known as W-I-P limit (Work in progress)
Typical benefits of Agile development methodology
  1. A clearer view of process flow which helps in identifying bottlenecks
  2. Flexibility in execution by incorporating smaller incremental goals as opposed to a monolithic, one-time development
  3. Focus on continuous delivery by producing a subset of working software which is added to the existing product
  4. Better tracking of issues and tasks
  5. Continuous feedback leading to Increased productivity
  6. Allows for change at any stage of the project development
  7. Focus on the user all the time; their feedback & input
The primary goal of Kanban and Scrum is pretty similar, i.e., help organizations reduce execution time, optimize resource utilization, improve productivity & provide insights to measure. Both Kanban & Scrum are models of agile execution. Kanban focusses on specific aspects of the production process, whereas scrum is an entire framework for development. Kanban strives to present a clear picture of the workflow, while scrum defines process, steps & routines for workflow execution. It’s not uncommon to find Kanban being incorporated in a scrum process