# PyCon TW 2016 Collaborative Talk Notes <br> Day 1 - R0 > ### Quick Links > - [Portal for Collobration Notes 共筆統整入口](https://hackfoldr.org/pycontw2016) (hosted by [hackfoldr](https://hackfoldr.org/about) and [HackMD](https://hackmd.io/)) > - [Program Schedule 議程時間表](https://tw.pycon.org/2016/events/talks/) > - [PyCon TW 2016 Official Site 官網](https://tw.pycon.org/2016/) > > ### How to update this note? > - Everyone can *freely* update this note. 任何人都能自由地更新內容。 > - Please respect all the participants and follow our [code of conduct](https://tw.pycon.org/2016/about/code-of-conduct/) during discussion. 討論、記錄時,請遵守大會的[行為準則](https://tw.pycon.org/2016/about/code-of-conduct/)。 ## Talk: Essential TDD (Test-Driven Development) for Pythoners - Info: https://tw.pycon.org/2016/events/talk/70169571679535177/ - Speaker: 曾君宇 [均一教育徵才中](http://www.junyiacademy.org/) - Slides: http://www.slideshare.net/excusemejoe/essential-tdd-pycontw2016 - TDD (Test-Driven Development) - Red, green, refactor cycle - 預想好使用情境 - 一次只會專注一個目標,一次解決一個問題 - 避免過度設計 - 其他 *DD - ATDD(驗收測試驅動開發): - 聚焦在客戶的需求 - 按照spec做開發 - BDD - TDD的八卦?! - 2014就掛惹! by Rails創作者 - [懶人包:TDD is Dead 戰文總整理 ](http://joe-dev.blogspot.tw/2014/06/tdd-is-dead.html) - PyCon結束再看 ^.< (不然PyCon就結束了) - 結論? Mindset:設計決策一次只聚焦在一個地方 好好評估環境適不適合TDD(連需求都不確定時,不建議使用TDD) 推薦書籍:[Test-Driven Development with Python](http://chimera.labs.oreilly.com/books/1234000000754) (O'RELLY) ## Talk: 那些年,我用 Django Admin 接的案子 - Info: https://tw.pycon.org/2016/events/talk/69827266518974528/ - Speaker: Michelle Leu - 從美容床開始的故事... - 實作範例:店家網站,有眾多分店,Account 和 branch之間有多對多的情形 - [Django Packages](https://www.djangopackages.com/):推薦許多好用的Packages -- [Django Suit](http://djangosuit.com/) ## Talk: Reactive Programming in Python - Info: https://tw.pycon.org/2016/events/talk/67738180727603248/ - Slides: http://keitheis.github.io/reactive-programming-in-python/ - PDF: https://speakerdeck.com/keitheis/reactive-programming-in-python - Speaker: Keith Yang #### What is reactive programming >game is reactive. - Programming PARADIGMS - Declarative - Imperative #### Stream > Everything can be a stream ##### Stream in `for in if` * list comprehension * generator expression > 眼睛會痛XD #### Why reactive programming - Abstraction - Focus on Business logic - Concise code - Performance - asynchronous programming #### PyFunctional - `from functional import seq` > core spirit: Stream [most.js](https://github.com/cujojs/most): Monadic reactive streams [Python reactive extension](https://github.com/ReactiveX/RxPY) Handle for you: - Thread-safty - Syncronization - etc ... Implementation: - RxPy - RxJava - RxCpp - etc ... > Asynchronous programming is HARD. ### RxPy #### Observable #### flat_map 複雜的 list 的扁平化(我要的值在 list 的每個event中) ```python str_ls = [['6', '7'], ['42']] ``` ### books * Python Reactive Programming * Reactive Programming with Scala and Akka * Reactive Programing with ## Talk: 大型互動展覽的 Python 應用 - Info: https://tw.pycon.org/2016/events/talk/68743273514008626/ - Speaker: 陳炯廷 互動業 (?) 常用工具:OpenFramework / PureData / Kinect ...etc #### 互動科技案例: - 簽名自動雷雕成名牌 HTML canvas => Django server => jpg file => 工讀生 - 解密科技寶藏 - 3D掃描 #### ID機 用Raspberry Pi 3 - Autoupdate要寫好 - Django (因為有admin所以非熟悉程式的人也可以用) - zeroconf + avahi 自己找主機 - 使用 QRCode 設定機器 (ex. reboot 逼一下就重開) - 全區開機、全區關機卡(實用! pip install wakeonlan) - 運用redis指令,可以摹擬很多人一起使用系統 - socket.io emitter 可以和場內server聯絡 #### 文件 因為不同公司有不同權限,Django和nginx串接來解決 去一個展場,需要安裝一個 App ,然後可能還沒看完,就離開了, App 又需要送審,相對於網頁,網頁打開就可以 work。 ## Talk: Boost Maintainability - Info: https://tw.pycon.org/2016/events/talk/58446570282024986/ - Speaker: Mosky Liu - 投影片: https://speakerdeck.com/mosky/boost-maintainbility 我們在開發程式的時候,都是 "read lines randomly" 的,不像電腦會逐行讀取。 > [Making wrong code look wrong](http://www.joelonsoftware.com/articles/Wrong.html) - Joel on software #### Maintainability 用人讀 code 的方式來定義 Maintainability > To understand a random line, the lines you need to read back. 相對於programmer的時間,運算資源比較不值錢。 把時間專注於想要做的事情,而不是 debug 上面。 #### Boost Maintainability - Define our "Maintainability" - Making it zero - progressive from zero ##### Maintainability Be exact & consistent (命名要精準且有一致性) ##### 舉個例子 ```python result = ... result = ... ``` 以這種方式來命名不夠準確所以很容易混亂 ##### 命名的好方法 常常用 dictionary,對一個領域不熟悉的話可以多查字典來找到更好的名字哦! #### Ops Hint 命名具有提示的作用,提示有怎樣的operation可以用 ```python page_no = ... page_html = ... ``` 這樣就可以知道 `page_no` 是一個數字,而 `page_html` 是一個字串 ```python allowed_field_set = set(requested_field) ``` 這樣能清楚知道他是一個集合(set) ##### consistent問題 用d來標示dictionary ```python user = User(...) user_d = {} ``` >Hint: func 的命名如果沒有取名好,那發現問題還需要查 document,這個更耗時 建議:func都用動詞開頭,就會記得加上() 不要把 `is_secure = True` 與 `req.is_secure()` 混用 以 `形容詞`、`介係詞` 來當 boolean 會比較好 或者用簡單的句子來表示 boolean: `req_is_secure = True` #### Ops Hint (Mosky 使用的習慣) - Hint which ops you should use - _no: numeric - <plural>: sequence, usually is mutable sequence(list). - _<type>: if no intuitive way - (這邊好像有缺漏,求有筆記到的幫補充) - <verb>_: imperative sentence - <yes-no question>: return boolean - to_<thing>: thing - boolean: <adj>, <prep>, <simple sentence> ##### return value - get_page_no -> numeric >= 1 - query_user -> user object - parse_to_tree -> tree object ##### avoid `None` Consider: ```python= user = query_user(uid) user.is_valid() ``` 如果查不到 user 就 ret None 的話,就會噴 Error 囉! Accept an exception ? - N: user dummy object like an empty string. - Y: just raise when you wanna assign to None. #### 如果沒有檢查好做好處理 ```python= tmpl = '<p>{}</p>'.format(name) name = '<script> ... </script>' #XSS ``` ```python= tmpl_html = ... .format( escape_to_html(name) ) ``` 這種不是 python 的東西,對 Python 而言就只是 str,所以要去處理 #### Structure Hint ```python= uid_email_map = { 'mosky': 'mosky@email' } ``` 這樣子的命名方式能夠更直覺 ##### for dict & tuple - <key>_<value>_map - tuple - _pair: 2-tuple - _pairs: 3-tuple #### Private Hint - _<name> - Dont use out of class, function #### Performance Hint - get: memory op (記憶體的操作) - parse_ / cale_: CPU-bound op - query_ : IO-bound op - query_or_get_: IO-bound op with cache #### Progressive from zero - 不要自己自創縮寫,可以去[網站](http://www.abbreviations.com/)上查 - 如果只是要在一個 func 裡面用而已,可以用註解來解釋縮寫定義 (目前著重於讓人能夠更快讀懂 code,所以才這樣說) - 把程式分段跟分節 - 把做一系列事情的分段及分節 - 用 `空行` 來把不同的事情分隔開 - 用 `section` 的方式來切開(Title comment 來區隔開不同的區塊) #### Line Function up(把程式連線起來) > Func A call Func U, Func B call Func U 可以從連線的方式來慢慢切開變成函式的模組化 >Hint: 最好把箭頭指向的方向全統一到同個方向 #### Face Bad Smell(察覺程式碼中的壞東西) >不要為了克服心理上的潔癖而造成開發上時間的損失 >就是不要因為覺得 code 很醜就浪費一下午改好又不能動 XD - 用 comment 來解決痛點而不是改寫 - 放很多 TODO,不是不改是時候未到 XD - Seal it:把他封起來就對了,或是用更好的名稱把他包起來 - def good_name(): bad_name() - Stay focused:認真寫 code,舊的東西先放著! #### Summary > Use hints to boost maintainability ! #### QA 1、如何影響同事在 co-working 上使用較好的命名? 絕對不要有 guild line,可是可以用 `I will prefer` 這種方式來慢慢改變同事的風格,當他們發現這麼做的好處就會漸漸跟著改變。 但是真的碰到沒有按照規則走的同事也不要太生氣,可以 comment 他(幫他補一堆 comment),幫他 wrapper,然後讓自己的工作更順利。 2、你會參考 google 的 programming guildline 嗎? 會參考唷!
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.