Skip to content
Open
28 changes: 28 additions & 0 deletions drafts/episode5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
> This episode is still **Work in progress**

# Building a calculator, episode 3

After finishing [episode 2][episode2] you should have a small codebase
and test suite, with some functions and an calculator 'object'
experiment.

To provide some more insight into 'objects', this time we are going to
do a little experimentation.

Move the provided `calculator.spec.js` into your experiment codebase.
(that you have set up during [episode 1][episode1])

The file consists of 3 parts.

1. 5 different ways of creating an calculator object
2. Picking our 'makeCalculator' factory
3. Testing our calculator

Goal:

1. Try out each form of implementing the calculator
2. Make sure you understand each form of implementing it
3. Figure out why certain tests fail in certain cases

[episode1]: https://github.com/matthijsgroen/js-tdd/tree/master/episode1
[episode2]: https://github.com/matthijsgroen/js-tdd/tree/master/episode2
File renamed without changes.
15 changes: 10 additions & 5 deletions episode3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ describe("Regression tests", () => {
```

## Refactoring the add function
Now we know the code works, we could refactor the `functions` into a
version with [lamda][lamdas], this is the "Modern way" to define
functions. They have a slightly different way how the scope works, but
we get to that later 😅

In short, we will refactor this:
What is [refactoring][refactoring]?
The process of refactoring is to structure software by applying a series of refactorings without changing its observable behaviour.
The last part is important, without changing its observable behaviour. Behaviour can be observed
with tests and this way we can make sure it does not change while we are structuring our code.

Now we know the code works, we could refactor the `functions` into a version with [lamda][lamdas],
this is the "Modern way" to define functions. They have a slightly different way how the scope works,
but we get to that later 😅

For our `add` function we will refactor this:
```js
export function add(left, right) {
return left + right;
Expand Down Expand Up @@ -96,3 +100,4 @@ export const square = (number) => times(number, number)
[episode2]: https://github.com/matthijsgroen/js-tdd/tree/master/episode2
[lamda]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
[4rosd]: https://www.theguild.nl/4-rules-of-simple-design/
[refactoring]: https://refactoring.com/
Loading