8000 cleanup method as function semantic in `@list` by Guest0x0 · Pull Request #2307 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cleanup method as function semantic in @list #2307

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

Merged
merged 2 commits into from
Jun 20, 2025

Conversation

Guest0x0
Copy link
Contributor

This PR reverts #2224, and fix some related issue.

We have deprecated the behavior of calling methods as functions directly. Currently, the recommended API design guideline is:

  • always favor method when the first parameter is Self
  • do not provide function alternative unless necessary

For existing library, library authors need to do nothing: downstream users will receive a deprecated warning when calling methods as function, and fix these usage. There is no need to provide fnalias for methods, as in #2224, unless necessary (for example, for math functions Double::sin etc, people are used to regular function syntax due to math notation convention).

So this PR reverts #2224, remove fnalias for @list.T methods. Downstream users of @list will receive a deprecated warning if they use @list.T methods as regular functions, and it is their responsibility to fix these usage. This is not a breaking change since it's a warning, not a fatal error.

One exception is zip. Since zip is a binary operation on list, it sometimes feels more natural to write @list.zip(xs, ys), so the fnalias for zip is kept in this PR.

cc @illusory0x0 @peter-jerry-ye

Copy link
Potential Backwards Compatibility Impact

Category
Correctness
Code Snippet
pub fnalias T::zip
Recommendation
Consider adding a deprecation warning for the function variant of other methods to help users migrate their code gradually.
Reasoning
While keeping only zip as function variant is justified by its binary operation nature, removing all other function variants without a deprecation period might break existing code silently. A deprecation warning would help users identify and fix affected code.

Documentation Needs Update

Category
Maintainability
Code Snippet
// Example:
/// ```mbt
/// let ls = @list.intersperse(@list.from_array(["1", "2", "3", "4", "5"]), "|")

Recommendation
Update code examples to use method syntax consistently, e.g.:

  let ls = @list.from_array(["1", "2", "3", "4", "5"]).intersperse("|")

Reasoning
Some code examples still use the function call syntax that is being deprecated. Documentation should reflect the recommended style to help users write idiomatic code.

Internal Function Visibility

Category
Maintainability
Code Snippet
fn[A] reverse_inplace(self : T[A]) -> T[A]
Recommendation
Add explicit visibility modifier (pub/priv) to internal functions like reverse_inplace
Reasoning
Function visibility should be explicitly declared to make the API boundaries clear. This helps prevent accidental usage of internal functions and makes refactoring easier.

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 7403

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 89.886%

Totals Coverage Status
Change from base Build 7401: 0.0%
Covered Lines: 8505
Relevant Lines: 9462

💛 - Coveralls

@Guest0x0 Guest0x0 merged commit 40b2888 into main Jun 20, 2025
16 checks passed
@Guest0x0 Guest0x0 deleted the Guest0x0/cleanup-method-as-func branch June 20, 2025 08:06
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.

2 participants
0