On Sat, Dec 9, 2017 at 9:03 PM,  <gavingro...@gmail.com> wrote:
>
> In the "math/big" package, the Rat, Int, and Float types only have methods
> that are attached to their pointer types, including the small handful of
> them that don't modify the type's data, such as String() and Text().
>
> func (x *Rat) String() { ... }
>
>
> Because I'm working with the contents directly instead of the pointers, this
> means when I print them I don't get the nicely formatted results:
>
> fmt.Println(big.NewRat(23, 17))  // 23/17 -- what I want
>
>
> fmt.Println(*big.NewRat(23, 17)) // {{false [23]} {false [17]}} -- what I
> get
>
>
> In order to get good formats, I've had to attach my own String() methods
> after naming the types to something else:
>
> type BigRat big.Rat
>
> func (br BigRat) String() { ... }
>
>
> This means I have to clutter my code with type conversions all over the
> place, making it look messy.
>
> Should the String() method really have been defined in the Go std lib
> directly on the Int, Rat, and Float types, instead of their pointer types?
> If not, why not? Maybe I'm misusing those types' intended purpose, although
> they work OK that way for me in all other respects.
>
> If so, will they be changed in the future, or would changing them break
> existing code out there?

It's definitely expected that people will simply use pointers for
these types.  Why do you find it useful to do otherwise?

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to