aster
aster copied to clipboard
API consistency
Builder interfaces already have many regularities. Here's what can be done to make them more regular.
fn new_with_callback- Should be renamed to
with_callback. - Sometimes takes additional arguments.
- Should be renamed to
- Invoking sometimes implicitly finishes building. E.g. building continues when an expr is built for
ConstBuilder, but building ends when a type is built. fn buildsometimes takes additional arguments.- All use of
To...traits can be replaced withstd::convert::Into.
@pczarn: I addressed your first comment in #49.
- The cases where these constructors take an argument are for
idandname, and etc, that need to be always provided. Think it'd be better if we just hadwith_nameandwith_name_and_callback? - You're right,
ConstBuilderis a bit funny. It should probably be changed to just have a type then an expression, as inbuilder().const().i32().i32(5)or with names:
builder().const()
ty().i32()
expr().i32(5)
buildtaking additional arguments was a naming issue. Sometimes you have something that takes an arbitrary number of items, like the slice builder. Then it makes sense to have a.build()to close off the structure. But then other times you might have already made an expression and you want to pass it in, but that expression closes off the structure. Do you have a better name than.build(expr)?- I don't think I can use
To...because both the types and theIntotrait don't exist in my library :(