software punk

43
Software Punk Lior Bar-On, 2016 Controversial ideas in Software Development That just might work. Source: songpop.wikia.com

Upload: lior-bar-on

Post on 16-Apr-2017

371 views

Category:

Software


0 download

TRANSCRIPT

Software Punk

Lior Bar-On, 2016

Controversial ideas in Software Development That just might work.

Source: songpop.wikia.com

Who is this Guy? (Lior Bar-On)

בלוג ארכיטקטורת תוכנה

Developer

Architect

Chief ArchitectBlogger

Inheritance & OOSource: schedule.sxsw.com

Inheritance is a bold violation of OO Principles!

1. Encapsulation (“הכמסה”)2. PolyMorphism (“ריבוי-צורות”)3. Inheritance (“הורשה”)

Violation

Flawed Inheritance Code Example

Composition > Inheritance

“... our second principle of object-oriented design:

Favor object composition over class inheritance.

Source: http://slidedeck.io/parnurzeal/why-opensource-slides Source: Addison wesley

A moment of Skepticism...

while (condition_always_true) { // do something ...}

Inheritance as tool for (poor?) abstractions

Inheritance as tool for (poor?) abstractions

Inheritance as tool for (poor?) abstractions

?

Inheritance as tool for (poor?) abstractions

Inheritance as tool for (poor?) abstractions

?

Inheritance as tool for (poor?) abstractions

?

Inheritance as tool for (poor?) abstractions

?

Inheritance as tool for (poor?) abstractions

Black Cab → A, B, C, D

Yellow Cab → A, E, F

Green Cab → A, B, D, E

Scooter → C, E, G

PHV → B, C, F

Inheritance breaking our reading flow

?

?

Recap

Inheritance can cause “unexpected behavior” - but it is rare.

Inheritance (“is-a” delegation) is too limited to expressed real world domain objects. Use Inheritance only with dead-simple cases.

1

2

In some programming languages, Inheritance makes the code less expressive.3

Bad, bad Abstractions

D.R.Y Happiness!

DRY = Don’t Repeat YourselfSource: dreamstime

D.R.Y Happiness @Gett-API

HTTP Retry: The POST case

...IDEMPOTENT_METHODS = [“GET”, “PUT”]if method in IDEMPOTENT_METHODS { // http request retry}...

HTTP Retry: The POST case #2

...if can_retry { if _err == CONNECTION_ERROR { // http request retry }} ...

The Safe Methods case

...if method == “GET” { // use cache}...

The Safe Methods Case #2 - POST (reading)

...if is_cacheable { // use cache}...

Cache TTL settings

...// some logic with cache times......

The Fallback cache Case

...if _err == CONNECTION_ERROR { // try to load response from fallback cache}...

Not very DRY, but simpler!

Code Duplication is mushrooming

The non-visible dependencies of that system...

Recap

Not only code Rots. Abstractions Rot too.It’s okay to occasionally favor Code Duplications and avoid non-meaningful abstraction.

When an Abstraction rots: Stop. do a reverse, and return the code duplication.

1

2

You Spend too much on Unit Tests

Automation “should” improve things...

Source: Lucidcharts

There are several ways to achievehigh quality....

Source: profiles.com.sg

Type A: Codename “Lisa” (a Unit Test)

Source: a presentation by Lior Bar-On

Type A: Codename “Lisa” (a Unit Test)

Source: a presentation by Lior Bar-On

Isolated unit test

Type B Codename “Bart”

Source: a presentation by Lior Bar-On

Type B Codename “Bart”

Source: a presentation by Lior Bar-On

Unit-Integration Test

Integration Test

Type B Codename “Bart”

Source: a presentation by Lior Bar-On

Example: Aggregating 11 model methods into a single test

Type C - Codename “Cat In The Hat”

Source: marocdeserttours.wordpress.com

Type C - Codename “Cat In The Hat”

Great Production Monitoring /w Continuous Deployment

Type C - Codename “Cat In The Hat”

Source: marocdeserttours.wordpress.com

Ideal Target: when covering 90%+ of the cases is not possible - or just too expensive

Recap

Unit Tests is great - but it has its costs.It fit perfectly for logical code units (if / for)

Integration / Unit-Integration tests are more broad - but more cost efficient.

1

2Sometimes, it worth monitoring things only on production.When done well - it can be cheap, otherwise - very expensive.

3

Don’t take things for granted