0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gitWatch > if文で{を使わない書き方の人はまだいるようだ

Last updated at Posted at 2015-04-29

https://github.com/neovim/neovim/commit/87b4093970c90fd36ff6a2ccb6e9bb7817f44d08
の変更で

Introduction of asserts broke bracketless if's.
とあり、

変更前.c
-   if (c != NULL) 
      assert(c >= 0 && c <= UCHAR_MAX);
      ptr[curwin->w_cursor.col] = (char_u)c;
- } else
変更後.c
+   if (c != NULL) {
      assert(c >= 0 && c <= UCHAR_MAX);
      ptr[curwin->w_cursor.col] = (char_u)c;
+   }
+ } else {

と修正されていた。

そもそもがif文を単文形式で書いているのが間違いの元だと思う。
assert()を追加した時だけ複文形式にするのでなく、ifを使う時は{をつけておくのがいくつかのコーディング規約でも書かれている。

最近の大きなバグ(名前忘れた)でも同じ間違いによりfalse/true反対の戻り値になっていたのがあったし、昔のバグから学ばないといけないと思う。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?