Showing posts with label Book. Show all posts
Showing posts with label Book. Show all posts

Sunday, June 21, 2020

花掉的錢都會自己流回來 [筆記]

我覺得這本書很有趣的地方在於作者 DaiGo 提出心理學的觀點來印證他提出的幾個原則。

https://drive.google.com/uc?export=view&id=1dVwkKu6KsboA2BAFxWuHB19khW9D_-Yy

如何創造金錢螺旋,大意就是找出自己的興趣,只把錢花在跟興趣有關的事上面,將興趣培養成工作,賺錢後再繼續投入興趣,這樣的一個迴圈。像是 amazon flywheel。

  • 作者花了一些篇幅講到 flow 心流體驗,稍微總結一下幾點如下。其中值得注意的是第五點:要進入 flow 需要即時的回饋。如果你可以在做事情之前先想想,什麼樣的回饋是能帶來滿足感的,就可以避免半途而廢,或是老是覺得自己無法專心很久的情況。
1. 明確的目的
2. 集中
3. 自我意識下降
4. 時間感消失
5. 即時的回饋:解決一項課題後,能夠感受到即時的回饋
6. 合適的難易度
7. 有能夠掌控全局的感覺
8. 能夠找出活動本身的價值

其實這部分如果你像我一樣以前看過其他flow相關文章就有點重複了。

  • 時間比金錢重要,Pareto principle 也就是 80/20 rules 法則,本來的意思是企業中工作能力強的前20%員工,能創造企業整體利益的80%! 換一個方式思考,這邊我們如果把20%的時間投入到喜歡的興趣之中,這筆投資將可以帶來80%的成果。
省時間的一些訣竅:把事情分成三種
不做也可以         ---> 就不要做了 省下來 (例如上臉書IG看電視等)
必須做但不想做 ---> 有效率的解決
想做

  • 值得一提的是 *將興趣收益化* 那章節,作者是這樣說的

“就是要讓身邊所有人都知道 我喜歡什麼 我對自己喜歡的事有多擅長 具體來說在這件事上 我能做到怎樣”

“不論你在哪一個領域有多麼高超的技能 只要沒有人知道你身懷絕技” 

“像 我們這次要舉辦OO的活動 你願不願意來幫忙呢 這種邀約機會 是絕對不可能從天而降的”

“當你對外公開自己喜歡什麼 而且希望將他活用在工作中之後 身邊的人才有可能改變對你的既定認識”

“因此不管今天出現在你面前的事不是初次見面的人 你都應該儘可能和更多人談談自己 喜歡的事物 和 擅長什麼 如此一來 你所說的話就也成為一種投資了!”

然後行銷時 對聽者來說可能是強迫推消 也別忘了奉獻 可以說 ”這是我喜歡的事 如果你有這方面需要我幫忙 別客氣 儘管開口 讓我祝你一臂之力“

“如果對方不知道你在做什麼 想要放手做自己想做的事會有些困難 因此 當有人問到 你是一個怎樣的人的時候 你應該回答在事前就先準備好的一段間單說詞”

重點就是鼓起勇氣 大聲說出你 擅長的事 喜歡的事物!
說明興趣 話越短越好: 請準備好一段 言簡意駭的一句話 用來說明你決心要做的事



  • 當一個給予者。互惠原理 (Reciprocity)可以幫你經營人心。
互惠原理的內容是說,當人們從別人那裡得到什麼之後,心裡會認為必須向對方回禮。
我們應該利用這個互惠原理,讓身邊的人成為自己的貴人。

送禮的重點其實在於 先發制人 和 不著痕跡。就算只是送一顆糖果給對方,天天週而復始地做下去,你的行為也會讓對方難以忘懷,覺得 “咦?那個人好像一直挺關心我的。”

慰勞的時機最好是在星期三。當人在身心都感到疲乏的時後,你做出的親切行為,最會令人銘感五內。

在 Give and Take (給予:華頓商學院最啟發人心的一堂課)中,心理學家Adam Grant 將人分為 -- 給予者 Giver, 索取者 Taker 和 互利者 Matcher 三種類型

給予者會去注意對方想要得到什麼,並在給予的過程中盡心盡力。
相反的,索取者行動時優先考量的是 自己能不能從中獲利。
而互利者則是在給予和接受之間尋求平衡。

你猜 在這三種人中能在事業取得巨大成功的是哪一類型呢? 沒錯 是給予者
那為什麼 Giver 會成功呢?先說索取者,因為 Taker 身邊的人都防著他,擔心這個人不知在盤算什麼,所以很難得到旁人幫助。再說互利者 Matcher 想的是 如何回收自己為其他人的付出,所以他們經常在腦中盤算 這個人真的會把我付出的那部分還給我嗎? 這種行為讓互利者無法及時採取行動,結果機會就白白的流失了,因此他無法搶得先機。
和其他兩者相比,給予者由於把對方的事情擺在第一位,互惠原理的作用讓他在許多事上可以拔得頭籌,給予者站在對方角度想,因此接受的人都會覺得很窩心。

這個想法就是
把錢用在其他人身上,就能產生遠超過金錢本身的價值,而且最後,他們還會回到自己身邊。


Sunday, May 12, 2019

Atomic habit 像原子般微小的事情最終將變成習慣

1
All big things come from small beginnings.
everything start with small thing.
small habits make a big difference.
作者自己的email list 從1000 email subscribers to 30,000 to 100,000.

Image result for 1 better every day
We often dismiss small changes because they don't seem to matter very much in the moment. If you save a little money now, you're sill not a millionaire. If you go to the gym three days in a row, you're still out-of-shape. If you study Mandarin for an hour tonight, you still haven't learned the language. We make a few changes, but the results never seem to come quickly and so we slide back into our previous routines.

You should be far more concerned with your current trajectory than with your current results.

Your outcomes are a lagging measure of your habits. Your net worth is a lagging measure of your financial habits. Your weight is a lagging measure of your eating habits. Your knowledge is a lagging measure of your learning habits. your clutter is a lagging measure of your cleaning habits. You get what you repeat.



我們希望努力帶來的成果是線性的 但其實不是 所以常會有失望時候 覺得自己努力了一個月了卻還不見成效
We often expect progress to be linear. In reality, the results of our efforts are often delayed.

Mastery requires patience. "When nothing seems to help, I go and look at a stone-cutter hammering away at his rock, perhaps a hundred times without as mush as a crack showing in it. Yet at the hundred and first blow it will split in two, and I know it was not that last blow that did it --- but all that had gone before it.

Goal vs system
Problem #1:  Winners and losers have the same goals.
Problem #2:  Achieving a goal is only a momentary change. (clean the room)
#3: Goal restrict your happiness. (goal create an "either-or" conflict: either you achieve or you fail)
When you fall in love with the process rather than the product, you don't have to wait to give yourself permission to be happy. You can be satisfied anytime your system is running.
#4: Goals are at odds with long-term progress.


2
changing our habits is challenging for two reasons:
(1) we try to change the wrong thing
(2) we try to change our habits in the wrong way

Image result for outcome based habit identity based habit
Most people don't even consider identity change when they set out to improve.
"I want to quit smoke" vs "I'm not a smoker"
"I want to get up in the morning" vs "I'm a morning person"

The ultimate form of intrinsic motivation is when a habit becomes part of your identity.
那要如何改變identity呢? identity是怎麼形成的?
其實就是習慣! 你習慣做什麼樣的事情, 你就有那樣的身分
The more you repeat a behavior, the more you reinforce the identity.
The most practical way to change who you are is to change what you do.
每一次你寫篇文章, 你就是一個作家
每一次你鼓勵員工, 你就是個領導者

壞習慣也是 每一次的壞習慣就對那個身分投了一票 但好在我們不需要全部票數一致 只需要過半數 大多數的票決定了你的身分

Two step process to change your identity
1. Decide the type of person you want to be
2. Prove it to yourself with small wins.

Ask yourself:
"Who is the type of person that could run a successful start-up?"
"Who is the type of person who could write a book?"
It's probably someone who is consistent and reliable. Now your focus shifts from writing a book(outcome-based) to being the type of person who is consistent and reliable (identity based)

The most effective way to change your habits is to focus not on what you want to achieve, but on who you wish to become.

3.
How to create a good habit
Cue:      Make it obvious
Craving:  Make it attractive
Response: Make it easy
Reward:   Make it satisfying

How to break a bad habit
Cue:      Make it invisible
Craving:  Make it unattractive
Response: Make it difficult
Reward:   Make it unsatisfying


5
Image result for the dopamine spike
(A) before a bit is learned, dopamine is released when the reward is experienced for the first time.
(B) Once a habit is learned, dopamine will not rises when a reward is experienced because you already expect the reward.
(C) when you expect reward but do not get one.
(D) when the reward is providing late.

The key takeaway is this: dopamine is released not only when you experience pleasure, but also when you anticipate it. Cocaine addicts get a surge of dopamine when they see the powder, not after they take it. Whenever you predict that an opportunity will be rewarding, your levels of dopamine spike in anticipation. And whenever dopamine rises, so does your motivation to act.

=> Temptation bundling. bind habit I need to habit I want.


思考一下你有什麼壞習慣想改變呢? 晚睡? 看電視看太久? 晚餐不定時吃
Bad habits repeat themselves again and again not because you don't want to change, but because you have the wrong system for change.

Habit awareness

Habit scorecard:

after work:
change cloth +
wash hand +
shower +
youtube tv -
netflix -
check phone -
check fb, ig -
masterclass +
play game -
watch cat -
check email, stuff -
before sleep, play ipad -

The process of behavior change always starts with awareness.

the first step to changing bad habits is to be on the lookout for them. If you feel like you need extra help, then you can try pointing-and-calling in your own life. Say out load the action that you are thinking of taking and what the outcome will be.

Many people think they lack motivation when what they really lack is clarity.
It is not always obvious when and where to take action. Once an implementation intention has been set, you don't have to wait for inspiration to strike. Do I write a chapter today or not? When the moment of action occurs, there is no need to make a decision. Simply follow your predetermined plan.



6. Environment context

cue最後會融入環境中, 我們會默默的為一個習慣指定一個地點, 一個人的沙發可能是他閱讀的地方, 對另一個人可能是看電視吃冰淇淋的地方, 這就是為什麼有時候離開舊的環境, 反倒是比較能專心, 因為你不用在對抗已經形成的cue
When you step outside your normal environment, you leave your behavioral biases behind. You aren't battling old environmental cues, which allows new habits to form without interruption.
所以剛搬家時是最能培養新的好習慣的時機阿! 當然不是說一定要搬家, 把家中的空間劃分清楚, 對於家裡小的人可以劃分讀書的椅子, 寫作的桌子, 吃飯的桌子
作者推薦 "one space, one use"!

You can do the same with your digital space. I know a writer who uses his computer only for writing, his tablet only for reading, and his phone only for social media and texting. Every habit should have a home.

If you can manage to stick with this strategy, each context will become associated with a particular habit and mode of thought. Habits thrive under predictable circumstances like these. Focus comes automatically when you are sitting at your work desk.

Gradually, your habits become associated not with a single trigger but with the entire context surrounding the behavior. The context becomes the cue. It's easier to build new habits in a new environment because you are not fighting against old cues.


10. How to find and fix the causes of your bad habits

Your habits are modern-day solutions to ancient desires.
每個行為都有表面上想要的跟底層的動機, 底層動機就像是:獲得食物跟水, 找到愛跟繁衍後代, 和他人連結, 獲得社會認可接受
A craving is just a specific manifestation of a deeper underlying motive.

- mindset shifting 改變想事情的方法
I "have to" wake up early to work. I "get to" wake up early to work.
You can reframe "I am nervous" to "I am excited and I'm getting an adrenaline rush to help me concentrate.
- Motivation ritual
You simply practice associating your habits with something you enjoy, then you can use the cue whenever you need a bit of motivation.

Habits are attractive when we associate them with positive feelings and unattractive when we associate them with negative feelings. Create a motivation ritual by doing something you enjoy immediately before a difficult habit.

11. Walk slowly but never backward
Motion makes you feel like you're getting things done. But really you're just preparing to get something done. When preparation becomes a form of procrastination, you need to change something. You don't want to merely be planning. You want to be practicing. If you want to master a habit, the key is to start with repetition, not perfection.

The two-minute rule
You will find that nearly any habit can be scaled down into a two minute version:
"Read before bed each night" becomes "Read one page."
"Do thirty minute yoga" becomes "Take out my yoga mat."

The idea is to make your habits as easy as possible to start. This is powerful strategy because once you've started doing the right thing, it is much easier to continue doing it.
A new habit should not feel like a challenge. The actions that follow can be challenging, but the first two minutes should be easy.
What you want is a "gateway habit" that naturally leads you down a more productive path.

The point is to master the habit of showing up. The truth is, a habit must be
established before it can be improved.


15. Make it satisfying. The cardinal rule of behavior change: What is rewarded is repeated. What is punished is avoided.
The first three laws of behavior change (make it obvious, attractive, and easy) increases the odds that a behavior will be performed "this" time. The fourth (make it satisfying) increases the odds that a behavior will be repeated "next" time. But there is a trick. We are not looking for just any type of sanctification. We are looking for immediate satisfactions.

雖然我們在現代大部分想得到的報酬是來自於延遲享樂, 例如我要存錢提早退休, 人類還是像遠古時代的動物一樣, 大腦的構造仍是偏好馬上得到的報酬, 這個在其他書中也常常提到的就是, 人的腦重視現在馬上得到的多過未來可能的到的事情,
所以當你要做的習慣屬於沒有回饋的種類, 像是我要停止喝酒, 我要少花錢, 這些事情長期下來是有好處的, 不過完成的當下並沒有帶來任何短期的報酬, 這時作者建議採用一種方法叫做 immediate reinforcement, 基本上就是想個法子給完成行為當下的自己馬上帶來的滿足感, 例如你很想要一件皮夾克, 所以每次只要你少喝一杯拿鐵, 飲料時, 就轉五元進入你的存款帳戶, 少看一部電影, 就轉十元, 這樣子你馬上看到了報酬, 帳戶的錢變多了, 最後你就拿買下一件昂貴的皮夾克 It's like creating a loyalty program for yourself. You are making it satisfying to do nothing.

最後等到這個習慣內化了, 他帶來的認同感大過了外部的報酬, 你保持這個習慣就是在認同自己這個身分!
Eventually, as intrinsic rewards like a better mood, more energy, and reduced stress kick in, you'll become less concerned with chasing the secondary reward. The identity itself becomes the reinforcer. You do it because it's who you are and it feels good to be you. The more a habit becomes part of your life, the less you need outside encouragement to follow through. Incentives can start a habit. Identity sustains a habit.



19. The Goldilocks Rule: How to stay motivated in life and work
- The Goldilocks Rule states that humans experience peak motivation when working on tasks that are right on the edge of their current abilities.
- Professional stick to the schedule; amateurs let life get in the way.

Avoid being "fair-weather meditators", "fair-weather athlete", or fair-weather anything.
Image result for the goldilocks rule


Wednesday, April 27, 2016

耐人尋味的人物角色

最近和一個舊朋友聊天,無意間想起了一個擱置許久想試著做的事情『總覺得我也能當個厲害的編劇啊!』

所以這篇就當作出發點吧。我發現在台灣有好幾個短期課程,在ptt上編劇版都能查到。可惜課程的時間都與我無緣,不過我可以自己練習。忘記從哪裡看到,一個成功的編劇,不只是個很會說故事,還要是一個很會寫作的人。

於是我找到了這本書,真是像撿到寶一樣開心,講的我點頭如搗蒜,『原來如此阿,這就是作家!』, 『原來人物角色要這樣細細地描繪呀!』。 真心的在一開頭就大推大澤在昌的 “暢銷作家寫作全技巧”。真的給了我很多啟發呢!





下面是書中提到的作家應具備的條件,當中的每日書寫這項,對於程式設計師來說也一樣,每日的工作並不一定會讓你真正的寫到一行又一行的代碼,有可能是在讀代碼,debug或是review,有些時甚至在開會的時間就度過了一日,在E社時,無所事事不必寫到代碼的日子也並不少見,這樣會在不知不覺中浪費了許多時間。冷卻過久的引擎,或是剛打開的熱水器在等熱水燒熱的時間。
  1. 用語精確
  2. 必須反覆校讀
  3. 每日書寫。真正的職業作家,可不是在趕截稿前徹夜寫稿,你要提早交稿就得養成每日寫出固定字數的習慣,許多作家都是全年無休的寫稿,有的每天不寫點什麼便渾身不對勁。寫作如同汽車的引擎一樣,一旦冷卻過久,就不容易啟動,所以即使你每天只寫了一頁,靈感和創意就源源而出,很快的進入創作的世界裡,因此力行每日書寫的習慣是何等重要啊!
  4. 勇氣與智慧。作家常遇上寫的不順,心情消沈的情形。

書中用老師對學生的方式來呈現,大澤老師有十堂課,分成十個章節。用口語的筆調將這些寫下來。複製幾段喜歡的段落。

每個登場人物都是活生生的個體。諸位在座的各位,現在聚在這裡,可離開了這裡,各自有各自的生活,各自的時間,依照自己所喜愛的方式過日子。小說裡登場的人物也一樣,他們有自己的生活時和時間。在哪裡和誰見面、吃著什麼食物,每個角色隨時都在活動著。

內容會像這樣以對話的方式,讓人讀來非常輕鬆易懂。

偏離主題時,需要從頭改寫嗎?
哈巴狗 寫短篇的時候,我可以一口氣完成,可是撰寫長篇小說,我在寫作中途卻因為查找資料,或被日常生活瑣事絆住,使得當初設定的故事情節或人物角色往不同的方向發展。重讀之後發現格格不入,像這樣的情況,我必須從頭開始改寫嗎?

大澤 這的確是個難題呢。直白的說,那篇作品還是重新改寫的好,所謂專業小說家,必須隨時讓自己維持最佳的寫作狀態。我除了自家寓所外,另外還有個工作室,現在,我幾乎都住在工作是裡面,我剛結婚的時候,往返於住家和工作室之間,那時我對太太說:“我外出工作(寫作)的時候,千萬不要讓我動怒或者開心喔。”也就是說,我希望隨時保持穩定的情緒狀態。... 我寫作小說的時候,如同屏著氣息潛入海底深處似的,突然地一通電話,迫使我得立刻緊急上升探出海平面上來,可想到待會兒『又得往下潛去呢!』就覺得手腳乏力啊!... 有許多作家很重視所謂的『寫作儀式』。例如,愛好音樂的作家,務必聽著這首曲子才開始動筆,有的是把鋼筆清洗乾淨填充墨水之後才開始,有的將鉛筆全部削好後排放整齊等等,這些儀式無非都是在尋找每種寫作的契機,努力使自己的情緒或是感知維持在穩定的狀態中。以我為例,我除了寫稿以外,一律不進書房。在工作室裡,有客廳和寢室,還有書桌和擺放著各種資料的書房。當我坐在書房的書桌前,就是『下筆』的時候了。我絕不會在那房間閱讀文學獎的入圍作品,或是用筆記型電腦查找資料。我一旦坐在書桌前,擺放在眼前的只有稿紙和文具而已。為了使自己進入『自發性的寫作』的狀態,在平時即要整頓好寫作環境。

讓小說主角更具魅力
各位學員筆下的主角形象,幾乎毫無魅力可言,就算是短篇小說,你也要寫出『若是這個主角出場,我真想往下讀啊』,或者『我好想再見到這個主角呢』。即使那個人物不是主角,你亦要寫的『這個角色還真有趣呢。只要有這個人物,故事應當會更加精彩。』

融入故事主角的靈魂
壽壽在自動販賣機錢買飲料的時候,背後有人拿氯仿之類的化學物品迷昏她並將之綁架。這部分的描寫太過於簡單。例如:『之後便失去了意識』這句話之前應該要有『她開始掙扎沒多久,強烈的氣味就從鼻孔中穿了進來。』以及『這是以往從來沒聞過的氣味』之類的描述。小說必須描寫到底發生了什麼事情,不將每個場面中壽壽的各種反應描寫出來,讀者很難感同身受。

課程的尾聲
當上職業作家以後,還有很多艱辛的挑戰。你要刻苦自求,把自己逼入絕境,朝更大的難關勇敢進發,並且相信前方還有更大的挑戰,卻依然能夠持續創作。當你使出百分百的力氣寫作,下次就能寫出120%的作品,只有拚到極限邊緣都想寫作的人,下一扇門才可能為他開啟。只有超越這個境界的作家,才得以在專業寫作的世界打出活血通到來。


大澤先生自稱在高二時就已經大量閱讀,他一年可以看完一千本書,也就是每日三本。雖然覺得自己已經算是常常在看書了,但一天三本的每天這樣,還真是一個了不起的事情。

大澤先生提到的練習
  • 用第一人稱寫作為課題的習作,中文字數約九千字。一張稿紙400字。五張一單位或十張一單位。
  • 12,000字的寫作練習,寫出結局『逆轉』的故事。
  • 寫出你最想寫的故事 15,000字
  • 寫出有薔薇與老舊建築的故事 12,000字
  • 描寫恐怖的心理 9000字
我想要我一次寫這麼多有點壓力,所以我也想用連載的方式,寫完這些練習。不過該努力的還是要花時間下去,品質跟下苦功也是看完這本書中,大澤先生一直想傳達的。

Tuesday, April 26, 2016

How to fly a horse


被稱為物聯網之父 Kevin Ashton的書。摘要一些我覺得很棒的句子。

創造唯一需要的,就是開始做。一旦開始做,就沒有所謂的做不到。創造的第一步不可能完美,想像力也需要反覆練習。創新的事物不會一出現就完好無缺,我們腦袋中的絕妙點子一旦拿到現實世界,就顯得搖搖欲墜。第一幅草圖的最大用途通常是填滿空白,此時的品質並不重要,只有一種草圖是糟糕的: 我們沒畫的那幅。

書的一開始就講了香草授粉的故事,非常吸引人。這個被稱為艾德蒙手勢,一個在Reunion島上有個叫Edmond非洲奴隸孩子的雕像。有興趣可以去書店翻完第一章就知道了(笑)

二十萬年前的智人使用的工具 一直到五萬年前才開始有變化,擁有改變的能力,想要更好的動力,創新,使人類有別於其他生物。

下苦功,是創新發明的靈魂。
下苦功是起早趕晚,不眠不休重複做 天天做即使毫無頭緒也要開始,走不下去也不能放棄,過程一點也不好玩,毫無樂趣可言。想要從事創造,就必須,劃破血管,讓血液蔓延。Paul Gallico: It is only when you open your veins and bleed onto the page a little that you establish contact with your reader. 

然後之後幾章節描述了一些創意的實驗:
1. 查理倒在地上,已經死亡。地上有水,還有玻璃碎片,湯姆還在房間內,how did Charlie die?
2. 犯人試圖從高點塔逃走,但牢房的繩子只足夠降落到地面距離的一半。他把繩子分割成兩半,再綁在一起,然後順利逃走。how did he did it?
3. 九點圖,四條線

答案就不提供啦,用跳脫框框的創意去想想!

有一章說到,阿基米德的故事幾乎可以確定不是真的,之後伽利略推測應是採用皇冠在水裡的重量,浮力,而不是溢出的水量。這也很有趣。

你們知道頭頂上的燈泡,燈泡變成點子的象徵。起源在哪嗎?
答案是:


所有的創造,不論是繪畫,飛機,都有相同基礎:不斷發現問題,解決問題。創造是思考的結果。決定你是否成功的關鍵,不在於你誇的步伐大小,而在你走了多少步。

之後又講了更多的故事當佐證,其中包括Folkman醫生的血管新生,他說創新是一連串週而復始的失敗。
Failure fallere 在拉丁文原意詭計意思是要我們不能上當
Melan Chloe/melancholy  憂鬱 黑膽汁
Chloe/choleric                   暴躁易怒 黃膽汁
Sanguis/sanguine              樂觀 血液
Phlegm/phlegmatic           冷淡遲鈍 黏液 

這句話我心裡也點點頭,"98%的老師都說,創造非常重要,應該每天教導,但在受試時,他們總是喜歡不太有創意的學生,勝過比較有創意的學生。"

為什麼我們會傾向拒絕新事物 (老湘就是個我馬上想到的活生生例子)?
這是因為當處於熟悉的環境,腦中海馬迴細胞放電速度比在新環境裡快了幾百倍,海馬迴連結杏仁核,主管情緒。海馬迴與杏仁核相連,是我們喜歡熟悉,排斥陌生的原因之一。

總之,也是一本可以在一個下午可以看完的好書。


 可以在amazon買得到   

Monday, April 18, 2016

零秒思考力

工作速度變快,腦袋就更靈活

此外,還能看出執行工作時該掌握哪些人脈?該說服那些人物?能看出所謂的要徑critical path,不是只有重視檯面下協調的日本企業才這樣,歐美國家也沒有太大不同,對於誰是部門的關鍵人物?要取得那個人的協助該怎麼做?為此又該先說服哪個人?該尋求誰的合作?

我覺得這是leader很重要的能力 (筆記筆記)。 此外,書中也提到了幾點我個人心裡非常認同的原則,可以應用在我們工程師的工作上。

提升工作速度八個原則

  • 首先要描繪全貌

若能了解全貌,你就會知道哪個部分重要,哪個部分不那麼重要。你會看出哪裡是絕對必須掌握的關鍵,那裡又是高風險所在。這樣就不會發生工作做得太細緻,超過所需,花太多時間在其實不那麼重要的部分,結果真正該做的事卻沒空處理的情況。

  • 抓住工作的重點

那麼,如何達到這麼完美的境界呢?首先想像該工作成功,進行得很順利的樣子,亦即要對工作成功的樣貌抱有明確想法。

  • 領先他人一步

領先他人一步對心理健康是非常有益的。所謂領先一步,是指比別人先想好該前進的方向,先調查好該瞭解的資訊,由自己主動先安排會議等等。 也就是要讓別人覺得,不知為何,你總是能在其他人發現並採取行動之前,先行動作。半步也好,只要比其他人走得前面一點,你就能展現出領導力。我們天生就是會跟著前面的人走,大家會去找這個人商量,各種資訊也會朝著這個人匯集,也因此,於是這個人會比較容易找到最佳做法,並且發揮領導力,以至於會有越來越多願意一同奮鬥的夥伴加入,工作又能加速進行。

透過寫筆記來達成零秒思考


赤羽雄二也寫了另一本書推廣筆記訓練,這種訓練能消除煩惱,可擺脫焦慮不安,讓人充分發會大腦原本的威力。做法是這樣,把A4紙平放,標題在左上角,日期在右上角,內容分成四到六行,並在一分鐘內寫完一張。他說只要在早上起床後到睡前這段時間內,每天寫十張,思緒就會變得非常清晰,如果能持之以恆每天寫十張,頭腦就會越來越靈活。

感覺有點浪費紙,我覺得寫下來這個動作是值得做的,但寫不一定要寫在紙上,手機note或者記事本都可以,重點是寫下來這個動作幫助我們釐清思緒。
透過寫筆記來消除焦慮不安,例如可以針對以下這些標題去寫:
  • 為什麼課長不把新專案交給我
  • 為什麼課長總是對我很嚴厲?
  • 如何能把下次簡報做好?
  • 該怎麼跟女友男友道歉?
  • 女友已經連續三天沒跟我聯絡了,是在生氣嗎?

最有效的資訊收集法

  • 不自己用腦想的人很危險

別人說什麼就信什麼,不動腦想的人,不論做什麼都很危險。這種人不太思考,理解淺薄,說起話來讓人難辨真假,即使反問他,試圖確認是這樣嗎?是的,沒錯。誒?不是這個嗎?阿,可能是耶。。。到底是哪個?可能會像這樣一無所獲。

  • 重要的文件須列印出來

每天早晚三十分鐘的資訊收集過程中,若看到特別重要的文件建議列印出來,並在上面註記,分門別類加以保存,會比在電腦上更容易記住。收集資訊不要再外出的時候以智慧型手來收集,家裡準備雷射黑白印表機就可以,非常好用。

  • 在家時可連接大型顯示螢幕,在家少用智慧型手機,平板電腦

用電腦與大型顯示螢幕,以最快的速度收集資訓,這樣得到的資訊才會又深又廣

  • 多多參觀各種展覽

每個月應參加一到二次左右的讀書會或研討會活動,這樣才能接受各層面的刺激,建立資訊收集的天線。
為了能時時確認讀書會,研討會得參加狀況,已掌握未來的計畫,我還準備了一個文件夾。將已參加過,預計要參加的讀書會及研討會的電子郵件等印出來,並標上日期後保存,這樣可以方便在最後一刻確認行程。

  • 選擇最有幫助的商量對象

光靠早晚三十分鐘上網收集資訊,仍會有不足之處,而所缺法的就是活生生的人的資訊。作者提到他剛進麥肯錫時,就曾天不怕地不怕地拜託日本分公司的老闆大前研一與他一對一聚餐。雖然周圍的人都說我不知天高地厚,但這件事卻在三個月後實現,成了人生一次寶貴的重大經驗。
以這種方式找到的商量對象,最好能以半年一次或一年一次的頻率與之聚餐,開會,已說明最新狀況。像是告訴對方你依期建議所做出的結果,也就是讓對方知道事情演變與成果,對方一定會很開心。

  • 多做演講以匯集資訊,進一步針對自己想學習的領域,鑽研的專業題材,爭取相關演講簡報工作

首先要建立該領域的部落格,以撰寫20~30篇相關文章為起點。每週更新一到兩次,持續三個月到半年左右,只要寫了這麼多篇部落個文章,就算原本是門外漢也會變得很內行。
覺得自己做不來的人,建議你一定要針對有興趣的領域,讀完100篇左右的部落格文章。會發現其中幾位撰文內容豐富多元的優秀寫手。只要參考這些人的方式,深入挖掘主題的方法,所運用的資料來源,漸漸的就能了解,自己如何針對自己喜歡的領域撰寫文章。

  • 英文會話能力

要加強英文會話能力,事先準備數百個溝通時想說的話,可能說的句子,並反覆念出來練習。例如
I think that is a great idea. I like it.
Let me share my opinion regarding this point.
作者說在韓國時也是這樣練習韓文的,因為韓文依禮貌程度不同,講法有差異,例如同樣是表示謝意,就有謝謝,感激不盡,和大恩大德沒齒難忘等不同的說法 (笑)

  • 能夠掌控電子郵件的人,就掌控了時間

好啦!差不多就是這些,希望自己時常回來看看,好好利用一定可以大有進步。有興趣的讀者可以去amazon.jp買來看看,博客來有中文版,這本簡單有用的書可以在兩三個小時內看完。



Tuesday, August 4, 2015

Team Geek

- p.7 bus factor: 
- p.9 interrupt protocol: 
- p.14 The moral is this: do not underestimate the power of playing the social game. It's not about tricking or manipulating people; it's about creating relationships to get things done, and relationships always outlast projects.
- p.17 your self-worth shouldn't be connected to the code you write. To repeat ourselves: you are not your code. Say that over and over. you are not your code.

- p.18 Failure is viewed as a golden opportunity to learn and improve for the next go-around. 
- p.19 "not hiding in the cave until it's perfect" 
       The key to learning from your mistakes is to document your failures. Write up "postmortems,' as they're often called in our business. (what was learned and what is going to change) 
       Don't erase your tracks, light them up like a runway for those who follow you! A good postmortem should include the following: A brief summary, timeline of event, primary cause, impact and damage assessment, a set of action items to fix the problem immediately, a set of action items to prevent the event from happening again, lesson learned.
- p.47 Comments should be focused on why the code is doing what it's doing, not what the code is doing.

Tuesday, June 2, 2015

How google works

"給認真努力的員工更好的待遇" 這樣的觀念一直是矽谷傳統。
原來在1960年代的時候,Bill Hewlett 和 David Packard就已經開始了,他們在Santa Cruz的山上買了一塊地,將其建造為Little Basin,是一個專為員工及員工的家人度假的地方。(Today it is a part of Big Basin Redwood state park)
他們也比Google早十年就請來了廚師免費招待餐點給員工和客戶了。



"schedule interviews for thirty minutes", 因為大部份的面試結果都是no-hire,所以Google認為不需要花超過三十分鐘來面試,如果真的相談甚歡,在安排下一次的面試也不會麻煩。於是如何在三十分鐘內讓面試討論的內容有意義才是關鍵。在早期,Google甚至對一位面試者面了三十次而且還無法做出決定!在做了些分析後他們發現,Decision accuracy在第四次面試後(85%)很快的下降,多一次的面試只增加不到1%的準確率,最後他們決定把面試次數上線改為五次,另一方面五是個質數(笑)。

Technical insight:
"To start with a solution to a narrow problem and look for ways to broaden it's scope"

"Disproportionate rewards"
就像職業棒球員一樣,明星球員的薪水可以到數百萬美元,而板凳球員就只有幾萬。"What's most important in the internet century is product excellence, so it follows that big rewards should be given to the people who are closest to great products and innovations, Pay outrageously good people outrageously well, regardless of their title or tenure. What counts is their impact"

"Plan your career"
    Here are some simple steps to creating a plan: 想想你的理想工作是什麼?不是現在而是五年之後的那份理想工作。你會想在哪裡上班?這份工作的內容是什麼?這份工作帶給你的薪水是多少? (where do you want to be? what do you want to do? how much do you want to make?)
把符合這份工作所需要的條件寫下來,就像是如果你在徵才網站上看到這份工作,上面寫的會是什麼?

    現在快轉五年,你真的得到這份工作了,你的履歷長什麼樣子,你是怎麼樣做的才可以讓你從五年前的狀況到達現在這裡? Keep thinking about that ideal job, and assess your strengths and weaknesses in light of it. How will you get there?  What training do you need? What work experience?


"Statistics is the new plastics"
Data is the sword of the twenty-first century, those who wild it well, the samurai. So start sharpening that blade, uruwashii, and take statistics.

"Know your elevator pitch"
    you pitch should explain what you are working on, the technical insight that 's driving it, how you are measuring your success(particularly, customer benefits), and perhaps how it fits into the big picture. Say it with conviction!
    Job seekers should also have an elevator pitch. This shouldn't be a condensed version of your resume, but should rather highlight its most interesting parts along with what you want to do and the packt you know you will have


Decision 和 Communication的章節像是與CEO比較相關,站在過來人的立場,給了許多當經理人的建議。Eric believes in the three-week rule: When you start a new position, for the first three weeks don't do anything. Listen to people, understand their issues and priorities, get to know and care about them, and ear their thrust. So in fact, you are doing something: You are establishing a healthy relationship.


"Innovation"
這章就很有趣,其中提到了Google[x]如何決定是否去執行一個idea:
1. 這個想法必須是能解決一個極具挑戰性的問題,一個可以影響幾億人的的機會。
2. 這個解決的辦法要和過去或已有的市場有著根本性的不同,不是要去改善現有的產品,而是start over。
3. 這個想法不是一個遙不可及的異想,是能在未來的幾年內能夠達成的,
Project Loon就滿足了這三個條件。
Before there can be innovation, there needs to be the proper context for innovation. This is usually found in markets that are growing quickly and full of competition (lots of companies are working on automated cards; most of them are actually car companies!) Don't look for empty space and then be lonely; it is much better to use an innovative approach to become a  player in a space that is or will be large. This may seems counterintuitive, since many entrepreneurs dream of entering "greenfield" markets that are brand new and have no competition. But usually there's a reason the market is empty: It's not big enough to sustain a growing venture.

To us, innovation entails both the production and implementation of novel and useful ideas. Since "novel" is often just a fancy synonym for "new," we should also clarify that for something to be innovative it needs to offer new functionality, but it also has to be surprising. If your customers are asking for it, you aren't being innovative when you give them what they want; you are just being responsive. That's a good thing, but it's not innovative. Finally, "useful" is rather underwhelming adjective to describe that innovation hottie, so let's add an adverb and make it radically useful. Voila:
For something to be innovative it needs to be new, surprising, and radically useful.
像是Google的Self-driving car.


"Derek Sivers: How to Start a Movement" https://www.ted.com/talks/derek_sivers_how_to_start_a_movement
First follower principle, 當你要開始一件活動,吸引第一個跟隨者是最重要的事。
"The first follower is what transform a lone nut into a leader...
If you really care about starting a movement, have the courage to follow and show others how to follow. and when you find lone nut doing something great, have the guts to stand up and join in!"

"1999 John Doerr, simple tool, think big, OKR"
一個目標必須是可以用輕易地用數字衡量是否達成了
例如:increase usage of feature by x percent, run a half marathon in under two hours, new WW systems serving significant traffic for XX large services with latency <YY microseconds
一個好的目標是有點超乎自己可達成範圍之後一點點所能夠完成的(stretch)


"Ship and Iterate"

"It's not about money"
那些成功的,鼎鼎有名的20% project,在Google裡是沒有錢可以拿的。原因很簡單:做這份任務中得到的成就感就是酬勞。"We don't provide any monetary incentive for 20 percent projects for the simple reason that we don't need to: The rewards comes from the work it self."
另外研究也指出外在的獎勵並不會刺激創意的發展,而且還有可能阻礙,把一份可以收穫很多的任務變成了只是為了賺外快的差事。



Tuesday, April 21, 2015

The Effective Engineer

最近發現這本Effective Engineer,一開始還以為是Effective C++系列的書,原來是現任於Quip的工程師寫的,內容應該是關於如何有效的選擇出最有影響力的工作任務來做,來提升自己。正好是我喜歡看的內容。二話不說就馬上買來看了

To be effective engineers, we need to be able to identify which activities produce more impact with smaller time investments. Not all work is created equal. Not all efforts, however well-intentioned, translate into impact.

第一章提到的這個點正是最近常想的事情,時間老是不夠用,但有許多事情是要花時間才的做完的,像是想要加入一間頂尖的公司,那得先花時間準備面試不是嗎?想要完美的呈現魔術表演,那得先花時間準備把戲,想瘦身也得花時間去運動。這麼多事情,加上每天吃飯洗澡睡覺開車瑣碎的小事,每一件都花一點時間,如果什麼都不想,日子就會一點一滴地流走,結果一點效果也沒有看到。所以如何挑出最有影響力的事情,然後用最少的時間去完成,才是聰明人的方法,work smart instead of work hard,以前附中的會讀又會玩的最高指導原則好像也有類似的精神喲。


overall leverage can only be increased in three way:
1. How can I complete this activity in a shorter amount of time?
2. How can I increase the value produced by this activity?
3. Is there something else that I could spend my time on that would produce more value?


"Dedicate Time on the job to develop new skills"

上班日總是覺得工作越來越多做不完,Task list上要做的事情一直增加,覺得自己跟不上進度嗎?
或許拿Google著名的20%時間是最好的例子,20%的時間相當於一個工程師每個禮拜中撥出一天來做side project來讓公司變得更好,對應到個人上面也一樣,我們也應該撥出時間來讓自己工作更有效率,與其花一整天八個小時,更建議大家每天花一到兩個小時來練習,這是為了培養出一個習慣。至於要練習什麼?  Edmond提供了十點建議:

1. Study code for core abstractions written by the best engineers at your company.
2. Write more code. [註1] 這點又再次被強調,看來達人們的建議都指向同一方向 :)
3. Go through any technical, educational material available internally.
4. Master the programming languages that you use. [註2] 正在練習中
5. Send your code reviews to the harshest critics.
6. Enroll in classes on areas where you want to improve.
7. Participate in design discussions of projects you're interested in.
8. Work on a diversity of projects [註3]
9. Make sure you're on a team with at least a few senior engineers whom you can learn from.
10. Jump fearlessly into code you don't know.

[註1] It's easy to think you understand something you've read, only to find large knowledge gaps when you actually set out to do it.
這句話我在同意也不過了,越聰明的人,領悟力可能也很好,看解答後好像一下就會了的樣子,但過兩天等短期記憶消失後還能夠在順利的寫出答案來嗎? 恐怕很難吧。
[註2] Make sure that at least one of your languages is a scripting language (e.g. Python or Ruby) that you can use as your Swiss army knife for quick tasks.
[註3] Interleaved practice of different skills is more effective than repeated, massed practice of a single skill at preparing people to tackle unfamiliar problems.


工作以外的時間呢?
- Invest in skills that are in high demand [註4]
- Read books  作者本人一個星期可以看完一到兩本書!
- Join a discussion group (e.g. book club, reading group)  
- Attend talks, conferences, and meetups [註5]
- Build and maintain a strong network of relationships. [註6]
- Write to teach [註7]
- Tinker on side projects, pursue what you love

[註4] 手機上的上網人口增加,手機銷售數量超過PC,當這些趨勢繼續,要是能具有mobile     development的技術說不定就能有更 多的機會。
[註5] 在十八世紀,一位叫做Benjamin Franklin的政治家和發明家組織了一個稱為"club of mutual improvement"的聚會,在每週五的晚上一群朋友們聚在一起,積極的討論著道德政治哲學,讓每個組員有系統地強化他們的能力。
[註6] "Lucky people dramatically increase the possibility of a lucky chance encounter by meeting a large number of people in their daily lives. The more people they meet, the greater opportunity they have of running into someone who could have a positive effect on their lives." The luck factor, Richard wiseman
[註7] "Writing also provides an opportunity for mindful reflection on what you've learned." Physics Nobel Prize winner Richard Feynman 這點也再次被許多成功人士分享,當我們將所學的知識寫下來時,會幫助自己在已知的地方有更深入的了解,原本不懂的地方也能pinpoint出那些不了解的細節與觀念,哪個是自己還沒了解的,這些事不寫下來是不會發現的!


Saturday, March 21, 2015

onward - Howard Schultz

Starbucks CEO寫的書,一直想要開一家自己的咖啡廳,打造一個舒服的環境讓宅宅們可以打電腦(笑)
如果真的有這個機會跟資本,那我這家cafe一定是明亮採光好,每個座位都是靠窗,中間是barista工作的地方,可以環顧四周的妹人客,每一杯咖啡都是花時間做出來的或是上面有著漂亮拉花圖案。因為自己希望處在空間感寬敞的地方,所以屋頂一定要挑高。店內不能有吃的味道,一定要充滿咖啡香,這點在Howard的書裡一樣,他覺得Starbucks提供的三明治(breakfast sandwitch)是個糟糕的決定,因為三明治裡面的起司加熱後有股討人厭的味道(that pungent smell he refered),完全破壞了店裡原有的咖啡香(rich, hearty coffee aroma),嚴重影響星巴克的核心價值-- coffee 。會這麼同意,大概也是我也對味道非常敏銳吧。

要像星巴克一樣開這麼多分店絕對是個挑戰,Howard說每兩年一次公司會舉辦長達一週的度假會議,讓所有店長,district manager,regional manager,還有international manager聚集在一起,賦予他們使命感,不只讓每家店要有profit,更重要的是每間店帶給那個區域的人們 people connection。

喜歡的幾段話其中之一是在Howard決定在某天讓全美的星巴克關門一天,重新訓練員工pour espresson的技術時提到的:

  There are moments in our live when we summon the courage to make choices that go against reason, against common sense and the wise counsel to people we trust. But we lean forward nonetheless because, despite all risk and rational argument, we believe that the path we choosing is the right and best thing to do. We refuse to e bystanders, even if we don not know exactly where our actions will lead.

  This is the kind of passionate conviction that sparks romances, wins battles, and drives people to pursue dreams others wouldn't dare. Belief in ourselves and in what is right catapults us over hurdles, and our lives unfold.

  "Life is a sum of all your choices," wrote Albert Camus. Large of small, our actions forge our futures, hopefully inspiring others along the way.


Onward-Starbucks-Fought-without-Losing-ebook

Sunday, June 15, 2014

A random walk down wall street

A practical guide for random walkers, a life cycle guide to investing

3. Dollar-Cost averaging can reduce the risks of investing in stocks and bonds.
Dollar-Cost averaging simply means investing the same fixed amount of money in at regular intervals over a long period of time.

Ex 每年投資$1000,在不穩定的市場跟穩定上漲的市場比較圖

If you expect to be a net saver during the next five years, should you hope for a higher or lower stock market during that period?

Many investor are elated when stock prices rise and depressed when they fall. This reaction makes no sense. Only those who will be sellers of equities in the near future should be happy at seeing stocks rise. Prospective purchasers should much prefer singing prices.

Ex 最初放$500, 之後每個月$100投資在Vanguard 500 Index mutual fund. $39,000 -> $265,000.

If possible, keep a small reserve (in a money fund) to take advantage of market declines and buy a few extra shares if the market is down sharply...
For the stock market as a whole, Newton's law has always worked in reverse: What goes down has come back up.


For those in their twenties, a very aggressive investment pro folio is recommended. At this stage, there is lots of time to ride out the peaks and valleys of investment cycles.





Tuesday, June 10, 2014

Coders at work 2

Douglas Crockford(Yahoo!):

"每次開會都會讓一些人閱讀他們各自的程式碼,...
如果你讓能力很強的同事閱讀程式碼,那麼他們周圍的新手們就會學到很多東西,而這一切是無法透過其他方式獲得的; 如果新手來閱讀程式碼,那他會得到很多極具價值的建議。
這需要給予團隊成員充分的信任,如果團隊不和睦,那就別指望這麼做了"

在招聘程式師時,如何識別優秀人才?
"我會讓應聘者帶來他們寫過的優秀程式碼並帶領我們閱讀這些程式碼。
我想考察這些人的展示能力,我想看看他們引以為傲的東西,我想知道這些程式碼是不是他們自己寫的。"

"好好學習寫作和閱讀"


Brendan Eich(Mozilla):

yacc, parser generator, context-free grammar

Thursday, May 15, 2014

Coders at work 1

Fitzpatrick 提到他為LiveJournal/Google招聘程式設計師時提到

"我總是找這種型別的人,他們會做很多別人沒要求他做的事,不僅是學校的專案或者前僱主要求他做的,他們對某些事情充滿熱情,有額外的專案。”

”HR的經驗中有這麼一條--- 一些人只會做讓他們做的事,沒有那種追求極致的熱情。他們會說:做好了,接下來幹什麼? 他們甚至不告訴你,自己就上網玩去了。“

他們在面試你時問了什麼? “任意長度的十進位數字字串相乘”
many solutions!
#!/usr/bin/env python
 
def digits(x):
    return [int(c) for c in str(x)]
 
def mult_table(xs, ys):
    return [[x * y for x in xs] for y in ys]
 
def polymul(xs, ys):
    return map(lambda *vs: sum(filter(None, vs)),
               *[[0] * i + zs for i, zs in enumerate(mult_table(xs, ys))])
 
def longmult(x, y):
    result = 0
    for v in polymul(digits(x), digits(y)):
        result = result * 10 + v
    return result
 
if __name__ == "__main__":
    print longmult(2**64, 2**64)

“Callgrind"
Profile你的程式,哪些function用去了最多的instruction
670,486  src/lcthw/bstrlib.c:bstrcmp [tests/bstree_tests]
  194,377  src/lcthw/bstree.c:BSTree_get [tests/bstree_tests]
   65,580  src/lcthw/bstree.c:default_compare [tests/bstree_tests]
   16,338  src/lcthw/bstree.c:BSTree_delete [tests/bstree_tests]
   13,000  src/lcthw/bstrlib.c:bformat [tests/bstree_tests]
   11,000  src/lcthw/bstrlib.c:bfromcstralloc [tests/bstree_tests]
    7,774  src/lcthw/bstree.c:BSTree_set [tests/bstree_tests]
    5,800  src/lcthw/bstrlib.c:bdestroy [tests/bstree_tests]
    2,323  src/lcthw/bstree.c:BSTreeNode_create [tests/bstree_tests]
    1,183  /private/tmp/pkg-build/coregrind//vg_preloaded.c:vg_cleanup_env [/usr/local/lib/valgrind/vgpreload_core-amd64-darwin.so]
,甚至清楚地指出哪一行的程式碼呢!
2,453  static inline BSTreeNode *BSTree_getnode(BSTree *map, BSTreeNode *node, void *key)
     .  {
61,853      int cmp = map->compare(node->key, key);
663,908  => src/lcthw/bstree.c:default_compare (14850x)
     .
14,850      if(cmp == 0) {
     .          return node;
24,794      } else if(cmp < 0) {
30,623          if(node->left) {
     .              return BSTree_getnode(map, node->left, key);
     .          } else {
     .              return NULL;
     .          }
     .      } else {
13,146          if(node->right) {
     .              return BSTree_getnode(map, node->right, key);
     .          } else {
     .              return NULL;
     .          }
     .      }
     .  }
”我覺得有些人只是在工作,而不是享受城市設計帶來的樂趣,這沒什麼問題。但把他們和那些核心程式師做比較就不行了,當一個人花的時間多十倍,不停地考慮怎麼寫好這程式,另一個人只為了工作而工作,那兩者的生產力上的差距又豈止十倍呢?“
你是因為覺得有趣才設計程式的? “是的,我還是會繼續做些小玩意,我的手機上有個無聊的棋類遊戲,我對她有點厭煩了,所以就寫了一個求解程式,其中試用了一些動態程式設計,處理不同的棋盤大小,還有很多隨機棋盤,解決棋局所需步數的長條圖。我把它發給作者..這是剪很有意思的事情,我想我可以退休後整天做這些事。”
src: 
http://c.learncodethehardway.org/book/ex41.html
http://rosettacode.org/wiki/Long_multiplication#Python

Wednesday, August 28, 2013

“abandon all hope, ye who enter here.”

haha..this is a cool comment


I might mention that there is a dark side to using complex algorithms in software systems. The algorithms may not be understandable by others (or even the original author, after a long passage of time). I had incorporated some sophisticated regular expression pattern matching technology into AWK. Although it is documented in the Red Dragon book, Brian Kernighan once took took a look at the pattern-matching module that I had written and his only addition to that module was putting a comment in ancient Italian: “abandon all hope, ye who enter here.” As a consequence, neither Kernighan or Weinberger would touch that part of the code. I was the one that always had to make the bug fixes to that module!


can someone become a better programmer?
Al: My number one suggestion is to think before you program. Then I would advocate
writing lots of code, having experts critique your code, reading good code written by
others, and participating in code reviews. If you’re really brave, you could try to teach students to write good code.
... ...
I have certainly found that in every book that I have written with programs in it, the programs have gotten more efficient and shorter with the writing of the book. During the year we wrote the AWK book, many of the programs in it became 50% shorter. This is because we learned how to use the abstractions in AWK even more effectively than we initially had thought.

Thursday, July 4, 2013

Writing solid code


  • Enable all optional compiler warnings.
  • Lint.
  • Maintain both ship and debug versions of your program.
  • Use assertions to validate function arguments.

#ifdef DEBUG
    void _Assert(char*, unsigned); /*prototype*/
    #define ASSERT(f)\
      if(f)          \
        {}           \
      else           \
        _Assert(__FILE__, __LINE__)

#else
    #define ASSERT(f)
#endif

void _Assert(char *strFile, unsigned uLine)
{
  fflush(NULL);
  fprintf(stderr, "\nAssertion failed: %s, line %u\n", 
           strFile, uLine);
  fflush(stderr);
  abort();
}



  • Strip undefined behavior from your code, or user assertions to catch illegal users of undefined behavior.
  • Don't waste people's time. Document unclear assertions.
/* Blocks overlap? Use memmove. */
ASSERT(pbTo>=pbFrom+size || pbFrom >= pbTo+size);
  • Either remove implicit assumptions, or assert that they are valid.
  • Use Assertions to detect impossible conditions.
  • Don't hide bugs when you program defensively.
  • Use a second algorithm to validate your results.
implement an ASSERT macro that the file name string(__FILE__) would be defined just once per file:
bury the details in a new ASSERTFILE macro that you use once at the start of each source file


  #ifdef DEBUG
    #define ASSERTFILE(str)    \
              static char strAssertFile[] = str;

    #define ASSERT(f)          \
              if(f)            \
                {}             \
              else             \
                _Assert(strAssertFile, __LINE__)
  #else
    #define ASSERTFILE(str)
    #define ASSERT(f)
  #endif
  • Eliminate random behavior. Force bugs to be reproducible.
#define bGarbage 0xA3
flag fNewMemory(void **ppv, size_t size)
{
  byte **ppb=(byte**)ppv;
  ASSERT(ppv!=NULL && size!=0);
  *ppb=(byte*)malloc(size);
  #ifdef DEBUG
  {
     if(*ppb != NULL)
       memset(*ppb, bGarbage, size);
  }
  #endif
  return (*ppb != NULL);
}
  • Destroy your garbage so that it's not misused.
  • If something happens rarely, force it to happen often.
Once you release memory, you don't own it, so you shouldn't touch it.
(some memory managers use free memory to store free-chain information, or other internal implementation data) Programmers either don't know, or regularly forget, that realloc can move blocks. Detecting this problem is important. =>
Stimulate what realloc does:
If the block is shrinking, pre-fill the soon-to-be released memory. If the block is expanding, force it to move(instead of expanding in place) by faking a realloc. If the block is the same size, don't to anything.

Remember that debug code is extra code, not different code. Unless there is a compelling reason not to, you should always execute the ship code, even if it's redundant.
  • Keep debug information to allow stronger error checking.
  • Design your test carefully, nothing should be arbitrary.
Choosing a value for bGarbage, recursed over the symbol table's tree structure with a pre-order traversal. Some choices are better than others.
  •  Setting "undefined" memory to a constant garbage value is one example of removing random behavior.
  • Make sure your tests work even for programmers who are unaware of them. The best tests are those that require no knowledge of their existence.
Programmers occasionally write coe that fills past the end of an allocated memory block. How you could enhance the memory subsystem checks to alert you to these types of bugs.

Allocate 1 extra byte for every block that you allocate: 檢查DebugByte有沒有被覆寫過去

#define dDebugByte 0xE1

#ifdef DEBUG
  #define sizeofDebugByte 1
#else
  #define sizeofDebugByte 0
#endif

flag fNewMemory(void **ppv, size_t size)
{
  byte **ppb = (byte**)ppv;
  ASSERT(ppv!=NULL && size !=0);
  *ppb = (byte*) malloc(size+sizeofDebugByte);

  #ifdef DEBUG
  {
    if(*ppb!=NULL)
    {
      *(*ppb+size)=dDebugByte;
      memset(*ppb, bGarbage, size);
      .
      .
      .


flag fResizeMemory(void **ppv, size_t sizeNew)
{
  byte **ppb = (**byte) ppv;
  byte *pbNew;
  .
  .
  .
  pbNew = (byte*)realloc(*ppb, sizeNew+sizeofDebugByte);
  if(pbNew!=NULL)
  {
    #ifdef DEBUG
    {
      *(pbNew+sizeNew)=dDebugByte;
      .
      .
      .


/* Verify that nothing wrote off end of block. */
ASSERT(*(pbi->pb + pbi->size) == dDebugByte);

how could you give testers the ability to fake out-of-memory conditions?
Normally by using a tool to gobble memory until the application's memory requests begin to fails.
It works, but not very precise --- it cause some allocation request somewhere in the program fail.
A better technique is to build an out-of-memory simulator directly into the memory manager.
在newMemory時,或在resizeMemory時,add an if statement

#ifdef DEBUG
  if(fFakeFailure(&fiMemory))
  {
    *ppb=NULL;
    return (FALSE);
  }
#endif

With these changes, the failure mechanism is in place. To make it work, you would call the SetFailure routine to initialize the failureinfo struct:

/* tell the failure system that you want to call the system five times before getting seven consecutive failures. */
SetFailures(&fiMemory, 5, 7); 

/* tow common calls to SetFailures: Don't fake any failures. Always fake failures */
SetFailures(&fiMemory, UNIT_MAX, 0);
SetFailures(&fiMemory, 0, UNIT_MAX);


The code below implements the four functions that make up the failure mechanism.

typedef struct
{
  unsigned nSucceed; /* # of calls before failing */
  unsigned nFail;    /* # of times to fail        */
  unsigned nTries;   /* # of times already called */
  int lock;          /* if > 0, disable mechanism.*/
} failureinfo;

void SetFailures(failureinfo *pfi, unsigned nSucceed, 
                  unsigned nFail)
{
  /* If nFail is 0, require that nSucceed be UNIT_MAX. */
  ASSERT(nFail != 0 || nSucceed == UINT_MAX);

  pfi->nSucceed = nSucceed;
  pfi->nFail    = nFail;
  pfi->nTries   = 0;
  pfi->lock     = 0;
}

void EnableFailures(failuresinfo *pfi)
{
  ASSERT(pfi->lock > 0);
  pfi->lock--;
}

void DisableFailures(failuresinfo *pfi)
{
  ASSERT(pfi->lock >=0 && pfi->lock < INT_MAX);
  pfi->lock++;
}

flag fFakeFailure(failureinfo *pfi)
{
  ASSERT(pfi != NULL);
  if(pfi->lock > 0)
    return (FALSE);

  /* Pin nTries at UINT_MAX. */
  if(pfi->nTries != UINT_MAX)
    pfi->nTries++;

  if(pfi->nTries <= pfi->nSucceed)
    return (FALSE);

  if(pfi->nTries - pfi->nSucceed <= pfi->nFail)
    return (TURE);

  return (FALSE);
}

  • Don't wait until you have a bug to step through your code
  • Step through every path (more than one code path: if and switch statements, &&, || and ?: operators)
  • As you step through code, focus on data flow ( Overflow and underflow bugs, Data conversion bugs, Off-by-one bugs, NULL pointer bugs, Bugs using garbage memory(oxA3 bugs), Assignment bugs in which you've use = instead of ==, Precedence bugs, Logic bugs, )
  • Source leve debuggers can hide execution details. Step through critical code at the instruction level.
  • Bugs don't grow in code spontaneously; they are the result of a programmer's writing new code or changing existing code. If you want to find bugs in your code, there is no better method than stepping through eery line of the code the moment it's compiled.
  • The problem with black-box testing is that you can't tell what goes on between stuffing in the inputs and receiving the outputs. The best way to catch bugs is to look for them the moment you write or change code. I don't know how many programmers who consistently write bug-free code, but the few I do know habitually step through all of their code

  • Make it hard to ignore error conditions. Don't bury error code in return values.
  • Always look for, and eliminate, flaws in your interfaces.
  • Don't write multipurpose functions. Write separate functions to allow stronger argument validation. 
  • Don't be wishy-washy. Define explicit function arguments.
getchar returns int
realloc return null (Ideally, realloc would always return an error code and a pointer to the memory block  regardless of whether the block was expanded.)

/* the if statement in the code ensures that the original pointer is never destroyed. */

flag fResizeMemory(void *ppv, size_t sizeNew)
{
  byte **ppb = (byte**) ppv;
  byte *pbNew;
  
  pbNew = (byte*) realloc(*ppb, sizeNew);
  if(pbNew!=NULL)
    *ppb=pbNew;
  return (pbNew!=NULL);
}



  • Write functions that, given valid inputs, cannot fail.
Implement standard tolower function to "return the lowercase equivalent of ch if one exist; otherwise, return the character unchanged" If you find that you can't eliminate error condition, consider disallowing the problematic cases altogether. use an assertion to verify argument.


char tolower(char ch)
{
  ASSERT(ch>='A' && ch<='Z');
  return (ch+'a'-'A');
}



  • Make the code intelligible at the point of call. Avoid boolean arguments.
UnsignedToStr(u, str, TRUE);
UnsignedToStr(u, str, FALSE);
=>
#define BASE10 1
#define BASE16 0
UnsignedToStr(u, str, BASE10);
UnsignedToStr(u, str, BASE16);
=>
void UnsignedToStr(unsigned u, char *str, unsigned base);

  • Write comments that emphasize potential hazards.

/* getchar -- equivalent to getc(stdin).
 *
 * getchar returns the next character from stdin. When
 * an error occurs. it returns the *int* EOF. A typical 
 * use is
 * 
 *   int ch;  //ch *must* be an int in order to hold EOF.
 * 
 *   if ((ch=getchar())!=EOF)
 *     //success
 *   else
 *     //failure
 */

int getchar*void)
...

/* realloc(pv, size)
 * ...
 * 
 * A typical use is
 * 
 *   void *pvNew;  //used to protect pv if realloc fails
 *   pvNew = realloc(pv, sizeNew);
 *   if(pvNew!=NULL)
 *   {
 *      //success --update pv
 *      pv=pvNew;
 *   }
 *   else
 *      //failure -- don't destroy pv with the NULL pvNew
 */

void *realloc(void *pv, size_t size)
...

why is the ANSI strncpy function bound to trip up the unwary programmer?
Sometimes strncpy terminates the dest str with a nul character, and sometimes it doesn't.

C++'s inline function specifier is valuable because it allows you to define functions that are as efficient as macros yet don't have the troublesome side effects that macro "functions" have in evaluating their parameters.

The serious problem with C++'s new & reference arguments is that such arguments hide the fact that you are passing the variable by reference , not by value, and that can cause confusion. For example, suppose ou redefine the fResizeMemory function so that it uses a reference argument. Programmers could then write
if( fResizeMemory(pb, sizeNew))
   resize was successful
But notice, programmers unfamiliar with the function would have no reason to believe that pb might be changed during the call. How do you think that will affect program maintenance?
A related concern is that C programmers often manipulate the formal arguments to their functions because they know those arguments are passed by value, not reference  But consider the maintenance programmer who fixes a bug in a function he didn't write. If that programmer fails to notice the & in the declaration  he could modify the argument without realizing that the change won't be local to hide function . & reference arguments are risky because they hid an importnat implementation detail. 

Saturday, January 12, 2013

大學生知道了沒

你學到了什麼,比你拿幾分更重要

何謂成功 何謂失敗

Thought on success: http://www.thecrimson.com/article/2009/2/23/thoughts-on-success-students-can-be/
Students can be very tough on themselves. It concerns me that some carry a very narrow definition of success and others see asking for help as a sign of weakness. Years ago, freelance writer Linda Weltner shared the following story attributed to Norris Lee in The Boston Globe: 

A lecturer stands in the front of a class of overachievers, holding a 1-gallon wide-mouth mason jar. He fills it with good-size rocks, then asks the group, “Is this jar full?” The audience agrees that it is. 

“Oh, really?” he asks. He pours in several handfuls of gravel. “Is the jar full now?” The audience is doubtful. Probably not. He pours a handful of sand into the jar, filling it to the brim. “How about now?” he asks. Not yet. He pours in a pitcher of water. 

“OK,” he asks. “What’s the lesson to be learned here?” 

“Well,” says a man sitting near the front, “you’ve just demonstrated that no matter how full your schedule is, you can always fit more in.” 

“You’re absolutely wrong,” says the teacher. “The point I’m making is that if you don’t put the rocks in first, you’ll never get them all in.” 

This story says a lot about success. Harvard educators have more than education as a job; they must help students identify what the “rocks” in their world are at any point. By “rocks,” I mean the things a student wants to place high priority on when assessing progress made or distance still to go. Students want to be successful, but too often they see success in a limited way (for instance, a near flawless transcript) or they don’t really know what they are working toward. 

In high school, it was simpler. Students pushed to assemble records that would get them into top colleges. With tougher competition in college, it becomes more difficult to achieve the near flawless transcript. And, with many more post-graduate options, it is difficult to feel a clear sense of direction. 

In the past, when I have asked advisees what they want to be sure gets into the jar, or what they will use as a marker of success, they have thought hard. Some responses come to mind: I want to feel like I fit in personally and have one or two really good friends; I want to make strong progress in identifying a concentration; I want to interview my grandmother, whose health is failing, in order to begin to write a memoir. These responses have given the students a personal compass and a chance to look back at the end of the year with—more often than not—a sense of accomplishment and self-worth. That awareness has mattered hugely. 

My second concern is about the act of asking for help. Clarissa Pinkola Estes, a poet and psychoanalyst, made the following statement: “Asking the proper questions is the central action of transformation. Questions are the key that causes the secret doors of the psyche to swing open.” I know that it can be hard to ask questions or to acknowledge that you don’t have the answers that appear critical to move forward. But, it is important to remember that this is a complicated place and this is a complicated period of one’s development. We think more—not less—of students who ask questions and who take advantage of the myriad resources and support services here. Doing so suggests a kind of agency or taking charge that is both appropriate and applaudable and that contributes significantly to the achievement of success.


行使你的教育自主權:

從接受的角色轉換為主張的角色
如果你能用熱忱與殷切的好奇心去學習,自然能完成那些達到好成績之前,所必須要的苦差事
善用教授們訂出的輔導時間
與教員們密切聯繫 : 在哪些課堂上較可能與教授建立私交?可以主動挑選這種課
在教室以外的地方開啟與faculty的學術對話/非學術對話
握有學習的主控權,進行策略性的思考,展現你的自制力,小心審慎哪些事重點,該在何時完成
懂得方法的學生不會試著把所有東西都塞進腦子裡,以為這樣就可以好好吸收,而是選擇特定的學習方式,屆此管理自己所吸收的資訊。在念書時,為什麼我要念這些東西?我從中應該學到什麼?他們能幫我回答什麼問題?透過我的學習與練習將來我有辦法解決什麼難題?

邁向成功的三個關鍵:
設定個人目標
培養學習策略
做計畫(找出阻礙你的原因,並且把它排除掉)

時間管理並不只是跟避免拖拖拉拉有關,他的經隨是,你必須主動管理,你怎樣使用時間這種最珍貴的資源。分析你是怎麼消耗掉一整天的。估算一下自己在一週之內做了哪些事。打開一個你自製的電子表格,在左邊欄位列出以半小時為單位的時間,頂端列出七欄代表七天。寫下你覺得在哪個時間點應該要做的事。把每件事花了多少時間都寫下來上課練習吃飯與同學碰面上網逛臉書睡覺。不要有所遺漏,包括運動玩樂看電視,在這些活動之間,你必須插入25~35小時的空檔溫習功課。
第二步驟是精確記入實際做的事情,當然不會百分百一樣誰都有發呆分心的時候,人生也有許多無法預期與計畫之外的事。重點是看出你與理想的計畫相差多遠。

提早一點起床,在上課前念書或溫習筆記,如果課堂間有一小時空檔,他們會坐下來念書而不是喝咖啡,聊天發呆。我認識的一些最有成就的學生,他們把白天時間當成在上班。這種觀念跟校園文化相反,大部分學生都是晚上七點才開始念書,然後一直念過午夜,如果你平均一天上三小時的課,那麼你等於是把八小時的白天時間浪費在學業以外的事情上面。你可以先把工作做完,然後好好享受剩餘的時光。

問你的授課老師,他們對於修課學生會提出哪些學習建議,請教那些跟你修同一門課但是表現較好的同學,問他們是怎樣吸收教材的。

把問題寫下,期中考試題也袋了,圈出他還不懂的地方,他先想好要做些什麼,把問題以及他不懂的一些關連列出來,大衛讓教授可以把注意力擺在一組特定的問題上,事後他可以獲得更多了解教材的洞見,

Friday, January 11, 2013

三本很受啟發的書

Outliers: the story of success
好上加好的馬太效應
一萬小時的努力
天才的迷思

上哈佛學到的事
每天讀四個小時的書,然後睡五個小時的覺。其他時間就去練舞或是練舞台劇。
就算是結果相同的事,也要做的與眾不凡。
追求最好的,盡最大的努力。而且一開始就要為了盡最大努力追求最好而祈禱。
想要有效率讀書,第一步就是要保留一段不受他人妨礙,數個小時的完整讀書時間。
和教授親近
真正的自信,是來自於將困難克服的那一刻。一再挑戰自己的極限,也將自己的能力做最大的延伸。
所謂不可能是不努力的人找的藉口
brown bag lunch
將時間好好安排,做真正想做的事情(像一間吃到飽餐廳,如果傻傻地想到什麼就吃什麼,很有可能會吃壞肚子,或是塞進一堆沒營養的東西,等看到真正美味的食物時,大概也吃不下了)
在哈佛待了一年之後,我用不同的角度審視我自己。以前的我只希望有所不同,希望變得更好,但卻不知道應該先從改變自己開始。每年都在同一塊土地上撥下相同的種子,用同樣的方式耕種,然後奢望今年比往年更豐收,簡直像個懶惰又貪心的農夫,如果每年都種一樣的農作物,久了地力就會逐漸損耗,這時就要採取休耕或是轉種其他作物,一直到地力恢復為止,這是另一種意義的領土擴張。用更具創意及生產立的方式來開發既有的土地,這點遠比擴大佔地更重要。也因此,一定要懂嘗試用不同的角度來看待相同的事物,只有想法改變,並不會讓結果有所不同。必須在行動及生活習慣上做改變,才可能有不同的結果。我們應該練習如何努力才能達成願望。
努力也是需要練習的,嘗試過的人才知道如何努力,光有決心是不夠的,
成就也一樣,要先知道如何成就小事,這樣才有可能成就大事

Talent is overrated. What really separates world-class performers from everybody else
我比別人更認真 刻意練習 讓自己發光
刻意練習是專為突破現狀,更上層樓而設計的活動,他挑戰你的心智,需要教練從旁協助
多年密集的刻意練習訓練會改造身體和大腦,讓卓越者比多數人感知更多,知曉更多,記憶更多
確知目標和方向:顯而易見卻值得深思的第一步:在於知道你想做什麼,這裡的關鍵字不是什麼,是知道。卓越之路需要經理多年的嚴苛考驗,若非全心全力投入,誰都不可能達成。你比需明確知道你想要做什麼,而不是覺得,傾向或考慮自己要做什麼
自發練習必須集中在上午,由於練習如此辛苦,這些小提琴家必須精確安排固定作息時間才能大量練習