Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
How to be a better PHP Developer
大澤木小鐵
January 12, 2013
Programming
62
39k
How to be a better PHP Developer
WebConf Taiwan 2013 議程簡報
大澤木小鐵
January 12, 2013
Tweet
Share
More Decks by 大澤木小鐵
See All by 大澤木小鐵
Effective Unit Testing
jaceju
3
510
JSConf Asia 2014 Sessions
jaceju
4
330
What happens in Laravel 4 bootstraping
jaceju
9
520
Deal with Laravel assets by Bower & Gulp
jaceju
30
1.8k
Leaning MVC By Example
jaceju
0
300
ng-conf_2014
jaceju
2
880
The Power of JavaScript in JSConf.Asia 2013
jaceju
5
340
jQuery vs AngularJS, dochi?
jaceju
20
2.7k
Begining Composer
jaceju
24
4.5k
Other Decks in Programming
See All in Programming
git on intellij
hiroto_kitamura
0
170
engineer
spacemarket
0
2.3k
Gitlab CIでMRを自動生成する
forcia_dev_pr
0
120
プロダクトのタイプ別 GraphQL クライアントの選び方
shozawa
0
5.4k
設計の学び方:自分流のススメ
masuda220
PRO
10
7k
Scrum Fest Osaka 2022/5年で200人になったスタートアップの アジャイル開発の歴史とリアル
atamaplus
1
920
Haskellでオブジェクト指向プログラミング
koheisakata
0
120
Jetpack Compose best practices 動画紹介 @GoogleI/O LT会
takakitojo
0
350
Cybozu GoogleI/O 2022 LT会 - Input for all screens
jaewgwon
0
340
模組化的Swift架構(二) DDD速成
haifengkao
0
390
JSのウェブフレームワークで高速なルーターを実装する方法
usualoma
1
1.9k
Modern Android Developer ~ 안내서
pluu
1
640
Featured
See All Featured
In The Pink: A Labor of Love
frogandcode
131
21k
The Invisible Side of Design
smashingmag
290
48k
Designing for Performance
lara
597
63k
Designing Experiences People Love
moore
130
22k
Adopting Sorbet at Scale
ufuk
63
7.6k
Code Review Best Practice
trishagee
43
9.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
316
22k
Web Components: a chance to create the future
zenorocha
303
40k
JazzCon 2018 Closing Keynote - Leadership for the Reluctant Leader
reverentgeek
172
8.4k
Building Better People: How to give real-time feedback that sticks.
wjessup
344
17k
Art, The Web, and Tiny UX
lynnandtonic
280
17k
Scaling GitHub
holman
451
140k
Transcript
jaceju@webconf 2013 如何成為更好的 PHP 開發者 磚業也要專業
Jace Ju 大澤木小鐵 http://plurk.com/jaceju http://twitter.com/jaceju http://weibo.com/jaceju http://www.jaceju.net jace@gmail.com 新浪微博軟體工程師 PHP
開發者
匠
牆
塌
老闆的想法
微薪 技佳
PHP 的困境 不需要高門檻 大量舊資訊充斥 社群過於多元化
捫心自問 我們真的瞭解 PHP 嗎 要不要繼續學 PHP
第一式 瞭解 PHP
門
瞭解新版本 4.x → 5.x http://php.net/manual/en/migration5.php 5.2 → 5.3 http://php.net/manual/en/migration53.php
瞭解運作環境 Error Reporting Session Save Path Web Server OS
瞭解執行模式 Web 執行模式 命令列執行模式
瞭解語法 // 交換變數內容 list($a, $b) = array($b, $a); // 直接取得指定位置的值
list( , $el) = getElements(); // PHP 5.4 :⽤用⽅方括號來直接取⽤用元素 $el = getElements()[1];
瞭解原生函式 // Bad $diff_ids = array(); foreach ($ids as $id)
{ if (!in_array($id, $actual_ids)) { $diff_ids[] = $id; } } // Good $diff_ids = array_diff($ids, $actual_ids);
瞭解技術原理������� HTTP 協定 資料庫存取 檔案存取 ...
學會 SPL 及內建介面 Standard PHP Library http://www.php.net/manual/en/book.spl.php Predefined Interfaces http://www.php.net/manual/en/reserved.interfaces.php
第二式 開發工具
編輯器 語法高亮度 自動完成 API 查詢 函式或類別方法的查找 其他工具的整合
NetBeans for PHP http://netbeans.org/
Eclipse PDT http://www.eclipse.org/projects/project.php?id=tools.pdt
除錯工具 中斷點設置 完整執行堆棧資訊 變數內容追蹤 .........
Xdebug http://xdebug.org/
FirePHP http://www.firephp.org/
版本控制 歷史紀錄 還原版本 解決衝突 支線版本
GitHub http://github.com/
Git 教育訓練課程投影片 http://ihower.tw/blog/archives/6696/
程式碼等級 一,,,要能對得起自己的良心 二,,,不能考驗測試人員的耐心 三,,,要能得到上頭的歡心 四,,,要能獲得客戶的信心 五,,,要能受到其他開發者的關心
第三式 成為團隊一份子
群
良好的程式架構 使用 Framework 減少溝通成本 減少開發成本
遵守編碼標準 統一團隊編碼風格 PHP-FIG https://github.com/php-fig/fig-standards
套件管理������� 避免套件散落各地 統一套件載入方式 Composer http://getcomposer.org/ https://packagist.org/
第四式 學會把程式寫活
Any fool can write code that a computer can understand.
Good programmers write code that humans can understand. Martin Fowler
以抽象角度看事物 // 找出特定作者的所有⽂文章 $sql = 'SELECT * FROM articles WHERE
'; $sql .= 'author = :author'; $sth = $dbh->prepare($sql); $sth->execute(array( ':author' => 'jaceju' )); $articles = $sth->fetchAll();
以抽象角度看事物 // 找出特定作者的所有⽂文章 $blog = new Blog(); $articles = $blog->fetchArticlesByAuthor('jaceju');
讓程式容易佈署 <?php include '/home/web/my/config.php';
讓程式容易佈署 <?php include __DIR__ . '/config.php'; // 假設 __DIR__ 在執⾏行時期的值為
// "/home/web/my"
一開始做對系統純屬神話 要將系統寫活來應付變化
組 合
讓系統可以被擴充 統一抽象介面 定義插入點 Template Method / Observer 模組化設計 管理�������介面
協
第五式 自我要求
注意安全 SQL Injection Cross Site Script (XSS) Cross Site Request
Forgery (CSRF)
Filter Input, Escape Output 不要信任瀏覽器所回傳的資訊 也不要直接輸出敏感的資訊
開發時嚴格 上線時寬鬆 解決掉所有警告與錯誤 隱藏但紀錄線上環境的 錯誤訊息
天下網站 無堅不摧 唯快不破
第六式 效能
原則 不做重複的事 放到背景執行 空間換取時間 執行路徑越短越好 保持輕量化 必要時才初始化 有異動才更新 資料少時全抓 資料多時分段抓
事先計算 善用快取
不做重複的事 function fib($n) { if ($n < 2) return $n;
$f[$n] = fib($n - 2) + fib($n - 1); return $f[$n]; } echo fib(30), "\n"; // 結果: 832040 ,共執⾏行 5.59556889534 秒
不做重複的事 function fib($n) { static $f = array(); if (isset($f[$n]))
return $f[$n]; if ($n < 2) return $n; $f[$n] = fib($n - 2) + fib($n - 1); return $f[$n]; } echo fib(30), "\n"; // 結果: 832040 ,共執⾏行 0.002144813537 秒
奧巴馬籌款網站的製作過程 http://www.ruanyifeng.com/blog/2012/12/ obama_fundraising_website.html
第七式 強健的程式碼
測試 確保系統舊有功能的完整 建立問題發生的情境
自動化測試框架 PHPUnit http://www.phpunit.de/ PHPSpec http://www.phpspec.net/ Behat http://behat.org/
重構 不是打掉重練 防止程式碼腐敗 搭配測試實行 Refactoring - Martin Fowler
第八式 不要只學寫程式碼
系統管理������� 系統安裝 Shell Script Service 管理������� 排程設定
學習使用雲端服務 AWS Linode Heroku ...
學習使用雲端服務 Hosting Plan http://blog.gslin.org/archives/2012/04/19/2865/ hosting-plan/ Startup : 如何挑選適合的 Hosting Plan?
http://blog.xdite.net/posts/2012/04/18/startup- hosting-plan/
學習其它語言 JavaScript (Browser) Perl / Python / Ruby / Node.js
C English
眼 神 死
關注國外資訊 PHP Master http://phpmaster.com/ nettuts+ http://net.tutsplus.com/category/tutorials/php/ PHP Mailing Lists http://php.net/mailing-lists.php
第九式 學會用輪子 也要學會造輪子
https://github.com/c9s c9s
PHPConf Taiwan 2013 http://phpconf.tw/
不要只問 自己勤練 真正的功夫
謝謝大家 版權所有.翻印必舊 - 定價 50 元 -