1 / 39

程式設計經驗分享

程式設計經驗分享. 以 C++ 期中考試題為例. Hello World. 別看貓沒點. After Hello World!!!. 卡關 ????. 破關方法. Ctrl + C Ctrl + V. 語言學習階段. 語法 跟語言本身有關 風格 跟人有關 演算法 跟運算效能有 關. 語法. 千萬不要背語法 考試 Open Book!!! 實務上 Open Book!. 演算法. 除非你打算做這行 成為一個好的程式設計員 : 花 10 年每天寫程式 學好演算法花兩年每天寫. 風格 Style. 養成好的習慣 , 習慣會跟著你一輩子

brad
Download Presentation

程式設計經驗分享

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 程式設計經驗分享 以C++期中考試題為例

  2. Hello World 別看貓沒點

  3. After Hello World!!! 卡關????

  4. 破關方法 Ctrl + C Ctrl + V

  5. 語言學習階段 • 語法跟語言本身有關 • 風格跟人有關 • 演算法跟運算效能有關

  6. 語法 • 千萬不要背語法 • 考試 Open Book!!! • 實務上 Open Book!

  7. 演算法 • 除非你打算做這行 • 成為一個好的程式設計員: • 花10年每天寫程式 • 學好演算法花兩年每天寫

  8. 風格 Style • 養成好的習慣,習慣會跟著你一輩子 • 課本和老師通常不教

  9. Style Simple and Elegant

  10. Simple Short and Easy

  11. Short Neat 乾淨簡潔

  12. Easy Easy to write *** Easy to read ***

  13. Hard to Read Bad int temp; for(int i = 0; i < size; i++){ for(int j = size - 1; j > i; j--){ if(arr[j - 1] > arr[j]){temp = arr[j-1]; arr[j-1] = arr[j]; arr[j] = temp;}}} //WTF????

  14. Easy to Read good int temp; for(int i = 0; i < size; i++){ for(int j = size - 1; j > i; j--){ if(arr[j - 1] > arr[j]){ temp = arr[j-1]; arr[j-1] = arr[j]; arr[j] = temp; } } }

  15. 如何提高程式的可讀性 縮排 命名 註解

  16. 命名 如果你不會命名你的 變數,常數,函示。 就代表你不會寫程式

  17. 命名 good bad double PI=3.14159; double area, r; 100 行之後 area = PI * r * r; double a=3.14159; double b, c; 100 行之後 b= a * c * c; //wtf?????

  18. 註解 註解跟調味料一樣 別加太多調味料浪費高貴的食材 過多的註解讓程式更難閱讀 適當的命名, 可減少註解

  19. 註解的其他妙用 註解可以用來暫時停止某些執行命令句 // area = PI * r * r; area = PI * r ** 2;

  20. 註解的其他妙用 記錄待辦事項: //下面的函式, 等看完布袋戲再說 void BubbleSort(intarr[], int size){}

  21. 程式可讀性 Debug(time) = coding(time) * 2 Maintain(time) = debug(time) * 10 Style 不好,請至少在上面的時間乘兩倍 再爛的話,砍掉重練

  22. 程式可讀性 出來混,欠人家 的總有一天要還

  23. Elegant Right tools Right place Right time

  24. Elegant • 計次用 for loop • 不計次用 while 當你只會用鐵鎚,全世界的東西你 都會看成是釘子

  25. 題目 自選或電腦選六個1~49的號碼 排序顯示所選及電腦開獎號碼 顯示抽中多少個號碼 結束後讓使用者選擇繼續或退出

  26. After Hello World!!! 卡關????

  27. 柿子挑軟的吃

  28. 什麼樣的柿子是軟的 你會的 常用的

  29. 史丹佛 while 迴圈 while(true){ // Do something if(結束條件==true) break; // Do something }

  30. do while 迴圈 do{ // Do something // 超級複雜的運算 }while(結束條件!=true);

  31. 史丹佛 while 迴圈 while(true){ // Do something if(結束條件==true) break; //超級複雜的運算 }

  32. 史丹佛 while 迴圈 別再使用Do while 迴圈

  33. 解決複雜問題的策略 Divide and Conquer

  34. How to eat an elephant?

  35. How to eat an elephant? One bite at a time.

  36. function 愛你的函式 許函式一個美好的未來

  37. function 切割工作用的(給main呼叫的) 常常會使用到的

  38. function 養成好習慣, 別省略掉函式的宣告 宣告放在 main()之前 定義放在 main()之後

  39. Function的設計 • 貪多嚼不爛 : • function 只作一件事, • 單純簡單的事 • 名實相符 : • function的名字=它所做的事 • 越短越好 : • 初學者不應超過10行程式碼

More Related