Showing posts with label TDD. Show all posts
Showing posts with label TDD. Show all posts

Monday, October 13, 2008

Getting Started With F#

First retrieve and install the latest release of F# (the Sept. 2008 CTP can be found here).

I'm a believer in TDD (Test Driven Development), so our first step after installation of the CTP is to create a test.

Step 1: Creating the Test Project:

1. Open Visual Studio and type Ctrl+Shift+N to create a new project.
2. Create a Test project by selecting a project type of Visual C#\Test\Test Project. ( Note: I'm using a C# test project in VS2008, but any other test project will do.)
3. Set the location to any desired path with a new destination folder of "FSharpGettingStarted".
4. Change the Name to "FSharpTests".
5. Ensure that "Create New Solution" is selected and that "Create Directory For Solution" is checked.
6. Click OK.

Step 2: Creating the First Test:

1. Delete the default class that was generated in the test project.
2. Right click the FSharpTests project and select "Add\New Test...".
3. Select the Unit Test template and set the Test Name to "FSharpSampleTests.cs" then click OK.
4. In the newly generated class, locate the method "TestMethod1" and rename it to CanCalculateNumberSquared.
5. Remove the text that was generated in the method and type:
int result = FSharpSample.CalculateNumberSquared(2);
Assert.AreEqual(result, 4);

Step 3: Creating the F# project:
1. Type Ctrl+Shift+N and select the project type of Visual F#\F# Library.
2. Change the name to "FSharpSample".
3. Change the Solution option to "Add to Solution" and click OK.

Step 4: Adding the F# Function From Our Test:
1. Delete the "Module1.fs" file that was generated.
2. Right click on the FSharpSample project and select Add\New Item\F# Signature File.
3. Name the file "FSharpSample.fsi".
4. Right click on the FSharpSample project and select Add\New Item\F# Source File.
5. Name the file "FSharpSample.fs". (Note: if you add the ".fs" file before the ".fsi" file you may see an error message that states "An implementation of file or module FSharpSample has already been given. Compilation order is significant in F# because of type inference. You may need to adjust the order of your files to place the signature file before the implementation.". If you see this error, simply delete the ".fs" file and recreate it or manually edit the ".fsproj" file so that the ".fsi" file reference is above the ".fs" file reference in the ItemGroups.)
6. Open the FSharpSample.fsi file and type "val CalculateNumberSquared: int -> int" in the line directly below the line that states "#light".
7. Open the FSharpSample.fs file and type "let CalculateNumberSquared x = x*x;;" in the line directly below the line that states "#light".
8. Add the FSharpSample project as a reference to your Test project.
7. Run your test and it should now pass.

That's all there is to setting up your first F# library created with TDD. Next we will start talking about what some of this all means.

Friday, October 10, 2008

A New Direction

As you may have noticed, I have not created a new post in over a year. This is mostly due to more work than time and a lot of other excuses.

I hope to change that trend over the next several months.

Last night I attended the Nasvhille .Net User Group (UG) to see a presentation by Elijah Manor. If you were unable to attend, you missed a great crash course on MVC (Model View Controller), JQuery, Ajax, etc. I strongly recommend downloading and reviewing the sample code.

While at the UG I was asked to put together a presentation for the meeting in March 2009. Now for the task of figuring out a topic...

My recent interests have primarily been focused on improving the performance of enterprise applications. This has led to research on scaling techniques (such as implementing REST (Representational State Transfer) with ROA (Resource Oriented Architecture), parallelism, and languages that inherently promote thread safety such as F#. There are some great Dot Net Rocks episodes that give an overview of some of these topics (http://www.dotnetrocks.com/default.aspx?showNum=367, http://www.dotnetrocks.com/default.aspx?showNum=375, http://www.dotnetrocks.com/default.aspx?showNum=377).

While it is likely that one of these topics will be chosen for the presentation, there are several other patterns and/or practices that may end up winning out. Some of these include: DI (Dependency Injection), Data Persistance Layer (NHibernate), DTO (Data Transfer Object), TDD (Test Driven Development).

Over the new few months I will be posting about various points of interests related to these topics.