2 ms·
One thing Haxe does well here is provide structural typing, effectively letting you declare the result of a deserialization process in type form. This isn't pe
by jdonaldson 12y ago
One thing Haxe does well here is provide structural typing, effectively letting you declare the result of a deserialization process in type form.
This isn't perfect... you still need to know in advance what kinds of object structures are possible, but generally this isn't too much to ask (e.g. relying on a server api to provide consistent records).
The next catch is that you can't treat these structural type results like typical classes. E.g., you can't have methods, getter/setter logic, etc. However, you can attach relevant methods with a special mixin directive (that does not alter the runtime object).
In this way, I have a pretty good way of providing a robust description of server responses in terms of type information, and a good way of loosely binding these responses to relevant methods.
- jdonaldson 12y agoquick sketch: http://try.haxe.org/#db206 http://try.haxe.org/#db206 I can't show the "using" method directly here since the two classes need to be in separate files... but I'm giving an example of what it would look like.