James Sinclair

フィード

記事のアイキャッチ画像
How to consume a paginated API using JavaScript async generators
James Sinclair
Generators 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.
1年前
記事のアイキャッチ画像
What’s so great about functional programming anyway?
James Sinclair
To 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?
2年前
記事のアイキャッチ画像
Why would anyone need JavaScript generator functions?
James Sinclair
You 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.
2年前
記事のアイキャッチ画像
What if the team assumes my functional JavaScript is slow?
James Sinclair
There'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?
2年前
記事のアイキャッチ画像
What if the team hates my functional code?
James Sinclair
What 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?
2年前
記事のアイキャッチ画像
JavaScript function composition: What’s the big deal?
James Sinclair
To 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?
2年前
記事のアイキャッチ画像
How not to write property tests in JavaScript
James Sinclair
Property-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?
2年前
記事のアイキャッチ画像
How to get started with property-based testing in JavaScript using fast-check
James Sinclair
Property-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.
3年前
記事のアイキャッチ画像
Rethinking the JavaScript ternary operator
James Sinclair
Lots of people treat the ternary operator with suspicion. At first glance, ternaries appear unnecessary. Nothing more than a tool for the overly clever to trim some characters from their code. A favourite hack for coders who don’t care about readability. And sure, it’s all too easy to turn ternaries into an indecipherable mess. But what if we’re missing something? What if there's more to ternaries than meets the eye?
3年前
記事のアイキャッチ画像
Sick of the stupid jokes? Write your own arbitrary-precision JavaScript math library
James Sinclair
Javascript has its fair share of ‘wat’ moments. Even though most of them have a logical explanation once you dig in, they can still be surprising. But JavaScript doesn’t deserve all the indignant laughter. And now that BigInt is officially part of the TC39 ECMAScript standard, we have options. I'm going to show you how to take advantage of them.
3年前
記事のアイキャッチ画像
Remote teams and the half-life of social capital
James Sinclair
Remote work is a mixed bag. Some aspects are wonderful. The lack of commute and extra flexibility is great. But there are drawbacks. Being remote comes with radical changes to how we communicate. Things that were effortless and unconscious in person become tiresome when we’re remote. And right now, so many of us are trying out this remote experiment together. But as time goes on, maybe the novelty is starting to wear off.
4年前
記事のアイキャッチ画像
The Algebraic Structure of Functions, illustrated using React components
James Sinclair
Did you know there’s an algebraic structure for functions? That may not surprise you at all. But it surprised me when I first found out about it. I knew we used functions to build algebraic structures. It never occurred to me that functions themselves might have an algebraic structure. The structure is fascinating, but functions can be rather abstract. So we'll look at some concrete things we can do with React functional components.
4年前
記事のアイキャッチ画像
How to write things people actually want to read
James Sinclair
Staring at a blank screen can be scary. And writing is hard work. Don’t let anyone tell you different. It takes extended periods of concentration to write anything significant. And that's a rare commodity these days. And even if you manage to beat your attention into submission, the craft of writing is still complex. It can be tough to know where to start. What if my writing turns out to be boring? What if nobody reads it? What if people hate it? Or worse, they start reading and get so bored they quit?
4年前
記事のアイキャッチ画像
What’s more fantastic than fantasy land? An Introduction to Static land
James Sinclair
Fantasy land is great. It opens up a whole world of interoperable functions and structures. And the title, though originally a joke, is quite fitting. But Fantasy land isn’t perfect. And it’s not the only way to do algebraic structures in JavaScript.
4年前
記事のアイキャッチ画像
Algebraic Data Types: Things I wish someone had explained about functional programming
James Sinclair
Algebraic data types and algebraic data structures sound similar. It’s like they ought to be the same thing. But they’re not. They both have ‘algebraic’ in the name, so it’s confusing. I got them mixed up at times. Others have too. But, they’re different concepts. Understanding the difference will help if you’re trying to learn functional programming.
5年前
記事のアイキャッチ画像
Type Classes: Things I wish someone had explained about functional programming
James Sinclair
Type classes are not the same thing as algebraic structures. But you'll find many people use the terms interchangably. And that can be confusing. It confused me for a long time. In this article we look at what type classes actually are. And we’ll also look at why programmers from other languages are so enthusiastic about them.
5年前
記事のアイキャッチ画像
Algebraic Structures: Things I wish someone had explained about functional programming
James Sinclair
Algebraic Structures are something I wish I’d understood better, sooner. I had a hazy idea of what they were, but didn’t know the correct terminology. That was a massive barrier to finding out more. This article is my attempt to stop that happening to others. We'll look at: What are algebraic structures? How do we use them in JavaScript? Why would we bother? What's the big deal?
5年前
記事のアイキャッチ画像
Things I wish someone had explained about functional programming
James Sinclair
It's hard learning functional programming on your own. But it ought not to be. You don't need a PhD to understand functional programming. The concepts are abstract, yes. But that doesn't make them incomprehensible. It shouldn't be this difficult. This is the first in a four-part series on things I wish someone had explained to me about functional programming.
5年前
記事のアイキャッチ画像
Functional JavaScript: What are higher-order functions, and why should anyone care?
James Sinclair
“Higher-order function” is one of those phrases people throw around a lot. But it's rare for anyone to stop to explain what that means. Perhaps you already know what a higher-order function is. But how do we use them in the real world? What are some practical examples of when and how they're useful? Can we use them for manipulating the DOM? Or, are people who use higher-order functions showing off? Are they over-complicating code for no good reason?
5年前
記事のアイキャッチ画像
Functional JavaScript: Traversing Trees with a Recursive Reduce
James Sinclair
Trees come up a lot in web development. As in, more than you would expect. They pop up all over the place. But trees can be tricky. If you're like me, you know that there ought to be a way to process them neatly. You might want to change all the values, or make some calculation on the tree. But the way to do it isn't always obvious. And utility libraries like Ramda or Lodash don't come with tree-traversing functions. So, what do we do?
5年前
記事のアイキャッチ画像
Magical, Mystical JavaScript Transducers
James Sinclair
Transducers are very cool. They give us a lot of power. But they are also a bit abstract. And that makes them hard to explain. But they also embody the dream of functional programming. We write tiny, simple functions. Then we piece them together with flexible tools that work for lots of different data structures. And we end up with powerful, performant programs.
5年前
記事のアイキャッチ画像
Functional JavaScript: Five ways to calculate an average with array reduce
James Sinclair
The JavaScript array reduce method seems to give people trouble. Part of the reason is that many tutorials start out using reduce only with numbers. So I wrote a previous article about the many other things you can do with reduce that don’t involve arithmetic. But what if you do need to work with numbers? How do you use reduce for real-world arithmetic problems?
5年前
記事のアイキャッチ画像
Functional JavaScript: How to use array reduce for more than just numbers
James Sinclair
The array reduce method is really powerful. But people often run into trouble as soon as they step beyond the basic examples. Simple things like addition and multiplication are fine. But as soon as you try it with something more complicated, it breaks. Using it with anything other than numbers starts to get really confusing. I think this is because the examples in most tutorials mask some of what's going on. This article looks at some of the more interesting things you can do with .reduce() that better show how it works.
5年前
記事のアイキャッチ画像
Elegant error handling with the JavaScript Either Monad
James Sinclair
JavaScript gives us a built-in language feature for handling exceptions: try…catch statements. And they're better than littering our code with if-statements. But they can be problematic. And they are not the only way to handle errors. In this article, we’ll take a look at using the ‘Either monad’ as an alternative to try…catch.
5年前
記事のアイキャッチ画像
How to run async JavaScript functions in sequence or parallel
James Sinclair
The async and await keywords are a great addition to Javascript. They make it easier to read (and write) code that runs asynchronously. But they can still be confusing. Asynchronous programming is hard. Anyone who tells you differently is either lying or selling something. But there are some simple patterns you can learn that will make life easier.
5年前
記事のアイキャッチ画像
How do you compose JavaScript functions with multiple parameters?
James Sinclair
As functional programmers, we like to piece our programs together out of small pieces. Our main tool for this is composition. We take an input, process it through a function, then pass it on to another function. And this all works great so long as all our functions take exactly one argument. Which never happens. So what do we do? In general, we turn to a set of tools called combinators. This article focusses on a particular combinator called lift.
5年前
記事のアイキャッチ画像
Object destructuring and currying in functional JavaScript
James Sinclair
Currying is one of the most formidable weapons in our functional programming arsenal. Combined with composition, it’s extremely powerful. But is currying useful if you’re doing object destructuring with your function parameters?
6年前
記事のアイキャッチ画像
How to deal with dirty side effects in your pure functional JavaScript
James Sinclair
If you start learning about functional programming, it won't be long before you come across the idea of pure functions. And as you go on, you will discover functional programmers appear to be obsessed with them. “Pure functions let you reason about your code,” they say. “Pure functions are less likely to start a thermonuclear war.” “Pure functions give you referential transparency”. On and on it goes. And they have a point. Pure functions are a good thing. But what do you do with the impure bits of your code?
6年前
記事のアイキャッチ画像
How to use React (and Redux) with your crufty old CMS
James Sinclair
Getting your JavaScript to run well on a CMS can be difficult at the best of times. But the difficulty grows exponentially when you add something like React and Redux. And this isn't the fault of the CMS. Unfortunately most React tutorials assume you're writing a Single Page web Application (SPA). And that's great if you are actually building an SPA. But what about when you're not? What about those of us who have a CMS imposed on us by our employer? What about those situations where a CMS is the best tool for the job?
6年前
記事のアイキャッチ画像
What’s the point of art?
James Sinclair
What is art for? What is the point of it? It’s not like food, clothing and shelter. We don’t die without art. At least, not straight away. Take away air, or water, or food, and we die. But we seem to be able to last much longer without art. Art doesn’t appear to be essential for life. In fact, it even seems frivolous at times. Its utility is not obvious. Yet, we humans keep making it. And the better our physical needs are met, the more art we seem to make.
6年前
記事のアイキャッチ画像
React, Redux and JavaScript Architecture
James Sinclair
Whether you use them or not, React and Redux are important. They have changed the way we think about structuring front-end web applications. They can be very powerful. But they are not magic. JavaScript code does not automatically become better just because it uses React. It is easy to write horrible React code, just like it's easy to write horrible vanilla JavaScript. So, why is React important then? The thing is, understanding how to write React and Redux code is one thing. Understanding why you'd want to use React and Redux is another matter entirely. Once you understand the why of React, then modern JavaScript starts to make more sense. This is true whatever framework you're using. Whether it's React, Vue, Ember, Angular, Web Components, or something else entirely. React and Redux have had a huge impact on how we organise front-end code.
6年前
記事のアイキャッチ画像
Flavours of prayer
James Sinclair
Have you ever visited different types of churches and listened to how they pray? Growing up, I had the privilege of visiting several churches. They were all different. And the people in them prayed with different styles.
7年前
記事のアイキャッチ画像
Faster, Better, Cheaper—The art of making software
James Sinclair
Nobody wants to deliver late, over-budget software. I don’t know a single software developer who wakes up in the morning and thinks “I’d like to do a rubbish job today. How can I cost my employer more money?” And yet, so many software projects don’t go well. And with every new project, there seems to be more and more pressure to go faster. So, if we’re in the business of making software, what do we do? How do we go faster without compromising quality?
7年前
記事のアイキャッチ画像
JavaScript. But less iffy.
James Sinclair
Have you ever started writing some code that seemed so simple? But then you had to validate the input? And handle an edge case? Oh yeah, and that weird thing the server sometimes does? And somehow this oh-so-simple piece of code turned into a mess? This article looks at how we can reduce the complexity introduced by conditionals.
7年前
記事のアイキャッチ画像
JavaScript Without Loops
James Sinclair
We've been talking about writing less complex JavaScript. We do this by choosing the right abstraction to solve a problem. But how do you know which abstraction to use? So far, we haven't looked at any concrete examples of how to do this. In this article we look at how to deal with JavaScript arrays, without using any loops. The end result is less complex code.
7年前
記事のアイキャッチ画像
Indentation is the enemy: Writing less complex JavaScript
James Sinclair
I’ve been working a lot with a legacy code-base lately. And this one is particularly troublesome. It has all the hallmarks of a rush job. The code is brittle. There are no tests. Things often seem to break at random. And to my embarrassment, I wrote most of it. So, I've been thinking about how I ended up here. How did the code get so intertwined and brittle? And how do I prevent it in future?
7年前
記事のアイキャッチ画像
Why Christians should write Fantasy Stories
James Sinclair
Is it OK for a Christian to write fantasy stories? The bible is pretty clear that people should not use magic. Why would it be OK to write about magic? And isn't the whole idea of writing fantasy stories frivolous anyway? Wouldn't our time be better spent serving the poor and telling people about Jesus, or even reading the bible? I would argue that not only is it OK, but if you are a Christian with the inclination to write fantasy stories, it’s helpful if you do.
8年前
記事のアイキャッチ画像
The Marvellously Mysterious JavaScript Maybe Monad
James Sinclair
Monads have a bad reputation in the JavaScript community. Douglas Crockford even said that monads are cursed: Once you reach enlightenment and finally understand monads, you immediately lose the ability to explain them to others. Even amongst experienced functional programmers, monads are treated with respect. But, if you can understand Promises then you can understand monads.
8年前
記事のアイキャッチ画像
Motivation, Self-control and Good News
James Sinclair
How to you make yourself do things that you don’t feel like doing? When it’s a cold winter morning and you have to get up in the dark to go to work, how do you make yourself leave the warm bed? If you’ve just started a diet, how do you resist the doughnuts your work colleague decided to share? How do you make yourself strap on the running shoes and go jogging? Doing things you don’t feel like doing is hard work---it takes willpower. But where do you get the motivation?
8年前
記事のアイキャッチ画像
One weird trick that will change the way you code forever: JavaScript TDD
James Sinclair
‘One weird trick’ is a cheesy title, I know. Originally I was using it as a draft placeholder title for a joke. But the more I thought about it, the more it seemed appropriate because it's true. Test Driven Development is one weird trick that will change the way you code forever. It will make you a more badass developer.
8年前
記事のアイキャッチ画像
How to fight like a man
James Sinclair
A friend of mine asked me for some advice before he got married. This was my response.
8年前
記事のアイキャッチ画像
TDD Should be Fun
James Sinclair
Sometimes TDD can seem like a drag. Are you writing mocks that are several times more complicated than the code you will test? Does your test suite take minutes (or hours) to run? Does refactoring your code fill you with dread because of all the tests to rewrite? If any of this sounds familiar then it may be time to try a new strategy.
8年前
記事のアイキャッチ画像
A Gentle Introduction to Javascript Test Driven Development: Part 3
James Sinclair
This is part three of a three-part series outlining my personal approach to JavaScript TDD. Testing code that creates HTML and manipulates the DOM can be tricky—especially when testing without a browser. In this article I outline one approach to this, and finish off the sample application we have been building through the series.
8年前
記事のアイキャッチ画像
A Gentle Introduction to Javascript Test Driven Development: Part 2
James Sinclair
Working with JavaScript network calls can be tricky when practicing Test Driven Development. This article gives an example of how to use stubs and Promises to make testing network calls easier. This is part two of a three-part series outlining my personal approach to JavaScript TDD.
8年前
記事のアイキャッチ画像
A Gentle Introduction to Javascript Test Driven Development: Part 1
James Sinclair
Getting started with test driven development (TDD) can be daunting. It sounds tedious, boring and hard. There’s also a confusing array of frameworks and libraries out there. Some work on the server; some work in the browser; some do both... it can be hard to know where to start. This is part one of a three-part series outlining my personal approach to JavaScript TDD.
8年前
記事のアイキャッチ画像
Star Wars: The Force Awakens—Philosophy, passion and Jesus
James Sinclair
I really like Star Wars, and I enjoyed The Force Awakens. I think that when you dig below the surface, the ways in which it agrees and disagrees with Christianity are different from what you might expect. In the end, the Star Wars movies are just that: a bunch of movies. But, as I've said before, if we watch in the right way, movies can point us to something deeper and more meaningful—a new and better hope.
8年前
記事のアイキャッチ画像
A Gentle Introduction to Functional JavaScript: Part 4
James Sinclair
In the last article of our four-part introduction to functional programming in JavaScript, we looked at higher-order functions. In this article we discuss how to use these new tools with style.
8年前
記事のアイキャッチ画像
A Gentle Introduction to Functional JavaScript: Part 3
James Sinclair
In the last article, we saw how functional programming can be used with arrays. In this article we examine higher-order functions—functions for making functions.
8年前
記事のアイキャッチ画像
A Gentle Introduction to Functional JavaScript: Part 2
James Sinclair
In the previous article, we saw how functions can be used to make certain code abstractions easier. In this article we apply these techniques to arrays and lists.
8年前
記事のアイキャッチ画像
A Gentle Introduction to Functional JavaScript: Part 1
James Sinclair
What is all the hype about Functional JavaScript? And why is it called functional? It’s not as though anyone sets out to write dysfunctional Javascript. What is it good for? Why would you bother?
8年前
記事のアイキャッチ画像
Righteousness
James Sinclair
Over Easter, our pastor challenged us to live like Jesus is actually risen. Someone I know (quite rightly) asked the question “but what does that look like?” My response is that part of the answer is righteousness, but that might need some explaining.
10年前
記事のアイキャッチ画像
Public perceptions of Christianity—a call to art
James Sinclair
First of all, I write this to myself as much as anybody. Now, with that said…I am concerned about how Christianity is perceived by those who don’t call themselves ‘Christian.’ It’s not that Christians are ridiculed in the media (we’ve always been ridiculed), but rather, what people assume I mean when I call myself a Christian is so very different from what I actually mean that I’m almost hesitant to use the word.
11年前
記事のアイキャッチ画像
Simple Parallel Processing in PHP with pcntl_fork()
James Sinclair
For a recent project I needed to process some code in parallel. A colleague pointed me to the pcntl_fork() function, and it turns out it’s not quite as scary and complicated as I thought. So I turned the simple use case into a generic function.
11年前
記事のアイキャッチ画像
Notes to self on working as a Christian web developer
James Sinclair
These are some notes to myself on how I would like to approach my work, at least, an ideal for who I would like to be as a Christian web developer. I write this mostly to organise my own thoughts, but I am publishing it just in case there are others who might find it helpful.
11年前
記事のアイキャッチ画像
Simple Parallel Processing with PHP and proc_open()
James Sinclair
You can find a reasonably sensible example of how to perform parallel processing with PHP using the `popen()` function at wellho.net. Sometimes though, the requirement to pass all the parameters to your function via command line arguments can be limiting.
11年前
記事のアイキャッチ画像
Why Christians should watch movies
James Sinclair
Why would Christians watch movies at all? They are full of violence and bad language and plenty of other things we try to avoid. They are made by people who have completely different world views than our own, and disagree with most of the beliefs we hold most dear. Why would we fill our heads with all this simply for the sake of *entertainment*?
12年前
記事のアイキャッチ画像
An introduction to Drush: The Drupal power tool
James Sinclair
Drush is a tool that allows you to perform common Drupal tasks from the command line.
13年前
記事のアイキャッチ画像
Communication, Knowledge, Bodies and God
James Sinclair
Why is communication so difficult?Sometimes I will talk to somebody, and think that I’m expressingmyself really clearly when I’m not. I seem to make perfect sense. Yetwhen I hear what the other person says in response, it is obvious thatthey heard something quite different from what I thought I said.
17年前