-
Notifications
You must be signed in to change notification settings - Fork 21
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
Adding advisory on the ref keyword itself #1248
Comments
Seems pretty reasonable to me. |
Not to me. I believe this
should be this
And it looks like wrong things happen from there on. If this suggestion is based on one or two misunderstandings while exploring ref vs mutable, that isn't a good starting point for a language suggestion. Would be better to discuss this in a forum or forums first, to make the situation about the features clear. I also wonder whether there are situations where reference cells are needed and/or more practical than mutables, in which case general advice about not using it would be strange. |
I was able to get the ref to work using:
The point is that if you had the original code of conversion |
I think the forward reference in fparsec is an example. At least I did not find a way to express this with mutables. |
Hmm, yes, there are also a few parts of FSharp.Core implementations that rely on passing a mutable value to |
The documentation seems to lack information about recent changes. doc : https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/reference-cells more : When the changes were released, excellent release information about these was also given. Not sure where it is, but should be easy to find, and can probably be largely pasted into the docs. EDIT on 2 March 2023: This is where I found the information first: https://devblogs.microsoft.com/dotnet/whats-new-in-fsharp-6/#bringing-f-forward-reducing-use-of-rarely-used-symbolic-operators |
@BentTranberg I updated the docs here: dotnet/docs#34337 |
The suggestion itself doesn't make a lot of sense to me - The mistake was misreading
but the message is pretty clear isn't it? |
I propose we add an advisory on the ref keyword itself; make it explicit that reference cells are no longer being recommended and that mutual should be used instead, though this is purely from assumption from the material I've been reading.
I've read the discussion that stemmed back in 2017 - 2021: #569 and read the proposal in the following link: fsharp-refcells-ops
I've been noticing in recent versions of F#, that there has been a shift away from using reference cells in favor of declaring mutable variables with the mutable keyword.
In VS2022, I'm told,
So I change my code
But then I'm told:
So I change my code, and now I'm told:
forcing me to do
So if this is the pathway, why not just put an advisory on using the ref keyword in general?
Next, during my refactor, I am allowed to have the following line with no errors, which to me doesn't make sense:
I don't see how this should ever be allowed. So I feel if
ref
is being allowed, that there should be a note about how we should pickref
ormutable
.So now I'm questioning, where are we on reference cells? Is this feature being deprecate? I see an article about Reference cells with no mention of deprecation: F# Reference cells
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: