0
我想知道在解釋僞代碼算法時,是使用代碼中的註釋解釋它,還是使用後面的解釋來解釋它是常見做法還是更好的風格。這是我的A級計算項目,當解釋我在設計部分使用的算法時。例如,比較如下:解釋僞代碼算法 - 中間或之後
例1
Declare Operand1 as Integer, Set = 5
Declare Operand2 as Integer, Set = 68
Declare Result as Integer
//Result variable is calculated by adding values of Operand1 and Operand2.
Set Result = Operand1 + Operand2
//The Result is printed on the Console.
Print Result
例2
Declare Operand1 as Integer, Set = 5
Declare Operand2 as Integer, Set = 68
Declare Result as Integer
Set Result = Operand1 + Operand2
Print Result
This algorithm creates two initialised integer variables, Operand1 and Operand2,
and a third uninitialised variable Result. The value of Result is calculated by
adding together the values of Operand1 and Operand2, and this Result is then
printed onto the Console.
我知道,代碼是合理的自我記錄,但想象代碼十分複雜需要解釋。
我也知道這是可疑的SO,但我不知道有一個更好的地方來問這個問題,所以如果有一個正確的方向,將讚賞一個點。
好的。你會說這些東西的一致性特別重要嗎?那麼總結一種算法並評論另一種算法會是一件壞事嗎? – Lou
@LeoKing - 不一定。在出版物中,你會以同樣的方式去做。但是在大量算法描述中,您可能會在上面/下面的註釋中描述一般概念,並在特定的技巧上插入註釋。如果它很明顯(如上面的代碼),則不需要任何內聯註釋。 –
+1並接受,回答我需要的一切:)。我仍然有興趣看到其他答案,因爲這似乎更多是一個主觀問題。 – Lou