10

Do not go gentle into that impure night

 4 years ago
source link: https://impure.fun/fun/2021/01/11/fable-validation-blocks/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Do not go gentle into that impure night — impure.fun · Mostly for profit
         ༶・・ ᗰદ૨૨y  ᘓમ૨ıડτന੨ડ ・・༶

                    F#
                    /\
          F#       /|>\       F#
          /\      / |> \      /\
         />=\     /"%A"\     />>\
        /"%d"\   /()->`a\   /"%i"\
~~~~~~~~~ [] ~~~ ``[||]`` ~~~ [] ~~~~~~~~~
~~~~~~~~~~~~~~~~~~~[||]~~~~~~~~~~~~~~~~~~~

Functional code for humans

Home

About F# ad astra series

Do not go gentle into that impure night

11 Jan 2021

splash

Don't miss the live demo link at the bottom of the article, it's juicy stuff 👇

If there’s anything worse than writing javascript, it’s having to read the javascript that you write. Thanks to Fable, you can write javascript that you don’t have to read, indeed you don’t even have to write it.

Similarly, FSharp.ValidationBlocks allows you to validate things without writing any validation code, only rules. Yes, you can try to do validation without it, but like going to the toilet without toilet paper, it’s possible but it can be messy.

Thanks, I’ll take both ✌

You’d be forgiven for trying to combine them like Voltron as web apps often display forms that require validation. Unfortunately the reflection that makes FSharp.ValidationBlocks magical also made it incompatible with Fable.

No happy ending? 💔

But hold on for a second - in a plot twist that everybody saw coming - these things can be used together now, and all it took was adding .Fable to the namespace FSharp.ValidationBlocks making a new namespace FSharp.ValidationBlocks.Fable. How did I not think of this before!

Should I try it?

I don’t know, let’s see:

  • Does doing proper ROP validation without writing a single Result<string, string list> sound good to you?
  • Is having all your guaranteed-to-be-valid types defined with as little as 3 lines of code music to your ears?
  • Does not having to think where validation rules go or remembering to check them appeal to you?

I’m going to stop now because I ran out of sound metaphors, but the point is, yes, you should definitely try it, and thanks to Fable now there’s a live demo 🎁! So meta…

Disclaimer

Don’t get triggered by my throwing shade at javascript, it’s just for comedic purposes, I have a lot of respect for that language that got many things right from the beginning.

© 2021 Luis Ferrao — Powered by Jekyll & Poole


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK