Basic exception handling in F#

F# has a similar exception handling mechanism like in C# or Java. The most straightforward way to raise an F# exception is by way of the built-in “failwith” function which accepts an exception message:

failwith "This won't work"

Read more of this post

Close unmanaged resources in F#

There are some object types in .NET that represent so-called unmanaged resources. These resources cannot be automatically disposed of by the garbage collector. It is up to the programmer to close them in code otherwise they can remain open unintentionally. Typical examples include streams, such as a file stream, or network connections of some sort such as database or HTTP connections. The programmer should never forget to close these resources after using them.

C# has the using block for resources that implement the IDisposable interface. A using block makes the programmer’s job easier so that they don’t need to call the Close method actively. It will be called automatically at the end of the using block where the unmanaged resource goes out of scope.

F# has a similar construct called “use”. Let’s see an example with the MemoryStream object:

Read more of this post

Using the Redis NoSql database with .NET Part 9: starting with the Redis .NET client

Introduction

In the previous post we looked at how Redis can be used as a message broker. Messaging is a technique to enable two disparate systems to communicate with each other. Communication usually happens via data types that most systems understand: strings, bytes and the like. The party sending a message to a channel is called a publisher or sender and the ones consuming the messages are called subscribers or consumers. Any Redis client can subscribe to a channel and get the messages registered on a certain channel. A system that sits in between the publishers and subscribers, i.e. that can create channels, accept messages to those channels and funnel them out to the subscribers is called a message broker. Redis offers a basic but very efficient messaging service. If you see a need for a simple messaging solution in your system without the more complex features of other message brokers then Redis may be all you need, especially if you already use it as a database.

In this post we’ll start looking at using Redis through .NET.

Read more of this post

Using the let keyword in .NET LINQ to store variables within a statement

It happens that we have a LINQ statement where we want to refer to partial results by variable names while expressing some computation. The “let” keyword lets us do that. Those who are familiar for the F# language already know that “let” is an important keyword to bind some value to a variable.

Suppose we have the following list of integers:

List<int> integers = new List<int>()
{
	5, 7, 4, 6, 10, 4, 6, 4, 5, 12
};

Read more of this post

Using the Redis NoSql database with .NET Part 8: messaging

Introduction

In the previous post we looked at transactions in Redis. A transaction is a collection of database operations that are executed as a unit. The commands of a transaction are executed atomically, meaning that the process is not interrupted by an external operation. The commands either pass or fail together. Redis has at least partial implementation of transactions. We can start and execute transactions but if one or more commands fail then the other members are still executed. In other words there is no rollback mechanism. Redis also offers a concurrency check through the WATCH command if we want to perform the transaction on an unchanged set of resources.

Redis also offers a basic messaging system which will be the topic of this post.

Read more of this post

Using NumberStyles to parse numbers in C# .NET

There are a lot of number formats out there depending on the industry we’re looking at. E.g. negative numbers can be represented in several different ways:

  • -14
  • (14)
  • 14-
  • 14.00-
  • (14,00)

…and so on. Accounting, finance and other, highly “numeric” fields will have their own standards to represent numbers. Your application may need to parse all these strings and convert them into proper numeric values. The static Parse method of the numeric classes, like int, double, decimal all accept a NumberStyles enumeration. This enumeration is located in the System.Globalization namespace.

Read more of this post

Using the Redis NoSql database with .NET Part 7: transactions

Introduction

In the previous post we looked at the hash data type in Redis. Hashes are key-value collections like dictionaries in .NET or maps in Java. For a given Redis key hashes can store multiple key-value pairs. Hashes offer a certain degree of object-oriented design where an object, such as a product or customer can be described by key-values like “id”: 23, “name”: “Unknown LTD” and so on. We can use the string data type to store the properties of an object as a JSON string as we saw before in this series. However, if you need to access the individual properties of an object then a hash can be a more suitable option.

We’ve now discussed all available data types in Redis. We’ll now turn our attention to transactions.

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: