Code refactoring with symfony2
蘇展 (bookjan) 2015/3/14
bookjan
Linkedin:https://www.linkedin.com/in/bookjan E-mail:[email protected]
TEL: (02) 2788-3799 ext. 1478
In This Talk• Part 1 - Refactoring 101
• What is refactoring?
• Reasons to Refactor
• Refactor v.s. Rewrite
• From developers view
• Part 2 - A Case Study: X2R
• What is X2R and What it does?
• Reasons to Refactor in X2R
• Code review in X2R component - USS
• Refactoring USS with symfony2
Part 1
- Refactoring 101
What is Refactoring?
https://www.flickr.com/photos/katy_tresedder/4902791464/
Reasons to Refactor?
• Code is duplicated.
• A function is too long.
• A loop is to long or too deeply nested.
• Global variables are used.
• A function has a poor name.
• Comments are used to explain difficult code.
• And more…
Code Complete - Chapter 24
Refactor v.s. Rewrite
• Code refactoring is the process of restructuring
existing computer code - without changing its external
behavior. (Wikipedia)
• “a change made to the internal structure of the soft-
ware to make it easier to understand and cheaper to
modify without changing its observable
behavior” (Fowler 1999).
Code Refactoring
https://www.flickr.com/photos/pascalbrax/5429971163
Code RewriteA rewrite in computer programming is the act or result
of re-implementing a large portion of existing
functionality without re-use of its source code or
writing inscription.
From developers view Refactor v.s. Rewrite
http://www.groomers-online.com/news/wp-content/uploads/2013/04/dog-computer.jpg
Rewrite
http://wallpaperist.net/file/413/dogs-animals-computer-bald.jpg
Refactor
http://www.graphics99.com/funny-dog-with-laptop-picture/
Part 2 -
A Case Study for Refactoring with symfony2 :
鏈結資料轉換⼯工具 (X2R)
沒有 X2R 的狀況
開發者
CSV
XML
JSON
RDF
觀測資料
氣象局
⽔水利署
地球所
csv2rdf4lod
Open Refiner
RDF Translator
針對不同來源不同格式的資料,要去學習各種 RDFizer 的設定
跟使⽤用。︒RDFizers
Raw Data
What is X2R and
What it does
沒有 X2R 的狀況
開發者
要學習SPARQL 語⾔言
還要到不同的Endpoints
去找合⽤用的 URIs
Endpoints
X2R - Workflow
開發者
開發者可以把上述的繁瑣步驟,通通交給 X2R
輸入既有資料
輸出鏈結資料
X2R 幫開發者處理中間繁瑣的步驟
現有資料
(多種不同格式,利⽤用變數 X 表⽰示)
鏈結資料
(RDF,利⽤用 開頭字母 R表⽰示)
X R2轉換成
(To ~⾳音同~ Two)
X2R 幫助程式設計師輕鬆地將現有資料轉換成
⾼高品質的鏈結資料
Reasons to Refactor in X2R
• Code is duplicated.
• A function is too long.
• A loop is to long or too deeply nested.
• Global variables are used.
• A function has a poor name.
• Comments are used to explain difficult code.
• And more…
Code Complete - Chapter 24
A brief of code review in X2R components:
URI Search Service (USS)
24
Input: search term
1. - Compose query and filter the endpoint-list to extract requested endpoint URL.Loop
2.1 - Connect individual endpoint and send query
Loop
2.2 - Integrates resultsLoop
Output: Results
A brief of demo: URI Search Service (USS)
The Refactoring Strategies in general
• Easy to maintain both Front&Back end
• Separate different classes and function
• restructuring existing code and logic
• DRY - Don’t repeat yourself
The Refactoring Strategies in Symfony2
• MVC - Model-View-Control pattern
• Modularized - Reusable functions of X2R
• Symfony2 Components
A brief of Demo after refactoring with symfony2
Thank You!
Q & A
本簡報授權聲明
除另有聲明外,本簡報內容採⽤用 Creative Commons「姓名標⽰示 - ⾮非商業性」台灣 3.0 版授權條款。 歡迎⾮非商業⺫⽬目的的重製、散布或修改本簡報的內容,但請標明:(1)原作者姓名;(2)本簡報標題;(3)演講⽇日期。 簡報中所取⽤用的圖形創作乃截取⾃自網際網路,僅供演講者於⾃自由軟體推廣演講時主張合理使⽤用,請讀者不得對其再⾏行取⽤用,除⾮非您本⾝身⾃自忖亦符合主張合理使⽤用之情狀,且⾃自負相關法律責任。
THANK YOU Website: www.openfoundry.org Phone: 02-2788-3799 ext. 1478