3 ms·
Go can do this easily: type Radians float type Degrees float func (r Radians) ToDegrees() Degrees { // maths here }
by NateDad 11y ago
Go can do this easily:
type Radians float
type Degrees float
func (r Radians) ToDegrees() Degrees {
// maths here
}
- sukilot 11y agoThat's not auto convert. Scala implicit is auto convert.
- NateDad 11y agoAuto converting is an anti pattern. Explicit is better than implicit. Auto conversion is how mistakes get made. This is why modern languages don't let you implicitly convert from a string to an int, for example.
- TheLoneWolfling 11y agoThat's not what I mean by autoconverting. I meant as in quite literally being able to use something of type Radians in something that expects Degrees and it "just works", and vice versa. I dislike Go's overuse of "explicit being better than implicit", and this is no exception. It's supposedly to prevent bugs, but it adds so much more verbosity that half the time you're adding more bugs by the additional verbosity than you're fixing via the reduction of magic.