JS Recursion in Production - Code with Hugo - May 20th 2019
Recursion in JavaScript has a special place in my career as a developer and as a content creator.
Recursion is a very powerful tool that can solve seemingly difficult problems in a wieldy and “clean” manner. The principles and tools that allow you to use recursion effectively are seldom taught (especially if you didn’t the specifics of the functional programming paradigm).
As a writer, content about recursion has been behind my biggest successes. My first post on HackerNoon (before it became a crypto-spamfest) is Recursion in JavaScript with ES6, destructuring and rest/spread. More recently I’ve also had some success with Impress interviewers with recursion in JavaScript with ES6 features, published on freeCodeCamp.
Both of these posts were received with praise but also criticism, eg. “in JS you’re likely to make the stack overflow”, “if someone used recursion in an interview I would see it as a negative”. I personally am quite critical of my own content on recursion, I find they’re good illustrations and reasonable introductory posts (it sparks “oh this is cool, let me read more”) but they don’t show how and where you would use recursion on a job.
Hot off the press
Avoiding recursion pitfalls: MongoDB nested query clause addition and removal: A case-study on where recursion can be useful for enterprise Node.js applications and how to avoid its common pitfalls like RangeError: Maximum call stack size exceeded. We’ll be implementing a solution to 2 real-world problems: Add an $or query clause to a MongoDB query and Remove references to a field in an MongoDB query (potentially) using $or and $and.
The full repository for this post is on GitHub: github.com/HugoDF/mongo-query-clause-modification
If you missed it
Read and parse POST/PATCH/PUT request JSON or form body with Express and no dependencies: body-parser is a dependency of Express and its main JSON parsing and url encoded body parsing functionality is exposed as express.json() and express.urlencoded() ie. middleware for parsing the most common request bodies is built into Express.
Docker Compose Local HTTPS with nginx or Caddy and mkcert: A solution to serve your Dockerized application on Docker Compose with TLS/SSL locally by leveraging a HTTPS reverse-proxy and mkcert.
An enterprise-style Node.js REST API setup with Docker Compose, Express and Postgres: The why and how of enterprise-style Node.js application.
Jest assert over single or specific argument/parameters with .toHaveBeenCalledWith and expect.anything(): With Jest it’s possible to assert of single or specific arguments/parameters of a mock function call with .toHaveBeenCalled/.toBeCalled and expect.anything().
From the web
The Architecture of Open Source Applications (Volume 2): SQLAlchemy by Michael Bayer: SQLAlchemy is a database toolkit and object-relational mapping (ORM) system for the Python programming language, first introduced in 2005. I highly recommend this post, it explains why Python can have auto-generated database migrations (based on changes to models files) where other languages (Ruby, JS, PHP) have manually defined ones. It also illustrates what good design of an ORM looks like, since SQLAlchemy is split into a database abstraction layer (Core) and the ORM itself.
Service-Oriented Architecture: Scaling the Uber Engineering Codebase As We Grow by Einas Haddad: Like many startups, Uber began its journey with a monolithic architecture, built for a single offering in a single city. At the time, all of Uber was our UberBLACK option and our “world” was San Francisco.
TDD Harms Architecture by Robert C. Martin: The idea that TDD damages design and architecture is not new. DHH suggested as much several years ago with his notion of Test Induced Design Damage; in which he compares the design he prefers to a design created by Jim Weirich that is “testable”.
Shipping is your company’s heartbeat | Inside Intercom by Darragh Curran: Software only becomes valuable when you ship it to customers. Before then it’s just a costly accumulation of hard work and assumptions. Shipping unlocks a feedback loop that confirms or challenges those assumptions.