5 ms·
Question to people having used Datomic: Based on experience with Prolog, I always thought using Datalog in a database like Datomic would mean being able to mod
by samuell 3y ago
Question to people having used Datomic:
Based on experience with Prolog, I always thought using Datalog in a database like Datomic would mean being able to model your data model using stored queries as a very expressive way of creating "classes". And that by modeling your data model using nested such queries, you alleviate the need for an ORM, and all the boilerplate and duplication of defining classes both in SQL and as objects in OO code ... since you already modelled your data model in the database.
Does Datomic live up to that vision?
- gleenn 3y agoClojure in general is all about passing around little maps of data and in particular not using OO to model. So Datomic naturally continues that by returning maps of nested structures to represent your query results and does side-step the ORM completely.
- PreachSoup 3y agoQuestion: What's the difference between nested oop objects (composition over inheiritance) vs maps of nested structures?
- xmcqdpt2 3y agoTo paraphrase a well known saying, objects are the poor person's nested maps and vis versa.
- gleenn 3y agoRich Hickey has a great talk about how Objects are data structures with unique interfaces that are unnecessary complexity. He showed and example of a web server with a web request object with request headers etc etc. Doing simple things like collecting information out of that nested object structure is bespoke and harder than it should be for no real gain. If everything is a map or list or set, it becomes completely trivial to extract and manipulate data from a structure. It's a subtle difference at first but when everything is like that it makes your system far simpler. Unfortunately I can't remember exactly where the part of this talk is.
- bavell 3y ago> Unfortunately I can't remember exactly where the part of this talk is. If you or anyone else remembers, I'd love to watch
- deleted 3y ago[deleted]
- sharms 3y agoHere is this specific part cut out from the larger talk "Clojure made simple": https://www.youtube.com/watch?v=aSEQfqNYNAc https://www.youtube.com/watch?v=aSEQfqNYNAc
- janosos 3y agohttps://youtu.be/aSEQfqNYNAc https://youtu.be/aSEQfqNYNAc The full video: [Time 0:49:06] https://www.youtube.com/watch?v=VSdnJDO-xdg https://www.youtube.com/watch?v=VSdnJDO-xdg Transcript here: https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/ClojureMadeSimple.md https://github.com/matthiasn/talk-transcripts/blob/master/Hi...
- deleted 3y ago[deleted]
- tyre 3y ago“No real gain” I don’t agree with this. iirc Rack ultimately uses and array to represent HTTP responses. It has three members: the status code, the headers, and the response body. If you’re shipping a new change, is it easier to mistake response[0] or response.headers? This is a trivial example, but the general class (ha) of trade-off is amplified with more complex objects. I love clojure and lisp but the blindness behind a statement like “no real gain” has always kneecapped adoption.
- augustl 3y agoIn Clojure, response.headers is still data :) You just use the built-in ways of reading named keys, such as (:headers response) or (get headers :response).
- blatant303 3y ago"It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures." Alan Perlis.
- samuell 3y agoThanks for the comment! I was more thinking of the means to define your data "classes" (or whatever it is called on this context) though, rather than how it is passed around.
- mtnygard 3y agoYou can definitely use Datomic in the way you describe, in at least a few different ways. I haven't often seen queries stored in the database itself. It's more common to have the queries as data in the application. Since queries are ordinary Clojure data structures, it's even more common to see functions that build queries from inputs or functions that transform queries (e.g., adding a tenant-id filter clause). Datomic also support rules, including recursive rules. I wrote a library to do OWL-style inference about classes of entities using rules. You can see an example here (https://github.com/cognitect-labs/onto/blob/master/src/onto/core.clj#L188 https://github.com/cognitect-labs/onto/blob/master/src/onto/...). This is a rule that infers all the classes that apply to an entity from an attribute that assigns it one class. I would also say that building an "entity type definition" system as entities in Datomic is almost the first thing every dev tries after the tutorial. It works... but you almost never _need_ it later.
- samuell 3y agoGreat, many thanks for this elaboration!
- abc_lisper 3y agoIt emphatically does. It has pull-syntax just for the nested entities obviating the need for ORM. I am surprised I had to scroll so far down to see this. This is its biggest selling point IMO.