【從學員練習影片觀察到一個關於 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 也不該是目標,目標永遠都是在實務上產生價值、解決問題、滿足需求。
同時也有10000部Youtube影片,追蹤數超過2,910的網紅コバにゃんチャンネル,也在其Youtube影片中提到,...
「bottom-up thinking」的推薦目錄:
- 關於bottom-up thinking 在 91 敏捷開發之路 Facebook 的精選貼文
- 關於bottom-up thinking 在 黃之鋒 Joshua Wong Facebook 的最佳解答
- 關於bottom-up thinking 在 コバにゃんチャンネル Youtube 的最讚貼文
- 關於bottom-up thinking 在 大象中醫 Youtube 的精選貼文
- 關於bottom-up thinking 在 大象中醫 Youtube 的精選貼文
- 關於bottom-up thinking 在 cognitive psychology - Bottom up thinking - what is it? 的評價
- 關於bottom-up thinking 在 Bottom-up vs. Top-down processing | Explained in 2 min 的評價
- 關於bottom-up thinking 在 Top Down Processing vs Bottom Up Processing (Examples!) 的評價
- 關於bottom-up thinking 在 Vintage Industrial Bar and Restaurant Designs - Pinterest 的評價
bottom-up thinking 在 黃之鋒 Joshua Wong Facebook 的最佳解答
【《金融時報》深度長訪】
今年做過數百外媒訪問,若要說最能反映我思緒和想法的訪問,必然是《金融時報》的這一個,沒有之一。
在排山倒海的訪問裡,這位記者能在短短個半小時裡,刻畫得如此傳神,值得睇。
Joshua Wong plonks himself down on a plastic stool across from me. He is there for barely 10 seconds before he leaps up to greet two former high school classmates in the lunchtime tea house melee. He says hi and bye and then bounds back. Once again I am facing the young man in a black Chinese collared shirt and tan shorts who is proving such a headache for the authorities in Beijing.
So far, it’s been a fairly standard week for Wong. On a break from a globe-trotting, pro-democracy lobbying tour, he was grabbed off the streets of Hong Kong and bundled into a minivan. After being arrested, he appeared on the front pages of the world’s newspapers and was labelled a “traitor” by China’s foreign ministry.
He is very apologetic about being late for lunch.
Little about Wong, the face of Hong Kong’s democracy movement, can be described as ordinary: neither his Nobel Peace Prize nomination, nor his three stints in prison. Five years ago, his face was plastered on the cover of Time magazine; in 2017, he was the subject of a hit Netflix documentary, Joshua: Teenager vs Superpower. And he’s only 23.
We’re sitting inside a Cantonese teahouse in the narrow back streets near Hong Kong’s parliament, where he works for a pro-democracy lawmaker. It’s one of the most socially diverse parts of the city and has been at the heart of five months of unrest, which has turned into a battle for Hong Kong’s future. A few weekends earlier I covered clashes nearby as protesters threw Molotov cocktails at police, who fired back tear gas. Drunk expats looked on, as tourists rushed by dragging suitcases.
The lunch crowd pours into the fast-food joint, milling around as staff set up collapsible tables on the pavement. Construction workers sit side-by-side with men sweating in suits, chopsticks in one hand, phones in the other. I scan the menu: instant noodles with fried egg and luncheon meat, deep fried pork chops, beef brisket with radish. Wong barely glances at it before selecting the hometown fried rice and milk tea, a Hong Kong speciality with British colonial roots, made with black tea and evaporated or condensed milk.
“I always order this,” he beams, “I love this place, it’s the only Cantonese teahouse in the area that does cheap, high-quality milk tea.” I take my cue and settle for the veggie and egg fried rice and a lemon iced tea as the man sitting on the next table reaches over to shake Wong’s hand. Another pats him on the shoulder as he brushes by to pay the bill.
Wong has been a recognisable face in this city since he was 14, when he fought against a proposal from the Hong Kong government to introduce a national education curriculum that would teach that Chinese Communist party rule was “superior” to western-style democracy. The government eventually backed down after more than 100,000 people took to the streets. Two years later, Wong rose to global prominence when he became the poster boy for the Umbrella Movement, in which tens of thousands of students occupied central Hong Kong for 79 days to demand genuine universal suffrage.
That movement ended in failure. Many of its leaders were sent to jail, among them Wong. But the seeds of activism were planted in the generation of Hong Kongers who are now back on the streets, fighting for democracy against the world’s most powerful authoritarian state. The latest turmoil was sparked by a controversial extradition bill but has evolved into demands for true suffrage and a showdown with Beijing over the future of Hong Kong. The unrest in the former British colony, which was handed over to China in 1997, represents the biggest uprising on Chinese soil since the 1989 pro-democracy movement in Beijing. Its climax, of course, was the Tiananmen Square massacre, when hundreds, perhaps thousands, of people were killed.
“We learnt a lot of lessons from the Umbrella Movement: how to deal with conflict between the more moderate and progressive camps, how to be more organic, how to be less hesitant,” says Wong. “Five years ago the pro-democracy camp was far more cautious about seeking international support because they were afraid of pissing off Beijing.”
Wong doesn’t appear to be afraid of irking China. Over the past few months, he has lobbied on behalf of the Hong Kong protesters to governments around the world. In the US, he testified before Congress and urged lawmakers to pass an act in support of the Hong Kong protesters — subsequently approved by the House of Representatives with strong bipartisan support. In Germany, he made headlines when he suggested two baby pandas in the Berlin Zoo be named “Democracy” and “Freedom.” He has been previously barred from entering Malaysia and Thailand due to pressure from Beijing, and a Singaporean social worker was recently convicted and fined for organising an event at which Wong spoke via Skype.
The food arrives almost immediately. I struggle to tell our orders apart. Two mouthfuls into my egg and cabbage fried rice, I regret not ordering the instant noodles with luncheon meat.
In August, a Hong Kong newspaper controlled by the Chinese Communist party published a photo of Julie Eadeh, an American diplomat, meeting pro-democracy student leaders including Wong. The headline accused “foreign forces” of igniting a revolution in Hong Kong. “Beijing says I was trained by the CIA and the US marines and I am a CIA agent. [I find it] quite boring because they have made up these kinds of rumours for seven years [now],” he says, ignoring his incessantly pinging phone.
Another thing that bores him? The media. Although Wong’s messaging is always on point, his appraisal of journalists in response to my questions is piercing and cheeky. “In 15-minute interviews I know journalists just need soundbites that I’ve repeated lots of times before. So I’ll say things like ‘I have no hope [as regards] the regime but I have hope towards the people.’ Then the journalists will say ‘oh that’s so impressive!’ And I’ll say ‘yes, I’m a poet.’ ”
And what about this choice of restaurant? “Well, I knew I couldn’t pick a five-star hotel, even though the Financial Times is paying and I know you can afford it,” he says grinning. “It’s better to do this kind of interview in a Hong Kong-style restaurant. This is the place that I conducted my first interview after I left prison.” Wong has spent around 120 days in prison in total, including on charges of unlawful assembly.
“My fellow prisoners would tell me about how they joined the Umbrella Movement and how they agreed with our beliefs. I think prisoners are more aware of the importance of human rights,” he says, adding that even the prison wardens would share with him how they had joined protests.
“Even the triad members in prison support democracy. They complain how the tax on cigarettes is extremely high and the tax on red wine is extremely low; it just shows how the upper-class elite lives here,” he says, as a waiter strains to hear our conversation. Wong was most recently released from jail in June, the day after the largest protests in the history of Hong Kong, when an estimated 2m people — more than a quarter of the territory’s 7.5m population — took to the streets.
Raised in a deeply religious family, he used to travel to mainland China every two years with his family and church literally to spread the gospel. As with many Hong Kong Chinese who trace their roots to the mainland, he doesn’t know where his ancestral village is. His lasting memory of his trips across the border is of dirty toilets, he tells me, mid-bite. He turned to activism when he realised praying didn’t help much.
“The gift from God is to have independence of mind and critical thinking; to have our own will and to make our own personal judgments. I don’t link my religious beliefs with my political judgments. Even Carrie Lam is Catholic,” he trails off, in a reference to Hong Kong’s leader. Lam has the lowest approval rating of any chief executive in the history of the city, thanks to her botched handling of the crisis.
I ask whether Wong’s father, who is also involved in social activism, has been a big influence. Wrong question.
“The western media loves to frame Joshua Wong joining the fight because of reading the books of Nelson Mandela or Martin Luther King or because of how my parents raised me. In reality, I joined street activism not because of anyone book I read. Why do journalists always assume anyone who strives for a better society has a role model?” He glances down at his pinging phone and draws a breath, before continuing. “Can you really describe my dad as an activist? I support LGBTQ rights,” he says, with a fist pump. His father, Roger Wong, is a well-known anti-gay rights campaigner in Hong Kong.
I notice he has put down his spoon, with half a plate of fried rice untouched. I decide it would be a good idea to redirect our conversation by bonding over phone addictions. Wong, renowned for his laser focus and determination, replies to my emails and messages at all hours and has been described by his friends as “a robot.”
He scrolls through his Gmail, his inbox filled with unread emails, showing me how he categorises interview requests with country tags. His life is almost solely dedicated to activism. “My friends and I used to go to watch movies and play laser tag but now of course we don’t have time to play any more: we face real bullets every weekend.”
The protests — which have seen more than 3,300 people arrested — have been largely leaderless. “Do you ever question your relevance to the movement?” I venture, mid-spoonful of congealed fried rice.
“Never,” he replies with his mouth full. “We have a lot of facilitators in this movement and I’m one of them . . . it’s just like Wikipedia. You don’t know who the contributors are behind a Wikipedia page but you know there’s a lot of collaboration and crowdsourcing. Instead of just having a top-down command, we now have a bottom-up command hub which has allowed the movement to last far longer than Umbrella.
“With greater power comes greater responsibility, so the question is how, through my role, can I express the voices of the frontliners, of the street activism? For example, I defended the action of storming into the Legislative Council on July 1. I know I didn’t storm in myself . . . ” His phone pings twice. Finally he succumbs.
After tapping away for about 30 seconds, Wong launches back into our conversation, sounding genuinely sorry that he wasn’t there on the night when protesters destroyed symbols of the Chinese Communist party and briefly occupied the chamber.
“My job is to be the middleman to express, evaluate and reveal what is going on in the Hong Kong protests when the movement is about being faceless,” he says, adding that his Twitter storm of 29 tweets explaining the July 1 occupation reached at least four million people. I admit that I am overcome with exhaustion just scanning his Twitter account, which has more than 400,000 followers. “Well, that thread was actually written by Jeffrey Ngo from Demosisto,” he say, referring to the political activism group that he heads.
A network of Hong Kong activists studying abroad helps fuel his relentless public persona on social media and in the opinion pages of international newspapers. Within a week of his most recent arrest, he had published op-eds in The Economist, The New York Times, Quartz and the Apple Daily.
I wonder out loud if he ever feels overwhelmed at taking on the Chinese Communist party, a task daunting even for some of the world’s most formidable governments and companies. He peers at me over his wire-framed glasses. “It’s our responsibility; if we don’t do it, who will? At least we are not in Xinjiang or Tibet; we are in Hong Kong,” he says, referring to two regions on Chinese soil on the frontline of Beijing’s drive to develop a high-tech surveillance state. In Xinjiang, at least one million people are being held in internment camps. “Even though we’re directly under the rule of Beijing, we have a layer of protection because we’re recognised as a global city so [Beijing] is more hesitant to act.”
I hear the sound of the wok firing up in the kitchen and ask him the question on everyone’s minds in Hong Kong: what happens next? Like many people who are closely following the extraordinary situation in Hong Kong, he is hesitant to make firm predictions.
“Lots of think-tanks around the world say ‘Oh, we’re China experts. We’re born in western countries but we know how to read Chinese so we’re familiar with Chinese politics.’ They predicted the Communist party would collapse after the Tiananmen Square massacre and they’ve kept predicting this over the past three decades but hey, now it’s 2019 and we’re still under the rule of Beijing, ha ha,” he grins.
While we are prophesying, does Wong ever think he might become chief executive one day? “No local journalist in Hong Kong would really ask this question,” he admonishes. As our lunch has progressed, he has become bolder in dissecting my interview technique. The territory’s chief executive is currently selected by a group of 1,200, mostly Beijing loyalists, and he doubts the Chinese Communist party would ever allow him to run. A few weeks after we meet he announces his candidacy in the upcoming district council elections. He was eventually the only candidate disqualified from running — an order that, after our lunch, he tweeted had come from Beijing and was “clearly politically driven”.
We turn to the more ordinary stuff of 23-year-olds’ lives, as Wong slurps the remainder of his milk tea. “Before being jailed, the thing I was most worried about was that I wouldn’t be able to watch Avengers: Endgame,” he says.
“Luckily, it came out around early May so I watched it two weeks before I was locked up in prison.” He has already quoted Spider-Man twice during our lunch. I am unsurprised when Wong picks him as his favourite character.
“I think he’s more . . . ” He pauses, one of the few times in the interview. “Compared to having an unlimited superpower or unlimited power or unlimited talent just like Superman, I think Spider-Man is more human.” With that, our friendly neighbourhood activist dashes off to his next interview.
bottom-up thinking 在 Bottom-up vs. Top-down processing | Explained in 2 min 的推薦與評價
![影片讀取中](/images/youtube.png)
Get My Free Ebook - 21 Productivity Strategies in Pictures Link ... ... <看更多>
bottom-up thinking 在 Top Down Processing vs Bottom Up Processing (Examples!) 的推薦與評價
![影片讀取中](/images/youtube.png)
Learn more about Top Down Processing: https://practicalpie.com/top-down-processing/Learn more about Bottom Up Processing: ... ... <看更多>
bottom-up thinking 在 cognitive psychology - Bottom up thinking - what is it? 的推薦與評價
The term 'bottom up' is used to describe an approach where no assumptions are made about the boundary of the problem space. The behaviour of ... ... <看更多>
相關內容