Created
September 3, 2012 16:09
-
-
Save gotwalt/3610355 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8:24:20 AM Aaron Gotwalt: we're having the collection-json vs other api forms argument tomorrow | |
8:24:36 AM Aaron Gotwalt: or hypermedia types, i suppose | |
8:25:00 AM Aaron Gotwalt: he's concerned about verbosity and that it presents the data in a format that is not ideal for either the client or the server | |
8:25:33 AM Larry Marburger: that's a feature | |
8:26:09 AM Larry Marburger: it's designed to be future proof which hand-rolled json won't be | |
8:26:19 AM Larry Marburger: it's an interchange format | |
8:26:31 AM Larry Marburger: i may have just made that up | |
8:26:34 AM Aaron Gotwalt: right, but it has processing cost on either side | |
8:26:39 AM Aaron Gotwalt: which is less of a concern in ruby-land | |
8:26:43 AM Aaron Gotwalt: but on ios | |
8:26:46 AM Aaron Gotwalt: with old devices | |
8:26:56 AM Larry Marburger: you're not really telling me it's expensive to parse cj, are you? | |
8:27:03 AM Larry Marburger: there's no way i'd buy that without benchmarks | |
8:27:06 AM Aaron Gotwalt: not a single data node | |
8:27:14 AM Aaron Gotwalt: yeah, fair | |
8:27:29 AM Aaron Gotwalt: i think my biggest cj love actually comes from inline collections | |
8:27:34 AM Aaron Gotwalt: i implemented it last week | |
8:27:41 AM Aaron Gotwalt: makes so much sense | |
8:27:45 AM Larry Marburger: sweet | |
8:27:57 AM Aaron Gotwalt: allows you to preserve normalization across your endpoints | |
8:28:14 AM Aaron Gotwalt: but without an insane http request cost | |
8:31:07 AM Larry Marburger: that | |
8:31:28 AM Aaron Gotwalt: really, my gripes just come down to the the data representation | |
8:31:46 AM Aaron Gotwalt: the first thing i do on either side is inject to get back to a hash | |
8:31:46 AM Larry Marburger: that's why i like it because it's easier that everything uses the same message format | |
8:32:01 AM Larry Marburger: you have that with anything, though | |
8:32:08 AM Larry Marburger: it's just abstracted | |
8:32:12 AM Aaron Gotwalt: well, why not just ship a hash across the wire then? | |
8:32:22 AM Aaron Gotwalt: metadata on elements? | |
8:32:35 AM Larry Marburger: then you're talking about remote objects which is completely different | |
8:32:59 AM Aaron Gotwalt: you just jumped across a philosophical line that isn't actually real | |
8:33:00 AM Larry Marburger: or more like rpc | |
8:33:21 AM Aaron Gotwalt: assume that the data coming across the wire is not a 1:1 representation of whatever's on the other side | |
8:33:25 AM Aaron Gotwalt: it's not a remote object | |
8:33:49 AM Aaron Gotwalt: it's serialized in the form of a hash, because it's a friendly representation for both client and server | |
8:33:57 AM Larry Marburger: oh i thought you were saying why not just serialize objects | |
8:34:11 AM Aaron Gotwalt: as well as reducing verbosity across the wire, which for 3g networks matters | |
8:34:51 AM Larry Marburger: but once it's gzipped, i don't think verbosity matters | |
8:35:12 AM Larry Marburger: or do you mean verbosity in the number of requests needed? | |
8:35:28 AM Aaron Gotwalt: inline helps solve the request problem | |
8:35:40 AM Aaron Gotwalt: even if you assume the verbosity argument is bunk due to gzip | |
8:35:46 AM Aaron Gotwalt: you still have this non-ideal middle format | |
8:35:52 AM Aaron Gotwalt: that is a middle format of a middle format | |
8:36:00 AM Larry Marburger: so anything you send is converted to bits | |
8:36:02 AM Aaron Gotwalt: why go so abstract | |
8:36:11 AM Larry Marburger: there's always a lower abstraction | |
8:36:22 AM Aaron Gotwalt: i can't come up with a compelling argument to annoy every developer who has to consume or produce this data | |
8:36:45 AM Larry Marburger: well you shouldn't use anything you don't think is delivering value | |
8:37:01 AM Aaron Gotwalt: well, everything until the data node delivers value, from my perspective | |
8:37:18 AM Larry Marburger: what about that? | |
8:37:39 AM Aaron Gotwalt: it throws out the elegance of native json, replacing it with a soap-like k/v structure | |
8:37:46 AM Aaron Gotwalt: no hierarchy kills me | |
8:37:58 AM Aaron Gotwalt: the lack of sub-arrays | |
8:38:14 AM Larry Marburger: the only thing i can say is it's designed that way for a reason | |
8:38:20 AM Larry Marburger: but it's not a one size fits all solution | |
8:38:23 AM Aaron Gotwalt: yeah | |
8:38:40 AM Aaron Gotwalt: that i get. i'm just trying to understand what those macro reasons are | |
8:38:50 AM Larry Marburger: and if you're really running into annoyances in your business logic because of CJ, that's an architecture problem | |
8:38:52 AM Aaron Gotwalt: because i'm going to have to defend my perspective on c+j to sam tomorrow | |
8:39:10 AM Larry Marburger: cj is a wire format. your business logic should not care at all about that | |
8:39:57 AM Larry Marburger: the fact that a json object can mostly be turned into a ruby hash is kind of an accident | |
8:40:53 AM Larry Marburger: you should still have something sitting on the boundary of your service that knows how to convert to and from whatever format you use | |
8:40:54 AM Aaron Gotwalt: well, they implicitly contain similar design objectives | |
8:41:58 AM Larry Marburger: right but converting json to a hash and passing it around may be easy but that doesn't mean it's a good idea from a design perspective | |
8:43:38 AM Larry Marburger: what i'm saying is you want some object that hides the underlying format | |
8:44:17 AM Aaron Gotwalt: hmm | |
8:45:05 AM Aaron Gotwalt: and where do you draw the line of over-abstraction? | |
8:45:10 AM Aaron Gotwalt: i mean | |
8:45:35 AM Aaron Gotwalt: assume we generate a json hash for data elements, rather than k/v | |
8:45:49 AM Aaron Gotwalt: assume that it's not a representation of the back-end data structures | |
8:46:12 AM Aaron Gotwalt: but "an object that hides the underlying format" | |
8:46:18 AM Aaron Gotwalt: and that we send it down the wire | |
8:46:53 AM Aaron Gotwalt: is that not a morally equivalent data structure? we still have to agree on how to parse it, but the end result is approximately the same. | |
8:47:59 AM Larry Marburger: does it really matter to you if the format is sent in js object format or nested arrays? | |
8:48:16 AM Aaron Gotwalt: practical example | |
8:48:22 AM Aaron Gotwalt: you have a node that contains an array of strings | |
8:48:22 AM Larry Marburger: in ruby, you'd do JSON(body) and get a hash | |
8:48:31 AM Aaron Gotwalt: how do you represent that? it isn't clear | |
8:48:35 AM Larry Marburger: so if you has CollectionJSON(body) and get a hash, wouldn't it be equal? | |
8:48:41 AM Aaron Gotwalt: aside from another http request | |
8:48:53 AM Aaron Gotwalt: to a nested resource that's a collection containing just strings | |
8:49:02 AM Aaron Gotwalt: which is hella complicated for an array of strings | |
8:50:27 AM Larry Marburger: does inline help you? | |
8:50:58 AM Larry Marburger: i guess i'd need to see the exact data | |
8:53:00 AM Aaron Gotwalt: i think i just arrive at it feeling aggressively prescriptive in its abstraction religion, but without an actual forseeable payout | |
8:54:24 AM Larry Marburger: it's designed for easy parsing | |
8:54:37 AM Aaron Gotwalt: so is a blob of json | |
8:54:38 AM Larry Marburger: that's why everything's an array | |
8:55:08 AM Larry Marburger: not really. you have to have something that makes sense of the object from the resulting json string. | |
8:55:49 AM Larry Marburger: for example | |
8:56:02 AM Aaron Gotwalt: I'm gonna put this up on branch | |
8:56:05 AM Aaron Gotwalt: this is a really interesting thread | |
8:56:21 AM Larry Marburger: you have an api that returns stuff. it could either be one or more things. do you return the one thing as a single object or do you return it as an array of one? | |
8:56:32 AM Aaron Gotwalt: oh, i love the collection bit | |
8:56:34 AM Aaron Gotwalt: basically | |
8:56:40 AM Aaron Gotwalt: i'm onboard until the data element | |
8:56:45 AM Larry Marburger: that's what i mean by ease of parsing. you always know what to expect. | |
8:56:52 AM Aaron Gotwalt: at which point it goes too far | |
8:57:12 AM Larry Marburger: whereas if you're hand-rolling, you either have an unspoken agreement between client and server or you just don't think about it (that's how i operated) | |
8:57:31 AM Larry Marburger: the format of the data element matches the format of everything else | |
8:58:22 AM Larry Marburger: links, data, items, etc. are all arrays of objects. | |
8:59:53 AM Larry Marburger: i think one of the main reasons for using arrays of objects and not a single object is because it's easier to convert text to a js string than to a js object key | |
9:00:40 AM Larry Marburger: i remember having that conversation but i don't exactly remember the reasoning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment