Skip to main content

2014 | Buch

Thinking in LINQ

Harnessing the power of functional programing in .NET applications

insite
SUCHEN

Über dieses Buch

LINQ represents a paradigm shift for developers used to an imperative/object oriented programming style, because LINQ draws on functional programming principles. Thinking in LINQ addresses the differences between these two by providing a set of succinct recipes arranged in several groups, including:

Basic and extended LINQ operatorsText processing Loop refactoring Monitoring code health Reactive Extensions (Rx.NET)Building domain-specific languages

Using the familiar "recipes" approach, Thinking in LINQ shows you how to approach building LINQ-based solutions, how such solutions are different from what you already know, and why they’re better. The recipes cover a wide range of real-world problems, from using LINQ to replace existing loops, to writing your own Swype-like keyboard entry routines, to finding duplicate files on your hard drive. The goal of these recipes is to get you "thinking in LINQ," so you can use the techniques in your own code to write more efficient and concise data-intensive applications.

Inhaltsverzeichnis

Frontmatter
Chapter 1. Thinking Functionally
Abstract
As you begin this book, I urge you to forget everything you know about programming and bear with me while I walk you through a high-level view of what I think programming is. To me, to program is to transform. I’ll give you a few simple examples to explain my viewpoint.
Sudipta Mukherjee
Chapter 2. Series Generation
Abstract
LINQ helps you generate series by using intuitive and readable code. In this chapter, you will see how to use several LINQ standard query operators (LSQO) to generate common mathematical and recursive series. All these queries are designed to run on LINQPad ( www.linqpad.net ) as C# statements.
Sudipta Mukherjee
Chapter 3. Text Processing
Abstract
Text processing is a blanket term used to describe any kind of string processing. Checking whether a pair of words are anagrams of each other is one example of text processing. Generating suggestions for an autocomplete or assisted input process is another. Some types of text processing, such as spell-check and correction features, have become so commonplace that software users now expect them to be present in virtually every program they use.
Sudipta Mukherjee
Chapter 4. Refactoring with LINQ
Abstract
When I help my colleagues refactor their loops by using LINQ, they always ask me, “How do you know what LINQ operator to use?” I am sure my colleagues are not alone. This chapter is dedicated to providing detailed examples to help answer that question.
Sudipta Mukherjee
Chapter 5. Refactoring with MoreLINQ
Abstract
In the preceding chapter, you saw how LINQ can help replace existing loops. Loop constructs can sometimes range from difficult to impossible to comprehend, especially when nested. This chapter extends the loop-to-LINQ replacement concept by showing how the open source LINQ API called MoreLINQ can help you refactor legacy code. By going beyond the core LINQ operators, the MoreLINQ API offers a wide range of operators that you can readily use to replace looping or looping/branching logic. After reading this chapter, you should be able to rewrite such code by using methods found in the MoreLINQ API.
Sudipta Mukherjee
Chapter 6. Creating Domain-Specific Languages
Abstract
Every domain has a language that helps practitioners communicate their thoughts easily. When a chef instructs a helper to sauté vegetables, both parties know what the term means. However, software solutions created for several domains using general-purpose, high-level programming languages such as C# or Java often quickly become difficult to maintain. Even only a few months later, the original authors of these solutions may find it difficult to remember how the code works so they can fix bugs.
Sudipta Mukherjee
Chapter 7. Static Code Analysis
Abstract
Programmers always tend to think that code and data are separate. However, for a general-purpose framework such as LINQ, code is also data. By taking advantage of LINQ and .NET Reflection, you can perform a great deal of static code analysis and gain a lot of insight into code. This chapter presents several LINQ scripts that will help you accrue knowledge about your code base.
Sudipta Mukherjee
Chapter 8. Exploratory Data Analysis
Abstract
Generalization is an extremely powerful concept when applied correctly. For example, in MATLAB even the most trivial addition is performed as a matrix addition. Data comes in many formats. Mostly these formats are not ready for analysis, so programmers, researchers, and data scientists often need to write a lot of data-wrangling code to get the data into a useful form. However, LINQ has changed the way programmers interact with data. LINQ works on the generalization that data is a list—of something. For example, you can think of a database table as a list of rows, an XML file as a list of nodes, a CSV file as a list of comma-delimited string arrays, and so on.
Sudipta Mukherjee
Chapter 9. Interacting with the File System
Abstract
You can use LINQ as you would a scripting programming language to perform several types of file system analytics operations. For .NET developers, LINQ can be as useful as PowerShell—in fact, sometimes even better, because when using LINQ, developers can still leverage all the other benefits that the host language has to offer (C# in this case).
Sudipta Mukherjee
Chapter 10. Lean LINQ Tips
Abstract
LINQ allows users to query any data source in a unified way. However, even with the LINQ standard query operators, used to create these queries, it’s easy to misuse these operators unless you have a solid understanding of how they work internally. Such misuse leads to inefficient queries that are slower —in some cases much slower—than the equivalent properly tuned query.
Sudipta Mukherjee
Chapter 11. Taming Streaming Data with Rx.NET
Abstract
Developers now have access to more streaming data than ever before. Much of this data originates from sensors connected to the Internet. These sensors continually post the data they collect.
Sudipta Mukherjee
Backmatter
Metadaten
Titel
Thinking in LINQ
verfasst von
Sudipta Mukherjee
Copyright-Jahr
2014
Verlag
Apress
Electronic ISBN
978-1-4302-6844-4
Print ISBN
978-1-4302-6845-1
DOI
https://doi.org/10.1007/978-1-4302-6844-4