-
Notifications
You must be signed in to change notification settings - Fork 281
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
defn- vs. defn ^:private #124
Comments
That's one interesting point. However, I don't recall ever seeing private macros or multimethods. Maybe we should just extend this a bit, to mention this consideration. |
My team prefers |
We prefer |
Edit: said |
And then there's some that would argue that since |
There are some projects where people attempted to java-style provide a public API hiding implementation details and helper functions... my experience with |
@halgari I think ^:private is a useful way to indicate author intention as to which parts of the ns are considered subject to change and which aren't. While it doesn't mean the same thing as it does in other languages, it's still useful. I personally use and prefer defn- over defn with ^:private b/c it's shorter and again, concisely communicates intent. @bbatsov I have seen private macros and multimethods (there are certainly some in Clojure itself). |
@arrdem |
I understand @arrdem's point, but it still makes sense to have shorthands for commonly used stuff (or there should be no shorthands at all for the sake of consistency). I think that |
My 2 cc: the |
We will not be adding any other "-" forms to core. I think perhaps if we could do it over, defn- would not be added either, but we're not going to take it away. |
@puredanger What about simply deprecating it ( |
I don't think we want to deprecate it, we just don't want to take the idea any further. |
I know I'm coming in a bit late here and I hope that's not a problem. A coworker just asked why I used ^:private instead of defn- and my rationale is the following: a. I'd rather have a descriptive attribute a beginner, or non-clojurist can understand than use a symbol that only someone who knows clojure can fully understand However, I think context is important here. If it was my job to work on Clojure I'd probably prefer defn- as well since everyone there would be expected to know what it means. Same if I was a Clojure based dev studio where we can count on hiring Clojure experts. Since I'm doing general app development with a few languages it's hard to say who we'll get. |
Me too don't understand why defn- is still considered a good style, when Clojure core contributor mentioned very clear 6(!) years ago (#124 (comment)), that creating defn- was a bad idea and ^:private is perfect for both def and defn cases. @bbatsov Please fix the style guide accordingly (in 3 places: |
That’s not what I said above. defn- is part of Clojure core, in common use, and perfectly acceptable. |
I think some of the confusion in the style guide comes from using That said, I'm not sure that section adds much value anyway. The only case where there's a stylistic point to argue is: (defn- internal-fun [] ...)
;; vs
(defn ^:private internal-fun [] ...) I've never seen the latter in code but, based on the comments here, clearly some people use it and like it -- and I can see the arguments in favor of consistency (using Perhaps that whole section should just be deleted as adding no value? |
Sorry, I think I misread that post. For me bad style is when you add no meaning by duplication (that's why (def ^:private private-var ...) is bad - var is private, what's the point to add private in the var name? - yes, one can say that this is a good old DRY principle, but it's up to guide's author whether to include it - for me it's good to remind about DRY because Clojure likes conciseness) or when you use an option that is in the language, but it's not recommended for use. If everyone uses defn-, that's ok, let it be so. About synonyms to private - I think it's very arguable theme. Some say private of course is internal, but for another ones that should be a different category (like warm and soft). Maybe it's even closer to universal KISS principle. Because when I read "...private internal...", I stop and think "hmm, so somewhere else may be private external things? ...or public internal?" - anyway, the code becomes harder to read and understand. |
@makarichevss You are misunderstanding my point: I suggested (defn- wibby-wobbly [] ...)
;; vs
(defn ^:private wibbly-wobbly [] ...) The point is not the name, it's how you indicate something is private in the Clojure language. Which is why I said I don't think the Private section is adding any value here, as it currently stands. |
Looking here it is suggested that
However reading up on this Google group discussion it seems that using
defn-
is a bit contradictory since there are otherdef
that do not have a complimentarydef-
option. Quoting VincentShould this continue to remain in the styleguide?
(I can submit a PR to make the change, however I felt that perhaps having a discussion prior to that would be appropriate)
The text was updated successfully, but these errors were encountered: