function foo (): {data: MyCustomObject, message: string}
so foo().data and foo().message is a valid object, while foo().bar will throw build error
I always try to have “clojure style” types where I don’t try to be too prescriptive - don’t lock things down if you don’t need to, just the minimum possible types to make sure the code I’m writing is correct, and nothing more - Rich Hicky’s talks on Clojure’s Spec was an eye opener.
I have been told by some java devs though that it is a matter of style - while unconditional it is possible to write java code with much less boilerplate if one uses newer language features and actually tries to hold the cruft at bay. Is that true?
TS though, the type declaration is amazing with it's union, optional and intersection type!
Dude, Elixir only recently introduced some sort of a type system...
> No, you cannot just do something like this: > ``` return { data, message: "OK" }; ```
Yes, in Java you can:
return new Object() {
String message = "OK";
Object data = itsValue;
};
There are many reasons to dislike Java and it is nowhere near my programming language of choice. The specific semantic deficiency you chose happens to be an invalid one.The same way one would when returning an anonymous map in JavaScript - via reflection and the assumption of what was returned.
While JavaScript makes the use of reflection less burdensome, it has the same collaboration fragility as a Java version. Just with less ceremony.
To each their own I guess, I've never felt burdened by types but I feel like I'm programming in the dark when using a non typed language.
No, you cannot just do something like this:
``` return { data, message: "OK" }; ```
you need to declare a class or struct that match the definition. There's mapper and builder everywhere. Adding / deleting 1 column from a datatype can force you to make changes in 5 places due to mapper / builder.