News for hackers. Stuff that matters.
Re:Guide: Writing Testable Code [pdf] by stevekl on Wednesday September 17, 2014 @09:37PM (#8333209)
I want to use this opportunity to open a discussion and get hacker news community's thoughts on preparing code examples.

I always find many contrieved examples in coding guides such as:

  class Bicycle
    def initialize(size_of_wheels)
      # blah
    end

    def run
      # blah
    end
  end
These are fine. But as such, the examples always fit well with the principles and you try to implement the principles, reality is a always far more messier.

Are there a better way to write coding examples? does it ever make sense, to grab snippets from a real code base and so that it is in touch with reality

Re:Guide: Writing Testable Code [pdf] by nstart on Thursday September 18, 2014 @01:05AM (#8333802)
There are better ways as given in Robert C Martin's excellent book, Clean Code. He constantly refers to code taken from the Fitnesse repo and shows how the code looked before and after refactoring and testing.

I do agree with the sentiment that real world code examples are more useful. When I was learning design patterns during my degree, we were actively discouraged from using Head First as THE reference even though it did simplify things. Our lecturer was later challenged on this view. He then took the students on a counter challenge to refactor and redesign code from real world examples (taken from students' projects). Reality hit quite hard for a lot of us as we struggled to see the patterns in less obvious situations.

An interesting point to note however, was that after gaining an understanding of the design patterns at a practical level, I could then reference simple examples as given in Head First and immediately formulate how I would use it to solve a practical scenario that I might have been stuck with. Funny how it worked one way but not the other.

Re:Guide: Writing Testable Code [pdf] by SoulMan on Thursday September 18, 2014 @01:58AM (#8333928)
Could have just posted the HTML link :) http://misko.hevery.com/code-reviewers-guide/
Re:Guide: Writing Testable Code [pdf] by lumpypua on Thursday September 18, 2014 @03:56AM (#8334177)
PDFs are nice. I print 'em out, read them on the crapper and pretend I'm at the googleplex. <3 Testing on the Toilet
Re:Guide: Writing Testable Code [pdf] by CoffeeDregs on Wednesday September 17, 2014 @08:47PM (#8333095)
Seems like a nice guide and I plan to read it through fully. Does anyone have suggestions for other "how to test software" guides?
Re:Guide: Writing Testable Code [pdf] by jrvarela56 on Wednesday September 17, 2014 @09:07PM (#8333138)
Follow http://googletesting.blogspot.com/ for weekly posts about specific testing techniques.
Re:Guide: Writing Testable Code [pdf] by co_dh on Thursday September 18, 2014 @09:03AM (#8334936)
I stop right at the "class". How possible can you test an OO class? Try some functional program, they are designed to be testable.