Skip to content
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

Infer var metadata for 'proxy' vars #171

Merged
merged 5 commits into from
Aug 3, 2023
Merged

Infer var metadata for 'proxy' vars #171

merged 5 commits into from
Aug 3, 2023

Conversation

vemv
Copy link
Member

@vemv vemv commented Aug 2, 2023

Part of clojure-emacs/cider-nrepl#788

Use case explained over there.

...I had attempted this before: clojure-emacs/cider-nrepl#790 but it was targeting the wrong middleware. This impl is simpler / more predictable, needing no pmap-like parallelism.

I've tried this one locally, and it works as intended.

Works on CLJ and CLJS, tests added for both.

Cheers - V

@vemv vemv requested a review from bbatsov August 2, 2023 20:16
@@ -41,7 +42,7 @@
(defn- maybe-add-spec
"If the var `v` has a spec has associated with it, assoc that into meta-map.
The spec is formatted to avoid processing in the client (e.g. CIDER)."
[v meta-map]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplifies a -> chain below

@bbatsov
Copy link
Member

bbatsov commented Aug 3, 2023

Is proxy/proxied the right terminology here? I think alias/aliased is much more accurate way to describe this.

@vemv
Copy link
Member Author

vemv commented Aug 3, 2023

I can see how 'proxy' is an overloaded term, but 'aliased' immediately brings to mind namespace aliases, which would seem greatly confusing to me (particularly in a project that already deals with aliases).

delegate might work, but I'd fail to see a difference with proxy.

@bbatsov
Copy link
Member

bbatsov commented Aug 3, 2023

When I hear of Clojure and proxy I immediately think of https://clojuredocs.org/clojure.core/proxy That's why I don't like this. And your examples in the tests are really aliases, after all this terminology extends to more than namespaces.

I'm open to other suggestions, even if I can't offer anything better than alias myself. @alexander-yakushev Any suggestions from you are welcome as well!

@bbatsov
Copy link
Member

bbatsov commented Aug 3, 2023

Btw, I don't want us to spend too much time on this - the implementation seems good and solves a real problem. If we don't come up with a better name relatively quickly (a day or so), I'm fine to stick with the current terminology.

(:require
[orchard.misc :as misc])
(:refer-clojure :exclude [find-ns find-var all-ns ns-aliases]))
[clojure.string :as string]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that str is the preferred alias across the project, any reason to have it different here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - it's best to be consistent about this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't mind I'd like to settle onstring then, project-wide. We can add a kondo rule for avoiding further churn.

My point of view as someone who tends to maintain other people's code a lot, is that Sierra-style aliases only make our lives easier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a big deal for me, but such changes should be discussed outside the scope of this PR.

Copy link
Member

@alexander-yakushev alexander-yakushev Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see str much more often than string (almost never the latter, actually). I don't know about feverishly enforcing some arbitrary rule one person established. Besides, he mentions exceptions in his blog post too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, most of all it's about not memorizing arbitrary abbreviations someone wrote years ago e.g. cljs.analyzer.api :as ana - those represent unnecessary cognitive load to me.

I agree that str is very well-known, but when one uses a convention 99.9% of the time, having an exception to break the rule isn't exactly convenient.

Copy link
Member

@alexander-yakushev alexander-yakushev Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So then everyone will have to memorize whether this is a project that chose string because of a convention or, you know, the rest 99.9% of the projects 😄.

Having said that, I claim no say in this issue.

@@ -98,37 +98,47 @@
;; a special symbol - always use :unqualified-sym
(some-> (cljs-ana/special-meta env unqualified-sym)
(cljs-meta/normalize-var-meta))
;; an NS

;; a NS
Copy link
Member

@alexander-yakushev alexander-yakushev Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well ackshually, an NS is correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it's pronounced as en es, so the normal rules about consonants don't apply here.

@alexander-yakushev
Copy link
Member

When I hear of Clojure and proxy I immediately think of https://clojuredocs.org/clojure.core/proxy That's why I don't like this. And your examples in the tests are really aliases, after all this terminology extends to more than namespaces.

I absolutely agree; I was reading through the code waiting and waiting where a proxy finally comes up, and only understood what it is about when looked at the tests.

I think it's worth picking up a better term. alias has its confusion too but still better than proxy. Maybe something like "indirect"? "Pass-through"?

@vemv
Copy link
Member Author

vemv commented Aug 3, 2023

Thanks for the input! I'll consider those.

How about "delegate vars"?

@bbatsov
Copy link
Member

bbatsov commented Aug 3, 2023

I think I like the most indirect as it's hard to confuse with anything else. When I here of delegate I immediately think of https://en.wikipedia.org/wiki/Delegation_pattern :-)

@alexander-yakushev
Copy link
Member

alexander-yakushev commented Aug 3, 2023

Same, I think of delegates in C++/C# (i.e., function pointers).

@vemv
Copy link
Member Author

vemv commented Aug 3, 2023

Merging. btw, I tested out this with Compliment and it works there too 🍻

@vemv vemv merged commit d3bf47b into master Aug 3, 2023
@vemv vemv deleted the proxy-vars branch August 3, 2023 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants