The enchanted electrical website of Dr. Sinclair
-
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?
-
JavaScript function composition: What’s the big deal?
Written by James SinclairTo hear some people talk, you’d think function composition was some kind of sacred truth. A holy principle to meditate upon whilst genuflecting and lighting incense. But function composition is not complicated. You probably use it all the time, whether you realise it or not. Why, then, do functional programmers get all worked up about it? What’s the big deal?
-
How not to write property tests in JavaScript
Written by James SinclairProperty-based tests give us more confidence in our code. They’re great at catching edge-cases we may not have thought of otherwise. But this confidence comes at a cost. Property tests take more effort to write. They force you to think hard about what the code is doing, and what its expected behaviour should be. It’s hard work. And on top of that, running 100+ tests, is always going to take longer than running 3-5 example-based tests. This cost is real, and it raises the question: How do we keep ourselves from over-specifying or writing unnecessary tests?
-
How to get started with property-based testing in JavaScript using fast-check
Written by James SinclairProperty-based testing helps us write better tests, with less code, and greater coverage. This leads to more confidence in our code, and fewer bugs in our applications. But, as always, there’s a price. Property tests take more effort to write, and they take longer to run. Still, I’m convinced that the trade-off is worth it. In this article, we’ll run through an example of how to write property tests using fast-check.