Danack / docs

Slides, presentations and other docs.
MIT License
0 stars 1 forks source link

Idea, Efficient coding through TDD #14

Open Danack opened 5 years ago

Danack commented 5 years ago

TDD is bollocks - or at least the reason people think it's good are not true.

People get confused by what something is meant to be important, and why it actually is good.

Bitcoin + blockchain. People who promote it says the distributed transactions are inherently good. Bitcoin is not good for that, but it's really good for buying and selling drugs.

OO was taught as being good for inheritance and abstract types for code re-use. Both those are no where near as good as people think. However writing OO code allows your IDE to use autocomplete. OO also avoids a large number of naming problems

$foo->toArray();
$bar->toArray()

vs

convertFooToArray($foo)
convertBarToArray($bar)

People say TDD is good because it allows you to design your code first.

This is bollocks.

TDD is good because of a side-effect - it is way more efficient to write code through an IDE than having to switch back and forth to a browser.

There are happypaths, and errors

To get happy path working you need to

1) Editing code in the IDE. 2) Switch to Browser, move to refresh the page. 3) Wait a moment, inspect the output. 4) Possibly need to do some more investigation i.e. change to port with xdebug enabled. 5) Check it's working.

To get error handling working you need to

1) Editing code in the IDE. 2) Switch to Browser, move to refresh the page. 3) Wait a moment, inspect the output. 4) Possibly need to do some more investigation i.e. change to port with xdebug enabled. 5) Check it the error is working. 7) Check the success case is still working

Calling everything from the IDE is a second or two faster each time. But the big wins are you don't have to keep checking that the working version is still working.

I don't like TDD. It forces me to write a test when I don't understand the code. It sometimes takes me a significant amount of time to understand what some code is going to do.

I often find the best way to understand a module is to use it....in this case, I can learn a lot about a module by....writing some useful code.

How to get into TDD.

1) Write a test to run the code. 2) Get the code working. 3) Add some assert to the test, to ensure it stays working. 4) Write an error test. 5) Write some code to get the error case working. 6) Add some asserts to the error test case.

Done.