優化開發環境 無料提升戰鬥力

138
Maxis Kao | Oct. 19, 2016 > 優化開發環境 無料提升

Upload: maxis-kao

Post on 16-Apr-2017

92 views

Category:

Software


0 download

TRANSCRIPT

Page 1: 優化開發環境 無料提升戰鬥力

Maxis Kao | Oct. 19, 2016

> 優化開發環境 無料提升戰⾾鬥⼒力

Page 2: 優化開發環境 無料提升戰鬥力

Maxis Kao

➔ Software Engineer at Yahoo

➔ Top Hack of Yahoo TW/JP Joint Hackday

➔ Winner of Yahoo Bot Challenge

Page 3: 優化開發環境 無料提升戰鬥力
Page 4: 優化開發環境 無料提升戰鬥力
Page 5: 優化開發環境 無料提升戰鬥力

範疇

Page 7: 優化開發環境 無料提升戰鬥力

環境決定論

Page 8: 優化開發環境 無料提升戰鬥力

⼯工程師⽣生態系

Page 9: 優化開發環境 無料提升戰鬥力

⾓角⾊色 / 需求• RD:程式

• PM:時程

• Company:成本 + ⾵風險

• Client:產品

Page 10: 優化開發環境 無料提升戰鬥力

原始⼈人寫程式

Page 11: 優化開發環境 無料提升戰鬥力

很久很久以前• PM:明天新功能上線!

• RD 1:⼤大部份都做好了,等等跟 RD 2 合併

• RD 2:我只差剩下的⼀一些⼩小 bug 待會修⼀一下就好

• QA:看起來還⾏行,但疑似有些 bug 無法重現 (reproduce)

• PM:沒關係,晚上衝⼀一下!明天開⼼心上線

Page 12: 優化開發環境 無料提升戰鬥力

半夜 12 點

Page 13: 優化開發環境 無料提升戰鬥力

RD• RD 1:我們來合⼀一下 code

[ 經過漫⻑⾧長的半⼩小時,解 conflict ]

• RD 2:奇怪為什麼我的電腦上有錯你的沒有

• RD 1:等等!我現在⼜又跑出奇怪的 bug,先來速速解⼀一下

Page 14: 優化開發環境 無料提升戰鬥力

QA• 之前壞掉的好像修好了

• 原本好的貌似變得不穩定

• 到底什麼時候可以給我最終版

Page 15: 優化開發環境 無料提升戰鬥力

PM• 什麼?!剛剛不是說快弄好了

• 乖乖

• 踱步

• 抓頭

Page 16: 優化開發環境 無料提升戰鬥力

早上 7 點

Page 17: 優化開發環境 無料提升戰鬥力

上線

Page 18: 優化開發環境 無料提升戰鬥力

悲劇

Page 19: 優化開發環境 無料提升戰鬥力

現代⼈人寫程式

Page 20: 優化開發環境 無料提升戰鬥力

“什麼是環境?”

Page 21: 優化開發環境 無料提升戰鬥力
Page 22: 優化開發環境 無料提升戰鬥力
Page 23: 優化開發環境 無料提升戰鬥力

⼯工作環境 開發環境 開發流程

Page 24: 優化開發環境 無料提升戰鬥力

⼯工作環境

Page 25: 優化開發環境 無料提升戰鬥力

M A C B O O K P R O

蘋 果

I P H O N E

寫 很 滿 的 筆 記 本

搖 滾 樂 + 莫 扎 特

便 宜 的 咖 啡

在 講 設 計 的 書很 普 通 的 鉛 筆

⼤大 桌 ⼦子

密 密 ⿇麻 ⿇麻 像 駭 客 ⼀一 樣

I K E A 的 檯 燈

Page 26: 優化開發環境 無料提升戰鬥力

開發環境 / ⼯工具

Page 27: 優化開發環境 無料提升戰鬥力

開發環境• OS

• Text editors

• Command line tools

• Web Platform

Page 28: 優化開發環境 無料提升戰鬥力

OS• Windows  

• Linux  

• Mac  OS  

• Ubuntu  

• Debian

Page 29: 優化開發環境 無料提升戰鬥力

Text editors• Notepad

Page 30: 優化開發環境 無料提升戰鬥力

Text editors• Notepad  

• Sublime  Text

Page 31: 優化開發環境 無料提升戰鬥力

Text editors• Notepad  

• Sublime  Text  

• vim  

• emacs

Page 32: 優化開發環境 無料提升戰鬥力

Command line tools• ZSH  (oh-­‐my-­‐zsh)

Page 33: 優化開發環境 無料提升戰鬥力

Command line tools• ZSH  (oh-­‐my-­‐zsh)  

• tmux  +  htop

Page 34: 優化開發環境 無料提升戰鬥力

Web platform as a service• AWS  

• Heroku  

• Google  App  Engine

Page 35: 優化開發環境 無料提升戰鬥力

開發環境 / 流程

Page 36: 優化開發環境 無料提升戰鬥力

程式設計 ≠ 軟體開發

Page 37: 優化開發環境 無料提升戰鬥力

個⼈人開發環境⼤大⼈人不在家,怎麼做都開⼼心

Page 38: 優化開發環境 無料提升戰鬥力

團隊開發流程⾃自⼰己亂寫就算了,但要為別⼈人設想

Page 39: 優化開發環境 無料提升戰鬥力

“10+ Deploys per Day Dev and Ops Cooperation at flickr”

- John Allspaw and Paul Hammond

Page 40: 優化開發環境 無料提升戰鬥力

Patrick DeBois#devops

Page 41: 優化開發環境 無料提升戰鬥力

#devops since 2009

Page 42: 優化開發環境 無料提升戰鬥力
Page 43: 優化開發環境 無料提升戰鬥力

– 蔣渭⽔水

“同胞須團結,團結真有⼒力”

Page 44: 優化開發環境 無料提升戰鬥力

在 DevOps 出現之前...

Page 45: 優化開發環境 無料提升戰鬥力

– an angry ops guy

“It’s not my machines, it’s your code!”

Page 46: 優化開發環境 無料提升戰鬥力

– an angry dev guy

“It’s not my code, it’s your machines!”

Page 47: 優化開發環境 無料提升戰鬥力

Dev Ops改變 穩定

Page 48: 優化開發環境 無料提升戰鬥力

Dev Ops改變 穩定

Page 49: 優化開發環境 無料提升戰鬥力

DevOps key points• automated infrastructure (⾃自動化集成)

• shared version control (共⽤用程式碼)

• one step build and deploy (持續建構/部署)

• feature flags (主幹開發)

• shared metrics (不藏私)

• IRC and IM robots (信息整合)

Page 50: 優化開發環境 無料提升戰鬥力

A survey

• 來源: RightScale

• 受訪者: 1,060 資訊⼈人員

• 42% 就職於超個 1,000 ⼈人的⼤大公司

Page 51: 優化開發環境 無料提升戰鬥力
Page 52: 優化開發環境 無料提升戰鬥力
Page 53: 優化開發環境 無料提升戰鬥力
Page 54: 優化開發環境 無料提升戰鬥力
Page 56: 優化開發環境 無料提升戰鬥力

“XP”

Page 57: 優化開發環境 無料提升戰鬥力
Page 58: 優化開發環境 無料提升戰鬥力

“Extreme Programming” - Kent Beck since 1996

Page 59: 優化開發環境 無料提升戰鬥力

YAHOO! +企業經驗

Page 60: 優化開發環境 無料提升戰鬥力

Extreme Programming• Fine-scale feedback (細微回饋)

• Continuous process (持續程式)

• Shared understanding (共識)

• Programmer welfare (⼯工程師的利益)

Page 61: 優化開發環境 無料提升戰鬥力

Fine-scale feedback (細微回饋)• Whole team

• Test-driven development (TDD)

• Planning game

• Pair programming

Page 62: 優化開發環境 無料提升戰鬥力

Fine-scale feedback (細微回饋)• Whole team

• Test-driven development (TDD)

• Planning game

• Pair programming

Page 63: 優化開發環境 無料提升戰鬥力

Dev ⬄ Client

Page 64: 優化開發環境 無料提升戰鬥力

Fine-scale feedback (細微回饋)• Whole team

• Test-driven development (TDD)

• Planning game

• Pair programming

Page 65: 優化開發環境 無料提升戰鬥力

先寫測試! 先寫測試! 先寫測試!

Page 66: 優化開發環境 無料提升戰鬥力

test environments & frameworks

Page 67: 優化開發環境 無料提升戰鬥力

Fine-scale feedback (細微回饋)• Whole team

• Test-driven development (TDD)

• Planning game (策劃遊戲)

• Pair programming

Page 68: 優化開發環境 無料提升戰鬥力

Exploration phase

• Write a Story

• Estimate a Story

• Split a Story

Page 69: 優化開發環境 無料提升戰鬥力

Commitment phase

• Sort by Value

• Sort by Risk

• Set Velocity

• Choose scope

Page 70: 優化開發環境 無料提升戰鬥力

Steering phase

• 估計誤差

• 客⼾戶需求改變

Page 71: 優化開發環境 無料提升戰鬥力

Fine-scale feedback (細微回饋)• Whole team

• Test-driven development (TDD)

• Planning game

• Pair programming (⼀一起寫扣)

Page 72: 優化開發環境 無料提升戰鬥力
Page 73: 優化開發環境 無料提升戰鬥力

“Is pair programming worth it?”

Page 74: 優化開發環境 無料提升戰鬥力

Continuous process (持續程式)• Small releases

• Continuous integration

• Design improvement

Page 75: 優化開發環境 無料提升戰鬥力

Continuous process (持續程式)• Small releases

• Continuous integration

• Design improvement

Page 76: 優化開發環境 無料提升戰鬥力
Page 77: 優化開發環境 無料提升戰鬥力

Continuous process (持續程式)• Small releases

• Continuous integration (持續整合)

• Design improvement

Page 78: 優化開發環境 無料提升戰鬥力

– Standard Bank: Our DevOps Journey

“The Chop Chop team”

Page 79: 優化開發環境 無料提升戰鬥力

Dawie (CIO) + Dev + Ops

War Room !

Page 80: 優化開發環境 無料提升戰鬥力

2000 x軟體交付速度的破壞性變⾰革

Page 81: 優化開發環境 無料提升戰鬥力

– Marissa Mayer

“沒有持續交付 (Continuous Delivery) 專案不得上線,我不是在說笑”

Page 82: 優化開發環境 無料提升戰鬥力

100%Continuous Delivery

Page 83: 優化開發環境 無料提升戰鬥力

– SJ Chou, Senior Engineer at Foxconn

“有事沒事就把⼤大家寫的 code 合起來 跑看看有沒有錯”

持續 整合

Page 84: 優化開發環境 無料提升戰鬥力

– SJ Chou, Senior Engineer at Foxconn

“有事沒事就把⼤大家寫的 code 合起來 跑看看有沒有錯”

持續 整合

Page 85: 優化開發環境 無料提升戰鬥力

– SJ Chou, Senior Engineer at Foxconn

“有事沒事就把⼤大家寫的 code 合起來 跑看看有沒有錯”

持續 整合

Page 86: 優化開發環境 無料提升戰鬥力

天下武功 無堅不破 唯快不破

Page 87: 優化開發環境 無料提升戰鬥力
Page 88: 優化開發環境 無料提升戰鬥力
Page 89: 優化開發環境 無料提升戰鬥力

Continuous process (持續程式)• Small releases

• Continuous integration

• Design improvement

Page 90: 優化開發環境 無料提升戰鬥力

“Refactoring”Improving the Design of Existing Code

Page 91: 優化開發環境 無料提升戰鬥力

Refactoring: Improving the Design of Existing Code

Martin Fowler

Page 92: 優化開發環境 無料提升戰鬥力

Refactoring ⬄ Users

Page 93: 優化開發環境 無料提升戰鬥力

Refactoring  is  boring.

Page 94: 優化開發環境 無料提升戰鬥力

ok, but how?

Page 95: 優化開發環境 無料提升戰鬥力
Page 96: 優化開發環境 無料提升戰鬥力

“Bad Smells”

Page 97: 優化開發環境 無料提升戰鬥力

Long Parameter List. Divergent Change. Shotgun Surgery.

Feature Envy. Data Clumps.

Primitive Obsession. Switch Statements.

Parallel Inheritance Hierarchies. Lazy Class.

Speculative Generality. Temporary Field. Message Chains.

Middle Man. Inappropriate Intimacy.

Alternative Classes with Different Interfaces. Incomplete Library Class.

Data Class.

Page 98: 優化開發環境 無料提升戰鬥力

Bad smells• Duplicated Code

• Long Method / Large Class

• Long Parameter List

• Switch Statements

• Indecent Exposure

• Feature Envy

• Comments

Page 99: 優化開發環境 無料提升戰鬥力

Duplicated Code• 恐怖份⼦子⾸首腦

• Don't Repeat Yourself!

Page 100: 優化開發環境 無料提升戰鬥力

Long Method / Large Class• ⼀一個 main() 上萬⾏行

• 負擔過多責任

• Extract Class / Subclass / Interface

Page 101: 優化開發環境 無料提升戰鬥力

Long Parameter List• Hard to understand

• Inconsistent

• set  (a,  b,  c,  x,  y,  z,  flag,  amount)  

• set  (a,  b,  c,  y,  x,  z,  flag,  amount)

Page 102: 優化開發環境 無料提升戰鬥力

Switch Statements• 「好的物件導向程式應該少⽤用 switch」

• open-closed principle (OCP)

Page 103: 優化開發環境 無料提升戰鬥力

Indecent Exposure• 家⾨門要記得關,沒必要的東⻄西不要隨便 public

Page 104: 優化開發環境 無料提升戰鬥力

Feature Envy• 特性依戀

Page 105: 優化開發環境 無料提升戰鬥力

Comments

/*        *    This  is  a  add  function,  returns  a  +  b    */  function  kerker  (a,  b){      return  a  +  b;  }

Page 106: 優化開發環境 無料提升戰鬥力

Comments

/*        *    Returns  a  +  b    */  function  add  (a,  b){      return  a  +  b;  }

Page 107: 優化開發環境 無料提升戰鬥力

@use JSDoc

Page 108: 優化開發環境 無料提升戰鬥力
Page 109: 優化開發環境 無料提升戰鬥力

Shared understanding (共識)• Simple design

• System metaphor

• Coding standard

• Collective code ownership

Page 110: 優化開發環境 無料提升戰鬥力

Shared understanding (共識)• Simple design

• System metaphor

• Coding standard

• Collective code ownership

Page 111: 優化開發環境 無料提升戰鬥力

Shared understanding (共識)• Simple design

• System metaphor

• Coding standard

• Collective code ownership

Page 112: 優化開發環境 無料提升戰鬥力

Shared understanding (共識)• Simple design

• System metaphor

• Coding standard

• Collective code ownership

Page 113: 優化開發環境 無料提升戰鬥力

long_function_name  

vs  

longFunctionName

Page 114: 優化開發環境 無料提升戰鬥力

Shared understanding (共識)• Simple design

• System metaphor

• Coding standard

• Collective code ownership

Page 115: 優化開發環境 無料提升戰鬥力

– SJ Chou, Senior Engineer at Foxconn

“有事沒事就把⼤大家寫的 code 合起來 跑看看有沒有錯”

持續 整合

Page 116: 優化開發環境 無料提升戰鬥力

version control• 根據定義,可以⽤用以下 check list 判斷是否 version control

Version Control check list:

[ ] record changes over time [ ] recall a specific version

Page 117: 優化開發環境 無料提升戰鬥力

version control• 根據定義,可以⽤用以下 check list 判斷是否 version control

Version Control check list:

[v] record changes over time [v] recall a specific version

Page 118: 優化開發環境 無料提升戰鬥力

“collective”

Page 119: 優化開發環境 無料提升戰鬥力

version control systems

Page 120: 優化開發環境 無料提升戰鬥力

Git ≠ Github

Page 121: 優化開發環境 無料提升戰鬥力

Git flowA successful Git branching model

Vincent Driessen

Page 122: 優化開發環境 無料提升戰鬥力

2 main + 3 supporting branches

Page 123: 優化開發環境 無料提升戰鬥力

main branches• develop  

• master

Page 124: 優化開發環境 無料提升戰鬥力

supporting branches• feature  

• release  

• hotfix

Page 125: 優化開發環境 無料提升戰鬥力

Commit Messages

Page 126: 優化開發環境 無料提升戰鬥力

* fde679b  -­‐  very  hot  fix  <allen>  

* d0ad381  -­‐  Kerker.  <maxis>  

* f007579  -­‐  test  <jason>  

* 09b9813  -­‐  fix  bug.  <maxis>  

* 2430918  -­‐  fix  bugs  <allen>  

* fde679b  -­‐  abc123  <jason>  

* b6c7ee1  -­‐  hot  fix  <allen>

Page 127: 優化開發環境 無料提升戰鬥力
Page 128: 優化開發環境 無料提升戰鬥力

7 rules of a great commit message

• Separate subject from body with a blank line

• Limit the subject line to 50 characters

• Capitalize the subject line

• Do not end the subject line with a period

• Use the imperative mood in the subject line

• Wrap the body at 72 characters

• Use the body to explain what and why vs. how

Page 129: 優化開發環境 無料提升戰鬥力

* fde679b  -­‐  Fix  typo  in  the  Search  Box  <allen>  

* d0ad381  -­‐  Revamp  Search  Box  UI  <maxis>  

* f007579  -­‐  Add  new  Search  Box  UI  <jason>  

* 09b9813  -­‐  fix  bug.  <maxis>  

* 2430918  -­‐  fix  bugs  <allen>  

* fde679b  -­‐  abc123  <jason>  

* b6c7ee1  -­‐  hot  fix  <allen>

Page 130: 優化開發環境 無料提升戰鬥力
Page 131: 優化開發環境 無料提升戰鬥力

Programmer welfare (⼯工程師的利益)

• Sustainable pace

Page 132: 優化開發環境 無料提升戰鬥力

“40-Hour Work Week”

Page 133: 優化開發環境 無料提升戰鬥力

雅⻁虎經驗

Page 134: 優化開發環境 無料提升戰鬥力

• Training - Ninja Kata

• DevOps - Docker

• CI/CD - Jenkins

Page 135: 優化開發環境 無料提升戰鬥力

– Peter Drucker

“Do the right thing”

Page 136: 優化開發環境 無料提升戰鬥力

Thanks :P

Page 137: 優化開發環境 無料提升戰鬥力

Q / A

Page 138: 優化開發環境 無料提升戰鬥力

可以這樣找到我

• Maxis Kao

[email protected]

• http://maxis1718.github.io