Professional Development – 2024 – Week 42

Image Credit: https://www.flickr.com/photos/54585499@N04/

.NET

You’re Doing Validation Wrong in .NET – Code Cop #023 (via Nick Chapsas)

The two types of validation considered were (1) method that returns bool if valid, and (2) method that returns IEnumerable<string> with the list of errors. Nick’s hang-ups were (1) a list was allocated, (2) not returning upon first failure (i.e., fail fast) means that extra work needs to be done — possibly API calls — to finish the validation. He considers both of the approaches “very, very bad.” His first round of suggestions… (1) make the validation method static, and have the return type be ValidationResult. His second suggestion was to use the LanguageExt.Core NuGet package which has a discriminated union called Validation.