add separate packages for builtin types #1502
Open
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
@hashmap
will favor the syntax@hashmap.new()
for calling things, while builtin types favor the syntaxMap::new()
. This is because some types in@builtin
don'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.T
for internal use, but later find out thatStringBuilder
has better performance. IfStrnigBuilder
has its own package, the user can import@stringbuilder
and alias it to@buffer
, then everything should just work because@buffer.T
andStringBuilder
have similar API. But currently this is not possible becauseStringBuilder
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.