{"action":"created","comment":{"url":"https://api.github.com/repos/codurance/site/pulls/comments/56411967","id":56411967,"diff_hunk":"@@ -0,0 +1,258 @@\n+---\n+layout: post\n+name: code-smells-part-one\n+title: Code Smells – Part I\n+date: 2016-03-16 12:10:00 +00:00\n+author: Ana Nogal\n+canonical:\n+    name: my personal blog\n+    href: http://www.ananogal.com/blog/code-smells-part-one/\n+image:\n+    src: /assets/img/custom/blog/code-smells.jpg\n+    attribution:\n+        text: Via Flickr/Creative Commons/Brian Fitzgerald (Creative Commons - Attribution-ShareAlike 2.0 Generic license)\n+        href: /assets/img/custom/blog/code-smells.jpg\n+tags:\n+- bloaters\n+- code smells\n+- long classes/methods\n+---\n+Last weekend I was at the [SoCraTes Canaries](https://twitter.com/hashtag/socracan16) and I gave my first talk ever about code smells.Oh boy! How nervous was I! But now that that has passed I was wondering what I should do with all information I collected. And then I thought, maybe it's a good idea to put it all in a nice blog post.\n+\n+## So what are code smells?\n+\n+As [Martin Fowler](http://martinfowler.com/) said in his book [\"Refactoring: Improving the Design of Existing Code\"](http://martinfowler.com/books/refactoring.html),\n+> **A code smell is a surface indication that usually corresponds to a deeper problem in the system.**\n+\n+I like to think that a  code smell is something that makes your developer instinct cry out to you, and you just know that something is wrong. This doesn’t mean you have to make changes in your code: there are occasions where these code smells are ok, but I think It’s important for us to detect them and know exactly why they are there.\n+\n+There are 5 categories in code smells:\n+\n+- Bloaters\n+- Object-Orientation Abusers\n+- Change Preventers\n+- Dispensables\n+- Couplers\n+\n+Today I'm going to talk about Bloaters. I'll leave the other categories for a future post.\n+\n+## Bloaters\n+\n+Bloaters can be big methods or classes, primitive obsessions, data clumps, or long parameters list.\n+\n+#### Long Parameter List/Data Clumps\n+\n+The Long Parameter List is when you have a method that has more than 3 parameters. Sometimes we see that when we receive an object, and instead of passing it all we pass some of its data. In this case, the best policy is to pass the whole object. Data Clumps are a bit different: they are, in general, primitive values that start do \"get together\". A good example of this is a startDate and endDate... Maybe it's worth creating a DateRange.\n+\n+#### Primitive Obsession\n+\n+This case is when we use primitives instead of small objects for simple tasks. Sometimes the use of primitives is justifiable, but when you start to have behaviour attached to this primitives, then it's time to stop and think that maybe a value type is in order. A simple example is a currency: we tend to put it in a float/double, instead of encapsulating it in a value type.\n+\n+#### Long Method / Large Class\n+This kind of code smell happens when you have a big method. But, when do you know that a method has become too big? Well, I have the rule that with more than 5 lines, you should, at least, look at it again. But, as [Sandro](https://twitter.com/sandromancuso) told me before, the right number of lines are just enough lines so a method only does one thing (and so it conforms to the 1st principle of [SOLID](https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)) the [Single responsibility principle](https://en.wikipedia.org/wiki/Single_responsibility_principle)).\n+\n+\n+To do this blog I started to look at my old code when I hadn't woken up yet to craftsmanship: If it was working that was good enough for me. Here's the code in Objective-C:","path":"_posts/2016-03-16-code-smells-part-I.md","position":55,"original_position":55,"commit_id":"0da1d09f4d94fc088b21684eeeb3f9c63075bad4","original_commit_id":"0da1d09f4d94fc088b21684eeeb3f9c63075bad4","user":{"login":"neomatrix369","id":1570917,"avatar_url":"https://avatars.githubusercontent.com/u/1570917?v=3","gravatar_id":"","url":"https://api.github.com/users/neomatrix369","html_url":"https://github.com/neomatrix369","followers_url":"https://api.github.com/users/neomatrix369/followers","following_url":"https://api.github.com/users/neomatrix369/following{/other_user}","gists_url":"https://api.github.com/users/neomatrix369/gists{/gist_id}","starred_url":"https://api.github.com/users/neomatrix369/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neomatrix369/subscriptions","organizations_url":"https://api.github.com/users/neomatrix369/orgs","repos_url":"https://api.github.com/users/neomatrix369/repos","events_url":"https://api.github.com/users/neomatrix369/events{/privacy}","received_events_url":"https://api.github.com/users/neomatrix369/received_events","type":"User","site_admin":false},"body":"small i in the If after craftsmanship","created_at":"2016-03-16T20:48:46Z","updated_at":"2016-03-16T20:48:46Z","html_url":"https://github.com/codurance/site/pull/146#discussion_r56411967","pull_request_url":"https://api.github.com/repos/codurance/site/pulls/146","_links":{"self":{"href":"https://api.github.com/repos/codurance/site/pulls/comments/56411967"},"html":{"href":"https://github.com/codurance/site/pull/146#discussion_r56411967"},"pull_request":{"href":"https://api.github.com/repos/codurance/site/pulls/146"}}},"pull_request":{"url":"https://api.github.com/repos/codurance/site/pulls/146","id":63021170,"html_url":"https://github.com/codurance/site/pull/146","diff_url":"https://github.com/codurance/site/pull/146.diff","patch_url":"https://github.com/codurance/site/pull/146.patch","issue_url":"https://api.github.com/repos/codurance/site/issues/146","number":146,"state":"open","locked":false,"title":"New Blog Post - Code Smells Part I","user":{"login":"ananogal","id":8417368,"avatar_url":"https://avatars.githubusercontent.com/u/8417368?v=3","gravatar_id":"","url":"https://api.github.com/users/ananogal","html_url":"https://github.com/ananogal","followers_url":"https://api.github.com/users/ananogal/followers","following_url":"https://api.github.com/users/ananogal/following{/other_user}","gists_url":"https://api.github.com/users/ananogal/gists{/gist_id}","starred_url":"https://api.github.com/users/ananogal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ananogal/subscriptions","organizations_url":"https://api.github.com/users/ananogal/orgs","repos_url":"https://api.github.com/users/ananogal/repos","events_url":"https://api.github.com/users/ananogal/events{/privacy}","received_events_url":"https://api.github.com/users/ananogal/received_events","type":"User","site_admin":false},"body":"Please let me know when it's good to merge because I need to publish it first in my blog. Thanks!","created_at":"2016-03-16T06:52:51Z","updated_at":"2016-03-16T20:48:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a64e21faceec308759f0750b7729c0f9db0cd92","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/codurance/site/pulls/146/commits","review_comments_url":"https://api.github.com/repos/codurance/site/pulls/146/comments","review_comment_url":"https://api.github.com/repos/codurance/site/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codurance/site/issues/146/comments","statuses_url":"https://api.github.com/repos/codurance/site/statuses/0da1d09f4d94fc088b21684eeeb3f9c63075bad4","head":{"label":"codurance:development","ref":"development","sha":"0da1d09f4d94fc088b21684eeeb3f9c63075bad4","user":{"login":"codurance","id":5751452,"avatar_url":"https://avatars.githubusercontent.com/u/5751452?v=3","gravatar_id":"","url":"https://api.github.com/users/codurance","html_url":"https://github.com/codurance","followers_url":"https://api.github.com/users/codurance/followers","following_url":"https://api.github.com/users/codurance/following{/other_user}","gists_url":"https://api.github.com/users/codurance/gists{/gist_id}","starred_url":"https://api.github.com/users/codurance/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codurance/subscriptions","organizations_url":"https://api.github.com/users/codurance/orgs","repos_url":"https://api.github.com/users/codurance/repos","events_url":"https://api.github.com/users/codurance/events{/privacy}","received_events_url":"https://api.github.com/users/codurance/received_events","type":"Organization","site_admin":false},"repo":{"id":38424930,"name":"site","full_name":"codurance/site","owner":{"login":"codurance","id":5751452,"avatar_url":"https://avatars.githubusercontent.com/u/5751452?v=3","gravatar_id":"","url":"https://api.github.com/users/codurance","html_url":"https://github.com/codurance","followers_url":"https://api.github.com/users/codurance/followers","following_url":"https://api.github.com/users/codurance/following{/other_user}","gists_url":"https://api.github.com/users/codurance/gists{/gist_id}","starred_url":"https://api.github.com/users/codurance/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codurance/subscriptions","organizations_url":"https://api.github.com/users/codurance/orgs","repos_url":"https://api.github.com/users/codurance/repos","events_url":"https://api.github.com/users/codurance/events{/privacy}","received_events_url":"https://api.github.com/users/codurance/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codurance/site","description":"","fork":false,"url":"https://api.github.com/repos/codurance/site","forks_url":"https://api.github.com/repos/codurance/site/forks","keys_url":"https://api.github.com/repos/codurance/site/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codurance/site/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codurance/site/teams","hooks_url":"https://api.github.com/repos/codurance/site/hooks","issue_events_url":"https://api.github.com/repos/codurance/site/issues/events{/number}","events_url":"https://api.github.com/repos/codurance/site/events","assignees_url":"https://api.github.com/repos/codurance/site/assignees{/user}","branches_url":"https://api.github.com/repos/codurance/site/branches{/branch}","tags_url":"https://api.github.com/repos/codurance/site/tags","blobs_url":"https://api.github.com/repos/codurance/site/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codurance/site/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codurance/site/git/refs{/sha}","trees_url":"https://api.github.com/repos/codurance/site/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codurance/site/statuses/{sha}","languages_url":"https://api.github.com/repos/codurance/site/languages","stargazers_url":"https://api.github.com/repos/codurance/site/stargazers","contributors_url":"https://api.github.com/repos/codurance/site/contributors","subscribers_url":"https://api.github.com/repos/codurance/site/subscribers","subscription_url":"https://api.github.com/repos/codurance/site/subscription","commits_url":"https://api.github.com/repos/codurance/site/commits{/sha}","git_commits_url":"https://api.github.com/repos/codurance/site/git/commits{/sha}","comments_url":"https://api.github.com/repos/codurance/site/comments{/number}","issue_comment_url":"https://api.github.com/repos/codurance/site/issues/comments{/number}","contents_url":"https://api.github.com/repos/codurance/site/contents/{+path}","compare_url":"https://api.github.com/repos/codurance/site/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codurance/site/merges","archive_url":"https://api.github.com/repos/codurance/site/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codurance/site/downloads","issues_url":"https://api.github.com/repos/codurance/site/issues{/number}","pulls_url":"https://api.github.com/repos/codurance/site/pulls{/number}","milestones_url":"https://api.github.com/repos/codurance/site/milestones{/number}","notifications_url":"https://api.github.com/repos/codurance/site/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codurance/site/labels{/name}","releases_url":"https://api.github.com/repos/codurance/site/releases{/id}","deployments_url":"https://api.github.com/repos/codurance/site/deployments","created_at":"2015-07-02T09:54:02Z","updated_at":"2016-03-14T09:39:20Z","pushed_at":"2016-03-16T20:25:14Z","git_url":"git://github.com/codurance/site.git","ssh_url":"git@github.com:codurance/site.git","clone_url":"https://github.com/codurance/site.git","svn_url":"https://github.com/codurance/site","homepage":null,"size":155090,"stargazers_count":1,"watchers_count":1,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":1,"default_branch":"master"}},"base":{"label":"codurance:master","ref":"master","sha":"39a28c09b337b031ba9dc6aa1c2ecaa4cc8797d2","user":{"login":"codurance","id":5751452,"avatar_url":"https://avatars.githubusercontent.com/u/5751452?v=3","gravatar_id":"","url":"https://api.github.com/users/codurance","html_url":"https://github.com/codurance","followers_url":"https://api.github.com/users/codurance/followers","following_url":"https://api.github.com/users/codurance/following{/other_user}","gists_url":"https://api.github.com/users/codurance/gists{/gist_id}","starred_url":"https://api.github.com/users/codurance/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codurance/subscriptions","organizations_url":"https://api.github.com/users/codurance/orgs","repos_url":"https://api.github.com/users/codurance/repos","events_url":"https://api.github.com/users/codurance/events{/privacy}","received_events_url":"https://api.github.com/users/codurance/received_events","type":"Organization","site_admin":false},"repo":{"id":38424930,"name":"site","full_name":"codurance/site","owner":{"login":"codurance","id":5751452,"avatar_url":"https://avatars.githubusercontent.com/u/5751452?v=3","gravatar_id":"","url":"https://api.github.com/users/codurance","html_url":"https://github.com/codurance","followers_url":"https://api.github.com/users/codurance/followers","following_url":"https://api.github.com/users/codurance/following{/other_user}","gists_url":"https://api.github.com/users/codurance/gists{/gist_id}","starred_url":"https://api.github.com/users/codurance/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codurance/subscriptions","organizations_url":"https://api.github.com/users/codurance/orgs","repos_url":"https://api.github.com/users/codurance/repos","events_url":"https://api.github.com/users/codurance/events{/privacy}","received_events_url":"https://api.github.com/users/codurance/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codurance/site","description":"","fork":false,"url":"https://api.github.com/repos/codurance/site","forks_url":"https://api.github.com/repos/codurance/site/forks","keys_url":"https://api.github.com/repos/codurance/site/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codurance/site/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codurance/site/teams","hooks_url":"https://api.github.com/repos/codurance/site/hooks","issue_events_url":"https://api.github.com/repos/codurance/site/issues/events{/number}","events_url":"https://api.github.com/repos/codurance/site/events","assignees_url":"https://api.github.com/repos/codurance/site/assignees{/user}","branches_url":"https://api.github.com/repos/codurance/site/branches{/branch}","tags_url":"https://api.github.com/repos/codurance/site/tags","blobs_url":"https://api.github.com/repos/codurance/site/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codurance/site/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codurance/site/git/refs{/sha}","trees_url":"https://api.github.com/repos/codurance/site/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codurance/site/statuses/{sha}","languages_url":"https://api.github.com/repos/codurance/site/languages","stargazers_url":"https://api.github.com/repos/codurance/site/stargazers","contributors_url":"https://api.github.com/repos/codurance/site/contributors","subscribers_url":"https://api.github.com/repos/codurance/site/subscribers","subscription_url":"https://api.github.com/repos/codurance/site/subscription","commits_url":"https://api.github.com/repos/codurance/site/commits{/sha}","git_commits_url":"https://api.github.com/repos/codurance/site/git/commits{/sha}","comments_url":"https://api.github.com/repos/codurance/site/comments{/number}","issue_comment_url":"https://api.github.com/repos/codurance/site/issues/comments{/number}","contents_url":"https://api.github.com/repos/codurance/site/contents/{+path}","compare_url":"https://api.github.com/repos/codurance/site/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codurance/site/merges","archive_url":"https://api.github.com/repos/codurance/site/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codurance/site/downloads","issues_url":"https://api.github.com/repos/codurance/site/issues{/number}","pulls_url":"https://api.github.com/repos/codurance/site/pulls{/number}","milestones_url":"https://api.github.com/repos/codurance/site/milestones{/number}","notifications_url":"https://api.github.com/repos/codurance/site/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codurance/site/labels{/name}","releases_url":"https://api.github.com/repos/codurance/site/releases{/id}","deployments_url":"https://api.github.com/repos/codurance/site/deployments","created_at":"2015-07-02T09:54:02Z","updated_at":"2016-03-14T09:39:20Z","pushed_at":"2016-03-16T20:25:14Z","git_url":"git://github.com/codurance/site.git","ssh_url":"git@github.com:codurance/site.git","clone_url":"https://github.com/codurance/site.git","svn_url":"https://github.com/codurance/site","homepage":null,"size":155090,"stargazers_count":1,"watchers_count":1,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codurance/site/pulls/146"},"html":{"href":"https://github.com/codurance/site/pull/146"},"issue":{"href":"https://api.github.com/repos/codurance/site/issues/146"},"comments":{"href":"https://api.github.com/repos/codurance/site/issues/146/comments"},"review_comments":{"href":"https://api.github.com/repos/codurance/site/pulls/146/comments"},"review_comment":{"href":"https://api.github.com/repos/codurance/site/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codurance/site/pulls/146/commits"},"statuses":{"href":"https://api.github.com/repos/codurance/site/statuses/0da1d09f4d94fc088b21684eeeb3f9c63075bad4"}}}}