code refactoring with symfony2
TRANSCRIPT
![Page 1: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/1.jpg)
Code refactoring with symfony2
蘇展 (bookjan) 2015/3/14
![Page 2: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/2.jpg)
bookjan
Linkedin:https://www.linkedin.com/in/bookjan E-mail:[email protected]
TEL: (02) 2788-3799 ext. 1478
![Page 3: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/3.jpg)
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
![Page 4: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/4.jpg)
Part 1
- Refactoring 101
![Page 5: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/5.jpg)
What is Refactoring?
![Page 6: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/6.jpg)
https://www.flickr.com/photos/katy_tresedder/4902791464/
![Page 7: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/7.jpg)
Reasons to Refactor?
![Page 8: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/8.jpg)
• 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
![Page 9: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/9.jpg)
Refactor v.s. Rewrite
![Page 10: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/10.jpg)
• 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
![Page 11: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/11.jpg)
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.
![Page 12: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/12.jpg)
From developers view Refactor v.s. Rewrite
http://www.groomers-online.com/news/wp-content/uploads/2013/04/dog-computer.jpg
![Page 13: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/13.jpg)
Rewrite
http://wallpaperist.net/file/413/dogs-animals-computer-bald.jpg
![Page 14: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/14.jpg)
Refactor
http://www.graphics99.com/funny-dog-with-laptop-picture/
![Page 15: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/15.jpg)
Part 2 -
A Case Study for Refactoring with symfony2 :
鏈結資料轉換⼯工具 (X2R)
![Page 16: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/16.jpg)
沒有 X2R 的狀況
開發者
CSV
XML
JSON
RDF
觀測資料
氣象局
⽔水利署
地球所
csv2rdf4lod
Open Refiner
RDF Translator
針對不同來源不同格式的資料,要去學習各種 RDFizer 的設定
跟使⽤用。︒RDFizers
Raw Data
![Page 17: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/17.jpg)
What is X2R and
What it does
![Page 18: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/18.jpg)
沒有 X2R 的狀況
開發者
要學習SPARQL 語⾔言
還要到不同的Endpoints
去找合⽤用的 URIs
Endpoints
![Page 19: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/19.jpg)
X2R - Workflow
開發者
開發者可以把上述的繁瑣步驟,通通交給 X2R
輸入既有資料
輸出鏈結資料
X2R 幫開發者處理中間繁瑣的步驟
![Page 20: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/20.jpg)
現有資料
(多種不同格式,利⽤用變數 X 表⽰示)
鏈結資料
(RDF,利⽤用 開頭字母 R表⽰示)
X R2轉換成
(To ~⾳音同~ Two)
X2R 幫助程式設計師輕鬆地將現有資料轉換成
⾼高品質的鏈結資料
![Page 21: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/21.jpg)
Reasons to Refactor in X2R
![Page 22: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/22.jpg)
• 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
![Page 23: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/23.jpg)
A brief of code review in X2R components:
URI Search Service (USS)
![Page 24: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/24.jpg)
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
![Page 25: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/25.jpg)
A brief of demo: URI Search Service (USS)
![Page 26: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/26.jpg)
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
![Page 27: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/27.jpg)
The Refactoring Strategies in Symfony2
• MVC - Model-View-Control pattern
• Modularized - Reusable functions of X2R
• Symfony2 Components
![Page 28: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/28.jpg)
A brief of Demo after refactoring with symfony2
![Page 29: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/29.jpg)
Thank You!
![Page 30: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/30.jpg)
Q & A
![Page 31: Code refactoring with symfony2](https://reader030.vdocuments.mx/reader030/viewer/2022020106/55c35575bb61eb9b4e8b4882/html5/thumbnails/31.jpg)
本簡報授權聲明
除另有聲明外,本簡報內容採⽤用 Creative Commons「姓名標⽰示 - ⾮非商業性」台灣 3.0 版授權條款。 歡迎⾮非商業⺫⽬目的的重製、散布或修改本簡報的內容,但請標明:(1)原作者姓名;(2)本簡報標題;(3)演講⽇日期。 簡報中所取⽤用的圖形創作乃截取⾃自網際網路,僅供演講者於⾃自由軟體推廣演講時主張合理使⽤用,請讀者不得對其再⾏行取⽤用,除⾮非您本⾝身⾃自忖亦符合主張合理使⽤用之情狀,且⾃自負相關法律責任。
THANK YOU Website: www.openfoundry.org Phone: 02-2788-3799 ext. 1478