
Test-driven design - breck
http://startuplab.googleventures.com/test-driven-design-2013-07-09
======
dhotson
Yep, this is how I think about TDD too.

Testing is a good tool for QA, but I find it's even better as a tool for
design.

Writing code that's designed to be testable helps clarify responsibilities,
dependencies, interfaces, and relationships.

The bit where you actually run the tests is less interesting to me. :-P

------
kushti
There is no one class of errors unit tests could solve, that's all about
human-powered magic. In contrast, static typing, static code analysis and some
methods of model checking could eliminate many kinds of errors before program
run.

TDD is necessary for dynamic languages with weak types. In other cases unit
tests are good to ensure some properties, but TDD is not the good tool at all.

~~~
brodo
I can see how you don't really need unit tests when using statically typed
languages, but they are still handy. TDD is not only about unit testing, it's
also about integration testing and acceptance testing. In my experience,
integration testing is a lot more valuable than unit testing because you may
make certain assumptions about the libraries you use which are not true. With
your own code that's less of a problem.

~~~
kushti
TDD is test-centric development, i.e when you write test first then code. Unit
tests are needed, other tests are needed too, the question is it worth to make
testing the core of development process. From my practice, no

~~~
sirmarksalot
So there's a hard-core "always test first" fringe, but very few people are
really advocating testing all your getters and setters. Heck, I think my code
coverage is probably something like 1% (most of the code base is dumb
construction of view models from CMS content), though I can't speak for other
programmers.

The practical approach is to test the complicated stuff, and design your code
so that you can test it if you need to. This leads to better modularity and
easier reusability across the board.

------
CmonDev
TDD is like Forex and semi-pro photo-shooting. The most probable way of
benefiting from it is to write books on it and make workshops.

------
sirmarksalot
Misko Hevery has several Google tech talks about this, and I found them very
interesting and easy to follow:
[http://www.youtube.com/watch?v=XcT4yYu_TTs](http://www.youtube.com/watch?v=XcT4yYu_TTs)

At the very least, it completely changed the way I think about and write code.

~~~
brodo
Second that. I've watched all these talks several times. It's a clear
explanation on why global State is bad and how to avoid global state using
dependency injection. Nowadays, I write all my stuff using manual dependency
injection. I would really recommend everyone to try it out.

------
gohrt
No one who uses the project name "Karma" has any right to use the adjective
"spectacular" to describe the project. They lost that privilege when the
melodramatics forced the name change.

~~~
grinich
A rose by any other name would smell as sweet.

~~~
IbJacked
And have thorns that cut just as deep.

------
vmarsy
Very interesting.

I'm not very familiar with Javascript but : The design used to solve test
problems here is to pass the useful variables in the parameters of the
function instead of using global variables.

Is it not slowing down all the program by passing all these variables by value
?

[http://stackoverflow.com/questions/518000/is-javascript-a-
pa...](http://stackoverflow.com/questions/518000/is-javascript-a-pass-by-
reference-or-pass-by-value-language)

~~~
vmarsy
I see thanks for the replies.

So it's OK as long as you use objects and not a simple integer as a counter
for instance.

~~~
astral303
Even then, use that simple integer as a counter and optimize only if it's
slow. Speed of development and testability are much more important than
optimizing parts of your code that rarely run.

------
thomasfl
Projects with good karma uses this. I have used it not only for angular, but
also for knockout and backbone.

