4 ms·
This is one of the cases where I like languages that allow extendable types. Being able to declare that a variable is in radians, for example. (Bonus points if
by TheLoneWolfling 12y ago
This is one of the cases where I like languages that allow extendable types.
Being able to declare that a variable is in radians, for example. (Bonus points if it can auto-convert.)
- NateDad 12y agoGo can do this easily: type Radians float type Degrees float func (r Radians) ToDegrees() Degrees { // maths here }
- sukilot 12y agoThat's not auto convert. Scala implicit is auto convert.
- NateDad 12y 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 12y 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.
- strictfp 12y agoSounds interresting! Could you provide a link? Can't seem to find anything relevant.
- TheLoneWolfling 12y agoFor a quick example, take C: typedef rad_f float; typedef degree_f float; Although in C there's no way that I know of to do implicit conversion between the two. The closest thing I've found to what I mean is C#'s implicit cast system: http://nathan.ca/2014/02/type-rich-programming/ http://nathan.ca/2014/02/type-rich-programming/
- strictfp 11y agoThanks for the response. I was more thinking about languages which have mechanisms for this though. What did you mean by extendable types?