Basic pattern matching in F#

Pattern matching in F# is somewhat similar to switch blocks in C#. However, pattern matching blocks can provide much more complex branching logic than switch blocks.

Consider the following F# function:

let isGreaterThan x y =     
    if x > y then (true, x - y)
    else (false, 0)

…, i.e. we return true and the difference between the two input integers if the first integer is greater. Otherwise we return a false and a 0. In other words the return type is a tuple with two elements, a boolean and an integer.

Read more of this post

Introduction to CouchDB with .NET part 3: starting with the CouchDB HTTP API

Introduction

In the previous post we looked at the CouchDB administrative UI called Fauxton. The UI that shipped with earlier versions of CouchDB is called Futon so you will still come across that name if you work with older CouchDB projects. Fauxton is quite easy and straightforward to use. The database section allows us to create, update and delete databases and documents. Many functions are meant to be handled by database admins such as CouchDB users, access rights, processes and configuration.

In this post we’ll start exploring the CouchDB HTTP-based API.

Read more of this post

Dynamically finding the value of a static field with Reflection in .NET C#

Say you do not have access to a .NET assembly at compile time but you want to execute code in it or read programmatic data from it.

One such scenario is when you’d like to extract some important field information from a class. Why would you ever need that?

Imagine that you have an application where people can upload their own plugins in the form of DLL’s. However, users do not programmatically build their own libraries in Visual Studio but rather use a GUI which will dynamically build a class file and compile it into a DLL based on the user’s selections on the GUI. This is possible if your users are not programmers or if the rules for the plugins are so complex that you wouldn’t want people to write their own solutions.

In such a scenario the class builder could write some important metadata in the form of static fields in the class, such as Version. E.g. if your app has multiple versions then the code generator would put the current version into the class so that your app can verify it. Then you can disallow plugins that were created with an older version of the app if the current version is not backward compatible.

Open Visual and create a new C# class library project called Domain. Add the following Customer class to it:

Read more of this post

Convert a dynamic type to a concrete object in .NET C#

Dynamic objects in C# let us work with objects without compile time error checking in .NET. They are instead checked during execution. As a consequence we can’t use IntelliSense while writing the code to see what properties and functions an object has.

Consider the following Dog class:

public class Dog
{
	public string Name { get; }
	public string Type { get;}
	public int Age { get; }

	public Dog(string name, string type, int age)
	{
		Name = name;
		Type = type;
		Age = age;
	}
}

Read more of this post

Introduction to CouchDB with .NET part 2: Fauxton UI basics

Introduction

In the previous post we laid the foundations for this series. We’ll discuss the basics of the NoSql document-based data store CouchDB. CouchDB stores its records in documents as JSON which makes integration with clients relatively easy. CouchDB comes with a web-based administrative UI that allows us to create databases, check their content, create users, administrators and many other things that we’ll eventually cover in this series. CouchDB is completely schemaless, has no data integrity checks and its JSON storage format allows us to store our domain objects in a more natural way than table-based relational databases do.

We successfully installed CouchDB on Windows. It was a straightforward and painless experience. The installer also set up a Windows Service so that the CouchDB server is up and running all the time. We had to solve one issue though after the initial setup: 3 administrative databases were not installed and we had to create them in the UI. In the absence of those tables the CouchDB server keeps logging the same exception message in the log file.

In this post we’ll be looking into various basic functions in the CouchDB management UI called Fauxton.

Read more of this post

Introduction to CouchDB with .NET part 1: foundations and setup

Introduction

CouchDB is a document based NoSql database by Apache written mostly in the Erlang programming language with C and C++ added in. It is also open-source and free-of-charge in both hobby and real-life commercial projects. If you’ve only worked with traditional relational databases like MS SQL with its tables, schemas, integrity checks, primary and secondary keys etc. then a document database will require a significant shift in the way you think of storing data. CouchDB shares a number of traits with MongoDB which is the most popular document based data store at this time. Both CouchDB and MongoDB store their data in documents, they don’t have any strictly enforced schema and no strict data integrity by way of secondary keys. They can both store our domain objects “as they are”, without the need of designing tables for them. In other words CouchDB represents our domain objects much closer than table-based relational databases can do. CouchDB and MongoDB can run on both Linux and Windows. Also, they can be clustered with in a master-slave setup with a primary database serves as the read/write node and the secondary databases all share the read-load. The master is then responsible for replicating data modifications such as inserts, updates and deletes to the secondary nodes.

CouchDB comes with a built-in management tool where we can view our databases and documents, edit them, delete them and perform a range of other administrative tasks. Relational databases are still the norm and the primary choice among developers for the data storage needs for their projects. However, it’s always good to know that there are alternatives that offer alternative ways of storing data. Both CouchDB and MongoDB provide fast read and write operations. CouchDB offers a REST API based query interface with the usual HTTP verbs like GET, PUT, DELETE etc. Querying can be performed with either predefined views or a new query language called Mango that was added to CouchDB 2.0.

In this series we’ll be looking at the basics of CouchDB, how to set it up on Windows, how to insert data, how to execute queries and finally how to communicate with a CouchDB database from your .NET project.

Read more of this post

Implementing a C# interface with an F# object expression

Suppose you have the following C# interface ICalculator with 4 functions:

namespace Project.Domains
{
	public interface ICalculator
	{
		int Add(int x, int y);
		int Subtract(int x, int y);
		float Divide(float x, float y);
		int Multiply(int x, int y);
	}
}

Read more of this post

ultimatemindsettoday

A great WordPress.com site

iReadable { }

.NET Tips & Tricks

Robin Sedlaczek's Blog

Developer on Microsoft Technologies

HarsH ReaLiTy

A Good Blog is Hard to Find

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

the software architecture

thoughts, ideas, diagrams,enterprise code, design pattern , solution designs

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

Anything around ASP.NET MVC,WEB API, WCF, Entity Framework & AngularJS

Cyber Matters

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: