The enchanted electrical website of Dr. Sinclair
-
Rendering mazes on the web
Written by James SinclairIt’s one thing to build a representation of a maze in memory. It’s quite another to render it so that people can view it in a web page. How do we do that? What are our options? And what happens if we try to make our maze rendering accessible?
-
The joy of recursion, immutable data, and pure functions: Generating mazes with JavaScript
Written by James SinclairGenerating mazes might not be something you do a lot in your typical front-end job. Some might call it a waste of time. Why bother if you’re not a game developer? Who needs that kind of thing? Sure, it might not be essential, but it’s a lot of fun. Building mazes also presents interesting real-world challenges. How do we deal with random numbers if we’re creating pure functions? How do we implement a repetitive algorithm without using loops? How do we work effectively with immutable data structures? And most importantly, can we have some fun while we’re at it?
-
What’s the difference between ordinary functions and arrow functions in JavaScript?
Written by James SinclairArrow functions (also known as ‘rocket’ functions) are concise and convenient. However, they have subtle differences compared to function declarations and function expressions. So how do you know which one to use, and when?
-
Is it better to be a good person, or religious?
Written by James SinclairA friend of mine asked this question the other day. “Is it better to be a good person, or religious?” The question turned out to be more thought-provoking than expected. Not because I was stumped. Rather, my first reaction was: “This question doesn’t make sense.” Those aren’t categories a Christian tends to think in.
-
How to compose JavaScript functions that take multiple parameters (the epic guide)
Written by James SinclairFunction composition is beautiful. It lets us create elegant function pipelines. And when everything lines up, the data flows like maple syrup over pancakes. But what happens when the functions don’t line up? What if some of those functions expect more than one argument? What do we do?
-
How to consume a paginated API using JavaScript async generators
Written by James SinclairGenerators can be powerful tools for efficient data processing. But things get a bit tricky when we add asynchronous calls into the mix. Asynchronous generators, however, come to the rescue by handling scenarios involving promises. They come in handy for a variety of real-world scenarios. And one of those came up recently.
-
What’s so great about functional programming anyway?
Written by James SinclairTo hear some people talk about functional programming, you’d think they’d joined some kind of cult. They prattle on about how it’s changed the way they think about code. They’ll extol the benefits of purity, at length. And proclaim that they are now able to “reason about their code”—as if all other code is irrational and incomprehensible. It’s enough to make anyone skeptical. Still, one has to wonder. There must be a reason these zealots get so worked up. What are they so excited about?
-
Why would anyone need JavaScript generator functions?
Written by James SinclairYou can go a long time as a JavaScript developer without ever feeling the need for generators. Hence, it’s natural to wonder: What are they good for? Why would you ever need one? What’s the point? But generators can do some neat tricks. And they may even change the way you approach certain problems.
-
What if the team assumes my functional JavaScript is slow?
Written by James SinclairThere’s a common myth that using a functional style with JavaScript is always slow. While this is truly a misconception, it has some basis in truth. There are a lot of traps we can fall into while writing functional JavaScript. So what are they? And how do we avoid them?
-
What if the team hates my functional code?
Written by James SinclairWhat happens when you learn functional programming and you start writing better code… but the rest of your team hates it? Do you give up? Write code you know is inferior? Do you quit and get a new job? What if quitting isn’t an option? What do you do then?