For Ruby
-
Cloc (counts).
-
Flog (ABC complexity).
-
Flay (structural similarities).
-
Breaking Up the Behemoth – zob. pkt. #3: for Churn.
-
RuboCop – static code analyzer (a.k.a. linter) and code formatter (style).
For Python
-
Cloc (counts). (Blog information).
-
McCabe (check McCabe complexity). (install mccabe 0.6.1).
-
Pylint (symilar: an independent similarities checker).
-
(…).
Ruby / Python
№ | For Ruby | For Python |
---|---|---|
1 |
Cloc (counts) |
Cloc (counts), (Blog information) |
2 |
Flog (ABC complexity) |
McCabe (check McCabecomplexity), (install mccabe 0.6.1) |
3 |
Flay (structural similarities) |
Pylint (symilar: an independent similarities checker) |
4 |
Breaking Up the Behemoth – zob. pkt. #3: for Churn. |
(…) |
5 |
RuboCop– static code analyzer (a.k.a. linter) and code formatter (style) |
Do wyszukiwania pain in Ruby code użyjemy narzędzia Flog – the higher the score, the more pain the code is in.
def verse(n)
"#{n == 0 ? 'No more' : n} bottle#{'s' if n != 1}" +
" of beer on the wall, " +
"#{n == 0 ? 'no more' : n} bottle#{'s' if n != 1} of beer.\n" +
"#{n > 0 ? "Take #{n > 1 ? 'one' : 'it'} down and pass it around"
: "Go to the store and buy some more"}, " +
"#{n-1 < 0 ? 99 : n-1 == 0 ? 'no more' : n-1} bottle#{'s' if n-1 != 1}"+
" of beer on the wall.\n"
end
flog -ad verse.rb # --all --details
36.2: flog total
36.2: flog/method average
36.2: main#verse verse.rb:1-8
15.2: branch
7.0: +
6.5: -
5.3: ==
5.2: !=
4.1: lit_fixnum
3.3: >
1.4: <
Code smells, refactorings – początek XXI wieku, Kent Beck.
Uruchomić RubyCritics – a Ruby code quality reporter – na większym projekcie napisanym w języku Ruby.
Programu reek można użyć do wypisania „zapachów” w projekcie napisanym w języku Ruby:
reek -f json KATALOG | jq .[].documentation_link | sort | uniq -c | sort -n
Jeśli katalog zawiera nie tylko pliki z kodem w języku Ruby, to modyfikujemy nieco to polecenie, na przykład tak:
find lib -name '*.rb' | xargs reek -f json | jq .[].documentation_link | sort | uniq -c | sort -n
Tutaj jest oficjalna lista code smells i refaktoryzacji dla języka Ruby i Java. Znaleźć trzy najczęściej występujące oficjalne zapachy w jakimś większym projekcie Ruby.
Na ile linijek kodu, średnio, wypada jeden zapach.
Zakładamy konto na portalu Exercism. Następnie wybieramy tracks z językiem obiektowym i przerabiamy ćwiczenia (10+).