-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Consider renaming ScopedValue
to ContextValue
#53644
Comments
We could potentially expose a somewhat lower-level interface, like this: f() = a[]
a = ContextValue(1)
ctx = current_context()
with(ctx, a => 2) do
f()
end Just a thought. I don't know if that is viable or not. |
The name was extensively debated during triage (We spent 2-3 meetings on it) and on slack. While on the surface
That is a fundamental misunderstanding of the terms variable and values. Julia does not (an likely never will) implement dynamically scoped variables. Variables only have lexical scope to consider.
|
@KristofferC Maybe allow some discussion rather than immediately closing? That's a bit rude and discourages feedback and contributions to the language. I sometimes wonder why I involve myself with this language.
I don't see how this relates to whether this feature can be described as "dynamic scoping".
I understand what variables and values are. The concept of dynamic scoping relates to the binding of variables. Your argument might be more convincing if the documentation was careful to use phrases like "dynamically scoped value", rather than claiming that Scoped Values are "an implementation of dynamic scoping in Julia". But as it currently stands, the messaging in the docs is misleading. Here is a list of misleading statements in the manual page:
P.S. It would be nice if core developers refrained from using phrases like "That is a fundamental misunderstanding of...". It's remarkable how often I hear that, and usually it's an incorrect assertion. It comes across as condescending and unwelcoming. |
My apologies, this particular bike-shed is very frustrating for me. I appreciate your comments and thoughts, but I have also debated this particular question for many hours of my life. The examples you showed were for variables not values, and ScopedValue's very intentionally say nothing about variables and only about the behavior of values.
I suspect this is where we disagree, for me "dynamic scoping" does not immediately imply "variables". I do deeply appreciate your documentation PR, clarifying things that might be obvious to me but not others is very important. There are also costs associated with renaming at this stage of the Julia 1.11 release process. (I suspect this is why Kristoffer closed the issue). I didn't pull the name out of thin air and we debated it at length. I asked the Java folks how they ended up with the name:
|
@vchuravy Thanks for the background info. |
Closing does not mean that there is no discussion allowed. As can be seen here, the discussion keeps going. (There is also https://discourse.julialang.org/t/naming-of-scopedvalues/110747 so it is a bit unfortunate to split the discussion into two places) |
Introduction
The new
ScopedValue
feature is really nice, but I think the name and the description of the feature in terms of dynamic scope is likely to lead to confusion.There was a claim on Discourse that the PR had "an extensive analysis and bikeshedding of the naming". However, I have read through the entire PR and I disagree with that statement. There is some discussion of the name, but it is not a very complete discussion. In particular, it is surprising that there was no discussion regarding using the terminology "context" instead of "dynamic scope". In PR #35833, @tkf pointed out that the "context" terminology is used in at least four major programming languages:
contextvars
ExecutionContext
CoroutineContext
Context
Julia is a lexically scoped language, and the Scoped Values PR does not change that. Below are a couple examples that I think emphasize that what
ScopedValue
provides is not dynamic scoping.(Disclaimer: I have only tested these using ScopedValues.jl. I need to install
juliaup
so I can get nightly.)Example 1
Example 2
Discussion
Both of these examples would work if
ScopedValue
provided true dynamic scoping. So essentially we are telling the user that Julia uses a subtle combination of lexical scoping and dynamic scoping. I think that's more confusing than it needs to be. We should describe this feature as a "context" feature rather than a "dynamic scoping" feature. This is about more than just the name, it is about our semantic understanding of what the feature provides.So, after a renaming, this feature could look like this:
Of course the precise naming is up for debate. Possible names for the context entering function:
with
withcontext
context
incontext
updatecontext
newcontext
I think
updatecontext
andnewcontext
are probably the most accurate names to describe what they do.The text was updated successfully, but these errors were encountered: