Web Development
-
Functional JavaScript: Five ways to calculate an average with array reduce
Written by James SinclairThe 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?
-
Functional JavaScript: How to use array reduce for more than just numbers
Written by James SinclairThe 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. -
Elegant error handling with the JavaScript Either Monad
Written by James SinclairJavaScript 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.
-
How to run async JavaScript functions in sequence or parallel
Written by James SinclairThe 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.
-
How do you compose JavaScript functions with multiple parameters?
Written by James SinclairAs 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.
-
Object destructuring and currying in functional JavaScript
Written by James SinclairCurrying 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?
-
How to deal with dirty side effects in your pure functional JavaScript
Written by James SinclairIf 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 giveyou 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?
-
How to use React (and Redux) with your crufty old CMS
Written by James SinclairGetting 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?
-
React, Redux and JavaScript Architecture
Written by James SinclairWhether 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.
-
Faster, Better, Cheaper—The art of making software
Written by James SinclairNobody 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?