aster icon indicating copy to clipboard operation
aster copied to clipboard

API consistency

Open pczarn opened this issue 10 years ago • 1 comments

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.
  • 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 build sometimes takes additional arguments.
  • All use of To... traits can be replaced with std::convert::Into.

pczarn avatar Sep 26 '15 09:09 pczarn

@pczarn: I addressed your first comment in #49.

  • The cases where these constructors take an argument are for id and name, and etc, that need to be always provided. Think it'd be better if we just had with_name and with_name_and_callback?
  • You're right, ConstBuilder is a bit funny. It should probably be changed to just have a type then an expression, as in builder().const().i32().i32(5) or with names:
builder().const()
  ty().i32()
  expr().i32(5)
  • build taking 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 the Into trait don't exist in my library :(

erickt avatar Nov 02 '15 19:11 erickt