Skip to content

Consider talking about defprotocol and deftype a bit more? #222

@lread

Description

@lread

On indentation

defprotocol can optionally include docstrings.

An example from rewrite-clj

(defprotocol Node "Protocol for EDN/Clojure/ClojureScript nodes." (tag [node] "Returns keyword representing type of `node`.") (node-type [node] "Returns keyword representing the node type for `node`.  Currently internal and used to support testing.") (printable-only? [node] "Return true if `node` cannot be converted to an s-expression element.") (sexpr* [node opts] "Return `node` converted to form applying `opts`. Internal, use `sexpr` instead.") (length [node] "Return number of characters for the string version of `node`.") (string [node] "Return the string version of `node`."))

The above indentation works for me, but I do see Calva (I expect not purposefully) formatting like so:

(defprotocol Node "Protocol for EDN/Clojure/ClojureScript nodes." (tag [node] "Returns keyword representing type of `node`.") (node-type [node] "Returns keyword representing the node type for `node`.  Currently internal and used to support testing.") (printable-only? [node] "Return true if `node` cannot be converted to an s-expression element.") (sexpr* [node opts] "Return `node` converted to form applying `opts`. Internal, use `sexpr` instead.") (length [node] "Return number of characters for the string version of `node`.") (string [node] "Return the string version of `node`."))

A small example of a defprotocol with docstrings would likely be helpful.

On usage of this
You'll notice in my example above I used node as the first argument name in my protocol methods.

In other examples I often see this used as the first argument name for methods in defprotocol and deftype.
The usage of this drives home that we are dealing with objects.

I'm thinking probably that both naming conventions are probably ok?
I personally used node because the protocol methods are exposed in the rewrite-clj API.

I think some guidance on this (pun intended) would be helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions