LINQ and Learning to Be Declarative
nickstambaugh.dev
LINQ and Learning to Be Declarative
1–10 of 60 posts
Re: LINQ and Learning to Be Declarative
#2I think C# is the best functional programming language because you always have access to a procedural code safety valve if the situation calls for it.
100% purity down the entire vertical is a very strong anti-pattern. You want to focus on putting the functional code where it is most likely to be wrong or cause trouble (your business logic). Worrying about making the underlying infrastructure functional is where I start to zone out.
Does F# care if a DLL it references was coded in a functional style?
Re: LINQ and Learning to Be Declarative
#3The final example has signature List but tries to return IOrderedEnumerable.
I recognise that this is very much a taster rather than even a full introduction, so the author didn't want to explain IOrderedEnumerable, but please when writing blogs, run through your code examples and make sure they compile.
This means that your audience can follow along.
( It just needs a .ToList() on the end. )
Re: LINQ and Learning to Be Declarative
#4If you're going to write code snippets, please make sure they compile! The final example has signature List but tries to return IOrderedEnumerable . I recognise that this is very much a taster rather than even a full introduction, so the author didn't want to explain IOrderedEnumerable , but please when writing blogs, run through your code examples and make sure they compile. This means that your audience can follow…
Re: LINQ and Learning to Be Declarative
#5Re: LINQ and Learning to Be Declarative
#6Fwiw in the final iteration I would still place each clause on a seperate line aligned by their leading '.' because I find it much easier to scan.
Re: LINQ and Learning to Be Declarative
#7Re: LINQ and Learning to Be Declarative
#8The author stating that the lambda is "better" because it's less lines is also silly. It's been a while since I've written C#, but pretty sure the SQL-like version can be formatted to a single line as well:
List GetExclusiveProducts(List source) => (from p in source where p.ProductTitle == "iPhone" orderby p.TypeOfPhone select p).ToList();
Re: LINQ and Learning to Be Declarative
#9Fwiw in the final iteration I would still place each clause on a seperate line aligned by their leading '.' because I find it much easier to scan.
Agreed. That's how I would write it in a professional codebase. I added it to show the transformation from separate functions -> LINQ one-liner. Cheers!
Re: LINQ and Learning to Be Declarative
#10If you're going to write code snippets, please make sure they compile! The final example has signature List but tries to return IOrderedEnumerable . I recognise that this is very much a taster rather than even a full introduction, so the author didn't want to explain IOrderedEnumerable , but please when writing blogs, run through your code examples and make sure they compile. This means that your audience can follow…
Thanks for the heads up, must've slipped my mind. Edit: fixed