6 ms·
I’m not sure I understand the “infrastracture” label, but certainly for the cases the author listed as “infra” typing can be cumbersome. Famously just json dese
by stu2b50 4y ago
I’m not sure I understand the “infrastracture” label, but certainly for the cases the author listed as “infra” typing can be cumbersome. Famously just json deserialization can be rather painful in statically typed languages, especially ones without complex compile time features.
- eropple 4y agoSerialization/deserialization can be really gross in something like Java, but TypeScript gives you some really good tools (zod, typebox, etc.) to validate and type-guard your inputs that I'm sure could be implemented in Python--if they're not already.
- pbalau 4y agoPydantic will do that for Python.
- eropple 4y agoYeah, I assumed as much. I've only looked at Pydantic in the context of FastAPI, as Python's not really my thing, but it looks really well-thought-out.
- amarant 4y agoIf serialisation is painful in Java, you're doing it wrong. Libraries like Jackson make it entirely painless. I would assume JSON parsing is a solved problem in any typed language.
- eropple 4y agoI've written a lot of code using Jackson and I strongly disagree that it's a solved problem. If you're Java on both ends, it's probably fine, but then your serde style is an implementation detail. And that's great, but if you're not, you are in a bear pit. The lingua franca for JSON specification is JSON Schema, and there is significant impedance mismatch between the standard JSON tools folks use in Java and with JSON Schema as used by most other folks. (Jackson has a nice JSON Schema module for exporting it, but importing/codegen is pretty gross.)
- sixbrx 4y agoI find Java pretty nice for handling JSON serialization/deserialization these days. Just define some records for the expected structure, and Jackson's object mapper handles the rest.
- eropple 4y agoIt's the "defining some records" part that's slow and gritty. JSON is usually an interchange format, and Java class construction is either slow, tedious, and manual, or involves massaging a code generator (which, at least the last time I checked a few months ago, weren't very good in Java).
- vips7L 4y agoI don’t see how declaring a data model class is anymore difficult in Java than another typed language. record Thing(String name, int size, LocalDate when) {} The only way I could see this being easier is to forgo type safety completely.
- eropple 4y agoYou're assuming you only have to define it in one language. JSON is an interchange format. The canonical way to express it is JSON Schema, and the tools are unpleasant in Java. So is dealing with structural typing of polymorphic responses. In an ideal world we wouldn't have those, but we live in this one. These things are just better when you aren't in a nominatively typed language with some pretty crusty assumptions.
- marcosdumay 4y agoHum... Almost all of the problems of serialization/deserialization in statically typed languages turn into testing problems in dynamically typed languages. That's not a gain in any way.
- stu2b50 4y agoIn this case it’s more about shifting where the static typing occurs, since the author is still arguing for a typed business layer. Since I/O is usually untyped, you need to cram it into a typed schema somewhere. In strictly typed languages, that must occur upon ingestion. The author is saying you can delay it by having a layer on top of the I/O transform the data in untyped fashion before being typed later on.
- Yoric 4y agoWhat's the benefit of delaying typing? By typing it at ingestion, you guarantee that invalid (with respect to structure) untrusted data will not break your code down the line. Doing otherwise means that you're manipulating untrusted data with a strong risk of forgetting that it is untrusted. I have seen large applications (think hundreds of millions of daily users) break because of such oopses.
- Yoric 4y ago> Famously just json deserialization can be rather painful in statically typed languages, especially ones without complex compile time features. That's funny, because last time I had to write json-related code in Python, I really missed Rust's serde, which makes deserialization + validation much easier to write in Rust than in Python. YMMV, of course.