Top “Must Know” Frameworks for Web Developers

Great article that lists popular tools used for web development with a short description of each.  Check it out.

http://tostring.it/2014/06/30/top-must-know-frameworks-for-net-web-developers/

Advertisements

.NET MultiDictionary

Check out the post below for an alpha release of MultiDictionary.

http://blogs.msdn.com/b/dotnet/archive/2014/06/20/would-you-like-a-multidictionary.aspx

Here’s a quick blurb showing how you would use MultiDictionary:

Introducing MultiDictionary

I could go into detail on the API and characteristics of MultiDictionary, but I’ll save that for later; let’s first look at some examples of typical usage for MultiDictionary.

MultiDictionary<string, int=""> myDictionary = new MultiDictionary<string, int="">();
myDictionary.Add("key", 1);
myDictionary.Add("key", 2);
myDictionary.Add("key", 3);
//myDictionary["key"] now contains the values 1, 2, and 3

When we index into our myDictionary, we get an ICollection<int> that contains the elements 1, 2, and 3. If the key wasn’t in the MultiDictionary, then an empty ICollection associated with that key will be returned.

All ICollection instances returned by indexing into the MultiDictionary function as indirections to the collections inside of our MultiDictionary, which means that as the MultiDictionary changes so does the ICollection and vice versa. Consider the following example that illustrates this:

MultiDictionary<string, int> myDictionary = new MultiDictionary<string, int>();
myDictionary.Add("key", 1);
ICollection myCollection = myDictionary["key"];
myCollection.Add(2);
//myCollection now contains the values 1, and 2

The MultiDictionary also has methods for adding or removing one key-value pair at a time as well as adding or removing multiple values per key.

MultiDictionary<string, int> myDictionary = new MultiDictionary<string, int>();
myDictionary.AddRange("key1", new int[] { 1, 2, 3 });
myDictionary.AddRange("key2", new int[] { 1, 2, 3 });
myDictionary.Remove("key1");
myDictionary.RemoveItem("key2", 2);
//myDictionary now contains key2 with values 1 and 3

There are a few more interesting and useful methods inside of the MultiDictionary, but I’ll let you explore those on your own!

C#.Net How To: Monitor Directory and files using C# FileSystemWatcher

http://a1ashiish-csharp.blogspot.com/2013/04/Csharp.Net-How-To-Monitor-Directory-and-files-using-Csharp-FileSyestemWatcher.html#.UYAKWOnwPpt.reddit

Understanding .NET Garbage Collection

http://blogs.telerik.com/justteam/posts/13-04-02/understanding-net-garbage-collection

Visual Studio Express 2012 Now Available for Desktop for Free

Visual Studio Express 2012 products provide free development tools for creating modern applications on the latest platforms.  Click here to download now.  Here’s more information I grabbed from the MSDN blog.

“It would be impossible to list every feature in Visual Studio Express 2012 for Windows Desktop. However, in this post I want to tell you about some of the new tools and capabilities in the product that have not been available in any other Express products in the past. I’d also like to answer some of the questions you’ve been asking about what we’re including in this edition. Unless otherwise mentioned, the features listed are supported for all languages that are included in Visual Studio Express 2012 for Windows Desktop – C++, C#, and Visual Basic.

Project Types

In Express for Windows Desktop, you’ll be able to create the same projects that you could in Visual Studio 2010 Express, for example, WinForms, WPF, Console and Class Libraries for Visual Basic and C#, and Win32 projects, class libraries, and CLR apps for C++. You can also combine C++, C#, and Visual Basic projects into a single solution, making it easy to write a single application using any of the available languages. Finally, you can round-trip your projects with Visual Studio 2010 SP1.

New Project dialog in Visual Studio Express 2012 for Windows Desktop

Unit Testing

We wanted to make it easy for you to write and run unit tests for your projects. To make that possible, Express for Windows Desktop includes our existing unit test framework for C# and Visual Basic and the new native C++ unit test framework. This lets you write, run and debug unit tests directly inside Visual Studio. Unit Test project templates are also included so you can start writing unit tests right away.

Unit Testing in Visual Studio Express 2012 for Windows Desktop

Code Analysis

We added a targeted set of code analysis rules to Express for Windows Desktop, which are the same code analysis rules that we added to Visual Studio Express 2012 for Windows 8. For C++ projects, these rules help detect common coding errors, such as buffer overflows, dereferencing null pointers, using uninitialized variables, or misusing APIs. These errors can potentially lead to security vulnerabilities or application crashes if the errors are not fixed. For managed projects we included rules that help ensure correct object disposal, comparison, and garbage collection performance.

Code Analysis in Visual Studio Express 2012 for Windows Desktop

TFS Integration

This release, we introduced Team Foundation Server Express 2012, as well as the Team Foundation Service atwww.tfspreview.com. We also included Team Explorer, which allows for integration with your TFS server into all of our Visual Studio 2012 Express products, including this one. We wanted to make it simple for you to use the source code control, work item tracking, and build automation that TFS provides.

Team Explorer in Visual Studio Express 2012 for Windows Desktop

Dependency Management with NuGet

Express for Windows Desktop includes NuGet, which makes it easier than ever to integrate libraries developed within your organization, or from 3rd parties, into your projects. To add or manage package dependencies for your projects, simply select the “Manage NuGet packages…” option from the project, or from the solution context menu in Solution Explorer.

NuGet in Visual Studio Express 2012 for Windows Desktop

Language specific features

The new VS 2012 language and library features are available in Visual Studio Express 2012 for Windows Desktop, including the async and await keywords in Visual Basic and C#, C++ AMP, and improvements to C++ 11 Standards conformance.

You can use Express for Windows Desktop with your Visual Basic and C# applications to target both .NET 4.0 and 4.5.

We also included the C++ 64-bit cross-compiler and libraries, so you can build 64-bit desktop applications without needing to install an older version of the Windows SDK.

Data Connections

In previous Express products, the ability to connect to a data source was limited to Database File. In Express for Windows Desktop, this capability has been extended to support all SQL Server data sources. For example, in Database Explorer, you can connect, navigate, query against and edit database objects through the latest SQL Server 2012 and Windows Azure SQL Databases.”

Check out the blog link below for more information.  And of course, there’s also free express editions for Web, Windows 8, & Team Foundation Server.

http://blogs.msdn.com/b/visualstudio/archive/2012/09/12/visual-studio-express-2012-for-windows-desktop-is-here.aspx

Free Microsoft Book: Patterns for Parallel Programming: Understanding and Applying Parallel Patterns with the .NET Framework 4

 

Thought I’d share in case you don’t already have this.  Has lots of examples and is pretty thorough.

Patterns for Parallel Programming: Understanding and Applying Parallel Patterns with the .NET Framework 4

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=19222

 

Here’s the Overview:

This document provides a detailed and in-depth tour of support in the Microsoft® .NET Framework 4 for parallel programming. This includes an examination of common parallel patterns and how they’re implemented without and with this new support in the .NET Framework, as well as covering best practices for developing parallel components utilizing parallel patterns.

 

C# .NET Collection Classes

The .NET Base Class Library (BCL) has a wide array of collection classes at your disposal which make it easy to manage collections of objects. While it’s great to have so many classes available, it can be daunting to choose the right collection to use for any given situation. As hard as it may be, choosing the right collection can be absolutely key to the performance and maintainability of your application!

This post will look at breaking down any confusion between each collection and the situations in which they excel. We will be spending most of our time looking at the System.Collections.Generic namespace, which is the recommended set of collections.

The Generic Collections: System.Collections.Generic namespace

The generic collections were introduced in .NET 2.0 in the System.Collections.Generic namespace. This is the main body of collections you should tend to focus on first, as they will tend to suit 99% of your needs right up front.

It is important to note that the generic collections are unsynchronized. This decision was made for performance reasons because depending on how you are using the collections its completely possible that synchronization may not be required or may be needed on a higher level than simple method-level synchronization. Furthermore, concurrent read access (all writes done at beginning and never again) is always safe, but for concurrent mixed access you should either synchronize the collection or use one of the concurrent collections.

So let’s look at each of the collections in turn and its various pros and cons, at the end we’ll summarize with a table to help make it easier to compare and contrast the different collections.

The Associative Collection Classes

Associative collections store a value in the collection by providing a key that is used to add/remove/lookup the item. Hence, the container associates the value with the key. These collections are most useful when you need to lookup/manipulate a collection using a key value. For example, if you wanted to look up an order in a collection of orders by an order id, you might have an associative collection where they key is the order id and the value is the order.

The Dictionary is probably the most used associative container class. The Dictionary is the fastest class for associative lookups/inserts/deletes because it uses a hash table under the covers. Because the keys are hashed, the key type should correctly implement GetHashCode() and Equals() appropriately or you should provide an external IEqualityComparer to the dictionary on construction. The insert/delete/lookup time of items in the dictionary is amortized constant time – O(1) – which means no matter how big the dictionary gets, the time it takes to find something remains relatively constant. This is highly desirable for high-speed lookups. The only downside is that the dictionary, by nature of using a hash table, is unordered, so you cannot easily traverse the items in a Dictionary in order.

The SortedDictionary is similar to the Dictionary in usage but very different in implementation. The SortedDictionary uses a binary tree under the covers to maintain the items in order by the key. As a consequence of sorting, the type used for the key must correctly implement IComparable so that the keys can be correctly sorted. The sorted dictionary trades a little bit of lookup time for the ability to maintain the items in order, thus insert/delete/lookup times in a sorted dictionary are logarithmic – O(log n). Generally speaking, with logarithmic time, you can double the size of the collection and it only has to perform one extra comparison to find the item. Use the SortedDictionary when you want fast lookups but also want to be able to maintain the collection in order by the key.

The SortedList is the other ordered associative container class in the generic containers. Once again SortedList, like SortedDictionary, uses a key to sort key-value pairs. Unlike SortedDictionary, however, items in a SortedList are stored as an ordered array of items. This means that insertions and deletions are linear – O(n) – because deleting or adding an item may involve shifting all items up or down in the list. Lookup time, however is O(log n) because the SortedList can use a binary search to find any item in the list by its key. So why would you ever want to do this? Well, the answer is that if you are going to load the SortedList up-front, the insertions will be slower, but because array indexing is faster than following object links, lookups are marginally faster than a SortedDictionary. Once again I’d use this in situations where you want fast lookups and want to maintain the collection in order by the key, and where insertions and deletions are rare.

The Non-Associative Containers

The other container classes are non-associative. They don’t use keys to manipulate the collection but rely on the object itself being stored or some other means (such as index) to manipulate the collection.

The List is a basic contiguous storage container. Some people may call this a vector or dynamic array. Essentially it is an array of items that grow once its current capacity is exceeded. Because the items are stored contiguously as an array, you can access items in the List by index very quickly. However inserting and removing in the beginning or middle of the List are very costly because you must shift all the items up or down as you delete or insert respectively. However, adding and removing at the end of a List is an amortized constant operation – O(1). Typically List is the standard go-to collection when you don’t have any other constraints, and typically we favor a List even over arrays unless we are sure the size will remain absolutely fixed.

The LinkedList is a basic implementation of a doubly-linked list. This means that you can add or remove items in the middle of a linked list very quickly (because there’s no items to move up or down in contiguous memory), but you also lose the ability to index items by position quickly. Most of the time we tend to favor List over LinkedList unless you are doing a lot of adding and removing from the collection, in which case a LinkedList may make more sense.

The HashSet is an unordered collection of unique items. This means that the collection cannot have duplicates and no order is maintained. Logically, this is very similar to having a Dictionary where the TKey and TValue both refer to the same object. This collection is very useful for maintaining a collection of items you wish to check membership against. For example, if you receive an order for a given vendor code, you may want to check to make sure the vendor code belongs to the set of vendor codes you handle. In these cases a HashSet is useful for super-quick lookups where order is not important. Once again, like in Dictionary, the type T should have a valid implementation of GetHashCode() and Equals(), or you should provide an appropriate IEqualityComparer to the HashSet on construction.

The SortedSet is to HashSet what the SortedDictionary is to Dictionary. That is, the SortedSet is a binary tree where the key and value are the same object. This once again means that adding/removing/lookups are logarithmic – O(log n) – but you gain the ability to iterate over the items in order. For this collection to be effective, type T must implement IComparable or you need to supply an external IComparer.

Finally, the Stack and Queue are two very specific collections that allow you to handle a sequential collection of objects in very specific ways. The Stack is a last-in-first-out (LIFO) container where items are added and removed from the top of the stack. Typically this is useful in situations where you want to stack actions and then be able to undo those actions in reverse order as needed. The Queue on the other hand is a first-in-first-out container which adds items at the end of the queue and removes items from the front. This is useful for situations where you need to process items in the order in which they came, such as a print spooler or waiting lines.

The Original Collections: System.Collections namespace

The original collection classes are largely considered deprecated by developers and by Microsoft itself. In fact they indicate that for the most part you should always favor the generic or concurrent collections, and only use the original collections when you are dealing with legacy .NET code.

Because these collections are out of vogue, let’s just briefly mention the original collection and their generic equivalents:

ArrayList
A dynamic, contiguous collection of objects.
Favor the generic collection List instead.
Hashtable
Associative, unordered collection of key-value pairs of objects.
Favor the generic collection Dictionary instead.
Queue
First-in-first-out (FIFO) collection of objects.
Favor the generic collection Queue instead.
SortedList
Associative, ordered collection of key-value pairs of objects.
Favor the generic collection SortedList instead.
Stack
Last-in-first-out (LIFO) collection of objects.
Favor the generic collection Stack instead.
In general, the older collections are non-type-safe and in some cases less performant than their generic counterparts. Once again, the only reason you should fall back on these older collections is for backward compatibility with legacy code and libraries only.

The Concurrent Collections: System.Collections.Concurrent namespace

The concurrent collections are new as of .NET 4.0 and are included in the System.Collections.Concurrent namespace. These collections are optimized for use in situations where multi-threaded read and write access of a collection is desired.

The concurrent queue, stack, and dictionary work much as you’d expect. The bag and blocking collection are more unique. Below is the summary of each with a link to a blog post I did on each of them.

ConcurrentQueue
Thread-safe version of a queue (FIFO).
For more information see: C#/.NET Little Wonders: The ConcurrentStack and ConcurrentQueue
ConcurrentStack
Thread-safe version of a stack (LIFO).
For more information see: C#/.NET Little Wonders: The ConcurrentStack and ConcurrentQueue
ConcurrentBag
Thread-safe unordered collection of objects.
Optimized for situations where a thread may be bother reader and writer.
For more information see: C#/.NET Little Wonders: The ConcurrentBag and BlockingCollection
ConcurrentDictionary
Thread-safe version of a dictionary.
Optimized for multiple readers (allows multiple readers under same lock).
For more information see C#/.NET Little Wonders: The ConcurrentDictionary
BlockingCollection
Wrapper collection that implement producers & consumers paradigm.
Readers can block until items are available to read.
Writers can block until space is available to write (if bounded).
For more information see C#/.NET Little Wonders: The ConcurrentBag and BlockingCollection
Summary

The .NET BCL has lots of collections built in to help you store and manipulate collections of data. Understanding how these collections work and knowing in which situations each container is best is one of the key skills necessary to build more performant code. Choosing the wrong collection for the job can make your code much slower or even harder to maintain if you choose one that doesn’t perform as well or otherwise doesn’t exactly fit the situation.

Remember to avoid the original collections and stick with the generic collections. If you need concurrent access, you can use the generic collections if the data is read-only, or consider the concurrent collections for mixed-access if you are running on .NET 4.0 or higher.