design principles 4 hackers - tech3camp (28142014)

51
Design principles for hackers Kuba Marchwicki @kubem

Upload: kuba-marchwicki

Post on 27-Jun-2015

318 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Design principles 4 hackers - tech3camp (28142014)

Design principles for hackers

Kuba Marchwicki@kubem

Page 2: Design principles 4 hackers - tech3camp (28142014)

@kubem

Page 3: Design principles 4 hackers - tech3camp (28142014)

@kubem

Page 4: Design principles 4 hackers - tech3camp (28142014)

Complex vs complicated

Simple to read, learn and understand

How easy it’s for novice programmer can maintain a significant program

Make stuff simple but not simplistic

@kubem

Page 5: Design principles 4 hackers - tech3camp (28142014)
Page 6: Design principles 4 hackers - tech3camp (28142014)

@kubem

Page 7: Design principles 4 hackers - tech3camp (28142014)

@kubem

Page 8: Design principles 4 hackers - tech3camp (28142014)

A flash is comming

Page 9: Design principles 4 hackers - tech3camp (28142014)

What’s wrong with this code

Page 10: Design principles 4 hackers - tech3camp (28142014)
Page 11: Design principles 4 hackers - tech3camp (28142014)

Ktoś upowszechnił

Page 12: Design principles 4 hackers - tech3camp (28142014)

Podstawowe zasady Wuja

• Nazywaj zmiennej w taki a taki sposób• Stosuj komentarze w takich a nie innych

przypadkach• Dziel funkcje na części zgodnie z takimi a

takimi zasadami• Stosuj abstrakcje, symetrię, prawo Demeter• Testuj, testuj, testuj, red – green – ….• Refaktoruj

@kubem

Page 13: Design principles 4 hackers - tech3camp (28142014)

Ktoś położył podwaliny

Page 14: Design principles 4 hackers - tech3camp (28142014)

• Kod jest podstawowym medium komunikacji w projekcie

• Jako zespół jesteśmy jednością– Jak ja pójdę na skróty, to kolega będzie się męczył– I jako całość i tak będziemy nieefektywni

• Programy są częściej czytane niż pisane• Więcej czasu poświęcamy na modyfikację

istniejącego kodu niż na tworzenie nowego

Wartości

@kubem

Page 15: Design principles 4 hackers - tech3camp (28142014)

• Komunikacja – kod źródłowy powinno się czytać jak książkę

• Prostota – wprowadzaj złożoność tylko wtedy, kiedy jest to konieczne

• Elastyczność – elastyczność to dodatkowa złożoność, więc wprowadzaj ją tylko tam gdzie to konieczne

Implementation patterns

@kubem

Page 16: Design principles 4 hackers - tech3camp (28142014)

• Lokalne konsekwencje – zmiana w jednym miejscu nie powoduje zmian w innych

• Minimalne powtórzenia – DRY• Dane i logika razem – ponieważ dane i logika z

reguły zmieniają się w tym samym czasie• Symetria– utrzymuj podobny poziom

abstrakcji w obrębie metody / klasy

Implementation patterns

@kubem

Page 17: Design principles 4 hackers - tech3camp (28142014)

„Czysty kod jest prosty i bezpośredni. Czysty kod czyta się jak dobrze napisaną

prozę. Czysty kod nigdy nie zaciemnia zamiarów projektanta; jest pełen

trafnych abstrakcji i prostych ścieżek sterowania.”

Grady Booch – to jeden z tych panów od UMLa

Page 18: Design principles 4 hackers - tech3camp (28142014)
Page 19: Design principles 4 hackers - tech3camp (28142014)
Page 20: Design principles 4 hackers - tech3camp (28142014)
Page 21: Design principles 4 hackers - tech3camp (28142014)
Page 22: Design principles 4 hackers - tech3camp (28142014)
Page 23: Design principles 4 hackers - tech3camp (28142014)
Page 24: Design principles 4 hackers - tech3camp (28142014)

Affordance

a quality of an object, which allows an individual to perform an action. For

example, a knob affords twisting, and perhaps pushing, while a cord affords

pulling

@kubem

Page 25: Design principles 4 hackers - tech3camp (28142014)
Page 26: Design principles 4 hackers - tech3camp (28142014)
Page 27: Design principles 4 hackers - tech3camp (28142014)
Page 28: Design principles 4 hackers - tech3camp (28142014)
Page 29: Design principles 4 hackers - tech3camp (28142014)
Page 30: Design principles 4 hackers - tech3camp (28142014)
Page 31: Design principles 4 hackers - tech3camp (28142014)

public class Sql { public Sql(String table, Column[] columns) public String create() public String insert(Object[] fields) public String selectAll() public String fieldByKey(

String keyColumn, String keyValue) private String ColumnList(Column[] columns) private String valuesList(

Object[] fields, final Column[] columns)}

Page 32: Design principles 4 hackers - tech3camp (28142014)

abstract public class Sql { public Sql(String table, Column[] columns) abstract public String generate();}

public class CreateSql extends Sql { public CreateSql(String table, Column[] columns) @Override public String generate()}

public class SelectSql extends Sql { public SelectSql(String table, Column[] columns) @Override public String generate()}

public class InsertSql extends Sql { public InsertSql(String table, Column[] columns) @Override public String generate() private String valuesList(Object[] fields, final Column[] columns)}

public class FindKeyBySql extends Sql { public FindKeyBySql(String table, Column[] columns, String keyColumn, String keyValue) @Override public String generate()}

public class ColumnList { public ColumnList(Column[] columns) public String generate()}

Page 33: Design principles 4 hackers - tech3camp (28142014)

George Miller

Page 34: Design principles 4 hackers - tech3camp (28142014)
Page 35: Design principles 4 hackers - tech3camp (28142014)

number of method parametersfunction / class size

external API method namesreadable & descriptive naming

@kubem

Page 36: Design principles 4 hackers - tech3camp (28142014)

@kubem

Page 37: Design principles 4 hackers - tech3camp (28142014)

Multi store memory model

@kubem

Page 38: Design principles 4 hackers - tech3camp (28142014)
Page 39: Design principles 4 hackers - tech3camp (28142014)
Page 40: Design principles 4 hackers - tech3camp (28142014)
Page 41: Design principles 4 hackers - tech3camp (28142014)
Page 42: Design principles 4 hackers - tech3camp (28142014)

Mihaly Csikszentmigalyi

Page 43: Design principles 4 hackers - tech3camp (28142014)

ME-HI CHICKS-SENT-ME-HI

Page 44: Design principles 4 hackers - tech3camp (28142014)
Page 45: Design principles 4 hackers - tech3camp (28142014)
Page 46: Design principles 4 hackers - tech3camp (28142014)

BJ Fogg

Page 47: Design principles 4 hackers - tech3camp (28142014)
Page 48: Design principles 4 hackers - tech3camp (28142014)

Po co to wszystko?

Page 49: Design principles 4 hackers - tech3camp (28142014)

Shu-Ha-Ri

@kubem

Page 50: Design principles 4 hackers - tech3camp (28142014)

Shu-Ha-Ri

Kuba Marchwicki@kubem

http://goo.gl/zd1YhU

Page 51: Design principles 4 hackers - tech3camp (28142014)

In case you ask – we are hiring