Re:Destroy All Ifs – A Perspective from Functional Programming
by buffyoda on Saturday July 16, 2016 @10:54PM
(#12108837)
That helps quite a lot, although for several, it's more programming-by-name than programming-by-semantics.
I'd like to be able to say the end angle has to be less than the start angle, that the unit has to be radians (AKA unit-less :), the unit of radius & that negative values are sensical, and so forth; and have all these properties checked by a compiler.
Which I can do in some modern languages, surprisingly. :)
Re:Destroy All Ifs – A Perspective from Functional Programming
by lomnakkus on Sunday July 17, 2016 @02:17AM
(#12109211)
Assuming you're right about the guesses for those parameters, we could go a little further. Let's define
data Directionality = Clockwise | Anticlockwise
data AngularInterval = {
beginAngle :: Double,
endAngle :: Double,
directionality :: Directionality
}
... and then we're down to three parameters, all of different types (so no opportunity for mistakes, assuming static checking) and who knows, you might even have other uses for AngularInterval.
https://stackoverflow.com/questions/107243/are-units-of-meas...