-
-
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
finalizer takes its arguments backwards (function should be first argument) #16307
Comments
Note that the second argument could also be a C pointer. |
Duplicate of #6454. |
We should probably have at least one of them open, since I think many people agree this would be good to do. |
Oops I thought the other was still open. I'll leave it to a maintainer to work out which to open/close. |
I agree that doing this offers more good and less of the less good than obtains not doing this. |
Triage agrees we should change this. |
And leave the inconsistency for pointer arguments? |
We can change the order for pointer arguments as well to be consistent. |
It'll still be inconsistent for the pointer one (and also the normal one) since both of them are operating on the object which is also usually (and more widely so) the first argument. |
... and that is why there is an issue to decide on a precedence of conventions. That precedence determines which argument goes first in this case. The proposal that @JeffBezanson made for convention precedence (which seems like a good one) dictates that the function argument goes first. |
I'll grant that there is no convention for where to put a C function pointer in an argument list. But @yuyichao is there even a single other function that uses the argument order |
That proposal is based on the For
Also note that the list doesn't even cover the case where an single object is to be operated on (not "Thing being mutated"). It is likely due to the absense/low number of functions in base that needs it (though there are a LOT in packages). That should ideally go to the first in the long term so that when we allow more explicit namespace control per object/type, we can write |
We are never doing that. Are you saying we should change the order of arguments to
Are you saying a lot of packages use the argument order |
If there are a lot of packages using |
Well, I believe that's one of the usecases of #1974 (or similar) where most people have agreed on. (allowing namespace separation)
Of course NOT.
Same as above, I'm only talking about functions (admittedly rare in Base) that there's an clear object that it operates on, or in another word, the cases that fits the traditional OO way well.
No. I'm saying functions where one expect a certain main object is the first object is very common in packages. And yes, there are object's methods (in OO sense) that accept functions (callbacks) too. Having only those functions that takes the arguments in a different order will be really unexpected.
For this exact argument you should not have an API that does obj = create()
do_thing1(obj, v1)
do_thing2(obj, v2)
do_thing3(callback, obj, v3)
do_thing4(obj, v4) When there isn't an |
I won't comment the
Base itself currently uses anonymous function as second arg of |
So those should be fixed. |
This argument that |
It's good enough to close this issue since that's the whole reason this was opened.
No. It is a bad idea because, well, it's a bad idea to not close resources explicitly. We can have more deterministic destruction syntax but that won't be a finalizer. |
This argument doesn't make any sense. You basically want to get rid of |
No. I don't want to get rid of it. I just want to prevent the bad style the original post want to do.
And so that's exactly what the code in #16307 (comment) is about. |
So the guts of this argument is over the priority of the order of operands conventions.
Surely this is an argument not to be had here, but instead at #19150 A better discussion would be at #19150 talking in the abstract. |
I think I'm missing something here; but if this is technically incorrect to use an anonymous function in |
Correct, @oxinabox, and since we don't actually have OO, the conflict does not really exist. As I understand it, @yuyichao wants to keep the order of the arguments to |
We don't have a lot that in Base which is why the convention doesn't have it. But it does exist in packages.
No. I'm also proposing to add that to the convention and I don't agree with the current convention on this.
Apparently this is true. #16307 (comment) is by itself a good example how the code must not be written. |
If you can make the case on #19150 that there's some other convention that should take precedence over function arguments being first, and that convention applies to |
If you have a issues with Jeff's proposed precedence of conventions, then make that clear over there, not on random comments on issues that are tangentially related. If the general argument holds up, then it automatically applies to this issue. If not, then |
I don't want to comment there mainly because of
And I still disagree with this completely. |
If a general case can't be made then there's no argument at all. |
Depending on what do you mean by "general case". There's of course a general case but there isn't as many cases in Base as in packages and the only overlapping case in base is |
You should explain the general case in #19150. Even if there aren't many examples in Base, it should be in the convention prioritization. |
@vtjnash suggests that we should deprecate the |
…16307) (JuliaLang#24605)" This reverts commit 52d81b0.
Finalizer is currently define to be
finalizer(x, function)
.But (I assert that) it should be
finalizer(function, x)
as this allows do-block syntax to define the function.
Right now I must write
Where as if it took the function as first argument,
like
map
,filter
, (Dict)get!
andremotecall
(#11406)I could be writing:
I suggest deprecating, and creating the new overload.
I wonder if it isn't worth search through the whole of Base and Core looking for methods that take functions (or things that look like functions), as a non-first parameter, then I could raise just one issue for all of them (or do PR)
(I could script that pretty easy using
parse
)The text was updated successfully, but these errors were encountered: