4 ms·
This is more complicated than it seems. First, how does it work with minimization? In Dart, string constants are not minimizable (will be included as-is in the
by skybrian 13y ago
This is more complicated than it seems.
First, how does it work with minimization? In Dart, string constants are not minimizable (will be included as-is in the source code). Symbol constants will be minimized. This includes all method names, field names, and things like named parameters. You can see this in the arguments to noSuchMethod; the named parameters map has Symbol keys, not strings.
Probably something could be worked out, though. Maybe put an annotation on the customer class to tell the compiler to save the original field names?
But a second issue is how it works with inheritance, including mixins. If a class is serializable, does that make all the superclasses and subclasses serializable as well? JSON doesn't have a standard way to represent a type tag, so does that mean we should invent one? If we do that, what happens to JSON interop with other languages?
Also keep in mind that Dart supports types that don't interop with JavaScript like unlimited precision integers. (Well, okay, that only works with the Dart VM, not dart2js...)
It gets worse. What if your class has a field type like List<dynamic>, which could contain any object? Does that mean the Dart compiler now has to preserve all symbols because any class could be serialized? And keep in mind that with optional types, all lists should behave the same when not in checked mode.
Having seen the mess that resulted in GWT-RPC, I would recommend just saying no to default serialization. Serialization and object inheritance don't really mix well which is why specs like JSON and protobufs don't support it.
(And now you know why language designers don't throw things into a language just because it seems like a good idea at the time.)
- shadowmint 13y agodoes anything actually work with dart2js? All I seem to hear is people complaining about it. Given so little effort is given to it, I halfway think they should just give up on javascript and javascript interop completely and focus on making dart awesome. Anyhow, what you say is totally true, but surely iterating recursively over an object and dumping values into a json block would be trivial. The hard part is deserializing that back into objects, but maybe you dont need to? The python json package does a pretty good job. You could just have it return a dynamic or something.
- floitsch 13y agoDisclaimer: I'm the TLM of dart2js. The dart2js team is one of the teams with the most developers on it. There is a huge effort going into it. Dart2js generally does a good job, but a few features (like mirrors) that are still in beta-quality, are currently a constant source of grieve for the developers. We would have liked to delay their release until they were more stable, but several customers really, really needed them. Things are getting better, though, and I hope that dart2js will fade into the background (as a simple working tool) soon.
- azakai 13y agoIs there a plan for fixing the behavior of integers so they are the same on the VM and dart2js?
- skybrian 13y agoIf there is one it's not public. Here's the bug to track: https://code.google.com/p/dart/issues/detail?id=1533 https://code.google.com/p/dart/issues/detail?id=1533
- shadowmint 13y agoI understand you guys are working on it, and it's a tough problem, but for a flagship javascript drop in replacement isn't releasing something that griefs developers really bad? Surely releasing a top quality library that works well is far more important than getting in early and releasing something that alienates developers and makes them try dart and them give up on it? It's obviously your prerogative to do what you feel is best, but it's certainly not the choice I would have endorsed. (I supposed the horse has bolted to a certain degree now, it's good to know that a lot of effort is being directed at dart2js I suppose, although from a developers persepective I don't really feel that it's particularly visible...)
- magicalist 13y ago> releasing something that griefs developers Maybe you only see (and/or notice) people talking about corner cases that still need addressing (like azakai's sibling comment about the mapping of arbitrary precision integers to JS's number type)? For the vast majority of code, AFAIK, dart2js has no issues and emits good JS code. I don't develop with dart, but I know a handful of developers that use dart2js to release their dart code on the web and it works just fine for them. mraleph just released IRHydra2[1], which is all Dart from top to bottom via dart2js and works really well (despite using the apparently still-nascent Dart port of Polymer). If you have specifics, by all means, talk about them, but "All I seem to hear is people complaining about it" seems like really shaky ground from which to make comments about griefing and alienating developers. [1] http://mrale.ph/blog/2014/01/28/prerelease-irhydra2.html http://mrale.ph/blog/2014/01/28/prerelease-irhydra2.html
- pfraze 13y agoCan you talk more about your experience with GWT-RPC?
- skybrian 13y agoGWT-RPC was designed before I got there, but the basic idea was to make it work just like Java serialization. To do this, you need to calculate at compile time which types the client might possibly have to deserialize and include client-side code to instantiate those types. But we don't want to do this for every Serializable type because of code bloat; when a type is declared Serializable in Java it's often intended for server-side serialization, not because anyone intended that type to be usable in a browser. This is pretty hard to do in a language that supports both inheritance and generic types. Suppose you have a field of type List<Foo>. What values could the server possibly send the client? - All subtypes of List: ArrayList, LinkedList. Also, ImmutableList and a bunch of other subtypes if Guava is in the classpath. - All the fields in Foo, its serializable supertypes, and all its subtypes. And then do the same calculation again for those types, recursively. Or if Foo is a widely used marker interface, anything implementing that marker interface in any library could possibly be sent. At this point, probably nobody working on the app has a good idea on why a particular type is included in the app. Of course you could tell people to tighten up their type declarations. For example, never use List in a DTO; instead use ArrayList. This doesn't work because it just takes one field declaration in one library to screw it up, so it's hardly worth doing. And I haven't even gotten into the complexities of things like: class Foo<T extends Something> extends Bar<T>. I heard a rumor once that someone proved that doing the calculation "properly" was NP-complete. In practice, we use approximations and there are bugs, though mostly people don't run into them too often. I think it makes more sense to generate serialization code from an IDL such as a protobuf declaration. Since there's no inheritance and no generics, it's clearer to everyone which fields can possibly be transmitted on the wire and what the semantics are for forwards and backwards compatibility. Or just write out the JSON serialization for each class; it's not that hard, just repetitive.
- pfraze 13y agoJust remembered this thread and came back. Thanks for the insight.
- zubspace 13y agoWouldn't it be possible to add some kind of @json class annotation then, which cannot be combined with "extends" and dynamic types? I understand that serialization of inheritance trees and arbitrary data is a complicated problem. So why not allow a simple case first and continue from there? I guess inbuilt json serialization of simple types would already cover alot of real world rest scenarios which most users care about.