This is a 3-in-1 set of exercises for doing tic-tac-toe in JS.
- OO in html
- Functional in html
- Command-line app with fully owned asynchronous IO
Recently, we put together an exercise in Ruby for OO programming.
JavaScript is a wilder beast than Ruby, with ew of the hard and fast conventions of Ruby. You can do OO, functional or procedural programming. While procedural programming is the gateway to pain and sorrow, getting comfortable with OO and functional paradigms in JS is a fundamental.
JavaScript is also unlike Ruby in that it is asynchronous by nature. In the browser, JS operates in an invisible event loop, running code linearly until it's done, then waiting for an event to trigger more code behavior. On the server in Node.js, asynchronicity becomes a first class citizen. Most standard libraries call the IO with a command and a callback. Over the years of callback misery, promises and async/await have cropped up to make asynchronous behavior easier to reason about.
Getting fluent in asynchronous behavior is important for JS, but it is a general fundamental separate from JavaScript. It can be applied to many things including data pipelines, background jobs and debugging of race conditions.
Each of the exercises has its own README with rules and instructions:
The last exercises allows you to choose between OO and functional at every step, and you will have to justify why you took that option at each step. So, make sure you nail the first two exercises well enough to understand best practices and trade offs.
You want to work with someone who has already done this exercise and gotten PR by PR feedback. Don't skip ahead to see their work, because everyone comes up with their own beautiful inventions.
For the first two features (at least). Do a separate PR for:
- Red: the failing tests
- Green: the bare minimum needed to make the test past (stupidly)
- Refactor: making the code pretty, and following the design rules
Do a PR for each of these, and to avoid pain, wait for feedback before moving to the next step.
This exercise starts out with just a passing high level acceptance test. As the code follows the design guidelines, more modules and classes will be extracted. Each of these should be easy to test, and instead of adding more high level tests, you should be moving detailed logic out of those tests and into unit and integrational tests.
After a 2+ features separating out red-green-refator into separate PRs, its time to start doing them all in one PR.
Tests can be run by the script npm test or yarn test depending on your
peferred tool.