Skip to content

LearnersGuild/pure-testing-lecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pure-testing-lecture

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.

Philosophical Interlude

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!

The Right Way to Get Started

  1. Clone the naive-implementation branch of this repo: git clone -b naive-implementation [email protected]:LearnersGuild/pure-testing-lecture.git
  2. Inspect the code. The CLI "harness" is in src/index.js and most of the actual implementation resides in src/write-top-crypto-coins.js.
  3. Refactor this code, eliminating any side-effects, by using "pure" functions.

Stuck?

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.

About

show how pure functions make testing easier

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published