4 ms·
Oof is this for people who reuse their DTO for business logic and/or share DTOs across different APIs. It never occurred to me to ever (in any language) have a
by bravesoul2 1y ago
Oof is this for people who reuse their DTO for business logic and/or share DTOs across different APIs.
It never occurred to me to ever (in any language) have a DTO with fields I wish (let alone require for security) not to unmarshall.
This seems doubly strange in Go the language of "Yes absolutely DO repeat yourself!"
Side rant:
JS (even with Typescript) pisses me off as this is unavoidable. Splats make it worse. But still a distinct DTO and business object and don't use splats would help. (Maybe make ... a lint error)
- IceDane 1y agoThis is not unavoidable in typescript at all. It really depends a lot on how you have structured your application, but it's basically standard practice at this point to use e.g. zod or similar to parse data at the boundaries. You may have to be careful here (remember to use zod's .strict, for example), but it's absolute not unavoidable.
- bravesoul2 1y agoI should have been clear. Yes it is avoidable but only by adding more checking machinery. The bare language doesnt help. In Go etc. If a struct doesn't a field foo then there will not be a field foo at runtime. In JS there might be. Unless you bring in libraries to help prevent it. You are relying on someone remembering to use zod on every fetch
- paulddraper 1y agoOpenAPI can do this too
- Toritori12 1y agohuh? does Java even support marshall/unmarshall json in the 'bare' language?
- commandersaki 1y agoDoes the origin of "DTO" come from Java? I've never seen it used anywhere else.
- paulddraper 1y agoDTO comes from OOP for which Java is the poster child. But you can find it many places. https://codewithstyle.info/typescript-dto/ https://codewithstyle.info/typescript-dto/
- zaphirplane 1y agoWhy is Java the poster child of OO when c++ was literally c with classes
- paulddraper 1y ago1. Java was made OO from ground up. No pointer arithmetic, all code is encapsulated in classes, etc. 2. C++ has some unusual OO features -- friends, multiple-inheritance. 3. Most importantly, Java is significantly more approachable than C++ due to automatic memory management.
- int_19h 1y agoThe poster child for statically typed OO is actually Simula 67. And Java is basically Simula with C-style syntax and packages.