The presentation that I did at Code PaLOUsa entitled CoffeeScript: Good, Bold, and with Sugar is now available on InfoQ at http://www.infoq.com/presentations/CoffeeScript-Good-Bold-and-with-Sugar.
You can find an HTML version of the slides here and various examples on my GitHub.
Thursday, July 5, 2012
Sunday, June 24, 2012
Functional JavaScript with LiveScript, Mocha, and ExpectThat
I've been playing with LiveScript a bit lately and have really been enjoying it! If you haven't heard of LiveScript, it's a "...fork of Coco, which is in turn derived from CoffeeScript..." (LiveScript Overview Page). It provides more features than Coco and CoffeeScript including several that assist in writing code in a more functional style.
Here's a quick example of a test written in LiveScript for Mocha and ExpectThat:
This shows off a couple of the features that help you write in a functional style with LiveScript. The first is the use of pattern matching within the isWeekend function. The second is the use of the pipe-forward operator when calling the isWeekend function.
The pattern matching syntax gives you a concise way of defining a basic switch statement in JavaScript. The pipe-forward operator allows you to compose things together. In the example above, the string 'sun' (which also could have been written in LiveScript as \sun) is being passed into the isWeekend function. This becomes even more powerful when the value to be passed into the next function is coming from another function, as shown in this example:
F# has these same concepts and many more, which makes LiveScript + F# a compelling combination!
There are a number of additional LiveScript features that assist in using a functional style. For more examples of LiveScript with Mocha and ExpectThat visit https://github.com/dmohl/expectThat/tree/master/example/mocha-LiveScript. To learn more about LiveScript, see a number of examples, and/or get setup for use, visit the LiveScript site at http://gkz.github.com/LiveScript/.
Here's a quick example of a test written in LiveScript for Mocha and ExpectThat:
This shows off a couple of the features that help you write in a functional style with LiveScript. The first is the use of pattern matching within the isWeekend function. The second is the use of the pipe-forward operator when calling the isWeekend function.
The pattern matching syntax gives you a concise way of defining a basic switch statement in JavaScript. The pipe-forward operator allows you to compose things together. In the example above, the string 'sun' (which also could have been written in LiveScript as \sun) is being passed into the isWeekend function. This becomes even more powerful when the value to be passed into the next function is coming from another function, as shown in this example:
F# has these same concepts and many more, which makes LiveScript + F# a compelling combination!
There are a number of additional LiveScript features that assist in using a functional style. For more examples of LiveScript with Mocha and ExpectThat visit https://github.com/dmohl/expectThat/tree/master/example/mocha-LiveScript. To learn more about LiveScript, see a number of examples, and/or get setup for use, visit the LiveScript site at http://gkz.github.com/LiveScript/.
Saturday, June 16, 2012
CodeStock 2012 F# and CoffeeScript Presentations
Monday, June 4, 2012
F#/C# ASP.NET MVC 4 Template for Visual Studio 2012 RC
The F#/C# ASP.NET MVC 4 template has been updated to support ASP.NET MVC 4 RC and Visual Studio 2012 RC. You will need to install the release candidate of ASP.NET MVC 4 to use this updated version of the template. The install can be found at http://www.asp.net/mvc/mvc4.
As with the previous release, the F#/C# ASP.NET MVC project template supports ASPX and Razor versions of an empty ASP.NET MVC 4 project template as well as a Razor version of the ASP.NET Web API project template. The templates work on both VS2010 and VS2012 RC.
As with the previous release, the F#/C# ASP.NET MVC project template supports ASPX and Razor versions of an empty ASP.NET MVC 4 project template as well as a Razor version of the ASP.NET Web API project template. The templates work on both VS2010 and VS2012 RC.
Labels:
ASP.NET MVC 4,
ASP.NET Web API,
F#,
Project Templates,
VS2012
Wednesday, May 23, 2012
Fog 0.1.3.0 Released
A new release of Fog is now available. The primary enhancement included in this release is support for Windows Azure Caching. Several bug fixes have also been included.
The caching functions are available in the Fog.Caching module. You can use them with code such as the following:
Fog is available via NuGet as ID Fog and the full source can be found on my GitHub.
The caching functions are available in the Fog.Caching module. You can use them with code such as the following:
[<DataContract>] type TestRecord = { [<DataMember>] mutable Id : Guid [<DataMember>] mutable Name : string } let testRecord = { Id = Guid.NewGuid(); Name = "Dan" } let key = testRecord.Id.ToString() Put key testRecord |> ignore let result = Get<TestRecord> key
Fog is available via NuGet as ID Fog and the full source can be found on my GitHub.
Sunday, May 20, 2012
Two Books in the Making
A few weeks ago I mentioned that my blog has been suffering due to a few other ongoing activities. Today, I'm going to tell you about what I've been working on.
A few months ago I had the opportunity to start working on a few different books:
The first is called jQuery Mobile Cookbook. This book is a collaborative effort between appendTo, O'Reilly, and the jQuery community. The effort is coming along nicely and from what I've seen so far, you're going to love it!
The second is a book on building web, cloud, and mobile solutions with F#. I've partnered with O'Reilly to create this collection of examples, tips, guidance, architectural approaches, functional+OO patterns and practices, and more. Subjects that are expected to be covered include, but are certainly not limited to, ASP.NET MVC 4, ASP.NET Web API, other frameworks for building HTTP services, using F# to build Windows Azure web and worker roles, WebSharper, and Pit.
If there is something that you would really like to see in either of these books, let me know!
A few months ago I had the opportunity to start working on a few different books:
The first is called jQuery Mobile Cookbook. This book is a collaborative effort between appendTo, O'Reilly, and the jQuery community. The effort is coming along nicely and from what I've seen so far, you're going to love it!
The second is a book on building web, cloud, and mobile solutions with F#. I've partnered with O'Reilly to create this collection of examples, tips, guidance, architectural approaches, functional+OO patterns and practices, and more. Subjects that are expected to be covered include, but are certainly not limited to, ASP.NET MVC 4, ASP.NET Web API, other frameworks for building HTTP services, using F# to build Windows Azure web and worker roles, WebSharper, and Pit.
If there is something that you would really like to see in either of these books, let me know!
Sunday, May 13, 2012
Introducing Fog: A Library for Interacting with Azure from F#
Fog is a library that makes it easier to use F# to interact with Windows Azure through the Windows Azure SDK for .NET. It provides functions for many of the common activities related to table storage, blob storage, and queue storage as well as service bus queues and topics. Provided functions include both course and fined-grained approaches that remove boiler plate code and make it easier to use various functional patterns and techniques. The course grained functions currently use config settings with specific names to allow most operations to only require a single function call.
The syntax of Fog is pretty straight forward. The following examples use the course grained approach. To see how to use the fined-grained functions, which match almost one to one with the Azure SDK for .NET methods, see the Fog integration tests.
Blob Storage
With Fog all you have to do to interact with Azure blob storage is to add the connection string information in the config with a name of "BlobStorageConnectionString". Once that is done, you can use syntax like the following:
The simplest way to interact with Azure table storage is to add the connection string information in the config with a name of "TableStorageConnectionString". Once that is done, you can use syntax like the following:
For queue storage, add the connection string configuration value with setting name "QueueStorageConnectionString".
There are a few service bus related config entries. Here's the list of expected names: ServiceBusIssuer, ServiceBusKey, ServiceBusScheme, ServiceBusNamespace, ServiceBusServicePath
To send a message do this:
The easiest way to get Fog is to install the Fog NuGet package. You can also find the full source as well as integration tests on the Fog GitHub site.
The syntax of Fog is pretty straight forward. The following examples use the course grained approach. To see how to use the fined-grained functions, which match almost one to one with the Azure SDK for .NET methods, see the Fog integration tests.
Blob Storage
With Fog all you have to do to interact with Azure blob storage is to add the connection string information in the config with a name of "BlobStorageConnectionString". Once that is done, you can use syntax like the following:
UploadBlob "testcontainer" "testblob" "This is a test" |> ignore DeleteBlob "testcontainer" "testblob"or
UploadBlob "testcontainer" "testblob" testBytes |> ignore DownloadBlob<byte[]> "testcontainer" "testblob"Table Storage
The simplest way to interact with Azure table storage is to add the connection string information in the config with a name of "TableStorageConnectionString". Once that is done, you can use syntax like the following:
[<DataServiceKey("PartitionKey", "RowKey")>] type TestClass() = let mutable partitionKey = "" let mutable rowKey = "" let mutable name = "" member x.PartitionKey with get() = partitionKey and set v = partitionKey <- v member x.RowKey with get() = rowKey and set v = rowKey <- v member x.Name with get() = name and set v = name <- v let originalClass = TestClass(PartitionKey = "tprt", RowKey = Guid.NewGuid().ToString(), Name = "test") CreateEntity "testtable" originalClass |> ignore let newClass = originalClass newClass.Name <- "test2" UpdateEntity "testtable" newClass |> ignore DeleteEntity "testtable" newClassQueue Storage
For queue storage, add the connection string configuration value with setting name "QueueStorageConnectionString".
AddMessage "testqueue" "This is a test message" |> ignore let result = GetMessages "testqueue" 20 5 for m in result do DeleteMessage "testqueue" mService Bus
There are a few service bus related config entries. Here's the list of expected names: ServiceBusIssuer, ServiceBusKey, ServiceBusScheme, ServiceBusNamespace, ServiceBusServicePath
To send a message do this:
type TestRecord = { Name : string } let testRecord = { Name = "test" } SendMessage "testQueue" testRecordTo receive a message, pass the queue name, a function to handle successful message retrieval, and another function to handle errors.
HandleMessages "testQueue" <| fun m -> printfn "%s" m.GetBody<TestRecord>().Name <| fun ex m -> raise exTo use topics in a pub/sub type of scenario, use something like the following to subscribe:
Subscribe "topictest2" "AllTopics4" <| fun m -> printfn "%s" m.GetBody<TestRecord>().Name <| fun ex m -> raise exMessage publishing can be accomplished like this:
Publish "topictest2" testRecordA few other handy functions include Unsubscribe and DeleteTopic:
Unsubscribe "topictest2" "AllTopics4" DeleteTopic "topictest2"How to get it
The easiest way to get Fog is to install the Fog NuGet package. You can also find the full source as well as integration tests on the Fog GitHub site.
Subscribe to:
Posts (Atom)