看到小夥伴的代碼,我表示深深的佩服。感覺自己離别人的差距怎麼就這麼大,心裡還真的很羨慕。按照要求,對小夥伴的代碼審查結果如下:
Code Review Checklist | |
General | |
· Does the code work? Does it perform its intended function, the logic is correct etc. | · 代碼大多數情況能夠正常運作,但是中間有一次出現了亂碼(燙燙燙燙燙),由于有随機數,是以沒能再次找到這個bug,除此之外,計算上有問題,發現有些式子的計算結果不對 |
· Is all the code easily understood? | · 代碼結構十厘清晰,這點讓我十分佩服。是以,我打算根據小夥伴的代碼結構,修改自己的程式 |
· Does it conform to your agreed coding conventions? These will usually cover location of braces, variable and function names, line length, indentations, formatting, and comments. | · 小夥伴的編碼習慣很不錯,有注釋,變量名也容易懂,閱讀代碼的時候十分容易 |
· Is there any redundant or duplicate code? | · 沒有備援,很多情況還簡化了代碼,比如運算的時候,使用/=符号,少寫了不少變量 |
· Is the code as modular as possible? | · 代碼結構很好,子產品化明顯,有主函數處理輸入輸出,有fraction類處理計算,有express類處理式子的相關結果 |
· Can any global variables be replaced? | · 全局變量不多,就幾個,沒必要替換,各自實作自己的功能 |
· Is there any commented out code? | · 沒有,也許是小夥伴在寫完程式之後就将多餘的代碼直接删除了 |
· Do loops have a set length and correct termination conditions? | · 循環都有終止條件,這些條件都是可控的,而且在測試過程中沒有發現有無限循環的情況 |
· Can any of the code be replaced with library functions? | · 有一個求最大公約數的函數可以替換,但是也是别人寫好的庫,并不是C++自帶的庫 |
· Can any logging or debugging code be removed? | · 沒有發現調試用代碼,估計是小夥伴在送出前就已經删除了吧 |
Security | |
· Are all data inputs checked (for the correct type, length, format, and range) and encoded? | · 輸入的格式沒有限制,調用了C的庫函數atoi(),但是當輸入參數是一個非數字字元時就會傳回0,這樣得到的結果就是不正确的 |
· Where third-party utilities are used, are returning errors being caught? | · 未使用第三方工具;沒有傳回異常值,傳回值都是0,不管格式正确與否,但是小夥伴列印輸出了相應的字元串說明相關異常 |
· Are output values checked and encoded? | · 輸出的表達式進行了除數是否為0和減法是否為負數的審查 |
· Are invalid parameter values handled? | · 未處理 |
Documentation | |
· Do comments exist and describe the intent of the code? | ·基本上在我覺得需要說明的地方都出現了注釋,有少部分需要聯系其他代碼才能看明白的代碼沒有comment |
· Are all functions commented? | · 不是每一個函數都有注釋,而且注釋并沒有說明函數的功能,這點我覺得需要改進一下 |
· Is any unusual behavior or edge-case handling described? | · 沒有描述 |
· Is the use and function of third-party libraries documented? | · 使用的第三方接口(函數)都是C庫中有的,是以未進行說明。 |
· Are data structures and units of measurement explained? | · 有作解釋,但是解釋并不多,隻是簡單的說明了一下 |
· Is there any incomplete code? If so, should it be removed or flagged with a suitable marker like ‘TODO’? | · 無未完成的代碼。 |
Testing | |
· Is the code testable? i.e. don’t add too many or hide dependencies, unable to initialize objects, test frameworks can use methods etc. | · 整個程式是容易測試的 |
· Do tests exist and are they comprehensive? i.e. has at least your agreed on code coverage. | · 沒有測試代碼。 |
· Do unit tests actually test that the code is performing the intended functionality? | · 沒有測試代碼。 |
· Are arrays checked for ‘out- of-bound’ errors? | · 數組都是定長的,而且按照理論是不可能越界的 |
· Could any test code be replaced with the use of an existing API? | · 不可 |
看了小夥伴的代碼,發現有不少可以改進的地方,但是更多的是值得自己學習的地方。我們都是用C++實作的,但是她的代碼看着很舒服,自己的代碼卻是連回頭看的想法都沒有,這一點,感覺自己特别失敗。希望在以後的學習中,慢慢改進自己不好的代碼風格,學習好的代碼結構,向小夥伴學習。