DEV Community

Discussion on: Pitch me on the pros and cons of your preferred web app framework

 
mrjjwright profile image
John Wright

Thank you so much for the full response! This data over protection angle is an interesting one that I had not heard in quite the way you are putting it.

Thread Thread
 
kspeakman profile image
Kasey Speakman • Edited

You are welcome.

I've also seen people get really hung up by validation when switching from OO. Because we're accustomed to using the same mechanisms to "protect invariants" as we do to defend mutable data. We can intercept every new object (in constructor) and data change (in methods) to protect those invariants. Coming to FP and records, consumers set the data directly. Specifically in F#, record constructors and the built-in update syntax are not interceptable. So when someone suggests "just make a validation function", this feels like it can't possibly be sufficient by comparison.

But it is. And it is a cleaner separation of concerns. Sometimes consumers want the ability to use invalid data. Like representing what the user typed, even when its not yet fit for submission. I can use the validation function to make sure invariants hold. Without having to care how it was constructed or changed before it got to me. The consumer can also use this function to know if it's Ok to send.

Thread Thread
 
mrjjwright profile image
John Wright

I thought this might be underlying what you were saying, that makes great sense.