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

Post on 16-Apr-2017

92 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Maxis Kao | Oct. 19, 2016

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

Maxis Kao

➔ Software Engineer at Yahoo

➔ Top Hack of Yahoo TW/JP Joint Hackday

➔ Winner of Yahoo Bot Challenge

範疇

環境決定論

⼯工程師⽣生態系

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

• PM:時程

• Company:成本 + ⾵風險

• Client:產品

原始⼈人寫程式

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

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

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

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

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

半夜 12 點

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

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

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

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

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

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

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

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

• 乖乖

• 踱步

• 抓頭

早上 7 點

上線

悲劇

現代⼈人寫程式

“什麼是環境?”

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

⼯工作環境

M A C B O O K P R O

蘋 果

I P H O N E

寫 很 滿 的 筆 記 本

搖 滾 樂 + 莫 扎 特

便 宜 的 咖 啡

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

⼤大 桌 ⼦子

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

I K E A 的 檯 燈

開發環境 / ⼯工具

開發環境• OS

• Text editors

• Command line tools

• Web Platform

OS• Windows  

• Linux  

• Mac  OS  

• Ubuntu  

• Debian

Text editors• Notepad

Text editors• Notepad  

• Sublime  Text

Text editors• Notepad  

• Sublime  Text  

• vim  

• emacs

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

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

• tmux  +  htop

Web platform as a service• AWS  

• Heroku  

• Google  App  Engine

開發環境 / 流程

程式設計 ≠ 軟體開發

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

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

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

- John Allspaw and Paul Hammond

Patrick DeBois#devops

#devops since 2009

– 蔣渭⽔水

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

在 DevOps 出現之前...

– an angry ops guy

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

– an angry dev guy

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

Dev Ops改變 穩定

Dev Ops改變 穩定

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

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

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

• feature flags (主幹開發)

• shared metrics (不藏私)

• IRC and IM robots (信息整合)

A survey

• 來源: RightScale

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

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

“XP”

“Extreme Programming” - Kent Beck since 1996

YAHOO! +企業經驗

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

• Continuous process (持續程式)

• Shared understanding (共識)

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

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

• Test-driven development (TDD)

• Planning game

• Pair programming

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

• Test-driven development (TDD)

• Planning game

• Pair programming

Dev ⬄ Client

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

• Test-driven development (TDD)

• Planning game

• Pair programming

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

test environments & frameworks

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

• Test-driven development (TDD)

• Planning game (策劃遊戲)

• Pair programming

Exploration phase

• Write a Story

• Estimate a Story

• Split a Story

Commitment phase

• Sort by Value

• Sort by Risk

• Set Velocity

• Choose scope

Steering phase

• 估計誤差

• 客⼾戶需求改變

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

• Test-driven development (TDD)

• Planning game

• Pair programming (⼀一起寫扣)

“Is pair programming worth it?”

Continuous process (持續程式)• Small releases

• Continuous integration

• Design improvement

Continuous process (持續程式)• Small releases

• Continuous integration

• Design improvement

Continuous process (持續程式)• Small releases

• Continuous integration (持續整合)

• Design improvement

– Standard Bank: Our DevOps Journey

“The Chop Chop team”

Dawie (CIO) + Dev + Ops

War Room !

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

– Marissa Mayer

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

100%Continuous Delivery

– SJ Chou, Senior Engineer at Foxconn

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

持續 整合

– SJ Chou, Senior Engineer at Foxconn

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

持續 整合

– SJ Chou, Senior Engineer at Foxconn

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

持續 整合

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

Continuous process (持續程式)• Small releases

• Continuous integration

• Design improvement

“Refactoring”Improving the Design of Existing Code

Refactoring: Improving the Design of Existing Code

Martin Fowler

Refactoring ⬄ Users

Refactoring  is  boring.

ok, but how?

“Bad Smells”

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.

Bad smells• Duplicated Code

• Long Method / Large Class

• Long Parameter List

• Switch Statements

• Indecent Exposure

• Feature Envy

• Comments

Duplicated Code• 恐怖份⼦子⾸首腦

• Don't Repeat Yourself!

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

• 負擔過多責任

• Extract Class / Subclass / Interface

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)

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

• open-closed principle (OCP)

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

Feature Envy• 特性依戀

Comments

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

Comments

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

@use JSDoc

Shared understanding (共識)• Simple design

• System metaphor

• Coding standard

• Collective code ownership

Shared understanding (共識)• Simple design

• System metaphor

• Coding standard

• Collective code ownership

Shared understanding (共識)• Simple design

• System metaphor

• Coding standard

• Collective code ownership

Shared understanding (共識)• Simple design

• System metaphor

• Coding standard

• Collective code ownership

long_function_name  

vs  

longFunctionName

Shared understanding (共識)• Simple design

• System metaphor

• Coding standard

• Collective code ownership

– SJ Chou, Senior Engineer at Foxconn

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

持續 整合

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

Version Control check list:

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

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

Version Control check list:

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

“collective”

version control systems

Git ≠ Github

Git flowA successful Git branching model

Vincent Driessen

2 main + 3 supporting branches

main branches• develop  

• master

supporting branches• feature  

• release  

• hotfix

Commit Messages

* 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>

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

* 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>

Programmer welfare (⼯工程師的利益)

• Sustainable pace

“40-Hour Work Week”

雅⻁虎經驗

• Training - Ninja Kata

• DevOps - Docker

• CI/CD - Jenkins

– Peter Drucker

“Do the right thing”

Thanks :P

Q / A

可以這樣找到我

• Maxis Kao

• maxis1718@gmail.com

• http://maxis1718.github.io

top related