Slide 1

Slide 1 text

Tech Talk: Code Modularization 31st August 2018 Taka

Slide 2

Slide 2 text

What is Modularization for?

Slide 3

Slide 3 text

To Make Good Software!

Slide 4

Slide 4 text

What is Good Software?

Slide 5

Slide 5 text

Good Software Meets Requirements!

Slide 6

Slide 6 text

Good Software (in my opinion) ● “At least” needs to meet the business requirements ○ Software that doesn’t meet the requirements is rubbish ■ What if Twitter didn’t have the feature to tweet your thoughts... ● Should be extensible, maintainable, and reusable ○ Because...

Slide 7

Slide 7 text

Why Extensibility / Maintainability / Reusability Matter?

Slide 8

Slide 8 text

To Meet the Requirements!

Slide 9

Slide 9 text

Business Requirements ● Business requirements frequently change ○ We may come up with a better idea 3 days after we decide something important ● New requirements constantly show up ○ We may want to launch a new service or feature instead of refining existing ones

Slide 10

Slide 10 text

Software Needs Updating!

Slide 11

Slide 11 text

Updating Software ● Software should be updated as quickly as possible ○ All of us want to deploy new features as soon as possible and ahead of competitors. ● Software should be as understandable as possible ○ The more your business grows, the more developers join you. It’s obvious that newcomers can easily catch up if the software is understandable.

Slide 12

Slide 12 text

That’s Why We Make Much of Extensibility, Maintainability, and Reusability

Slide 13

Slide 13 text

Again, What is Modularization for?

Slide 14

Slide 14 text

Code Modularization Contributes to ● Maintainability ● Extensibility ● Reusability

Slide 15

Slide 15 text

Code Modularization Contributes to Updating Software Easily, which Contributes to Providing Services That Meet the Requirements

Slide 16

Slide 16 text

What If Requirements Never Change If we are 100% sure requirements won’t change forever and there is no need to maintain the software, extensibility, maintainability, and reusability don’t matter. It might be possible in some special occasions, but practically, it hardly ever happens when you are developing services.

Slide 17

Slide 17 text

Example for Modularization

Slide 18

Slide 18 text

Let’s Say You’re Building Software to Produce Pringles

Slide 19

Slide 19 text

Before Doing Pringles... I’m going to use ‘mathematical-function-like-programs’. f(x) = y ● f: the name of the function (program) ● x: the parameter of the function (program) ● y: the result of the function (program) given ‘x’

Slide 20

Slide 20 text

Example of a Function calculate_property_value(postcode, number_of_bath_rooms) ● Program name: calculate_property_value ● Parameters: postcode, number_of_bath_rooms ● Result: the value of the given information This program will calculate the property value based on the given postcode and the number of bath rooms.

Slide 21

Slide 21 text

Simplified Processes of Production 1. Grow Potatoes 2. Cut Potatoes 3. Fry Potatoes 4. Season Potatoes 5. Pack Potatoes 6. Ship it!

Slide 22

Slide 22 text

Simplified Processes of Production 1. Grow Potatoes 2. Cut Potatoes 3. Fry Potatoes 4. Season Potatoes 5. Pack Potatoes 6. Ship it! Let’s make a program to do these 4 steps!

Slide 23

Slide 23 text

The Program to Make You can pass potatoes and this program will produce pringles! produce_pringles(potatoes) = a_pack_of_pringles ● Name: produce_pringles ● Parameters: (potatoes) ● Result: a pack of pringles

Slide 24

Slide 24 text

Use Case of the Program 1. Jed cultivates potatoes 2. Nino receives potatoes from Jed and uses the ‘produce_pringles’ program 3. The ‘produce_pringles’ program produces Pringles 4. Nino sends Pringles to Taka 5. Taka enjoys Pringles!

Slide 25

Slide 25 text

Usage of the Program As long as you have enough potatoes, you can produce as much as Pringles you want by using this program. If Nino has 100 units of potatoes (1 unit is for one pack of Pringles), Nino can get 100 packs of Pringles by calling ‘produce_pringles’ 100 times.

Slide 26

Slide 26 text

Nino’s Job with and without the Program Without the Program 1. Cut potatoes 2. Fry potatoes 3. Season potatoes 4. Pack potatoes 5. Ship it With the program 1. Use the program 2. Ship it

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

A New requirement is coming...

Slide 29

Slide 29 text

Nino produces normal Pringles, but Taka wants beer-flavored one.

Slide 30

Slide 30 text

Nino needs a new program!

Slide 31

Slide 31 text

Details of the Current Program What is happening inside the program is: ● Cut potatoes ● Fry potatoes ● Season potatoes <= Using only salt right now ● Pack potatoes

Slide 32

Slide 32 text

First Solution (Non-modularized) produce_pringles_beer_flavored(potatoes) ● Name: produce_pringles_beer_flavord ● Parameter: potatoes ● Result: Beer flavored Pringles

Slide 33

Slide 33 text

Comparison between two programs produce_pringles 1. Cut potatoes 2. Fry potatoes 3. Season potatoes with salt 4. Pack potatoes produce_pringles_beer_flavord 1. Cut potatoes 2. Fry potatoes 3. Season potatoes with beer 4. Pack potatoes

Slide 34

Slide 34 text

Closer look at Cut Potatoes I haven’t told it, but cutting potatoes consists of 10 steps. 1. Wash potatoes 2. Peel potatoes 3. etc.

Slide 35

Slide 35 text

More Realistic Details of Two Programs produce_pringles 1. Cut potatoes (10 steps) a. Wash potatoes b. Peel potatoes c. And so on... 2. Fry potatoes (5 steps) 3. Season potatoes with salt (12 steps) 4. Pack potatoes (3 steps) produce_pringles_beer_flavord 1. Cut potatoes (10 steps) a. Wash potatoes b. Peel potatoes c. And so on... 2. Fry potatoes (5 steps) 3. Season potatoes with beer (12 steps) 4. Pack potatoes (3 steps)

Slide 36

Slide 36 text

The regulation of washing potatoes has changed! You need to update your software to follow the new law!

Slide 37

Slide 37 text

Updated Two programs produce_pringles 1. Cut potatoes (10 steps) a. Wash potatoes b. Sanitize potatoes c. Peel potatoes d. And so on... 2. Fry potatoes (5 steps) 3. Season potatoes with salt (12 steps) 4. Pack potatoes (3 steps) produce_pringles_beer_flavord 1. Cut potatoes (10 steps) a. Wash potatoes b. Sanitize potatoes c. Peel potatoes d. And so on... 2. Fry potatoes (5 steps) 3. Season potatoes with beer (12 steps) 4. Pack potatoes (3 steps)

Slide 38

Slide 38 text

Let’s make new programs (modules)!

Slide 39

Slide 39 text

New programs (modules) ● cut_potatoes(potatoes) ● fry_potatoes(potatoes) ● season_potatoes(potatoes, flavor) ● pack_potatoes(potatoes)

Slide 40

Slide 40 text

Updated Programs with new modules produce_pringles 1. cut_potatoes(potatoes) 2. fly_potatoes(potatoes) 3. season_potatoes(potatoes, salt) 4. pack_potatoes(potatoes) produce_pringles_beer_flavord 1. cut_potatoes(potatoes) 2. fry_potatoes(potatoes) 3. season_potatoes(potatoes, beer) 4. pack_potatoes(potatoes) To cope with the new potato law, you no longer need to modify two places. Instead, you just need to update the ‘cut_potatoes(potatoes)’ program!

Slide 41

Slide 41 text

Look for similarity for further abstraction produce_pringles 1. cut_potatoes(potatoes) 2. fly_potatoes(potatoes) 3. season_potatoes(potatoes, salt) 4. pack_potatoes(potatoes) produce_pringles_beer_flavord 1. cut_potatoes(potatoes) 2. fry_potatoes(potatoes) 3. season_potatoes(potatoes, beer) 4. pack_potatoes(potatoes) Most parts of both programs are pretty much the same! You may make a new program that is more reusable!

Slide 42

Slide 42 text

More Reusable Program ● Old ○ produce_pringles(potatoes) ○ produce_pringles_beer_flavord(potatoes) ● New ○ produce_pringles(potatoes, flavor)

Slide 43

Slide 43 text

Benefits of the new one ● You only need to maintain only one program, instead of two ● You don’t need to create a new program to produce a new flavored Pringles

Slide 44

Slide 44 text

You got more extensible, maintainable, and reusable program!

Slide 45

Slide 45 text

Our modules for websites https://www.immo.co.uk/styleguide

Slide 46

Slide 46 text

Summary ● Code Modularization is for ○ Maintainability ○ Extensibility ○ Reusability ■ Each of which is for updating software to meet the requirements

Slide 47

Slide 47 text

Thanks a million!