News for hackers. Stuff that matters.
Re:Destroy All Ifs – A Perspective from Functional Programming by greggman on Saturday July 16, 2016 @10:04PM (#12108719)
since I'm not a fp expert what about a function like

    ctx.arc(10, 20, 30, 0, 6.28, false);
There's nothing special about boolean. How do you encode all of those above into types in fp so that it's impossible to get them wrong and so they're self documenting? I hope you're not suggesting there be a horizontalFloat type and a verticalFloat type or are you?
Re:Destroy All Ifs – A Perspective from Functional Programming by GregBuchholz on Saturday July 16, 2016 @10:18PM (#12108760)
How about keyword parameters...

    ctx.arc(center=Point(10,20), radius=30, beginAngle=0, endAngle=6.28, Clockwise);
...and don't forget about units of measurement/dimensional analysis.

https://stackoverflow.com/questions/107243/are-units-of-meas...

    ctx.arc(center=Point(10cm,20cm), radius=30mm, beginAngle=0rad, endAngle=6.28rad, Clockwise);
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.
Re:Destroy All Ifs – A Perspective from Functional Programming by buffyoda on Saturday July 16, 2016 @10:52PM (#12108832)
I'm a big fan of the philosophy that "Every literal in a program is a bug." :)

But I know what you're getting at! Personally, I'm a fan of programming with units and dimensions, and safely representing the distinction between absolute quantities and relative quantities.

That doesn't mean I'd want an infinite number of "float" values for all possible units and dimensions, however; just a powerful enough type system I can give myself some help at compile-time for properly threading sensical values through my programs.

Re:Destroy All Ifs – A Perspective from Functional Programming by eru on Sunday July 17, 2016 @02:12AM (#12109200)
> "Every literal in a program is a bug."

But we use plenty of literals in our programs all the time. Eg lambdas are function literals. (And definitions of named functions are just a special case folding binding and a lambda.)