あなたが今まで見た中で最も有用でないコメントは何ですか? [閉まっている]

StackOverflow https://stackoverflow.com/questions/143429

  •  02-07-2019
  •  | 
  •  

質問

コードをコメントすることは、コードを理解するためのコーディングスタイルの重要な部分であることを知っています。

ただし、コメントがマスタードをカットしないことがあります。私は明らかな冗談やvent折したフラストラトンについて話しているのではなく、説明を試みているように見えるコメントについて話しているのですが、あまりにもうまく行かないかもしれません。 短すぎるわかりにくい、または単なる間違っているのコメント。

因果関係の物語として、あなたが見たもののうち本当に本当にあの悪いであるものを共有し、それが明らかでない場合は、それが参照していたコードを示し、それで何が間違っているかを指摘してください?代わりに 行っておくべきものは何ですか?

参照:

役に立ちましたか?

解決

典型的なComp Sci 101タイプのコメントだけ:

$i = 0; //set i to 0

$i++; //use sneaky trick to add 1 to i!

if ($i==$j) { // I made sure to use == rather than = here to avoid a bug

そのようなこと。

他のヒント

未記入のjavadocボイラープレートコメントは特に役に立ちません。有用なものを提供することなく、多くの画面領域を消費します。そして、最悪の部分は、そのようなコメントが表示される場所で、他の何百人もが確実に遅れていることです。

/**
 * Method declaration
 *
 *
 * @param table
 * @param row
 *
 * @throws SQLException
 */
void addTransactionDelete(Table table, Object row[]) throws SQLException {

私は以前、この小さな宝石を書いていることに気付きました:

//@TODO: Rewrite this, it sucks. Seriously.

通常、その夜のコーディングセッションが終了したことを示す良い兆候です。

// remember to comment code

wtf? :D

次のようなもの:

// This method takes two integer values and adds them together via the built-in
// .NET functionality. It would be possible to code the arithmetic function
// by hand, but since .NET provides it, that would be a waste of time
private int Add(int i, int j) // i is the first value, j is the second value
{
    // add the numbers together using the .NET "+" operator
    int z = i + j;

    // return the value to the calling function
    // return z;

    // this code was updated to simplify the return statement, eliminating the need
    // for a separate variable.
    // this statement performs the add functionality using the + operator on the two
    // parameter values, and then returns the result to the calling function
    return i + j;
}

など。

コードが言うことを繰り返すだけのコメントはすべて役に立たない。コメントはコードが何をするかを教えてはいけません。プログラミング言語を十分に知らない場合、コードを読むだけで何が起こっているかを理解するには、そのコードをまったく読むべきではありません。のようなコメント

// Increase i by one
i++;

はまったく役に立ちません。私は1つ増えていることがわかります、それはコードが言っていることです、私はそれについてコメントする必要はありません!コメントを使用して、なぜ何かが行われたのか(明白でない場合)、またはなぜ何かがそのように行われ、他の方法ではないのかを説明する必要があります他のプログラマーが行った特定の設計決定を理解し、それはすぐには明らかではありません)。さらなるコードは、コードを簡単に確認しても何が起こっているのかを完全に判断できないトリッキーなコードを説明するのに役立ちます(たとえば、数値に設定されたビット数をカウントするトリッキーなアルゴリズムがあります。このコードが何をするのかを知っていれば、そこで何が起こっているのかを推測することはできません。

Thread.Sleep(1000); // this will fix .NET's crappy threading implementation

以前、奇妙なCコンパイラを使用してプロジェクトに取り組んでいました。 2つのステートメントの間にコメントが挿入されない限り、有効なコードに対してエラーが発生しました。そこで、コメントを次のように変更しました。

// Do not remove this comment else compilation will fail.

そしてそれは素晴らしく機能しました。

信じられません。 22の回答があった後にこの質問に出くわしましたが、おそらく最も有用ではないタイプのコメントは誰も指摘しませんでした。

間違っているコメント。

コードの理解を妨げる余分なコメントを書くことは十分に悪いことですが、何かがどのように機能するかを説明する詳細なコメントを誰かが書いた場合、それはそもそも間違っているか、コードを変更せずに変更した後に間違っていますコメント(より可能性の高いシナリオ)、それは間違いなく最悪の種類のコメントです。

GhostDocには、かなり興味深いものがいくつかあります。

/// <summary>
/// Toes the foo.
/// </summary>
/// <returns></returns>
public Foo ToFoo()
// secret sauce
// Don't know why we have to do this
try
{
...some code...
}
catch
{
// Just don't crash, it wasn't that important anyway.
}

*ため息

ファイル全体に1回出現しました。数千行のコード。そのほとんどは非常に恐ろしいものです。悪名の変数、ループのトリッキーな条件、ファイルの中央に埋め込まれた1つのコメント。


   /* Hmmm. A bit tricky. */
//' OOOO oooo that smell!! Can't you smell that smell!??!??!!!!11!??/!!!!!1!!!!!!1

If Not Me.CurrentMenuItem.Parent Is Nothing Then
    For Each childMenuItem As MenuItem In aMenuItem.Children
        do something
    Next

    If Not Me.CurrentMenuItem.Parent.Parent Is Nothing Then
        //'item is at least a grand child
        For Each childMenuItem As MenuItem In aMenuItem.Children
            For Each grandchildMenuItem As MenuItem In childMenuItem.Children
                do something
            Next
        Next

        If Not Me.CurrentMenuItem.Parent.Parent.Parent Is Nothing Then
            //'item is at least a grand grand child
            For Each childMenuItem As MenuItem In aMenuItem.Children
                For Each grandchildMenuItem As MenuItem In childMenuItem.Children
                    For Each grandgrandchildMenuItem As MenuItem In grandchildMenuItem.Children
                        do something
                    Next
                Next
            Next

        End If
    End If
End If

IDEによって挿入されるデフォルトのコメント。

WebSphere Application Developerを使用して最後に取り組んだプロジェクトには、多数のメンテナンス開発者と請負業者がいました。

/**
 * @author SomeUserWhoShouldKnowBetter
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */

よくコメントされたソースファイルを実際に見つけたと思ってから、それがもう1つのデフォルトのコメントであることに気付くまでの間、常にその一瞬がありました。 p>

昨日、C#アプリでこのコメントを見ました:

//TODO: Remove this comment.

私のお気に入りのすべてのコメント。

/* our second do loop */
do {

誰が書いた-あなたはあなたが誰であるかを知っています。

何年も前のCの非常に大規模なデータベースエンジンプロジェクト-短い変数名とスペルミスのある数千行のコード、コメントなし...次のコメントが表示されました。

//if you get here then you really f**ked

その時までに、私たちはすでにそれを知っていたと思います!

巨大なVB5アプリケーションの場合

dim J
J = 0 'magic
J = J 'more magic
for J=1 to 100
...do stuff...

参照は明らかにこれ ...そしてはい、これら2行のないアプリケーションは、実行時に不明なエラーコードで失敗します。理由はまだわかりません。

私のブログ投稿のいずれかから取得:

  

私が管理しているプロジェクトのソースコードの一部をクリーンアップする過程で、次のコメントに出会いました:

/*
   MAB 08-05-2004: Who wrote this routine? When did they do it? Who should 
   I call if I have questions about it? It's worth it to have a good header
   here. It should helps to set context, it should identify the author 
   (hero or culprit!), including contact information, so that anyone who has
   questions can call or email. It's useful to have the date noted, and a 
   brief statement of intention. On the other hand, this isn't meant to be 
   busy work; it's meant to make maintenance easier--so don't go overboard.

   One other good reason to put your name on it: take credit! This is your
   craft
*/

さらに少し下に:

#include "xxxMsg.h" // xxx messages
/*
   MAB 08-05-2004: With respect to the comment above, I gathered that
   from the filename. I think I need either more or less here. For one
   thing, xxxMsg.h is automatically generated from the .mc file. That might
   be interesting information. Another thing is that xxxMsg.h should NOT be
   added to source control, because it's auto-generated. Alternatively, 
   don't bother with a comment at all.
*/

そしてさらにもう一度:

/*
   MAB 08-05-2004: Defining a keyword?? This seems problemmatic [sic],
   in principle if not in practice. Is this a common idiom? 
*/

AHHHRRRGGHHH古代のコードでこれを見つけたばかりです。

private
  //PRIVATE means PRIVATE so no comments for you
  function LoadIt(IntID: Integer): Integer;

最悪のコメントは、コードが何をするかの間違った説明を与えるものです。 それはコメントがまったくないよりも悪い。

この種のことは、コメントが多すぎるコードで見たことがあります(コードはそれ自体で十分に明確なので、そこにあるべきではありません)。など)がコメントとともに更新されません。

良い経験則は次のとおりです。何をするのかではなく、なぜコードが何かをしているのかを説明するコメントを書くだけです。

間違いなくエラー処理の代わりに立つコメントでなければなりません。

if(some_condition){
    do_stuff();
}
else{
    //An error occurred!
}

コメントアウトされたコード行の前の行に書かれたこれを見つけました:

//This causes a crash for some reason. I know the real reason but it doesn't fit on this line.

vb6からvb.netに移植された100k LOCアプリケーション。前の開発者が1つのメソッドにコメントヘッダーを付けてから、それ以降に書いたすべてのメソッドに正確なコメントをコピーして貼り付けたかのように見えます。数百のメソッドとそれぞれが誤ってコメントされています...

最初に見たとき、私は笑いました... 6か月後、ジョークは薄く着ています。

これは、データベーストリガーからの絶対に実際の例です。

/******************************************************************************
   NAME:       (repeat the trigger name)
   PURPOSE:    To perform work as each row is inserted or updated.
   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        27.6.2000             1. Created this trigger.
   PARAMETERS:
   INPUT:
   OUTPUT:
   RETURNED VALUE:
   CALLED BY:
   CALLS:
   EXAMPLE USE:
   ASSUMPTIONS:
   LIMITATIONS:
   ALGORITHM:
   NOTES:
******************************************************************************/
/** function header comments required to pass checkstyle */

今まで見た中で最も役に立たない2つのコメント...

try
{
  ...
}
catch
{
  // TODO: something catchy
}

私もこれをDaily WTFに投稿したので、コメントだけにトリミングします...

  // TODO: The following if block should be reduced to one return statememt:
  // return Regex.IsMatch(strTest, NAME_CHARS);
  if (!Regex.IsMatch(strTest, NAME_CHARS))
    return false;
  else
    return true;

非常に役に立たなかったもの:

<!--- Lasciate ogne speranza, voi ch'intrate --->
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top