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?