This is the second of three lectures on integrating domain-specific languages with general-purpose programming languages. In particular, SQL for database queries. This lecture presented LINQ, Language Integrated Query, together with some background on Microsoft’s .NET framework, and the language features added to C# to support LINQ.
The last lecture showed how established frameworks like JDBC for accessing databases from programs do this by building SQL queries through string manipulation. This fails to take advantage of the rich high-level structure of SQL as a language: missing opportunities for static checking, compile-time optimization. It is also the root cause of the security vulnerabilities by SQL injection, as sanitizing user input becomes essential but also difficult.
SQL queries are programs in a structured high-level language, but we treat them as unstructured text.
This lecture looked at LINQ, Language Integrated Query, a recent addition to the Microsoft .NET framework that begins to bridge this gap between languages. There was some background on the nature of .NET, and in particular its approach to supporting development in multiple programming languages. Treating LINQ in particular, there was a direct comparison of query construction in JDBC/ADO.NET (with strings) and in LINQ (with structured data). LINQ exposes queries to static checking, IDE support and compile-time optimization by making them part of the host language.
This language/query integration goes deep: queries become meaningful data structures in the host language, not just raw strings of syntax.
Creating LINQ, though, required various extensions to the C# language. We briefly looked through them: lambda expressions; free-standing method declarations; structural datatypes; anonymous record types; and type inference. These are new to C#, but based on well-established concepts from other existing languages. Moreover, all are useful in other contexts, and genuinely enrich the programming language. In particular, LINQ uses first-class expressions, which lead into structured reflection and metaprogramming, the topics of the next lecture.
Link: Slides
Homework
Read the “Introduction to LINQ” piece from this MSDN Library text:
- Visual Studio 2010: LINQ (Language-Integrated Query)
http://msdn.microsoft.com/en-gb/library/bb397926.aspx
Tuesday’s lecture will be about metaprogramming in F#:
- Find an online tutorial about F#
- Post its URL as a comment below
Further Reading
The final slide from the lecture contains additional references which you might find useful.
quick f# introduction: http://en.wikibooks.org/wiki/F_Sharp_Programming/Basic_Concepts
As an introduction, I thought this was a bit indigestible — after all, it starts with a table of sixteen different basic datatypes. The later chapters, on specific language features, seem much more approachable, like this one:
https://secure.wikimedia.org/wikibooks/en/wiki/F_Sharp_Programming/Values_and_Functions
http://msdn.microsoft.com/en-us/fsharp/ff759495.aspx#FT
The tutorial video provided by Microsoft. I find the one at the bottom quite useful because the speaker is the creator of the language.
Video, excellent. There are videos of interviews with Don Syme here:
http://fsharpnews.blogspot.com/2010/10/introduction-to-f-with-don-syme-part-1.html
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
but it seems that not so many programmer are using f# now though it is provided as one of the main languages in vs2010.
You’re right that the numbers aren’t huge. The drop in ranking might be because it did have a surge about a year ago, when entry into VS2010 was becoming well known:
http://www.itjobswatch.co.uk/jobs/uk/fsharp.do
Remember, this is a language that until this year wasn’t commercially supported anywhere at all.