{"action":"created","comment":{"url":"https://api.github.com/repos/PyConPL/Book/pulls/comments/75584642","id":75584642,"diff_hunk":"@@ -0,0 +1,94 @@\n+# Object calisthenics\n+\n+## Czym jest kalistenika?\n+\n+Według definicji podanej przez Wikipedię[1] kalistenika to \"aktywność fizyczna polegająca na\t treningu siłowym opartym o ćwiczenia z wykorzystaniem własnej masy ciała\". Kiedy mówimy o kalistenice, najprościej jest zwizualizować to pojęcie przywołując gladiatorów. Aż do XX wieku nie istniały siłownie - żadnej bieżni mechanicznych, rowerów stacjonarnych, hantli. Był tylko człowiek i masą swojego ciała, którą mógł wykorzystać do ćwiczeń. Efektem takich ćwiczeń, bez wykorzystania dodatkowego sprzętu, była czysta siła, a masa mięśniowa stanowiła dodatkowy efekt uboczny - nie była celem samym w sobie.\n+\n+Podobnie sprawa ma się z kalisteniką obiektową. Pod tym pojęciem kryją się proste ćwiczenia. Zupełnie podstawowe reguły, które nie wymagają nadzwyczajnych umiejętności, ani dodatkowych narzędzi. Celem jest poprawa jakości kodu, pisanie kodu prostszego w utrzymaniu, prostszego w zrozumieniu, możliwego do ponownego użycia oraz takiego, który można łatwo testować.\n+\n+Kalistenika obiektowa (dalej w skrócie OC) została pierwotnie przedstawiona w eseju Jeffa Bay’a i opublikowana w książce pt. *ThoughtWorks Anthology*[2]. Początkowo została pomyślana z przeznaczeniem dla zastosowanie w Javie, natomiast później zaadoptowano ją na potrzeby innych języków programowania.\n+\n+Dosyć popularnym powiedzeniem jest, że kod jest dużo częściej czytany niż pisany. Dlatego tak ważne jest, by kod ten był łatwy do przeczytania, zrozumienia, testowania i ponownego zastosowania w innym miejscu. O podobnym celu jest mowa w *Czystym kodzie*[3] Roberta C. Martina.\n+\n+Bez zbędnego przedłużania, zobaczmy konkretnie jakie reguły składają się na Object Calisthenics.\n+\n+## 1. Nie używaj więcej niż jednego poziomu wcięcia na metodę.\n+\n+ Zbyt wiele zagnieżdżeń w ramach jednej funkcji lub metody źle wpływa na czytelność i prostotę utrzymania. Wiele poziomów pętli i warunków sprawia, że działamy na różnych poziomach abstrakcji, a to może oznaczać, że metoda robi więcej niż jedną rzecz. To może nam również pokazać że nazwa metody nie odzwierciedla wprost celu metody. Przez to trudniej jest jej użyć ponownie w innym miejscu, jak również przetestować.\n+\n+ Zupełnym przeciwieństwem jest kilku bądź kilkunastolinijkowa metoda, która ma wyłącznie jedną odpowiedzialność - robi jedną rzecz, robi ją dobrze, a dodatkowo jest adekwatnie nazwana. Dobra nazwa metody może znacznie ułatwić zrozumienie jej celu w trakcie czytania kodu. Jeśli wiemy, co dokładnie jest celem metody, to chętniej jej użyjemy w innym miejscu. Ponadto krótki kod, który zmienia stan wyłącznie jednego obiektu i nie posiada efektów ubocznych, jest łatwo testowalny.\n+\n+## 2. Nie używaj słowa kluczowego `else`\n+\n+ Konstrukcja `if/else` jest obecna w prawie każdym języku programowania i łatwo ją zrozumie nawet laik. Wielu z nas zna przypadek wielokrotnie powtarzanych ciągów `if … elif … elif … else`. Trudno się je czyta, trudno zrozumieć, częściej trudno zmodyfikować - a pokusa dopisania kolejnego `else` jest ogromna. Tego typu sytuacje często prowadzą do duplikowania kodu oraz wielu błędów.\n+\n+ Jednym z rozwiązań pozwalającym unikać takich konstrukcji jest polimofizm, wzorzec strategii lub wzorzec stanu. Kod, który korzysta z takiego podejścia, znacznie łatwiej się czyta i jest łatwiejszy w utrzymaniu.","path":"2016/presentations/object_calisthenics/text.md","position":25,"original_position":25,"commit_id":"b27e45007014a3c3a1180e8de6edab1bffb2b9e2","original_commit_id":"b27e45007014a3c3a1180e8de6edab1bffb2b9e2","user":{"login":"deshipu","id":1181357,"avatar_url":"https://avatars.githubusercontent.com/u/1181357?v=3","gravatar_id":"","url":"https://api.github.com/users/deshipu","html_url":"https://github.com/deshipu","followers_url":"https://api.github.com/users/deshipu/followers","following_url":"https://api.github.com/users/deshipu/following{/other_user}","gists_url":"https://api.github.com/users/deshipu/gists{/gist_id}","starred_url":"https://api.github.com/users/deshipu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deshipu/subscriptions","organizations_url":"https://api.github.com/users/deshipu/orgs","repos_url":"https://api.github.com/users/deshipu/repos","events_url":"https://api.github.com/users/deshipu/events{/privacy}","received_events_url":"https://api.github.com/users/deshipu/received_events","type":"User","site_admin":false},"body":"polimo**R**fizm","created_at":"2016-08-20T20:50:51Z","updated_at":"2016-08-20T20:50:51Z","html_url":"https://github.com/PyConPL/Book/pull/50#discussion_r75584642","pull_request_url":"https://api.github.com/repos/PyConPL/Book/pulls/50","_links":{"self":{"href":"https://api.github.com/repos/PyConPL/Book/pulls/comments/75584642"},"html":{"href":"https://github.com/PyConPL/Book/pull/50#discussion_r75584642"},"pull_request":{"href":"https://api.github.com/repos/PyConPL/Book/pulls/50"}}},"pull_request":{"url":"https://api.github.com/repos/PyConPL/Book/pulls/50","id":81979060,"html_url":"https://github.com/PyConPL/Book/pull/50","diff_url":"https://github.com/PyConPL/Book/pull/50.diff","patch_url":"https://github.com/PyConPL/Book/pull/50.patch","issue_url":"https://api.github.com/repos/PyConPL/Book/issues/50","number":50,"state":"open","locked":false,"title":"Article: Object calisthenics - pierwsza wersja","user":{"login":"pawel-lewtak","id":5846223,"avatar_url":"https://avatars.githubusercontent.com/u/5846223?v=3","gravatar_id":"","url":"https://api.github.com/users/pawel-lewtak","html_url":"https://github.com/pawel-lewtak","followers_url":"https://api.github.com/users/pawel-lewtak/followers","following_url":"https://api.github.com/users/pawel-lewtak/following{/other_user}","gists_url":"https://api.github.com/users/pawel-lewtak/gists{/gist_id}","starred_url":"https://api.github.com/users/pawel-lewtak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pawel-lewtak/subscriptions","organizations_url":"https://api.github.com/users/pawel-lewtak/orgs","repos_url":"https://api.github.com/users/pawel-lewtak/repos","events_url":"https://api.github.com/users/pawel-lewtak/events{/privacy}","received_events_url":"https://api.github.com/users/pawel-lewtak/received_events","type":"User","site_admin":false},"body":"Przesyłam pierwszą wersję artykułu na temat _Object Calisthenics_\r\nBędę wdzięczny na komentarze i uwagi.","created_at":"2016-08-19T13:14:47Z","updated_at":"2016-08-20T20:50:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0a8705a4b19e510de897e4251a9c8c4db4282bb9","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/PyConPL/Book/pulls/50/commits","review_comments_url":"https://api.github.com/repos/PyConPL/Book/pulls/50/comments","review_comment_url":"https://api.github.com/repos/PyConPL/Book/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PyConPL/Book/issues/50/comments","statuses_url":"https://api.github.com/repos/PyConPL/Book/statuses/b27e45007014a3c3a1180e8de6edab1bffb2b9e2","head":{"label":"pawel-lewtak:master","ref":"master","sha":"b27e45007014a3c3a1180e8de6edab1bffb2b9e2","user":{"login":"pawel-lewtak","id":5846223,"avatar_url":"https://avatars.githubusercontent.com/u/5846223?v=3","gravatar_id":"","url":"https://api.github.com/users/pawel-lewtak","html_url":"https://github.com/pawel-lewtak","followers_url":"https://api.github.com/users/pawel-lewtak/followers","following_url":"https://api.github.com/users/pawel-lewtak/following{/other_user}","gists_url":"https://api.github.com/users/pawel-lewtak/gists{/gist_id}","starred_url":"https://api.github.com/users/pawel-lewtak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pawel-lewtak/subscriptions","organizations_url":"https://api.github.com/users/pawel-lewtak/orgs","repos_url":"https://api.github.com/users/pawel-lewtak/repos","events_url":"https://api.github.com/users/pawel-lewtak/events{/privacy}","received_events_url":"https://api.github.com/users/pawel-lewtak/received_events","type":"User","site_admin":false},"repo":{"id":66082169,"name":"Book","full_name":"pawel-lewtak/Book","owner":{"login":"pawel-lewtak","id":5846223,"avatar_url":"https://avatars.githubusercontent.com/u/5846223?v=3","gravatar_id":"","url":"https://api.github.com/users/pawel-lewtak","html_url":"https://github.com/pawel-lewtak","followers_url":"https://api.github.com/users/pawel-lewtak/followers","following_url":"https://api.github.com/users/pawel-lewtak/following{/other_user}","gists_url":"https://api.github.com/users/pawel-lewtak/gists{/gist_id}","starred_url":"https://api.github.com/users/pawel-lewtak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pawel-lewtak/subscriptions","organizations_url":"https://api.github.com/users/pawel-lewtak/orgs","repos_url":"https://api.github.com/users/pawel-lewtak/repos","events_url":"https://api.github.com/users/pawel-lewtak/events{/privacy}","received_events_url":"https://api.github.com/users/pawel-lewtak/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pawel-lewtak/Book","description":"This is a book which will be created by PyCon PL Organizers, based on PyCon PL Speaker's talks for PyCon PL Attendees.","fork":true,"url":"https://api.github.com/repos/pawel-lewtak/Book","forks_url":"https://api.github.com/repos/pawel-lewtak/Book/forks","keys_url":"https://api.github.com/repos/pawel-lewtak/Book/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pawel-lewtak/Book/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pawel-lewtak/Book/teams","hooks_url":"https://api.github.com/repos/pawel-lewtak/Book/hooks","issue_events_url":"https://api.github.com/repos/pawel-lewtak/Book/issues/events{/number}","events_url":"https://api.github.com/repos/pawel-lewtak/Book/events","assignees_url":"https://api.github.com/repos/pawel-lewtak/Book/assignees{/user}","branches_url":"https://api.github.com/repos/pawel-lewtak/Book/branches{/branch}","tags_url":"https://api.github.com/repos/pawel-lewtak/Book/tags","blobs_url":"https://api.github.com/repos/pawel-lewtak/Book/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pawel-lewtak/Book/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pawel-lewtak/Book/git/refs{/sha}","trees_url":"https://api.github.com/repos/pawel-lewtak/Book/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pawel-lewtak/Book/statuses/{sha}","languages_url":"https://api.github.com/repos/pawel-lewtak/Book/languages","stargazers_url":"https://api.github.com/repos/pawel-lewtak/Book/stargazers","contributors_url":"https://api.github.com/repos/pawel-lewtak/Book/contributors","subscribers_url":"https://api.github.com/repos/pawel-lewtak/Book/subscribers","subscription_url":"https://api.github.com/repos/pawel-lewtak/Book/subscription","commits_url":"https://api.github.com/repos/pawel-lewtak/Book/commits{/sha}","git_commits_url":"https://api.github.com/repos/pawel-lewtak/Book/git/commits{/sha}","comments_url":"https://api.github.com/repos/pawel-lewtak/Book/comments{/number}","issue_comment_url":"https://api.github.com/repos/pawel-lewtak/Book/issues/comments{/number}","contents_url":"https://api.github.com/repos/pawel-lewtak/Book/contents/{+path}","compare_url":"https://api.github.com/repos/pawel-lewtak/Book/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pawel-lewtak/Book/merges","archive_url":"https://api.github.com/repos/pawel-lewtak/Book/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pawel-lewtak/Book/downloads","issues_url":"https://api.github.com/repos/pawel-lewtak/Book/issues{/number}","pulls_url":"https://api.github.com/repos/pawel-lewtak/Book/pulls{/number}","milestones_url":"https://api.github.com/repos/pawel-lewtak/Book/milestones{/number}","notifications_url":"https://api.github.com/repos/pawel-lewtak/Book/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pawel-lewtak/Book/labels{/name}","releases_url":"https://api.github.com/repos/pawel-lewtak/Book/releases{/id}","deployments_url":"https://api.github.com/repos/pawel-lewtak/Book/deployments","created_at":"2016-08-19T12:52:58Z","updated_at":"2016-08-19T12:53:00Z","pushed_at":"2016-08-19T13:09:25Z","git_url":"git://github.com/pawel-lewtak/Book.git","ssh_url":"git@github.com:pawel-lewtak/Book.git","clone_url":"https://github.com/pawel-lewtak/Book.git","svn_url":"https://github.com/pawel-lewtak/Book","homepage":"http://pl.pycon.org/","size":6728,"stargazers_count":0,"watchers_count":0,"language":"TeX","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"PyConPL:master","ref":"master","sha":"fec0ebd4f9e9346f35f999706afed2fb5ba64faa","user":{"login":"PyConPL","id":5347274,"avatar_url":"https://avatars.githubusercontent.com/u/5347274?v=3","gravatar_id":"","url":"https://api.github.com/users/PyConPL","html_url":"https://github.com/PyConPL","followers_url":"https://api.github.com/users/PyConPL/followers","following_url":"https://api.github.com/users/PyConPL/following{/other_user}","gists_url":"https://api.github.com/users/PyConPL/gists{/gist_id}","starred_url":"https://api.github.com/users/PyConPL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PyConPL/subscriptions","organizations_url":"https://api.github.com/users/PyConPL/orgs","repos_url":"https://api.github.com/users/PyConPL/repos","events_url":"https://api.github.com/users/PyConPL/events{/privacy}","received_events_url":"https://api.github.com/users/PyConPL/received_events","type":"Organization","site_admin":false},"repo":{"id":22459875,"name":"Book","full_name":"PyConPL/Book","owner":{"login":"PyConPL","id":5347274,"avatar_url":"https://avatars.githubusercontent.com/u/5347274?v=3","gravatar_id":"","url":"https://api.github.com/users/PyConPL","html_url":"https://github.com/PyConPL","followers_url":"https://api.github.com/users/PyConPL/followers","following_url":"https://api.github.com/users/PyConPL/following{/other_user}","gists_url":"https://api.github.com/users/PyConPL/gists{/gist_id}","starred_url":"https://api.github.com/users/PyConPL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PyConPL/subscriptions","organizations_url":"https://api.github.com/users/PyConPL/orgs","repos_url":"https://api.github.com/users/PyConPL/repos","events_url":"https://api.github.com/users/PyConPL/events{/privacy}","received_events_url":"https://api.github.com/users/PyConPL/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PyConPL/Book","description":"This is a book which will be created by PyCon PL Organizers, based on PyCon PL Speaker's talks for PyCon PL Attendees.","fork":false,"url":"https://api.github.com/repos/PyConPL/Book","forks_url":"https://api.github.com/repos/PyConPL/Book/forks","keys_url":"https://api.github.com/repos/PyConPL/Book/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PyConPL/Book/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PyConPL/Book/teams","hooks_url":"https://api.github.com/repos/PyConPL/Book/hooks","issue_events_url":"https://api.github.com/repos/PyConPL/Book/issues/events{/number}","events_url":"https://api.github.com/repos/PyConPL/Book/events","assignees_url":"https://api.github.com/repos/PyConPL/Book/assignees{/user}","branches_url":"https://api.github.com/repos/PyConPL/Book/branches{/branch}","tags_url":"https://api.github.com/repos/PyConPL/Book/tags","blobs_url":"https://api.github.com/repos/PyConPL/Book/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PyConPL/Book/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PyConPL/Book/git/refs{/sha}","trees_url":"https://api.github.com/repos/PyConPL/Book/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PyConPL/Book/statuses/{sha}","languages_url":"https://api.github.com/repos/PyConPL/Book/languages","stargazers_url":"https://api.github.com/repos/PyConPL/Book/stargazers","contributors_url":"https://api.github.com/repos/PyConPL/Book/contributors","subscribers_url":"https://api.github.com/repos/PyConPL/Book/subscribers","subscription_url":"https://api.github.com/repos/PyConPL/Book/subscription","commits_url":"https://api.github.com/repos/PyConPL/Book/commits{/sha}","git_commits_url":"https://api.github.com/repos/PyConPL/Book/git/commits{/sha}","comments_url":"https://api.github.com/repos/PyConPL/Book/comments{/number}","issue_comment_url":"https://api.github.com/repos/PyConPL/Book/issues/comments{/number}","contents_url":"https://api.github.com/repos/PyConPL/Book/contents/{+path}","compare_url":"https://api.github.com/repos/PyConPL/Book/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PyConPL/Book/merges","archive_url":"https://api.github.com/repos/PyConPL/Book/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PyConPL/Book/downloads","issues_url":"https://api.github.com/repos/PyConPL/Book/issues{/number}","pulls_url":"https://api.github.com/repos/PyConPL/Book/pulls{/number}","milestones_url":"https://api.github.com/repos/PyConPL/Book/milestones{/number}","notifications_url":"https://api.github.com/repos/PyConPL/Book/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PyConPL/Book/labels{/name}","releases_url":"https://api.github.com/repos/PyConPL/Book/releases{/id}","deployments_url":"https://api.github.com/repos/PyConPL/Book/deployments","created_at":"2014-07-31T07:04:58Z","updated_at":"2016-07-16T16:20:58Z","pushed_at":"2016-08-20T14:42:20Z","git_url":"git://github.com/PyConPL/Book.git","ssh_url":"git@github.com:PyConPL/Book.git","clone_url":"https://github.com/PyConPL/Book.git","svn_url":"https://github.com/PyConPL/Book","homepage":"http://pl.pycon.org/","size":6746,"stargazers_count":17,"watchers_count":17,"language":"TeX","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":41,"mirror_url":null,"open_issues_count":5,"forks":41,"open_issues":5,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/PyConPL/Book/pulls/50"},"html":{"href":"https://github.com/PyConPL/Book/pull/50"},"issue":{"href":"https://api.github.com/repos/PyConPL/Book/issues/50"},"comments":{"href":"https://api.github.com/repos/PyConPL/Book/issues/50/comments"},"review_comments":{"href":"https://api.github.com/repos/PyConPL/Book/pulls/50/comments"},"review_comment":{"href":"https://api.github.com/repos/PyConPL/Book/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PyConPL/Book/pulls/50/commits"},"statuses":{"href":"https://api.github.com/repos/PyConPL/Book/statuses/b27e45007014a3c3a1180e8de6edab1bffb2b9e2"}}}}
{"actor":{"display_login":"deshipu"}}