18 ms·
> It baffles me that people expect it to arbitrarily map JSON to those classes when the associated complexity is well-known That's because you're adding comple
by d2p 12y ago
> It baffles me that people expect it to arbitrarily map JSON to those classes when the associated complexity is well-known
That's because you're adding complexity that nobody is asking for. Deserialising JSON onto a simple PODO with no inheritance, no mis-matching of properrty names, etc., is a pretty trivial requirement. The impelementation complexity is being used as an excuse not to meet a really basic need of a web app.
Please tell me - how am I supposed to get data from a server, into a data structure that will give me code-completion and type checking? Other languages with types do this fine; why should I hand-code a load of mapping of basic values in Dart?
- dragonwriter 12y ago> Please tell me - how am I supposed to get data from a server, into a data structure that will give me code-completion and type checking? Write a fromMap constructor. > Other languages with types do this fine; why should I hand-code a load of mapping of basic values in Dart? For one thing, to reduce the degree of coupling between your client code and the interchange format. With a fromMap constructor, anything interchange format that can deserialize into a generic map-of-strings-and-lists-of-strings format can be used (and different external JS structures can be supported, as well, with a simple Map-to-Map converter.) Automagic mapping that relies on matching field names between objects and interchange formats results in tight coupling between client and interchange format.
- deleted 12y ago[deleted]
- DCKing 12y ago> Deserialising JSON onto a simple PODO with no inheritance, no mis-matching of properrty names, etc., is a pretty trivial requirement. This is not serializing into a PODO. This is serializing into a simple struct. Dart does not have simple structs, so you get no deserialization of simple structs. Imagine that you write a core library function that does what you want. It cannot map arbitrary classes, but only a subset of classes that adheres to a "simple structure". The developers would then have to tell you which classes you can use it on, and which classes you can't. It would give you runtime errors when you happen to include inheritance somewhere in your project. It's an unmaintainable situation, and most safety of static checking would be gone. Not just in your project, but every project using that feature. Think of the developers' perspective. Why would they want to include such a fragile feature in the first place? You could argue that Dart needs a "struct"-like construct just to support deserialization. Still the problems remain that that still has all the fragility problems of reflection. Good luck with convincing the developers about adding a language feature for that. They have already shown to not be receptive to that idea [1][2]. You are free to hack your way around typesafety, but you cannot make this a problem of the developers. A type safe language simply brings you inconvenience when you're trying to shoehorn dynamic data in static structure definitions. This is not the Dart developers' problem: increased type safety is their goal. > Please tell me - how am I supposed to get data from a server into a data structure that will give me code-completion and type checking? You either write your own code to do this or don't do this at all and just use the data in another shape. You can keep repeating this point all day long; you won't demonstrate why it is anything more than "nice to have", let alone that it's a "necessity". > Other languages with types do this fine. AFAIK only .NET-based languages and Go do this out of the box. Both can include this out-of-the-box because they are server oriented languages and can include all the complexity they want. Those languages don't care for the binary size of their applications as much as Dart applications. [1]: https://groups.google.com/a/dartlang.org/forum/#!topic/misc/obmjDJJZq8A https://groups.google.com/a/dartlang.org/forum/#!topic/misc/... [2]: https://code.google.com/p/dart/issues/detail?id=10374 https://code.google.com/p/dart/issues/detail?id=10374