Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save philsof/b386cdee6109a3d53e25 to your computer and use it in GitHub Desktop.
Save philsof/b386cdee6109a3d53e25 to your computer and use it in GitHub Desktop.
Code review for pair-jesskrich,san115 branch on scraping-hn-1-building-objects-challenge

Good work!

##The good stuff:##

  • Very nice that you created separate to_s methods for your post class and comment class, and that your post class to_s utilizes the comment class to_s. Very sharp separation of responsibilities!
  • Very wise and clean to separate the parsing of the data and creating of the objects from the rest of your code. Also I like the names of your modules because they clearly convey what each module is doing: PostFactory and CommentFactory. These modules show you are grasping what it means to separate responsibilities.
  • Good use of map_with_index here

##Stuff to work on:##

  • It looks like your add_comment method is doing a lot more than adding one comment object to your post object; it is actually creating multiple comment objects via your CommentFactory module, and then adding all of those comment objects to your post object. This is a mixing of responsibilities! We want each of our methods to have a single responsibility. Thus your add_comment method should do exactly one thing: add one comment to your post. Like this:
    def add_comment(comment)
      @comments << comment
    end
  The creating of `comment` objects should not occur in your `add_comment` method.  (It needs to occur, but not here. That's for another method!)

* Your `to_s` method in your `comment` class has [two lines](https://github.com/nyc-chorus-frogs-2016/scraping-hn-1-building-objects-challenge/blob/pair-jesskrich%2Csan115/comment.rb#L13-L14), but watch out: without an explicit return statement, Ruby will only return the last line in a method. Thus, this `to_s` method is only printing `@content` to the console; it is simply ignoring `@user_name`. (That's why the user names are not printing to the console.) (Side thing for when you have time: check out "Some tips on using to_s" in [this gist for another pair](https://gist.github.com/philsof/b1129c5a04c067714690), to get some tips on how to better utilize a `to_s` method.
* Heads up: [This line](https://github.com/nyc-chorus-frogs-2016/scraping-hn-1-building-objects-challenge/blob/pair-jesskrich%2Csan115/runner.rb#L11) in your runner code is not doing anything. You could safely delete it.
* Heads up: [this method](https://github.com/nyc-chorus-frogs-2016/scraping-hn-1-building-objects-challenge/blob/pair-jesskrich%2Csan115/comment.rb#L28) is not accurately named. It is actually creating and returning multiple comments, and thus should be named `new_comments` or `create_comments` or something that clearly indicates it is returning more than one comment.

##Challenge:##
When you have time, see if you can refactor your code in such a way that your entire runner code could be simply:
```ruby
hacker_news_url = #put any Hacker News post URL here
my_post = PostFactory.new_post(hacker_news_url)
puts my_post

Hint: You would need to refactor much more than your runner file to achieve this result.

Good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment