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

doc(string): add more design details #2203

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 25, 2025
Merged

Conversation

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

Should we rename it to README.mbt.md so that it more visible to the public? @bobzhang

Copy link
peter-jerry-ye-code-review bot commented Jun 4, 2025
Consider using consistent terminology for indices

Category
Maintainability
Code Snippet

  • Offset: UTF-16 index (counts code units)
  • Offset or Charcode Index: UTF-16 index (counts code units)
    Recommendation
    Choose either 'Offset' or 'Charcode Index' consistently throughout the document. Update all references to maintain consistency.
    Reasoning
    Using multiple terms for the same concept can be confusing for readers. The document uses both 'offset' and 'charcode index' interchangeably, which might lead to misunderstandings.
Test example for View conversion could be more complete

Category
Maintainability
Code Snippet
test "view conversion" {
fn process_text(text : View) -> Int {
text.length()
}
let str = "Hello World"
let view = str.charcodes(start=0, end=5)
Recommendation
Add assertions to verify the expected behavior:

test "view conversion" {
  fn process_text(text : View) -> Int {
    text.length()
  }
  let str = "Hello World"
  let view = str.charcodes(start=0, end=5)
  assert(process_text(str) == 11)
  assert(process_text(view) == 5)
}
**Reasoning**
Test cases should verify the expected behavior. The current example shows the API usage but doesn't verify the results, making it less useful as a documentation example.

</details>
<details>

<summary> Missing important detail about View lifetime </summary>

**Category**
Correctness
**Code Snippet**
- **Performance**: Views are more performant than creating new String instances
    when working with substrings. They avoid string copying and memory allocation
    by maintaining references to the original string
**Recommendation**
Add explicit documentation about View lifetime and its dependency on the original String:
'Views maintain a reference to the original String. Therefore, the original String must outlive all its Views.'
**Reasoning**
When dealing with references, it's crucial to document lifetime constraints to prevent potential use-after-free bugs. This is especially important in a systems programming language.

</details>

@coveralls
Copy link
Collaborator
coveralls commented Jun 4, 2025

Pull Request Test Coverage Report for Build 18

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

Totals Coverage Status
Change from base Build 17: 0.0%
Covered Lines: 3528
Relevant Lines: 3948

💛 - Coveralls

Yu-zh and others added 2 commits June 25, 2025 16:11
@bobzhang bobzhang enabled auto-merge (rebase) June 25, 2025 08:11
@bobzhang bobzhang merged commit 5d1332e into moonbitlang:main Jun 25, 2025
11 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
39E8
Development

Successfully merging this pull request may close these issues.

3 participants
0