8000 doc(string/view): fix documentation by Yu-zh · Pull Request #2351 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

doc(string/view): fix documentation #2351

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 1 commit into from
Jun 26, 2025
Merged

Conversation

Yu-zh
Copy link
Collaborator
@Yu-zh Yu-zh commented Jun 26, 2025

@string.View::char_at is an O(1) method. This PR fixed the documentation.

Copy link
Documentation correction for time complexity of char_at method

Category
Correctness
Code Snippet
/// This method has O(n) complexity.
pub fn View::char_at(self : View, index : Int) -> Char
Recommendation
The updated documentation correctly states O(1) complexity and clarifies the index meaning
Reasoning
Accurate documentation is crucial for API users to make informed decisions. The previous O(n) complexity claim could mislead developers into avoiding this method in performance-critical code paths

Consider adding more detailed parameter documentation

Category
Maintainability
Code Snippet
pub fn View::char_at(self : View, index : Int) -> Char
Recommendation
Add parameter documentation explaining that 'index' is a byte offset:
/// @param index: The byte offset into the string (not character position)
Reasoning
While the comment mentions this isn't the n-th character, explicit parameter documentation would make the API more self-documenting and prevent misuse

Consider adding example usage in documentation

Category
Maintainability
Code Snippet
///|
/// Returns the Unicode character at the given index. Note this is not the n-th character.
Recommendation
Add example usage:
///|
/// Returns the Unicode character at the given index. Note this is not the n-th character.
/// Example:
/// /// let v = View::from("hello") /// let c = v.char_at(0) // Returns 'h' ///
Reasoning
Examples in documentation help users understand the correct usage pattern, especially for methods where the index parameter behavior might not be immediately obvious

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 40

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.332%

Totals Coverage Status
Change from base Build 35: 0.0%
Covered Lines: 3517
Relevant Lines: 3937

💛 - Coveralls

@peter-jerry-ye peter-jerry-ye merged commit 3d419d3 into moonbitlang:main Jun 26, 2025
10 checks passed
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.

3 participants
0