Clojure spec - naming entity keywords












2















Is it considered bad practice to use namespace-qualified keywords with nonexistent namespaces, for defining specs? I'd like to have entity maps defined in common domain namespace... so to avoid loosing data when merging specs, I've used convention :entity/attribute instead of ::entity-attribute for attributes and standard ::entity for entities. It aligns nicer to database tables and columns. Each entity in a separate namespace reminds me of Java classes, doesn't sound like a good idea.



(s/def :country/id   ::nilable-nat-int)
(s/def :country/name ::non-empty-string)

(s/def ::country
(s/keys :req [:country/id
:country/name]))

;; ----------------------------------------

(s/def :location/id ::nilable-nat-int)
(s/def :location/name ::non-empty-string)
(s/def :location/zipcode ::nilable-non-empty-string)

(s/def ::location
(s/merge
(s/keys :req [:location/id
:location/name
:location/zipcode])
(s/or :country ::country
:country-id
(s/keys :req [:country/id]))))









share|improve this question




















  • 1





    On the mailing list: groups.google.com/d/msg/clojure/TcRXF3a0bNI/pafdYbTnAwAJ

    – glts
    Nov 13 '18 at 18:39
















2















Is it considered bad practice to use namespace-qualified keywords with nonexistent namespaces, for defining specs? I'd like to have entity maps defined in common domain namespace... so to avoid loosing data when merging specs, I've used convention :entity/attribute instead of ::entity-attribute for attributes and standard ::entity for entities. It aligns nicer to database tables and columns. Each entity in a separate namespace reminds me of Java classes, doesn't sound like a good idea.



(s/def :country/id   ::nilable-nat-int)
(s/def :country/name ::non-empty-string)

(s/def ::country
(s/keys :req [:country/id
:country/name]))

;; ----------------------------------------

(s/def :location/id ::nilable-nat-int)
(s/def :location/name ::non-empty-string)
(s/def :location/zipcode ::nilable-non-empty-string)

(s/def ::location
(s/merge
(s/keys :req [:location/id
:location/name
:location/zipcode])
(s/or :country ::country
:country-id
(s/keys :req [:country/id]))))









share|improve this question




















  • 1





    On the mailing list: groups.google.com/d/msg/clojure/TcRXF3a0bNI/pafdYbTnAwAJ

    – glts
    Nov 13 '18 at 18:39














2












2








2


1






Is it considered bad practice to use namespace-qualified keywords with nonexistent namespaces, for defining specs? I'd like to have entity maps defined in common domain namespace... so to avoid loosing data when merging specs, I've used convention :entity/attribute instead of ::entity-attribute for attributes and standard ::entity for entities. It aligns nicer to database tables and columns. Each entity in a separate namespace reminds me of Java classes, doesn't sound like a good idea.



(s/def :country/id   ::nilable-nat-int)
(s/def :country/name ::non-empty-string)

(s/def ::country
(s/keys :req [:country/id
:country/name]))

;; ----------------------------------------

(s/def :location/id ::nilable-nat-int)
(s/def :location/name ::non-empty-string)
(s/def :location/zipcode ::nilable-non-empty-string)

(s/def ::location
(s/merge
(s/keys :req [:location/id
:location/name
:location/zipcode])
(s/or :country ::country
:country-id
(s/keys :req [:country/id]))))









share|improve this question
















Is it considered bad practice to use namespace-qualified keywords with nonexistent namespaces, for defining specs? I'd like to have entity maps defined in common domain namespace... so to avoid loosing data when merging specs, I've used convention :entity/attribute instead of ::entity-attribute for attributes and standard ::entity for entities. It aligns nicer to database tables and columns. Each entity in a separate namespace reminds me of Java classes, doesn't sound like a good idea.



(s/def :country/id   ::nilable-nat-int)
(s/def :country/name ::non-empty-string)

(s/def ::country
(s/keys :req [:country/id
:country/name]))

;; ----------------------------------------

(s/def :location/id ::nilable-nat-int)
(s/def :location/name ::non-empty-string)
(s/def :location/zipcode ::nilable-non-empty-string)

(s/def ::location
(s/merge
(s/keys :req [:location/id
:location/name
:location/zipcode])
(s/or :country ::country
:country-id
(s/keys :req [:country/id]))))






clojure clojure.spec






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 11:10







Nikola

















asked Nov 13 '18 at 10:58









NikolaNikola

305




305








  • 1





    On the mailing list: groups.google.com/d/msg/clojure/TcRXF3a0bNI/pafdYbTnAwAJ

    – glts
    Nov 13 '18 at 18:39














  • 1





    On the mailing list: groups.google.com/d/msg/clojure/TcRXF3a0bNI/pafdYbTnAwAJ

    – glts
    Nov 13 '18 at 18:39








1




1





On the mailing list: groups.google.com/d/msg/clojure/TcRXF3a0bNI/pafdYbTnAwAJ

– glts
Nov 13 '18 at 18:39





On the mailing list: groups.google.com/d/msg/clojure/TcRXF3a0bNI/pafdYbTnAwAJ

– glts
Nov 13 '18 at 18:39












1 Answer
1






active

oldest

votes


















0














As @glts commented, here is the right answer: mailing list.



I've decided to make keywords more specific, added this to the domain namespace:



(doseq [ns ["entity-1" ,,, "entity-n"]]
(->> (str "project.domain." ns)
(symbol)
(create-ns)
(alias (symbol ns))))


And then ::entity-n/attribute evaluates to :project.domain.entity-n/attribute.



Only one additional : is needed for the attributes from the question-example:



(s/def ::location/id ::nilable-nat-int)





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279505%2fclojure-spec-naming-entity-keywords%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As @glts commented, here is the right answer: mailing list.



    I've decided to make keywords more specific, added this to the domain namespace:



    (doseq [ns ["entity-1" ,,, "entity-n"]]
    (->> (str "project.domain." ns)
    (symbol)
    (create-ns)
    (alias (symbol ns))))


    And then ::entity-n/attribute evaluates to :project.domain.entity-n/attribute.



    Only one additional : is needed for the attributes from the question-example:



    (s/def ::location/id ::nilable-nat-int)





    share|improve this answer




























      0














      As @glts commented, here is the right answer: mailing list.



      I've decided to make keywords more specific, added this to the domain namespace:



      (doseq [ns ["entity-1" ,,, "entity-n"]]
      (->> (str "project.domain." ns)
      (symbol)
      (create-ns)
      (alias (symbol ns))))


      And then ::entity-n/attribute evaluates to :project.domain.entity-n/attribute.



      Only one additional : is needed for the attributes from the question-example:



      (s/def ::location/id ::nilable-nat-int)





      share|improve this answer


























        0












        0








        0







        As @glts commented, here is the right answer: mailing list.



        I've decided to make keywords more specific, added this to the domain namespace:



        (doseq [ns ["entity-1" ,,, "entity-n"]]
        (->> (str "project.domain." ns)
        (symbol)
        (create-ns)
        (alias (symbol ns))))


        And then ::entity-n/attribute evaluates to :project.domain.entity-n/attribute.



        Only one additional : is needed for the attributes from the question-example:



        (s/def ::location/id ::nilable-nat-int)





        share|improve this answer













        As @glts commented, here is the right answer: mailing list.



        I've decided to make keywords more specific, added this to the domain namespace:



        (doseq [ns ["entity-1" ,,, "entity-n"]]
        (->> (str "project.domain." ns)
        (symbol)
        (create-ns)
        (alias (symbol ns))))


        And then ::entity-n/attribute evaluates to :project.domain.entity-n/attribute.



        Only one additional : is needed for the attributes from the question-example:



        (s/def ::location/id ::nilable-nat-int)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 1:22









        NikolaNikola

        305




        305






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279505%2fclojure-spec-naming-entity-keywords%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation