Giter Club home page Giter Club logo

2018's Introduction

2.10.2018 🚀

The usual way in which we plan today for tomorrow is in yesterday’s vocabulary. We do so, because we try to get away with the concepts we are familiar with and that have acquired their meanings in our past experience. Of course, the words and the concepts don’t quite fit because our future differs from our past, but then we stretch them a little bit.

— Edsger W. Dijkstra
On the cruelty of really teaching computer science
  • Zaczynamy od przeczytania/przejrzenia 🛁 Clean Code concepts adapted for Ruby.
    Na wykładzie wyjaśnimy dokładniej niektóre opisanych tam zaawansowanych rzeczy, na przykład co oznacza skrótowiec SOLID, co rozumiemy przez refaktoryzację kodu oraz czy kod który smells to przeciwieństwo kodu który jest clean.

  • Literatura – na początek wystarczą nam dwie książki Sandi Metz i jej prezentacja z YouTube:

Note about Ruby language from Sandi Metz

Ruby is very friendly. The language permits nearly anyone to create scripts to automate repetitive tasks, and an opinionated framework like Ruby on Rails puts web applications within every programmer’s reach.

The syntax of the Ruby language is so gentle that anyone blessed with the ability to string thoughts into logical order can produce working applications. Programmers who know nothing about object-oriented design can be very successful in Ruby.

Laboratoria

1–4. Measuring Code Quality – WTF, ABC Complexity

Metrics, Duplication, Churn, Style – koniec XX wieku.

  1. Cloc (counts).

  2. Flog (ABC complexity).

  3. Flay (structural similarities).

  4. Turbulence (churn&complexity).

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

Zob. też Breaking Up the Behemoth – Design Stamina Hypothesis, Procedural vs Object-Oriented Code, Churn and Complexity.

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; zob. też Bryan Helmkamp, Deciphering Ruby Code Metrics

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:   <

See Chapter 10. Text Formatting for examples of colored, line-through formatting.

5–7. Following Rules

No rules KATA.

Rules.

  1. Baruco 2013: Rules, by Sandi Metz. No more than

    1. 100 lines per class

    2. 5 lines per method

    3. 3 parameters per method

  2. SOLID – coined by Michael Feathers and popularized by Robert Martin:

    1. Single Responsibility,

    2. Open-Closed,

    3. Liskov Substitution,

    4. Interface Segregation,

    5. Dependency Inversion.

  3. DRY (Don’t Repeat Yourself) – Andy Hunt and Dave Thomas’s

  4. LoD (the Law of Demeter) – the Demeter project at Northeastern University

  5. Our rules?

    1. Replace Conditional with Polymorphism

    2. Avoiding If Statements

8–12. Code Treatment

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.

Wykłady 13, 14, 15 – prezentacje projektów

Zapoznajemy się z cyklem TDD

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

2018's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.