[main page]

Benefits of dynamic typing, part 1

25 October, 2026 / color theme: ef-spring

Introduction

I like statically typed languages and reasoning in types, but I think that sometimes features of dynamically typed languages helps to produce better programs.

Dynamic typing is fun, but the tricks from dynamically typed programs don’t get enough attention.

When I discuss static and dynamic typing with people, usually we are too focused on the benefits of statically typed programs, and not don't talk about the costs. That's why I created a list of the benefits of dynamic typing. It compares Clojure and Python with TypeScript and Go, since those are the languages I know.

I also like validation schemas that allow us to define types at runtime and use them for validation, test generation and linters. Think Clojure’s spec and malli, Zod from JavaScript, and JSON Schema.

Also, I believe that if the code is LLM-generated, the right architecture, the language, and the tools matter a lot, especially for big projects in the long run (which most of us do for a living).

This series were influenced by the “Maybe Not” talk and the more recent “In Context”, both by Rich Hickey, among other sources.

Duck typing

Duck typing is defined as follows: if something looks like a duck and moves like a duck, we should be able to pass it to the function quack(ducky). It is used heavily in Clojure and Python.

TypeScript has structural typing, which is a similar concept, and Go has interfaces that work like duck typing but only for methods, not for structure fields, which is pretty limiting. Let’s talk about TypeScript.

Culturally, people got used to specifying concrete types there and passing them as function arguments. Duck typing, on the other hand, implicitly specifies different minimal interfaces for every function. In TypeScript, I haven't seen code where every function argument was specified with a minimal interface, and I’m sure having 20 new interfaces for 20 new functions would be rejected in a code review.

In my opinion, embracing duck typing results in a more flexible programs that are open for change.

Let’s say we make an e-commerce shop. In code we have a Product type with fields like cost, ID, weight, a URL of the image and others.

Also, we have a function totalCost(products), which returns the total cost of the products from the products array.

In one service

It is considered a good practice to define different types for what a database returns, what we send in response, and what lives in a domain layer.

What if we need to calculate totalCost for all three types? Duck typing lets us define such a function once and don’t duplicate the code.

TypeScript allows us to create an interface, but again, I can't imagine having 20 such functions with interfaces for each.

Also, what if the property we need is three levels deep inside the argument's type? It’s not fun to specify such interfaces.

It is also easier to work with other services

Imagine other team manages a recommendation service, which returns the recommended products for the client. What if their definition of the Product type is different?

In statically typed languages, it’s common to parse such types into the domain.

In a language with duck typing, we don’t need that, we can use totalCost directly on their products. The integration with another service happens faster and it requires less cross-team scheduling. This leads to better systems.

No accidental coupling

Imagine a function requires cost and id fields, but the Product type has lots of other fields. It couples the fields like weight and imageURL with the function, and that’s accidental coupling.

In TypeScript this is solved by creating an interface with cost and id fields, but it's hard to name properly if cost and id without weight and imageURL don’t have any domain meaning.

Having the function require only cost and id makes it more reusable for cases when we only have cost and id (e.g. after a partial select from the database, an entity from a 3rd-party service, and so on).

No need to create partial types or types with additions

If you saw types like DataWithInfo, CarWithoutYear, they are not necessary in dynamically typed languages.

Next