Hacker News new | ask | show | jobs
by mapcars 663 days ago
> Look at projects like FastAPI (which uses pydantic) for an an example where having types at runtime has been handy.

What is it, they have nice error messages? I don't expect them to fix code at runtime when type error happens.

> Also, if types are enforced at runtime logging is better, debugging is better

These can't even happen with type checking in the first place.

> you have more options for data validation

In my experience serializing/deserializing data is pretty much the only place where its useful, and it doesn't have to be built-in on a language level, Pydantic is doing it well enough.

> doing dynamic or metaprogramming likely more easily

This is where you lose me, I have never seen it being useful in reasonable large projects in popular languages. Dynamic or metaprogramming only works in a very specific category of languages (lisp-likes), doing it in any other language will become a problem sooner or later.

> more options when and how to enforce types

Again its only on serialization level, apart from that type checking will cover everything before runtime, it's weird to me how you can think that encountering problem later has any advantage of doing it earlier.

1 comments

> What is it, they have nice error messages? I don't expect them to fix code at runtime when type error happens.

FastAPI validate both data (serialization) and schemas (used to create APIs and specs). Pydantic can also help with safe casting, not sure if FastApi uses that or not, but it is available

> These can't even happen with type checking in the first place.

I mean when you're debugging any problem or learning an API. It is nice to have rich types built in, especially while in a REPL, where you can inspect types.

> In my experience serializing/deserializing data is pretty much the only place where its useful, and it doesn't have to be built-in on a language level, Pydantic is doing it well enough.

Pydantic relies on Python having types built into the language and available at runtime.