Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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)






This 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.

I 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


OpenAPI can do this too

huh? does Java even support marshall/unmarshall json in the 'bare' language?

Does the origin of "DTO" come from Java? I've never seen it used anywhere else.

DTO comes from OOP for which Java is the poster child.

But you can find it many places.

https://codewithstyle.info/typescript-dto/


Why is Java the poster child of OO when c++ was literally c with classes

The poster child for statically typed OO is actually Simula 67. And Java is basically Simula with C-style syntax and packages.

1. 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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: