The purpose of this repo is to demonstrate how refactorig your code (as much as possible) into "pure" functions can make testing much, much easier.
Once you learn the basics of coding, you'll start to feel confident. You'll be able to implement solutions to problems with some effort, and you may even take a first pass at "refactoring" your code to make it easier to read, and perhaps to eliminate duplication.
What many people don't realize is that, when Brendan Eich first created JavaScript, he wanted to create Scheme in the browser. However, corporate forces got in the way of his ideal vision, requiring him to make it look syntactially like Java. Nonetheless, he was a functional programmer in his soul, and JavaScript has a lot of roots in FP (e.g., functions as first-class objects, closures).
Some functional programming concepts are valuable even in the absence of a functional programming language. In particular, the concept of "pure" functions (a function without side-effects) can make your code not only more readable, but much more easily tested. And that's really the point of this repository: to show a "naive" implementation first, and then to show how one might refactor it into one that is much more easily tested via the use of pure functions.
Enjoy!
- Clone the
naive-implementation
branch of this repo:git clone -b naive-implementation [email protected]:LearnersGuild/pure-testing-lecture.git
- Inspect the code. The CLI "harness" is in
src/index.js
and most of the actual implementation resides insrc/write-top-crypto-coins.js
. - Refactor this code, eliminating any side-effects, by using "pure" functions.
If you get stuck, you can look at the pure-refactor
branch, which will show a commit-by-commit refactoring to make things easy to test.