C#7 – Design Meeting Notes for Jan 21, 2015

Working with data

Today’s programs are connected and trade in rich, structured data: it’s what’s on the wire, it’s what apps and services produce, manipulate and consume.

Traditional object-oriented modeling is good for many things, but in many ways it deals rather poorly with this setup: it bunches functionality strongly with the data (through encapsulation), and often relies heavily on mutation of that state. It is “behavior-centric” instead of “data-centric”.

Functional programming languages are often better set up for this: data is immutable (representing information, not state), and is manipulated from the outside, using a freely growable and context-dependent set of functions, rather than a fixed set of built-in virtual methods. Let’s continue being inspired by functional languages, and in particular other languages – F#, Scala, Swift – that aim to mix functional and object-oriented concepts as smoothly as possible.

Here are some possible C# features that belong under this theme:

  • pattern matching
  • tuples
  • “denotable” anonymous types
  • “records” – compact ways of describing shapes
  • working with common data structures (List/Dictionary)
  • extension members
  • slicing
  • immutability
  • structural typing/shapes?

A number of these features focus on the interplay between “kinds of types” and the ways they are used. It is worth thinking of this as a matrix, that lets you think about language support for e.g. denoting the types (type expressions), creating values of them (literals) and consuming them with matching (patterns)

Continue reading “C#7 – Design Meeting Notes for Jan 21, 2015”

Download 50+ e-books on popular technologies for free from Syncfusion!

All e-books are in Amazon Kindle and PDF formats

The download link is at the bottom of this page 

Cassandra Succinctly
by Marko Švaljek

Step outside the relational world and learn how to store data with Apache Cassandra, the massively popular NoSQL distributed database system.

Directory Enabled Applications Succinctly
by Giancarlo Lelli

Easily manage network resources by automating tasks.

PowerPivot Succinctly
by James Beresford

Take control of vast amounts of data using an easy-to-learn tool found within Microsoft Excel.

CUDA Succinctly
by Chris Rose

Use that high-end graphics card for more than games—use it to run massively parallel operations with CUDA, NVIDIA’s technology for programming with its hardware.

Microsoft Unity Succinctly
by Ricardo Peres

Incorporate Microsoft Unity when writing enterprise applications.

Continue reading “Download 50+ e-books on popular technologies for free from Syncfusion!”

Visual Studio and Git

So it happens that the company I started working for yesterday uses Git for all their source control needs. Having heard a lot of positive stuff about Git, but having no experience of actually using it,I had to dig around to find some decent integration tools that work well with Visual Studio 2013.

To my surprise, as of Visual Studio 2012.2, Microsoft already supports Git (I had to double check this and pinch myself!) There are Visual Studio Tools for Git available for download directly from Microsoft and there is quite a chunky write up Getting Started with Git in Visual Studio and Team Foundation Service

Will try it out at work today!

C#6 – String interpolations

String interpolation lets you more easily format strings. String.Format and its cousins are very versatile, but their use is somewhat clunky and error prone. Particularly unfortunate is the use of numbered placeholders like {0} in the format string, which must line up with separately supplied arguments:

var s = String.Format("{0} is {1} year{{s}} old", p.Name, p.Age);

String interpolation lets you put the expressions right in their place, by having “holes” directly in the string literal:

var s = "\{p.Name} is \{p.Age} year{s} old";

Just as with String.Format, optional alignment and format specifiers can be given:

var s = "\{p.Name,20} is \{p.Age:D3} year{s} old";

The contents of the holes can be pretty much any expression, including even other strings:

var s = "\{p.Name} is \{p.Age} year\{(p.Age == 1 ? "" : "s")} old";

Notice that the conditional expression is parenthesized, so that the ‘: “s”’ doesn’t get confused with a format specifier.

Note: This describes the syntax that works in the Preview. However, they have decided to change the syntax, to even better match that of format strings. In a later release you’ll see interpolated strings written like this:

var s = $"{p.Name,20} is {p.Age:D3} year{{s}} old";

They are adding a scheme so that you can influence the formatting behavior; e.g. to use Invariant Culture.

Some Rx goodness

The observer pattern

In .NET 4 Microsoft introduced the IObserver<T> and IObservable<T> interfaces. These interfaces give you a generic way of providing push-based notification, which is also known as the observer pattern. The provider (IObservable<T>) must implement a Subscribe method, which lets the caller indicate it wants to receive push-based notifications. The caller passes an instance of the observer. The observer (IObserver<T>) must implement three methods (OnNext, OnError and OnCompleted) which the provider calls to send different kinds of notifications.

For slightly more detail and some simple examples, take a look at the interfaces for IObservable<T> andIObserver<T> in the msdn documentation.

A quick and high level overview of Rx

The Reactive Extensions libraries from Microsoft provide implementations of the interfaces outlined above. Rx uses LINQ to allow incredibly powerful but simple and declarative solutions to complex problems, when dealing with sequences of events. It is available as a number of different packages on NuGet. To install them all, look for Rx-Main. There is also an “Extensions for Reactive Extensions” package available on NuGet, called Rxx. This provides many more useful Reactive LINQ extensions that aren’t in the main Rx library from Microsoft.

View original

Entity Framework 7

The first thing to know about EF7 is that, like EF6, it’s open source. But rather than being developed on CodePlex, EF7 is on GitHub, along with the rest of the upcoming version of ASP.NET. The URL for EF7 development is github.com/aspnet/EntityFramework. As with EF6, you’ll be able to see the details of EF7 as it evolves. You can explore the source, as well as its progress through branches and commits, follow the discussions, raise issues, fork the source, and submit pull requests for the team to examine and potentially commit to the code base.

Here’s the high-level view of what’s exciting in EF7:

  • Support for non-relational data stores and even in-memory data for testing.
  • Support for machines and devices that don’t use the full .NET Framework. This means you can use EF7 in Windows Phone and Windows Store apps, as well as on Linux and Macintosh machines that are running Mono.
  • Support for many features that developers have requested but couldn’t be achieved with the existing code base.
  • Continued support for applications that use the full .NET Framework such as Windows Presentation Foundation and other client applications.
  • EF7 will be distributed in the same manner as ASP.NET 5 and can be used with ASP.NET 5 apps.

View Original

Understanding TypeScript

In many ways, it’s useful to think of TypeScript on its own merits. The TypeScript language specification refers to TypeScipt as “a syntactic sugar for JavaScript.” That’s true and probably an essential step in reaching to the language’s target audience—client-side developers currently using JavaScript.

And you do need to understand JavaScript before you can understand TypeScript. In fact, the language specification (you can read it at bit.ly/1xH1m5B) often describes TypeScript constructs in terms of the resulting JavaScript code. But it’s equally useful to think of TypeScript as a language on its own that shares features with JavaScript.

For example, like C#, TypeScript is a data-typed language, which gives you IntelliSense support and compile-time checking, among other features. Like C#, TypeScript includes generic and lambda expressions (or their equivalent).

But TypeScript, of course, is not C#. Understanding what’s unique about TypeScript is as important as understanding what TypeScript shares with the server-side language you’re currently using. The TypeScript type system is different (and simpler) than C#. TypeScript leverages its understanding of other object models in a unique way and executes inheritance differently than C#. And because TypeScript compiles to JavaScript, TypeScript shares many of its fundamentals with JavaScript, unlike C#.

View Original

Blog at WordPress.com.

Up ↑