0

まず、この質問を認識しています: コード内のコメントの標準フォーマットはありますか?

しかし、それは私の答えではありませんでした。コードを書くときは常に、コメントがすべて一貫していることを確認する習慣を身に付けようとしますが、コード形式の規則については、ときどき優柔不断になります。特に、コードを 80 行程度にしたいので。

言うまでもなく、コード形式の規則は次のようにする必要があります。

  • 読みやすい
  • 変更が容易

また、コードのさまざまな部分でさまざまなコメント形式が存在する可能性があるため、一貫性と読みやすさを維持することが重要です。

ここではいくつかの例を示します。

単線

// simple comment in lowercase
do_something();

// longer comment in lowercase. but now it doesn't seem like a proper sentence.
do_something();

// Longer comment in sentence case. But should we use sentence case for short comments too?
do_something();
// Like this one?
do_something_else(); // Or even this one.

複線

// This code is very detailed and so I must continue further.
// Every time you start a new line you need to ensure you add //.
// If you finish your comment and forget to add something, you're screwed.
// You'll have to add your something and then make sure all the lines are 80 characters or less,
// and if they aren't you need to restructure all the lines below it.

/*  This is better but you need to make sure it's properly indented each line.
    Although you have to worry about those comment delimiters getting in the way. 
    At least it's compact. */

/*  This comment seems better.
    No need to worry about that last delimiter being inside your comment block.
*/

/*  
    Or maybe this is better?
    At least it looks clean.
*/

/*  GOOD FOR FUNCTION DEFINITIONS
    Or maybe this is even better?
    Who knows?
*/
4

1 に答える 1

1

回答 1 - 中括弧について議論するのは時間の無駄です。

回答 2 - 必要に応じて 1 つだけ選んでください。http://www.possibility.com/Cpp/CppCodingStandard.html

于 2011-01-22T02:31:15.163 に答える