Ruby on Rails Code Quality Checklist
鳥取のホテルでWebをチェックしていたらいいページを発見。
Ruby on Rails Code Quality Checklist http://www.matthewpaulmoore.com/articles/1276-ruby-on-rails-code-quality-checklist#skinny
Railsアプリがうまく設計されているかを確認するためのチェックシート。とくに前半が有意義だな〜。いま会社でやっているRailsプロジェクトをチェックしてみる。。。
1. Each controller action only calls one model method other than an initial find or new.
×:単純なアクション以外はだめだめだな。2. Only one or two instance variables are shared between each controller and view. ...
×:これは確かに有効だよな。いまは3つ以上使ってるな。。3. All model and variable names are both immediately obvious (to a new developer) and as short as possible without using abbreviations. ...
○:判断基準が不明確だけど、いちおうよしかな。4. All custom "finds" accessed from more than one place in the code use named_scope instead of a custom method. ...
×:2.0系つかってるからな。移行すべきだな〜。5. A .find or .find_by_ is never called in a view or view helper. ...
×:すみません、find_by多用してます。。6. There is zero custom code that duplicates functionality of a built-in function in rails. ...
○:大丈夫だとおもわれる7. Code has been aggressively DRYed during development. ...
△:割と注意はしているけど。。8. All functionality used in two or more models has been turned into a library/module. ...
△:これは最近ようやく対応。9. All logic duplicated between two or more apps has been turned into a gemified plugin. ...
○:いちおう再利用できそうなものは。10. STI is not used anywhere ...
××:ダブル×です。STI使ってます。スッゲー後悔です。連休がおわったら相談しよう。11. Every design choice should yield the most simplistic design possible for the need of users at the current time.
?:これはどういうこと?12. Close to full test coverage exists at the highest level of the application: on and between controller actions.
×:そもそもテストコードが。。13. All tests pass before code is merged into a shared repository. ...
×:すみません、、、14. Every fixed defect on a deployed product has tests added to prevent regression. ...
×:もうしわけない。。。15. Every plugin installed has been code reviewed. ...
×:これもいまいちです。すみません
というわけで、改善すべき事項はたくさんあるorz
ところでRailsを本格的に使って半年たつけど、サーバーサイドのコーディングは楽々になったな〜。Rubyによるところも大きいけど。でもerbは結構詰まることがありますね。selectタグってform_helperでどうやってかくんだっけ?とか。form_forとform_tagの使い分けでちょっと戸惑ったり。。このチェックリストでもビューのコーディングにはほとんど触れていないが、そのへんはあんまり困ってないのかな?俺だけ?一時期はJavaのWicket的なビューの実装ってけっこういいな、とおもってたけど、最近はどういうアプローチがはやっているのだろう。SAStrutsのtaglibとかはどんな感じなのかな。