?說明:因為本次一些特殊的原因,我與一位韓國留學生同學、以及六班的一位同學一起結對編程。
General
- (N) Does the code work? Does it perform its intended function, the logic is correct etc.
兩位結對的伙伴的代碼都只能實現需求功能中的一部分:
- Z同學目前實現的功能有:只能生成10000以內數目的,沒有經過去重判斷的,整數的加減乘除題目。
這位同學沒有實現的需求功能有:分數參與運算、生成的部分題目需含有括號、生成的題目不重復、用命令行控制參數、參數出錯的提示、給定題目和答案文件進行檢查、支持10000以上的數據量。
? 這位同學實現錯的功能有:值域范圍包含了-r的參數該值。
- Y同學目前實現的功能有:從鍵盤鍵入的0~10整數范圍內的簡單的加減乘除單項的答案檢查(不包含括號)。
這位同學沒有實現的需求功能較多,基本上沒有完成功能。
- (Y) Is all the code easily understood?
因為他們代碼實現功能較弱,兩位同學都是用C++寫的,都只有main函數:(。相對而言代碼結構十分簡單清晰。
- (N) (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.
雖然代碼行數較少,但是Z同學的代碼變量命名我不是很習慣,他的命名是這樣的:
int an = 0;int n;int r;int i=0;int nINT;int number_num;int op_num;int number;其中各個變量旁均沒有注釋說明與解釋其意義:(。
Y同學的代碼變量命名(雖然只有兩個)也比較簡短,與我習慣的變量命名習慣略微不同。
其他方面的話,Z同學的縮進風格比較差,因為while循環等與后面是等齊的,部分代碼如下:
while(an<n){ op_num = 1+rand()%3; number_num = op_num+1; while(i<op_num){number=1+rand()%r;cout<<1+rand()%r;nINT = rand()%4;Y同學相對而言縮進風格比較好,至少看起來比較舒服。
Z同學在循環的開頭有部分注釋,但是Y同學沒有注釋。
- (N) Is there any redundant or duplicate code?
?
Z同學和Y同學的代碼中沒有冗余的代碼。(因為確實是寫得比較簡單)
?
- (N) Is the code as modular as possible?
兩位同學都是使用C++寫的,并且都只有main函數。并沒有模塊化的思想...
- (N) Can any global variables be replaced?
這個題選N的原因是...我的結對伙伴沒有使用全局變量。
- (N) Is there any commented out code?
兩位同學看起來均沒有經歷過較長的代碼開發時間,所以沒有過時的代碼與調試的代碼。
- (Y) Do loops have a set length and correct termination conditions?
有。并且從代碼來看未發現無限循環的情況。
- Can any of the code be replaced with library functions?
Z同學的代碼和Y同學的代碼實現的功能相對簡單,能實現使用庫函數的都使用了庫函數。
- Can any logging or debugging code be removed?
兩位同學的代碼中沒有記錄或用來debug遺留的代碼。
?
Security
- Are all data inputs checked (for the correct type, length, format, and range) and encoded?
Z同學只是對輸入的-n參數>10000時進行了報錯處理,在其他情況如n為負數,r為負數等情況沒有進行出錯檢查。(看到這里,實際上我的代碼里也沒有這方面的出錯處理,只是對參數的輸入位置出錯時會有提示,但是沒有考慮n和r為負數的情況,真是我的失策:(。)
Y同學在自己的0~10的單項表達式的計算程序中對輸入的數字的范圍(0~10)進行了判斷與限定,但是沒有進行任何的報錯處理。
- Where third-party utilities are used, are returning errors being caught?
Z同學未使用第三方工具;程序中并沒有主動拋出任何可控異常,一些出錯的情況使用了打印輸出的形式進行處理。
Y同學沒有任何的輸出錯誤說明。
- Are output values checked and encoded?
兩位同學都對輸出的表達式進行了除數是否為0進行了檢查。
但是兩位同學都沒有對減法的結果是否為負數進行檢查。其余的因為功能也并未實現,所以并沒有做出該有的檢查。
- Are invalid parameter values handled?
這兩位同學都默認用戶輸入是合法的。所以并沒有對無效的參數進行處理。
?
Documentation
- Do comments exist and describe the intent of the code?
只有Z同學有類似于overview的簡短注釋,但是Y同學沒有任何描述性的注釋。
- Are all functions commented?
兩位同學都只有main函數,Z同學算是都有注釋,Y同學沒有注釋。
- Is any unusual behavior or edge-case handling described?
兩位同學都沒有對邊緣情況的處理(雖然代碼中處理了)寫進注釋中。
- Is the use and function of third-party libraries documented?
沒有...都沒有使用...
- Are data structures and units of measurement explained?
如果數組算是數據結構的話,Z同學使用了數組的數據結構并寫注釋說明了它的作用。
- 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.
兩位同學只有main函數,基本無法構造測試樣例。
- 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?
不可以...
?
本次結對編程的伙伴代碼能力稍差一些,我們在經過商討后(已經跟羅老師說過)我打算使用帶新人的結對編程模式:我對每個功能進行詳細的模塊劃分后,作為領航員觀察他們完成部分小的模塊和一些單元測試。然后我寫一些代碼以及詳細注釋,讓他們每天進行理解與自我消化。希望他們能在和我結對編程的過程中學到一些知識:D。