Hi again,
On 27/03/2024 00:40, Saki Takamachi wrote:
Do we also need `toFloat` and `toInt` functions? Seems like using explicit
functions will be safer than casting.
For toInt I'd expect an exception if the value is outside the range of possible
ints. For toFloat it might be nice to have a flag
argument to give the developer the choice of having it throw if the value is
outside the range of floats or return INF or -INF,
or possibly the user should just check for infinite values themselves.
I was thinking about those features too. However, I'm concerned that proposing
too many features will complicate the RFC and make it difficult to get it
approved.
Coming back to this point, I think these are basic features that people
would expect to be there - I think I would find just slightly
frustrating to start learning how to use a class like this and then
find that it doesn't have these functions. Casting and calling `intval`
or `floatval` all feel like slightly awkward workarounds that shouldn't
be needed in a greenfield project. We know that the string
inside the object is always a numeric string, so it should be easier to
parse it as an int than to parse it as a date or a JSON document. Code
doing the latter should stand out as odd looking.