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 1 year has passed since last update.

リーダブルコード 第4章 美しさ まとめ

Posted at
  • 「=」の位置を各行でそろえておくことで、タイプミスに気づくことができる
    例)
    a.

    details = request.POST.get(`details`)
    location = request.POST.get(`location`)
    phone = equest.POST.get(`phone`)
    email = request.POST.get(`email`)
    url = request.POST.get(`url`)
    

    b.

    details  = request.POST.get(`details`)
    location = request.POST.get(`location`)
    phone    = equest.POST.get(`phone`)
    email    = request.POST.get(`email`)
    url      = request.POST.get(`url`)
    

    a.よりもb.の方が、
    phone = equest.POST.get(phone)
    においてのスペルミス(requestのはずがequestとなっている部分)
    に気づきやすくなる

  • 変数を定義する順番にも気を付ける必要がある
    例)以下のような変数定義があったとする

    details  = request.POST.get(`details`)
    location = request.POST.get(`location`)
    phone    = request.POST.get(`phone`)
    email    = request.POST.get(`email`)
    url      = request.POST.get(`url`)
    

    並べ方には、

    • 重要度順
    • アルファベット順
      などが挙げられる

    アルファベット順で並べると、

    details  = request.POST.get(`details`)
    email    = request.POST.get(`email`)
    location = request.POST.get(`location`)
    phone    = request.POST.get(`phone`)
    url      = request.POST.get(`url`)
    

    のようになる

  • 開きかっこ、閉じかっこの位置を、プログラムごとに統一した方がよい
    括弧の位置を、

    class Logger {
      ...
    };
    

    なのか、

    class Logger 
    {
      ...
    };
    

    なのかを統一した方がよい

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?