wbzyl / 2018

Zaawansowane Języki Programowania, 2018/19.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

14.10.2018 ✨

Laboratoria

1, 2. Wyszukujemy w kodzie fragmenty WTF

For Ruby

  1. Cloc (counts).

  2. Flog (ABC complexity).

  3. Flay (structural similarities).

  4. Breaking Up the Behemoth – zob. pkt. #3: for Churn.

  5. RuboCop – static code analyzer (a.k.a. linter) and code formatter (style).

For Python

  1. Cloc (counts). (Blog information).

  2. McCabe (check McCabe complexity). (install mccabe 0.6.1).

  3. Pylint (symilar: an independent similarities checker).

  4. (…​).

  5. Pylint

Tabl

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)

Pylint

ABC of discovering a pain in the code

Do wyszukiwania pain in Ruby code użyjemy narzędzia Flog – the higher the score, the more pain the code is in.

verse.rb
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:   <

3. Wyszukujemy i naprawiamy problemy w kodzie

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.

Code smell of the week

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.

20. Piszemy kod do gotowych testów

Zakładamy konto na portalu Exercism. Następnie wybieramy tracks z językiem obiektowym i przerabiamy ćwiczenia (10+).

About

Zaawansowane Języki Programowania, 2018/19.


Languages

Language:Ruby 100.0%