js promises are the new threads

Years ago I read that ORM was the Vietnam of Computer Science… That was certainly not the first time I’d read a pithy comparison, but it stuck with me.

I had lunch with a friend last weekend, and reminded him of a lunch many years earlier. This was probably… 2008. I’d picked him up for lunch, and our lunch was cut short with “I gotta get back – we’re having some major thread issues on a section of the code, and we’re behind on getting this shipped”.

This was Java, and it was 2008. There were behaviour bugs that no one could track down outside of “this is a threading issue”.

It came to mind because I was recently (the day before) dealing with some inherited JS that was heavy on deferred/promise/async/callback stuff. Guess what? Something wasn’t working. In the course of adding a new feature, I stumbled on something that looked like it’s been non-functioning for months, if not years. Low priority UI thing, but… frustrating.

I spent time trying to track it down – no luck. I reached out to one of the guys who wrote some of this, and has used the codebase (and built on top of it) for years. At first he thought it was a misunderstanding on my part – I’m new on this project, and that’s been the pattern. “Oh, Mike just doesn’t get this”. 10 minutes later I got something like “this is baffling – it’s just not working”. He spent another half hour or so trawling through everything he could think of. No joy.

I write this not with some great words of wisdom, or some silver bullet to cure everything. You use JS frameworks, you’re probably going to be using some degree of callbacks. But… in my old age, I may be more of a luddite than earlier. I avoid callbacks when possible (and again, I know it’s not always possible). But as I get older, I’m trying to optimize for clarity and understandability, and I don’t think promise/callback style development aids that, not on its own, anyway. You have solids tests, sample data and documentation around the code? Go for it! Absent those (which most people don’t do) it’s a harder sell for me.

And… 10 years ago doing Java, I shied away from reliance on threads wherever possible. Bottom line, to me, it’s just difficult to reason about. And, from what I’ve seen, it’s actually difficult for other people too (multiple anecdata from 20+ years of various development work). I’m just not sure people recognize that something is actually adding some potentially unneeded complexity and that is difficult to reason about and test, vs something just being difficult because it’s, perhaps, somewhat new to them.

Again – these tools all have their place, but I tend to view these as necessary evils vs “go to” first practices when architecting something.

Leave a Reply

Your email address will not be published. Required fields are marked *