Skip to content

yosevu/practicing-functional-javascript

Repository files navigation

Practicing Functional JavaScript

Why bother?

The biggest problem in the maintenance of large-scale software systems is complexity—large systems are hard to understand.

Out of the Tar Pit

Functions are simple. They are the simplest building blocks we have for making useful software. Simplicity matters because building software is hard. It is also easy to make building software more complex than necessary to solve the essential user problem. This accidental complexity makes software harder to understand, harder to test, harder to maintain, more expensive, and ultimately not very fun to work with. But it doesn’t have to be that way!

The difference between simple and complex is not just that complex things have more parts but that those parts are folded together—entwined. Working with pure functions and composing them to solve problems are essential functional programming skills that can be used to untwine and simplify this type of complexity.

Note: Simple does not mean easy. Hard problems are still hard. Simplicity only makes a hard problem easier to think about by breaking it into independent subproblems. These subproblems are easier to understand and solve in isolation and can be composed to form the larger solution.

Contents

Start

  • Clone this repository: git clone [email protected]:yosevu/practicing-functional-javascript.git.
  • Change to the exercises directory: cd practicing-functional-javascript/src/exercises.
  • Run tests: npm test hello-world.
  • Run tests in watch mode: npm watch hello-world.
  • Lint exercises: npm run lint.

Exercises

This is an index of the the exercises.

  1. Hello World
  2. Two Fer
  3. Resistor Color
  4. Resistor Color Duo
  5. Gigasecond
  6. RNA Transcription
  7. Space Age

Questions

What is this?

Practicing Functional JavaScript is a collection of exercises that help you level up your functional programming skills with JavaScript. These exercises emphasize experience and building patterns through exposure to many examples. Understanding concepts like function composition and referential transparency is more useful when you can recognize them through repeated exposure to the patterns in specific examples.

The exercises focus on the functional part of functional programming and the techniques that are available when working with pure functions. Working with functions is the best practical place to get started with functional programming and a great way to practice patterns that can be used in any code base.

Note: This is not intended to cover the equally important (but more advanced topics) of structuring data and managing state and side effects.

Why does this exist?

The purpose of Practicing Functional JavaScript is to create an example-based resource of exercises for practicing functional patterns in JavaScript, bridging the gap between imperative and functional thinking.

There are some great functional programming resources that use JavaScript. They give a good overview of functional programming and explain core concepts through thoughtful and engaging discussions with pertinent examples. The focus of Practicing Functional JavaScript is practice—practice to gain exposure to functional patterns and functional thinking, practice refactoring imperative to functional code, and examples to anchor functional concepts to.

Who is this for?

Practicing Functional JavaScript is for anyone who wants to practice functional programming patterns and functional thinking in JavaScript.

This is not intended to be used on its own, especially for people who are learning to code. Functional programming is a great introduction to programming, but Practicing Functional JavaScript doesn’t try to teach the concepts, it simply provides a resource of examples for mapping those concepts to. For some great introductory resources, see resources.

What is the approach?

Solve each exercises in two ways.

  1. Use core JavaScript functional functions, methods, and other features.
  2. Use Ramda utility functions and functional programming patterns.

Exercism

Code Practice and Mentorship for Everyone.

Exercism is a great platform to practice programming and is the foundation for Practicing Functional JavaScript for three main reasons:

  1. 101 open source JavaScript exercises
  2. Test-driven
  3. Modern JavaScript development environment and tooling

ESLint and eslint-plugin-functional

A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript.

ESLint rules to disable mutation and promote fp in JavaScript and TypeScript.

Linting is great for learning because it can help you begin to notice patterns and think about concepts that you may not have been aware of. In a multi-paradigm language as flexible as JavaScript, linting is essential for writing understandable and maintainable code. ESLint is great because it is configurable and customizable with plugins like eslint-plugin-functional. This plugin enforces functional patterns and is also a great source of practical information about functional programming.

Ramda

A practical functional library for JavaScript programmers.

Ramda is a popular JavaScript functional programming library. It is practical, easy to get started with, and it provides a flexible set of utilities to start using the functional concepts and patterns that you don’t get out of the box with JavaScript. It also has great documentation and a great community. There is a wealth of information to learn from and understand functional programming.

Hindley Milner Types

A classical type system for the lambda calculus with parametric polymorphism.

Type systems are not strictly required for functional programming since the Lambda Calculus foundation that Functional Programming is based on can be typed or untyped. Whether strongly typed or dynamic like JavaScript, thinking about the type signatures of functions is a useful skill. We will use the standard Hindley-Milner type system and annotate our functions in comments. See Chapter 7: Hindley-Milner and Me of Professor Frisby's Mostly Adequate Guide to Functional Programming for a fun and accessible introduction.

Resources

About

Practice functional programming by refactoring Exercism coding exercises from imperative to functional solutions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published