C#

Understanding the Philosophy of LINQ

LINQ is Microsoft’s greatest gift to software developers ever.

Functional programming has been a sweet spot for emerging trends in software development for years. And I agree that functional programming will become even more important during the coming years as Moore’s law fails.

But ever since I read Seven Languages in Seven Weeks by Bruce A. Tate and its section on Prolog I’ve had another paradigm in mind for the future, declarative programming. Speaking more to the correctness of the question than the answer, declarative programming is the essence of what a good SQL query should be, a concise, complete question about the nature of the universe. And through math I do not need to memorize or conjure on demand, the answer is available quickly (if the correct index was created).

This is the beauty of LINQ. It is declarative. It is functional. It is the past. It is the future.

The declarative SQL-like nature of LINQ is obvious to anyone who’s looked at the Query syntax of LINQ. Perhaps a little better organized for app developers who want to think of how it is done instead of the question first, the FROM, WHERE, and SELECT clauses are all there for us to see in nearly unadulterated SQL-esque glory. The method syntax uses names that are no different, but it becomes much clearer that this is also a functional style as well. Particularly when we see a simple translation puts all the terms into their more common functional programming clothes.

Aggregate -> Reduce
Where -> Filter
Select -> Map

Combined with C# lambda notation to express and create functional concepts, it is rare day that I pull out any of the imperative looping structures I was taught in school. By redressing functional concepts in SQL syntax, LINQ is approachable in a way that functional libraries in other languages never will be. By embracing a functional style we allow parallelization to kick Moore’s law down the road for a couple more decades. By (re)embracing declarative programming, we acknowledge that all we were ever doing was just math that usually didn’t need to memorize, just encode once in a compiler, optimize, and trust.

Now we can stop focusing on getting the correct answers, and start asking what are the correct questions.