Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

制御文の中括弧に関するコーディング規約を決める #315

Closed
massongit opened this issue Oct 29, 2018 · 5 comments
Closed
Assignees

Comments

@massongit
Copy link
Collaborator

制御文の記述方法で意見の食い違いが発生しているため、このあたりのコーディング規約を決めた方が良いかと思います。
具体的には、ESLintのルールcurlyのパラメータをどのような値に設定するかという形で議論するのが良いと思われます。

@massongit
Copy link
Collaborator Author

massongit commented Oct 29, 2018

自分としてはallに設定するのが良いと考えています。
理由としては、

if (condition) process()

if (condition) {
   process()
   process2()
}

のように書き換えたいと思ったときに、

if (condition) 
   process()
   process2() // if文のブロックの中に入っているつもり (実際にはブロックの外)

という風に間違った書き方をしてしまうのを防ぐため、単文であっても、中括弧を付けた方が良いのではないかと考えているからです。

@kujirahand
Copy link
Owner

良い提案をありがとうございます!
特に、es-lintのオプションで語るのは良いですね。

とは言え、プログラミングコードの見やすさから言っても、断然、multiが良いように感じます。

特に、forやwhileの繰り返しの中からの脱出で、条件が明確な場合に、脱出のif文が3行になると、めちゃくちゃプログラムが見づらくなるので。フォントのサイズを比較的大きくしてプログラミングしているので、とにかく、行数が少なくなり、見やすさが向上するのは、大歓迎です。

while (n > 50) {
    if (n === 3) break
    hoge
    hoge
    if (n === 47) return
    hoge
}

@massongit
Copy link
Collaborator Author

allにした方が良いと考えた理由で示したものについても、IDEの補完機能を使えば、ある程度防げるものではあるので、multiで良いのではないでしょうか。

@kujirahand
Copy link
Owner

なるほど、@massongitさんはIDEを利用していましたね。確かに、IDEを使えば、allを採用した場合にも自動でカッコ内を省略したりと、見やすくしてくれますね。私はIDEを使っていないので気づきませんでした。利用する環境に応じても、コードの記述スタイルの好みが反映されますね。

とは言え、JavaScriptをIDEで書く人は少数と思いますので、IDEを使わなくても見やすいmultiでいきましょう!(最初から最後まで、強情ですみません。)

@kujirahand
Copy link
Owner

curlyをallに変更する

@kujirahand kujirahand reopened this Apr 13, 2019
@massongit massongit self-assigned this Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants