Skip to content

MONGOID-5702: Monkey Patch Removal: Remove __numeric__ class method from Numeric module #5746

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

johnnyshields
Copy link
Contributor

It is now inlined into its only usage. It was previously declared @api private so assume it is safe to delete.

…dule. It is now inlined into its only usage. It was previously declared @api private so assume it is safe to delete.
@johnnyshields johnnyshields changed the title Monkey Patch Removal: Remove __numeric__ class method from Numeric module MONGOID-5702: Monkey Patch Removal: Remove __numeric__ class method from Numeric module Nov 13, 2023
@johnnyshields johnnyshields changed the title MONGOID-5702: Monkey Patch Removal: Remove __numeric__ class method from Numeric module [READY FOR REVIEW] MONGOID-5702: Monkey Patch Removal: Remove __numeric__ class method from Numeric module Nov 25, 2023
@johnnyshields johnnyshields requested a review from a team as a code owner May 5, 2025 20:44
@johnnyshields johnnyshields requested a review from jamis May 5, 2025 20:44
@johnnyshields
Copy link
Contributor Author

This should be a straightforward merge.

@jamis jamis changed the title [READY FOR REVIEW] MONGOID-5702: Monkey Patch Removal: Remove __numeric__ class method from Numeric module MONGOID-5702: Monkey Patch Removal: Remove __numeric__ class method from Numeric module May 5, 2025
@jamis
Copy link
Contributor

jamis commented May 5, 2025

@johnnyshields thanks for this one, yeah, it should be totally safe to apply, thanks to that private flag.

However, I feel like this is a step backward in readability. The evolve method is harder to grok at a glance. I understand wanting to remove monkeypatched methods on standard classes (three cheers for fixing that, hurray!) but I feel like there's still value in isolating the responsibility that __numeric__ currently holds.

Mongoid::Utils might be a reasonable host for such functionality, if the goal is primarily to remove that monkeypatch.

@johnnyshields
Copy link
Contributor Author

johnnyshields commented Jul 8, 2025

this is a step backward in readability

@jamis how so? The previous method was:

 def evolve(object) __evolve__(object) do |obj| __numeric__(obj) rescue obj # <-- this line is now inlined end end

There is nothing particularly "readable" about the old method--by reading this, can anyone really tell me what __evolve__ vs. __numeric__ does? I doubt it...

Mongoid::Utils might be a reasonable host for such functionality

This PR is a stepping stone to putting evolve and/or __evolve__ in a Util, so there's no need to consider to put __numeric__ in a Util...

@jamis
Copy link
Contributor

jamis commented Jul 10, 2025

@johnnyshields we'll have to agree to disagree, then. I find the original version infinitely more readable -- the intention is immediately apparent by glancing at the implementation. By inlining the implementation of __numeric__, we've "unrefactored" it, taking a step backward (IMO) and requiring a bit more mental work to parse what the intent of the method is.

I won't try to convince you, though; it's fine if you have a different opinion. But I'm not comfortable inlining the __numeric__ method in evolve, there.

@johnnyshields
Copy link
Contributor Author

johnnyshields commented Jul 10, 2025

Readability is neither here nor there-- the goal of this PR is to get rid of monkey patches. It's far better to "unrefactor" to remove the monkey patches first, then the "re-refactor" them into a sustainable, non-monkey patched structure. If we don't take this approach, and puritanically insist that all methods be maximally readable at all times, we'll never actually get rid of our monkeys 🐒 🐒 🐒

Put another way, trading a slightly less-readable method for eliminating a monkey patch is a good trade--and is a two-way door.

@jamis
Copy link
Contributor

jamis commented Jul 10, 2025

@johnnyshields -- we aren't going to agree on this. Ultimately, we do agree that the monkey-patches on core classes should be minimized. I suggested moving __numeric__ to the Utils module as a step toward that end. I could say that you responded rather puritanically yourself to that idea, yeah? 😜

Regardless, inlining __numeric__ is off the table (unless there were significant performance gains to be had from it, or some similar argument).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants