Coding defines reality

Post on 14-Apr-2017

584 views 0 download

Transcript of Coding defines reality

Coding Defines RealityCode Mania #101

@varokas BIGBEARS.

Design

Design

Creating Solutions based on

1. Requirements

2. Desired Properties

• Available

• Reliable

• Performance

• Maintainable

• Reusable

• Usable

Design is very easyKnowing what you want is very hard

Christopher Alexander

Christopher Alexander

Principles of Emergent Design

Contextual Force

Force

Force

Force

Force

Force

Force

Force ForceDesign

Force Force

Force

Force

Force

Force

Force

Force

Design

–Johnny Appleseed

“Type a quote here.” Force Force

Force

Force

Force

Force

Force

Force

Design

Feel the force!Do not put in one that does not exist

Patterns

Design Patterns

Patterns

“The Pattern is in the problem”

–Johnny Appleseed

“Type a quote here.”

Pattern

Problem

“Don't Solve the Problem. Discover the Pattern”

Emergent Design

Change from Create Solutions

to Discover Solutions

Discovering Techniques

• Code Properties Analysis

• Commonality Variability Analysis

• Programming by Intention

• Tests (TDD)

CommonalityVariabilityAnalysis

CommonalityVariabilityAnalysis

• What is in Common?

• What Varies?

• Under a certain Context of Use

CVA Example (non-software)

CVA Exercise (Pen-Pencil)

Pen

• write with ink • can't erase

Pencil

• write with lead • can erase

?

• write • cylinder • can put in a box • breakable • ....

CVA Exercise (Pen-Pencil)

Pen

• write with ink• can't erase

Pencil

• write with lead• can erase

WritingTool

• write• cylinder • can put in a box

WritingUser

CVA Exercise (Pen-Pencil)

Pen

write() { //inkImpl}

Pencil

write() { //leadImpl}

WritingTool

write()

WritingUser

CVA Exercise (Pen-Pencil)

Penwrite() { //inkImpl}

Pencil

write() { //leadImpl}

WritingTool

write()

interface WritingTool { def write() }

class Pen extends WritingTool { def write() { //ink impl } }

class Pencil extends WritingTool { def write() { //lead impl } }

CVA Exercise (Pen-Pencil)

Pen

write() { //inkImpl}

Pencil

write() { //leadImpl}

WritingTool

write()

WritingUser

CVA Exercise (2)

• There are two types of shape (Circle, Square)

• There are two types of writer (Pen, Pencil)

• Each shape can print itself on different writers

CVA Exercise (2)

Pen

write() { //inkImpl}

Pencil

write() { //leadImpl}

Writer

write() • There are two types of shape (Circle, Square)

• There are two types of writer (Pen, Pencil)

• Each shape can print itself on different writers

CVA Exercise (2)

Pen

write() { //inkImpl}

Pencil

write() { //leadImpl}

Writer

write()

Square

Shape

• There are two types of shape (Circle, Square)

Circle

CVA Exercise (2)

Pen

write() { //inkImpl}

Pencil

write() { //leadImpl}

Writer

write()

Square

Shape

print()

• Each shape can print itself on different writers

Circle

Programming by Intention

• "So what do we want to do"?

Perspective

• Conceptual

• Specification

• Implementation

Starbucks

• Create a software for cashier and barista

• A program accepts order from user

• Retrieve cost based on the order

• A program shows the barista what to do

Starbucks• A program creates

order from user

• Retrieve cost based on the order

• A program shows the barista what to do

order = user.createOrder()

cost = order.getCost()

inst = order.whatToDo()

Starbucks

• Select Size of cup (S,M,L)

• (S) Cup -> Coffee

• (M) Cup -> Coffee x 2

• (L) Cup -> Coffee x 3

• S = 100, M = 120, L = 150

order = user.createOrder() { selectSize() }

cost = order.getCost() inst = order.whatToDo()

Starbucks

• Select Size of cup (S,M,L)

• (S) Cup -> Coffee

• (M) Cup -> Coffee x 2

• (L) Cup -> Coffee x 3

• S = 100, M = 120, L = 150

M

coffee() { //2}price() { //120}

Cup

coffee()price()

S

coffee() { //1}price() { //100}

L

coffee() { //3}price() { //150}

Starbucks

order = user.createOrder() { selectSize() }

cost = order.getCost() { order.getCup().getPrice() } M

coffee() { //2}price() { //120}

Cup

coffee()price()

S

coffee() { //1}price() { //100}

L

coffee() { //3}price() { //150}

Order

Closing Thoughts

When does design starts?When does it end?

Happy Coding! (Designing)

Other slides

Starbucks (v2)• Select Coffee Type (Hot/Cold) [ cold serve with ice ]

• Select Size of cup (S,M,L)

• (S) Cup -> Coffee

• (M) Cup -> Coffee x 2

• (L) Cup -> Coffee x 3

• S = 100, M = 120, L = 150, Hot/Cold = Same price

Starbucks (v3)• Select Coffee Type (Hot/Cold) [ cold serve with ice ]

• Americano [ Coffee + Water ]

• Cappuccino [ Coffee + Milk + Whip the milk ]

• Latte [ Coffee + Milk ]

• Select Size of cup (S,M,L)

• (S) Cup -> Coffee

• (M) Cup -> Coffee x 2

• (L) Cup -> Coffee x 3

• S = 100, M = 120, L = 150, Hot/Cold = Same price, Latte +10, Cappucino + 20