Course Introduction: Safer JavaScript with the Maybe type

Andy Van Slaars
InstructorAndy Van Slaars
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

JavaScript's dynamic typing makes the language incredibly flexible. That flexibility comes at a cost. Because any variable can potentially be of any type, it's easy to inadvertently introduce runtime Type errors into an application.

The Maybe data type encapsulates the defensive coding needed to avoid such errors, keeping our application code focused on the task at hand.

In this course, we'll look at the Maybe type in action. We'll be relying on the Maybe exposed by the crocks library, but the core concepts and much of the API translates to other implementations. We'll learn how to construct a Maybe and apply transformations to data within those safe confines. We'll also cover point-free utility functions that let us build up function compositions for working with Maybes

After completing this course, you'll have the tools to write safe, declarative JavaScript that can be easily composed while avoiding the unnecessary noise of sprinkling imperative conditional statements throughout your code.

Instructor: [00:01] JavaScript's dynamic typing makes the language incredibly flexible. That flexibility comes at a cost. Because any variable can potentially be of any type, it's easy to inadvertently introduce runtime-type errors into an application. We can, and often do, alleviate this by adding conditional checks throughout our code to handle such cases, but this leads to bloated code that can be hard to follow.

[00:24] The maybe data type allows us to encapsulate the defensive coding needed to avoid such errors, keeping our application code focused on the task at hand. In this course, we'll look at the maybe type in action. We'll be relying on the maybe exposed by the crocks library, but the core concepts and much of the API translates to other implementations.

[00:43] This course starts with an overview of the maybe type and its underlying types, the just and the nothing. We'll cover various approaches for constructing this data type, and learn how to apply transformations to data within the safe confines of a maybe. We'll also cover the point-free utility functions provided by crocks that let us build up function compositions for working with our maybes.

[01:03] After completing this course, you'll have the tools and knowledge needed to add some safety to your JavaScript with declarative code that can be easily composed while avoiding the unnecessary noise of sprinkling imperative conditional statements throughout your code.

Christian
Christian
~ 6 years ago
Benjamin
Benjamin
~ 6 years ago

Hope you don't mind a slightly meta question, are you able to let us know the font you're using, and the extension which is providing the live preview for variables and errors?

Guy
Guy
~ 6 years ago

Hey Benjamin, can't speak for the font, but the extension being used is called quokka.js. FWIW, I think it is a fantastic JS scratchpad, can't recommend it enough. https://quokkajs.com/

Andy Van Slaars
Andy Van Slaarsinstructor
~ 6 years ago

Hope you don't mind a slightly meta question, are you able to let us know the font you're using, and the extension which is providing the live preview for variables and errors?

The font is operator mono, and Guy is right. The live preview is coming from Quokka.

Benjamin
Benjamin
~ 6 years ago

Thanks for the answers! Going to have to try these both out myself.

Aaron
Aaron
~ 6 years ago

What's the plugin you're using for vscode to eval your JS inline with the editor?

Andy Van Slaars
Andy Van Slaarsinstructor
~ 6 years ago

That plugin is called Quokka - https://quokkajs.com/

Nathan Cox
Nathan Cox
~ 6 years ago

@Benjamin there's a really good Operator Mono alternative called Dank (https://dank.sh) which is quite a bit more affordable.

Andy Van Slaars
Andy Van Slaarsinstructor
~ 6 years ago

Dank Mono is fantastic, recently switched to it myself.

Maxime Beaudoin
Maxime Beaudoin
~ 6 years ago

Do you think its possible and clean to use the library with TypeScript ?

Andy Van Slaars
Andy Van Slaarsinstructor
~ 6 years ago

Do you think its possible and clean to use the library with TypeScript ?

Since TS is a superset of JS, it’s possible. I don’t know if crocks has typings defined, so you might not get the type support you’d get out of the box with other libraries.

A. Lion
A. Lion
~ 6 years ago

Hi Andy, First off, thanks for your videos; really enjoyable explanations on Functional Programming topics. Second - to allow the continuation of the meta questions: Which VS color scheme are you using here? (Yes, we want to be exactly like you ;))

Andy Van Slaars
Andy Van Slaarsinstructor
~ 6 years ago

I’m glad you’re enjoying the videos :)

The theme used in this video is the one found here:

https://github.com/orefalo/bcmarinacci.theme-material-operator-1.3.0

Markdown supported.
Become a member to join the discussionEnroll Today