-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Style: indentation of multiple-arity functions #95
Style: indentation of multiple-arity functions #95
Conversation
This indentation style seems logical and attractive, IMO it should be merged. 👍 |
I think default style of using 2 spaces is much more intuitive in this case. |
Why is it intuitive? It differs from the standard function structure. People have the tendency to confuse things that they're used to with things that are actually intuitive.
A discussion in clojure-mode's issue tracker makes me believe that no tool except |
Ok, my bad about tools support. On 12/03/2014 03:38 PM, Bozhidar Batsov wrote:
|
In the absence of any clear reasons not to, matching the indentation style for single-arity functions seems like the right way to go here. |
@@ -148,6 +148,28 @@ You can generate a PDF or an HTML copy of this guide using | |||
(baz x))) | |||
``` | |||
|
|||
* <a name="indent-multiple-arity"></a> | |||
Indent each arity form of a function vertically aligned with its |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of a function definition
arguments -> parameters
I agree with the PR in general, but I've added a bit of stylistic comments. |
@bbatsov I can rebase those commits if you'd like |
|
||
;; bad - extra indentation | ||
(defn foo | ||
"I have many arities." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
many -> two
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops - fixed
Yes, please. |
Rebased |
P.S. A better commit message would be "Add a rule about the indentation of multi-arity functions" |
Sure, happy to change it. I did a quick browse of the git history to see if I could divine a pattern |
Style: indentation of multiple-arity functions
👍 |
This isn't representative of what people are doing in the core libraries. They indent the body after arguments in multi-arity functions. It's everywhere in clojure, clojurescript, core.async, tools.reader, and probably more. In fact, clojure.pprint will indent one space after the arguments in multi-arity. Paste this code into the online clojure.pprint service to see it: (defn symbol
([name]
(if (symbol? name)
name
(let [idx (.indexOf name "/")]
(if (== idx -1)
(symbol nil name)
(symbol (.substring name 0 idx)
(.substring name (inc idx) (. name -length)))))))
([ns name]
(let [sym-str (if-not (nil? ns)
(str ns "/" name)
name)]
(Symbol. ns name sym-str nil nil)))) after clojure.pprint: (defn symbol
([name]
(if (symbol? name)
name
(let [idx (.indexOf name "/")]
(if (== idx -1)
(symbol nil name)
(symbol
(.substring name 0 idx)
(.substring name (inc idx) (. name -length)))))))
([ns name]
(let [sym-str (if-not (nil? ns) (str ns "/" name) name)]
(Symbol. ns name sym-str nil nil)))) |
Much code in the wild was affected by an unfortunate bug in |
I find the new style from clojure-mode makes multi-arity functions harder to read because the different arglist-body pairs don't stand out as well (especially for shorter ones). |
This pull request adds guidelines on how to indent multiple-artity functions. The exact style here is to vertically align arguments and function body - as elements of any sequence would be indented; however this is up for discussion as there is no de facto agreement on how to indent these forms. Different tools have arbitrarily chosen different indentation styles and it would be good to reach an agreement on what most people prefer so that we can all conform to a consistent code style.