6 ms·
I think many people are satisfied with the alternatives presented in that thread. A very large percentage will probably even be happy with the serialization to
by DCKing 12y ago
I think many people are satisfied with the alternatives presented in that thread. A very large percentage will probably even be happy with the serialization to Lists and Maps - because that is what JavaScript already does! I understand that you have your preferences, and you are entitled to have those. In my opinion, you are not entitled to:
- Present your complaints as though Dart is missing basic functionality (not in the presence of the presented alternatives). It just misses your specific desired functionality!
- Assume your use case is representative for a significant amount of other developers.
- Extend your entitlement to the HN front page.
C# JSON support appears to be awesome, and you are very free to make a Dart library that does exactly that. You are also free to request it to be merged into the core Dart libraries [1]. You are not free, in my opinion, to drag out this complaint so much.
As a reference, here's a list of other typed languages that don't support JSON deserialization-to-classes in their core libraries:
- Java (Scala, Groovy, Xtend, etc...)
- GWT Java
- Kotlin (both on JVM and in browser)
- Ceylon
- C++
- OCaml
- Swift
- ...
Seeing those languages are often used to consume web services, it seems Dart is in good company. There's probably a good reason why this stuff is relegated to third party libraries. I'd speculate that 1) accomplishing this is messy and complex in the context of type safety and 2) the problem you are complaining about simply isn't as big as you think it is.
[1]: https://code.google.com/p/dart/wiki/Contributing https://code.google.com/p/dart/wiki/Contributing
- d2p 12y ago> Present your complaints as though Dart is missing basic functionality In many peoples opinions, it is. Your opinion is no more fact than mine. > Assume your use case is representative for a significant amount of other developers I can assume what I want. I believe it's true. It might not be; but it seems like a pretty basic requirement; and there are many other people in that thread that share the opinion. > Extend your entitlement to the HN front page. I didn't put it there, the people did. > you are very free to make a Dart library that does exactly that That's the whole point - there is no sensible way to implement this from the outside; that's the whole point of my thread. All of the ways of achieving this suck for one reason or another. Doing this well needs better support from the language/Dart tools. > the problem you are complaining about simply isn't as big as you think it is I've still yet to see anyone anywhere post a small code sample showing a Dart class and some simply JSON that works, without a hand-coded mapping from a Map. Is this really what we should be spending our time doing using Google's "new language for the web"?
- DCKing 12y ago> Your opinion is no more fact than mine. You've got that right. My problem is that you framed your thread title and general discussion so that it implies that Dart is lacking in JSON support. It's not; Dart's JSON support is better than or on par with almost all other languages out there (including JavaScript). The problem for you is that it lacks a certain style of JSON support, which I think you'll find a hard time arguing why it's basic functionality. > I didn't put it there, the people did. Come on. You submitted it, and did not want it on the front page? > That's the whole point - there is no sensible way to implement this from the outside; that's the whole point of my thread. All of the ways of achieving this suck for one reason or another. Doing this well needs better support from the language/Dart tools. Yes there is. Dart's reflection APIs are more than adequate for you to implememt such a thing. Reflection is the way to go in these statically typed languages; it's how Java libraries do it, and it's how C# does it. It's the only way to dynamically construct classes. > I've still yet to see anyone anywhere post a small code sample showing a Dart class and some simply JSON that works, without a hand-coded mapping from a Map. Is this really what we should be spending our time doing using Google's "new language for the web"? If you choose to spend your time on that, that's your choice. Why do you find it necessary? Do you really want to use a web service as an ORM? Web applications come with no obligation to have a direct JSON <-> typesafe class mapping. Such mappings are ill-defined and bug prone if done automatically or with runtime reflection, and open to different styles of implementation. I don't think it's the job of the core library to solve that problem for you, not if it already allows you to work with JSON in other ways. Many people are fine to just use the Maps without the unjustified pretense of type safety, and other people are fine with manual mapping and validation. Considering the problems of reflective mapping and the availability of plenty of other solutions, I think you are being overzealous in your complaining.
- d2p 12y ago> Come on. You submitted it, and did not want it on the front page? I never said I didn't want it there; I said I didn't put it there. You can't tell me I have no right to put something on the homepage when it ended up there because of HN's algorithm (which suggests that others did want it there). > Yes there is. Dart's reflection APIs are more than adequate for you to implememt such a thing I was told by someone on the Dart Team: "using mirrors just isn't practical for real applications". If that's not actually true, great! However I suspect if it wasn't, then there would be a Dart-Team owned mirror-based implementation? > Do you really want to use a web service as an ORM? My data store is on a server; not in your browser. I need to get data (or some form) from the client back to the server, and vice versa. This is nothing to do with using a web service as an ORM, this is how web apps work - code runs in your browser, and needs to communicate with a server where I can retrieve or persist things. How do you think Gmail marks an email as Read when you open it? Fetches your email? etc. > Web applications come with no obligation to have a direct JSON <-> typesafe class mapping. Such mappings are ill-defined and bug prone if done automatically or with runtime reflection This is nonsense. Pulling data from a server into a Map is bug-prone, because if you use it as a map, all of your code can be wrong. If it's converted to a type, then only the mapping can be wrong, and the rest of the code can have static analysis. This is one of the selling points of Dart, and it's totally stupid to throw it away. People are "ok" without the type safety because they have no other option. This is supposed to be one of the advantages of Dart over JS!
- adrianlmm 12y agoThe moto of Dart is to make the life easier for developers. I think that moto doesn't fit Dart at all, I use Dart and I have to make some workarounds that I just shouldn't be doing, but I have to because the language doesn't have the functionality that other languajes already have. The problem I see is that the Dart language developers never put them self in the shoes of the developer using their languaje. In this case, I would be easy for them to add JSON serialization to objects, you know, but they didn't, why? polictics, apathy, whatever, but not technical problems. So, my self, had to adapt to programming in Dart, so I every class must have a toJSON and fromJSON methods where I manually put the values to a map and then I use convert.JSON. But, I now I gave up using classes and now I just use Maps, just to write less code and is already the type Dart suppor for JSON serialization.
- dragonwriter 12y ago> The moto of Dart is to make the life easier for developers. The word your looking for is "motto". > I think that moto doesn't fit Dart at all, I use Dart and I have to make some workarounds that I just shouldn't be doing, but I have to because the language doesn't have the functionality that other languajes already have. Newer languages that are comparatively young are usually going to have a less complete ecosystem and its a tradeoff between this and the unique features/approach they offer initially as the ecosystem matures. > In this case, I would be easy for them to add JSON serialization to objects, you know, but they didn't, why? Perhaps because they would have had to not do something else to get Dart released on the same timeline to do it. Lots of things are easy considered in isolation, but there are always opportunity costs, especially if you try to do every easy thing before you release anything.
- adrianlmm 12y agoAre you part of the Dart team?
- dragonwriter 12y agoNo.