Skip to content
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

New vs Create, and other API cleanups, and Instantiating Numbers #58

Open
pascallouisperez opened this issue Jan 28, 2018 · 5 comments
Open
Milestone

Comments

@pascallouisperez
Copy link
Contributor

pascallouisperez commented Jan 28, 2018

Renames

  • Remove NewValue and replace it instead by a NewNumber of some sort -- see below. Right now, because we have NewUndefined, NewText, and NewBool, the generic helper NewValue is used only to create numbers;
  • Rename NewDefinitions to ParseDefinitions to more clearly indicate what's involved;
  • Rename NewWorksheet to CreateWorksheet to differentiate it from creating new values: worksheets can be mutated and have a lifecycle, whereas undefined/text/bool/number are immutable values.
  • Rename NewStore to NewDbStore because it creates a *DbStore. (We could imagine having a FileStore at some point, or similar.)

Instantiating Numbers
Provide two constructors which are guaranteed not to panic, plus the constructor from string:

  1. func NewNumberFromInt(int64) *Number
  2. func NewNumberFromFloat(float64) *Number
  3. func NewNumberFromString(string) (*Number, error)

Here is a quick survey of the Golang world of arbitrary-precision math libraries which informed the suggestion above:

  • apd offers
    • func New(coeff int64, exponent int32) *Decimal
    • func NewFromString(s string) (*Decimal, Condition, error)
    • func NewWithBigInt(coeff *big.Int, exponent int32) *Decimal
  • math/big offers
    • func NewFloat(x float64) *Float
    • func NewInt(x int64) *Int
    • func NewRat(a, b int64) *Rat
  • decimal offers
    • func New(value int64, exp int32) Decimal
    • func NewFromBigInt(value *big.Int, exp int32) Decimal
    • func NewFromFloat(value float64) Decimal
    • func NewFromFloatWithExponent(value float64, exp int32) Decimal
    • func NewFromString(value string) (Decimal, error)
@pascallouisperez pascallouisperez added this to the 0.2 milestone Jan 28, 2018
@cbelsole
Copy link
Contributor

For the func NewInt(int64) *Number consider func NewNumberFromInt64(int64) *Number since you are returning a Number and it shares a package with multiple types and FromInt64 since that leaves you open to create func NewNumber(int) *Number as a default. That also sets the func NewNumber(string) (*Number, error) to be func NewNumberFromString(string) (*Number, error) and func NewNumberFromFloat64(float64) *Number respectively.

@pascallouisperez
Copy link
Contributor Author

+1 @cbelsole thanks!

@pascallouisperez
Copy link
Contributor Author

Some updates:

@pascallouisperez
Copy link
Contributor Author

Looking at this a few months later, not a fan of ParseDefinitions: it's not just parsing, it's also some level of semantic interpretation (e.g. no duplicate names, options wiring, some type checking, etc). Maybe LoadDefinitions, or CompileDefinitions?

Some inspirations

@pascallouisperez
Copy link
Contributor Author

We're going to go with LoadDefinitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants