【從學員練習影片觀察到一個關於 TDD 的有趣現象】
極速開發的課後練習作業,雖說重點是放在極速開發要學習的技巧與刻意練習的模型,但開發的方式、順序也是刻意安排成類似 TDD 的進行方式,來讓生產力最大化(TDD 本來就是幫助開發的,不是幫助測試的)
我從2位第一次上我課的學員(當然就是 #極速開發,代表他們沒上過#單元測試 跟 #TDD與持續重構),雖然他們是照著示範影片、上課教學用 TDD 在寫整個 tennis 的過程,但從他們執行測試的時間點就可以發現:
「他是用測試來驗證 production code 的正確性」,即使他先寫了測試,也不先執行,沒有看到紅燈,每次都等到 production code 寫完了,應該要綠燈時,才執行測試。
而其他上過 TDD 課的同學 ,或是上過單元測試的同學,知道測試是用來描述情境,如果現在「加入的這個情境是新的需求或需求異動,代表目前 production code 還不支援這個情境,執行測試跑出的紅燈,就是等等 production code 要完成的 #目標」
test-frist 從來都只是 TDD 其中一個小小的衍生產物,而不是全貌。TDD, 測試驅動開發 從來都是一種開發方法,而不是測試方法。
總有些人老愛把 TDD 拿來跟測試相提並論,就總是喜歡把 test-first 當作靶子打,覺得違反人性跟直覺,覺得先寫測試在很多情況下是浪費時間或是不 work,可能拿來跟一堆測試的方法論相提並論,或總是只拿回歸測試的效益來當作 TDD 的整體。抑或是陷入 isolation unit test 與 integration test (其實就是非 isolation 等級、有實際依賴的自動測試)之爭。
```
註:TDD 事實上是可以不是單元測試等級的。
```
要比較正確看待 TDD 的角度,首先要知道它是幫助開發的、它是一種開發方式(當然不是唯一一種,甚至也不會是最好的一種,因為根本沒有最好,只有剛好)
接著要了解 TDD 可能用 IPO 模型還比較貼切,input-process-output,在你開發任何功能之前,你總要先想過這件事。而先想這件事,才是 TDD 的最基本精神。
接著是怎麼把你想好的東西,變成可執行的 spec,我們只是用測試程式來「描述」你腦袋中的「IPO模型」,把 process 的過程當作一個黑箱子。
而這個 IPO 模型在結合成「使用情境」,就會帶來「高易用性 API 的好處」,只有在一開始就先想好怎麼給別人用,最後才會好用。所謂的一開始想好,指的不是預先設計一堆 class,而是 input/output 想清楚期待(一般會結合實例化需求,搭配 Given/When/Then 的 gherkin style 來把前置條件、資料、前提想好,當發生什麼事,應該是怎樣的結果),然後描述它。在紅燈定義清楚目標,綠燈完成 input/output 關係且沒弄壞前面的所有情境後,來針對 process 進行重構(事實上 Kent Beck 的 TDD by Example 更多是用 refactor 來 #完成 process。
```
註:所謂的 output 不一定只有回傳值,包含外部依賴狀態、資料的改變,甚至顆粒度小一點,針對物件導向設計的話,物件內部狀態的改變也算,只是物件內部狀態改變,驗證點要嘛是拿得到內部狀態,要嘛就是要驗證物件哪個行為會因這個內部狀態而有所不同。
```
## 戰 TDD 之前該先做好的功課
要戰 TDD,是不是至少要把 Kent Beck 的 TDD by Example 看完?
要戰 TDD,請不要拿它跟測試方法論來比,那只是一下就被人看破手腳。因為它是個開發方法論。
要戰 TDD,請不要把它的好處只限縮在跟回歸測試、自動測試的比較,因為那只是它的衍生好處,當你試過在白海報紙上 TDD 就懂,TDD 是在釐清你的思緒的同時,又可以以終為始,確保你在 production code 的每一個動作都是為了滿足某個期待的情境。
要戰 TDD,請不要去把 單元測試、整合測試捲進來,那是測試的顆粒度,那是測試的分類,TDD 從來都不是只能限於單元測試。
要戰 TDD,請不要在那邊戰他是 bottom-up ,是直接從程式/class 的角度出發,事實上 TDD 既不是 bottom-up, 也不是 top-down, (書裡面就有講這件事咩),實務上的 TDD 結合倫敦派(GOOS)跟芝加哥派(Classic TDD),會更像 Outside-In 的進行方式,先定義好驗收情境,接著從最外部(也就是使用者看得到的部份)一路把依賴往另一邊的系統邊界推,直到推到系統以外的依賴資源(persistence 或 external API/service)
```
註: ATDD by Example 中 ATDD by Example, Kent Beck 寫的序最後的一段話。
Kent Beck:
「就像我曾說過的,TDD的一個缺點是,它可能會退化為一種用來滿足開發人員需求的編程技能。某些開發人員從更廣泛的角度來看待TDD,輕易在他們測試的不同抽象級別間跳躍。然而在ATDD中不存在歧義,這是一種加強與非編程人員溝通的技術。我們之間良好的協作關係,以及作為這種關係基礎的溝通,能夠使軟件開發更有效率。採用ATDD是向著溝通更清晰這個目標邁進的重要一步,而此書是一本全面又平易近人的入門讀物。」
```
要戰 TDD,請不要只關注在 test-frist,因為他只是用 test 來幫助你 think-first,不要邊寫邊想。然後不要過份依賴或相信你腦袋的能力,把你想好的東西具體化出來,最好可以被直接執行,最好除了你以外每個人執行出來的結果都會一樣(不管是對的,還是錯的)
要戰 TDD, 請不要把論點放在見樹不見林,如果你有看 TDD by Example 的 Part 1, Part 2 那兩個加起來共 24 個章節,就知道一開始就得把當下想到的全貌紀錄在一個「紙本」的 backlog (所謂的紙本,只是要講這並不依賴於任何工具)
而這個需求輪廓的全貌,會隨著你逐漸完成一部分一部分的情境,設計逐漸浮現後,而隨時跟著增減調整。
但不代表 TDD 就是先想到一個測試案例,就直接先幹下去了,那根本是亂搞。
以上這些,都還不是在列 TDD 的好處,而是針對那些從來沒搞懂 TDD 但又愛戰 TDD 的人一點提醒,你戰的很可能是「你誤解的 TDD」。
TDD 還有許多實務上的用途,列上我在譯者序中的一小段:
>> 測試驅動開發(Test-Driven Development, TDD)!一種以測試為開發輔助、以測試來描述需求情境、以測試來當作目標、以測試來表達期望、以測試來驗證疑問、以測試來實驗學習、以測試來溝通協作、以測試來協助設計高易用性 API 的「開發方法」。
譯者序有開放給大家看,請見:https://tdd.best/book/tdd-by-example/
拜託,要戰之前去看一下祖師爺 Kent Beck 對 TDD 的原始見解:https://www.tenlong.com.tw/products/9789864345618?list_name=srh
如果你想正確的使用 TDD 來幫助你在實務上產生許多的價值,帶來許多的好處,尤其是需求釐清、持續重構、小步快跑的部份,最好理解的培訓課就在這:https://tdd.best/courses/classic-tdd-by-example-video-training/
最後我想講一段話:
TDD 從來都不該被導入到團隊中,但它是一種很好的自我鍛鍊與學習的方式,也是一種能用很低的成本來帶來很多好處的開發方法(見下方註腳),然而它也不是適用所有的情況,但它可以讓『完美』變成一個動詞,而非不變的形容詞。
```
註:
Kent Beck 在 DHH 靠腰:《TDD is Dead》 之後寫的一篇反串文:《RIP TDD》
https://www.facebook.com/notes/1063422864115918/
我幾年前的簡易翻譯,通常也是 TDD 可以幫助你解決的問題,如下:
- Over-engineering (過度設計)
- API feedback (改善API的設計與可用性)
- Logic errors (想的跟寫的不一樣,寫的跟需求不一樣)
- Documentation (寫跟維護文件是痛苦的)
- Feeling overwhelmed (找不到切入點)
- Separate interface from implementation thinking (抽象設計)
- Agreement (確保已修正問題的證據)
- Anxiety (改東壞西的擔心受怕)
```
很久沒對 TDD 發表這種長篇大論了,因為不理解、不想理解、不同角度理解的人居多,能真的到各自的塔上用不同角度來看原義,以及實務上用它來幫助解決的問題有哪些的人,真的太少。
大部分人只想針對這個詞彙來攻訐以博得流量跟吸引目光,而不是想著「我可以用它來幫助我什麼」
問題跟需求是中性的,解決問題跟滿足需求的手段與方式有千萬種,不會只有一種,也不會有所謂的對錯,多點角度去了解不同的方法、方式,然後融會貫通,發揮綜效,在實務上用最少的成本與風險來產生最大的價值,這才是真正的目標。
導入敏捷不該是目標,導入 TDD 也不該是目標,目標永遠都是在實務上產生價值、解決問題、滿足需求。
同時也有24部Youtube影片,追蹤數超過4萬的網紅Sugar Melon 衰哥霉人,也在其Youtube影片中提到,等了四个月,你们的愿望终于实现了!当上@Ryan Sylvia 老板娘Sylvia的工具人会发生什么悲惨事件? 如果这个视频有8000赞,我们下一集就做4个人的工具人!任您挑选! 8000 likes and we will do a 4 person slaves for the next ep...
「implementation」的推薦目錄:
- 關於implementation 在 91 敏捷開發之路 Facebook 的最讚貼文
- 關於implementation 在 外交部 Ministry of Foreign Affairs, ROC(Taiwan) Facebook 的精選貼文
- 關於implementation 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於implementation 在 Sugar Melon 衰哥霉人 Youtube 的最佳解答
- 關於implementation 在 Sugar Melon 衰哥霉人 Youtube 的最讚貼文
- 關於implementation 在 Dr. Violette Xin Hui Youtube 的精選貼文
implementation 在 外交部 Ministry of Foreign Affairs, ROC(Taiwan) Facebook 的精選貼文
聯合國大會開議第三天,#諾魯 總統安格明呼籲聯合國接納台灣
諾魯總統安格明真誠感謝台灣持續協助對抗武漢肺炎疫情,並呼籲聯合國確保台灣人享有與其他國家人民相同的權利,同時表示不該忽視台灣對抗武漢肺炎疫情的貢獻,台灣是全球對抗疫情的重要夥伴,而台灣不僅有能力也已做好準備。
台灣應當有權利以平等夥伴身分,參與聯合國永續發展目標的實現,台灣也應該被納入「我們的共同議程」願景。
台灣的夥伴價值,值得聯合國重視。
_ _
We’d like to thank President Lionel Rouwen Aingimea of #Nauru for the speech he gave on the third day of the #UNGA76 General Debate, praising Taiwan’s efforts to help our partners around the world during the pandemic and calling for our inclusion in the UN, as follows:
“Our efforts to respond to COVID-19 and vaccinate our people would not have been possible without the valuable support provided by our partners. We are truly grateful to our genuine friends Australia, India, Japan and the Republic of China (Taiwan), for their ongoing assistance.
Mr. President, we call on the United Nations to embrace willing and able partners like Taiwan who share common global challenges and to ensure that the people of the Republic of China (Taiwan) enjoy the same rights as the peoples of other nations. The United Nations must live up to its ideals of universality and equality, respecting the worth of every individual. Taiwan is an important partner in the global response to this pandemic, and its exemplary response to the global pandemic should not be ignored. Taiwan is ready to share its experience and aspire to do so by joining the World Health Assembly. Taiwan should have the right to participate as an equal partner in the implementation of the SDGs as they have demonstrated their ability and supported many in the SDG fields. They should also be part of our ‘Our Common Agenda’ vision.”
#SDG17 #PartnershipForTheGoals #HearTaiwan
implementation 在 Taipei Ethereum Meetup Facebook 的精選貼文
📜 [專欄新文章] Gas Efficient Card Drawing in Solidity
✍️ Ping Chen
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
Assign random numbers as the index of newly minted NFTs
Scenario
The fun of generative art NFT projects depends on randomness. The industry standard is “blind box”, where both the images’ serial number and the NFTs’ index are predetermined but will be shifted randomly when the selling period ends. (They call it “reveal”) This approach effectively solves the randomness issue. However, it also requires buyers to wait until the campaign terminates. What if buyers want to know the exact card right away? We’ll need a reliable onchain card drawing solution.
The creator of Astrogator🐊 isn’t a fan of blind boxes; instead, it thinks unpacking cards right after purchase is more interesting.
Spec
When initializing this NFT contract, the creator will determine the total supply of it. And there will be an iterable function that is randomly picking a number from the remaining pool. The number must be in range and must not collide with any existing ones.
Our top priority is accessibility/gas efficiency. Given that gas cost on Ethereum is damn high nowadays, we need an elegant algorithm to control gas expanse at an acceptable range.
Achieving robust randomness isn’t the primary goal here. We assume there’s no strong financial incentive to cheat, so the RNG isn’t specified. Implementers can bring their own source of randomness that they think is good enough.
Implementation
Overview
The implementation is pretty short and straightforward. Imagine there’s an array that contains all remaining(unsold) cards. When drawIndex() is called, it generates a (uniform) random seed to draw a card from the array, shortens the array, and returns the selected card.
Algorithm
Drawing X cards from a deck with the same X amount of cards is equal to shuffling the deck and dealing them sequentially. It’s not a surprise that our algorithm is similar to random shuffling, and the only difference is turning that classic algo into an interactive version.
A typical random shuffle looks like this: for an array with N elements, you randomly pick a number i in (0,N), swap array[0] and array[i], then choose another number i in (1,N), swap array[1] and array[i], and so on. Eventually, you’ll get a mathematically random array in O(N) time.
So, the concept of our random card dealing is the same. When a user mints a new card, the smart contract picks a number in the array as NFT index, then grabs a number from the tail to fill the vacancy, in order to keep the array continuous.
Tweak
Furthermore, as long as the space of the NFT index is known, we don’t need to declare/initialize an array(which is super gas-intensive). Instead, assume there’s such an array that the n-th element is n, we don’t actually initialize it (so it is an array only contains “0”) until the rule is broken.
For the convenience of explanation, let’s call that mapping cache. If cache[i] is empty, it should be interpreted as i instead of 0. On the other hand, when a number is chosen and used, we’ll need to fill it up with another unused number. An intuitive method is to pick a number from the end of the array, since the length of the array is going to decrease by 1.
By doing so, the gas cost in the worst-case scenario is bound to be constant.
Performance and limitation
Comparing with the normal ascending index NFT minting, our random NFT implementation requires two extra SSTORE and one extra SLOAD, which cost 12600 ~ 27600 (5000+20000+2600) excess gas per token minted.
Theoretically, any instantly generated onchain random number is vulnerable. We can restrict contract interaction to mitigate risk. The mitigation is far from perfect, but it is the tradeoff that we have to accept.
ping.eth
Gas Efficient Card Drawing in Solidity was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.
👏 歡迎轉載分享鼓掌
implementation 在 Sugar Melon 衰哥霉人 Youtube 的最佳解答
等了四个月,你们的愿望终于实现了!当上@Ryan Sylvia 老板娘Sylvia的工具人会发生什么悲惨事件?
如果这个视频有8000赞,我们下一集就做4个人的工具人!任您挑选!
8000 likes and we will do a 4 person slaves for the next episode!
如果你喜欢衰哥霉人的视频,请大家按讚和分享!
https://www.youtube.com/channel/UCrfQP9z0XHbDEQ2uonZcwxw?sub_confirmation=1
?记得跟随我们!
Facebook - https://www.facebook.com/sugarmelonshow
Instagram - https://www.instagram.com/sugarmelonshow
Tiktok - https://www.tiktok.com/@sugarmelonshow
?衰哥霉人
梓杰 - https://www.instagram.com/raozijie
彦维小二 - https://www.instagram.com/yanweixiaoer
Nina - https://www.instagram.com/ninatsf
Sylvia - https://www.instagram.com/sylsylnoc
---
? 任何合作邀約/商业咨询, 請直接聯繫:
sales@noc.com.sg (cc bella@noc.com.sg, virus@noc.com.sg )
Disclaimer: This video was recorded prior to the implementation of additional restrictions in Phase 2 (Heightened Alert). All precautionary measures were taken during the production.*
#sugarmelon #衰哥霉人 #一日工具人
implementation 在 Sugar Melon 衰哥霉人 Youtube 的最讚貼文
又来看帅哥了!这次能适合Nina跟Sherr的口味吗?
如果你喜欢衰哥霉人的视频,请大家按讚和分享!
https://www.youtube.com/channel/UCrfQP9z0XHbDEQ2uonZcwxw?sub_confirmation=1
?记得跟随我们!
Facebook - https://www.facebook.com/sugarmelonshow
Instagram - https://www.instagram.com/sugarmelonshow
Tiktok - https://www.tiktok.com/@sugarmelonshow
?衰哥霉人
Nina Instagram - https://www.instagram.com/ninatsf
Sherr Instagram - https://www.instagram.com/sherrng
---
? 任何合作邀約/商业咨询, 請直接聯繫:
sales@noc.com.sg (cc bella@noc.com.sg, virus@noc.com.sg )
Disclaimer: This video was recorded prior to the implementation of additional restrictions in Phase 2 (Heightened Alert). All precautionary measures were taken during the production.*
#sugarmelon #衰哥霉人 #抖音 #tiktok
implementation 在 Dr. Violette Xin Hui Youtube 的精選貼文
Everyone desires to have their pearly whites pearly white (pun intended). Yet despite brushing our teeth everyday, there seems to be a limit to how much we can "whiten" them. Why is that so? And is there a way to fix this?
? REFERENCES
1.Odell's Clinical Problem Solving in Dentistry - 4th Edition
2. Implementation of Water Fluoridation Programme in Malaysia 2006
http://ohd.moh.gov.my/images/pdf/xtvtnsop/Implementation-of-Water-Fluoridation-Programme-in-Malaysia-2006.pdf
3. Water Fluoridation Re-introduced
https://www.thestar.com.my/news/community/2010/12/31/water-fluoridation-reintroduced
?INTERESTING READS
1. Impact of a reduction in fluoride concentration in the Malaysian water supply on the prevalence of fluorosis and dental caries
https://onlinelibrary.wiley.com/doi/full/10.1111/cdoe.12407
2. Charcoal toothpastes 'don't whiten teeth'
https://www.bbc.com/news/health-48216116
L E T ' S C O N N E C T !
? Instagram: http://instagram.com/xinhuilovette
? Facebook: https://www.facebook.com/xinhui1205
implementation 在 implementation - 實施 - 國家教育研究院雙語詞彙 的相關結果
實施 · implementation · 名詞解釋: (一)完成電腦軟體及硬體設計後的建置工作。 (二)與電腦系統的安裝和運轉相關的若干步驟。 (三)軟體工程開發步驟之一,即根據系統設計規範 ... ... <看更多>
implementation 在 Definition of implementation - Merriam-Webster 的相關結果
Implementation definition is - an act or instance of implementing something : the process of making something active or effective. How to use implementation ... ... <看更多>
implementation 在 IMPLEMENTATION在劍橋英語詞典中的解釋及翻譯 的相關結果
Recall that the standard implementation of set membership shown in figure 1 uses one three-way comparison per visited node. 來自Cambridge English Corpus. Action ... ... <看更多>