concept expression in category .net

appears as: expressions, expression, n expression, expression, expressions, The expression
Concurrency in .NET

This is an excerpt from Manning's book Concurrency in .NET.

This is an exciting time to learn to write multithreaded code, and it’s rewarding to improve the performance of your program with the functional programming (FP) approach. Functional programming is a programming style that treats computation as the evaluation of expressions and avoids changing-state and mutable data. Because immutability is the default, and with the addition of a fantastic composition and declarative programming style, FP makes it effortless to write concurrent programs. More details follow in section1.5.

The methods that run asynchronously are bound to a different construct that uses the ! (pronounced bang) operator, which is the essence of an asynchronous workflow because it notifies the F# compiler to interpret the function in an exclusive way. The body of a let! binding registers the expression as a callback, in context for future evaluation to the rest of the asynchronous workflow, and it extracts the underlying result from Async<'T>.

In the expression

Listing 9.9 Async.Start
let computationUnit() = async {   #1  
    do! Async.Sleep 1000
    use client = new WebClient()
    let! manningSite =     
         client.AsyncDownloadString(Uri("http://www.manning.com"))
 printfn "Size %d" manningSite.Length   #2  
    } 
Async.Start(computationUnit())   #3  

#1   Creates an asynchronous computation to download a website, with a one-second delay to simulate heavy computation
#2   Prints the website’s size from inside the body of the expression
#3   Runs the computation without blocking the caller thread

Because Async.Start doesn’t support a return value, the size of the website is printed inside the expression, where the value is accessible. What if the computation does return a value, and you cannot modify the asynchronous workflow? It’s possible to discharge the result from an asynchronous computation using the Async.Ignore function before starting the operation.

C# in Depth

This is an excerpt from Manning's book C# in Depth.

The important point is that this code is much more compact and readable (once you understand the syntax, of course). We wanted the list ordered by name, and that’s exactly what the code says. It doesn’t say to sort by comparing the name of one product with the name of another, like the C# 2 code did, or to sort by using an instance of another type that knows how to compare one product with another. It just says to order by name. This simplicity of expression is one of the key benefits of C# 3. When the individual pieces of data querying and manipulation are so simple, larger transformations can remain compact and readable in one piece of code. That, in turn, encourages a more data-centric way of looking at the world.

(explicitly-typed-parameter-list) => expression

LINQ to SQL is capable of translating a wide range of expressions. Let’s try a slightly more complicated query from chapter 11, just to see what SQL is generated.

IronPython in Action

This is an excerpt from Manning's book IronPython in Action.

If you enter an expression, the resulting value will be printed to the console. The result of the last expression, whether value or object, is available in the interpreter by using the underscore (_). If you can’t find a calculator, then you can always turn to the Python interpreter instead.

At last you’ve reached the end of the section devoted to the basic datatypes. It’s time to move from the mortar to the bricks. Functions and classes contain code, which uses the basic types. This code will be comprised of statements and expressions, so the first part of the section on basic constructs will cover these.

2.2.1. Statements and expressions

Python draws a distinction between statements and expressions. This wouldn’t be true in a purely functional programming language where everything is an expression.