You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #1472, the API style of builtin types and other types is different. Types defined in a regular package such as @hashmap will favor the syntax @hashmap.new() for calling things, while builtin types favor the syntax Map::new(). This is because some types in @builtin don't have their own package, such as Map/Set/Iter/StringBuilder.
This divergence of API style is bad, because sometimes it forbids abstraction over data structure. For example, if a user is using @buffer.T for internal use, but later find out that StringBuilder has better performance. If StrnigBuilder has its own package, the user can import @stringbuilder and alias it to @buffer, then everything should just work because @buffer.T and StringBuilder have similar API. But currently this is not possible because StringBuilder does not have its own package.
This PR add new packages for builtin types Map/Set/Iter/Iter2/StringBuilder. These new packages contain wrappers to the actual implementation in @builtin. This way, the API of these types would be more consistent with other types. In the future, we may also refactor @builtin and move the implementations to separated packages as well.
‼️ This code review is generated by a bot. Please verify the content before trusting it.
I'll analyze the git diff and point out potential issues I've noticed:
Potential Copyright Year Issue:
All files have a copyright year of 2025 in their headers, which appears to be a future date. This might need to be updated to the current year or the actual copyright year.
// Copyright 2025 International Digital Economy Academy
Type Alias Consistency:
There's an inconsistency in how type aliases are defined across modules. For example:
iter/iter.mbt uses T[X]
iter2/iter2.mbt uses T[X, Y]
stringbuilder/stringbuilder.mbt uses just T
Consider standardizing the naming convention for type aliases across modules.
Function Parameter Documentation:
In map/map.mbt, the new function has a default parameter value that's not fully specified in the interface file:
// In map.mbti:
fn new[K, V](capacity~ : Int = ..) -> Map[K, V]
This might benefit from explicit documentation of the default value (which appears to be 8 based on the implementation).
These issues are mostly related to consistency and documentation rather than functional problems, but addressing them would improve the codebase's maintainability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In #1472, the API style of builtin types and other types is different. Types defined in a regular package such as
@hashmapwill favor the syntax@hashmap.new()for calling things, while builtin types favor the syntaxMap::new(). This is because some types in@builtindon't have their own package, such asMap/Set/Iter/StringBuilder.This divergence of API style is bad, because sometimes it forbids abstraction over data structure. For example, if a user is using
@buffer.Tfor internal use, but later find out thatStringBuilderhas better performance. IfStrnigBuilderhas its own package, the user can import@stringbuilderand alias it to@buffer, then everything should just work because@buffer.TandStringBuilderhave similar API. But currently this is not possible becauseStringBuilderdoes not have its own package.This PR add new packages for builtin types
Map/Set/Iter/Iter2/StringBuilder. These new packages contain wrappers to the actual implementation in@builtin. This way, the API of these types would be more consistent with other types. In the future, we may also refactor@builtinand move the implementations to separated packages as well.