Date post: | 06-May-2015 |
Category: |
Technology |
Upload: | phillip-trelford |
View: | 3,591 times |
Download: | 3 times |
F# Eye 4 the C# GuyPhil Trelford, @ptrelford
#dddnorth, Sunderland 2013
Visual F#
The F in F# stands for FUN!
Halo 3 with F# Skills
XBLA: Path to Go – F# AI
Facebook: Monopoly
F#
• Statically Typed• Functional First• Object Orientated• Open Source• .Net language• In Visual Studio
& Xamarin Studio
F# for Profit: Kaggle
The F# code is
consistently shorter,
easier to read,
easier to refactor and contains far fewer bugs.
…we’ve become
more productive.
LIVE DEMOSPhil Trelford, @ptrelford
DDD North, Sunderland 2013
Light Syntax: POCOs
F#type Person(name:string,age:int) = /// Full name member person.Name = name /// Age in years member person.Age = age
C#public class Person{ public Person(string name, int age) { _name = name; _age = age; }
private readonly string _name; private readonly int _age;
/// <summary> /// Full name /// </summary> public string Name { get { return _name; } }
/// <summary> /// Age in years /// </summary> public int Age { get { return _age; } }}
Light Syntax: DI
F#type VerySimpleStockTrader (analysisService:IStockAnalysisService, brokerageService:IOnlineBrokerageService) = member this.ExecuteTrades() = () // ...
C#public class VerySimpleStockTrader { private readonly IStockAnalysisService analysisService; private readonly IOnlineBrokerageService brokerageService;
public VerySimpleStockTraderImpl( IStockAnalysisService analysisService, IOnlineBrokerageService brokerageService) { this.analysisService = analysisService; this.brokerageService = brokerageService; }
public void ExecuteTrades() { // ... }}
Unit Testing
F# NUnitmodule MathTest =
open NUnit.Framework
let [<Test>] ``2 + 2 should equal 4``() = Assert.AreEqual(2 + 2, 4)
C# NUnitusing NUnit.Framework;
[TestFixture]public class MathTest{ [Test] public void TwoPlusTwoShouldEqualFour() { Assert.AreEqual(2 + 2, 4); }}
Mocking
F# Foqlet [<Test>] ``order sends mail if unfilled``() = // setup data let order = Order("TALISKER", 51) let mailer = mock() order.SetMailer(mailer) // exercise order.Fill(mock()) // verify verify <@ mailer.Send(any()) @> once
C# Moqpublic void OrderSendsMailIfUnfilled(){ // setup data var order = new Order("TALISKER", 51); var mailer = new Mock<MailService>(); order.SetMailer(mailer.Object); // exercise order.Fill(Mock.Of<Warehouse>()); // verify mailer.Verify(mock => mock.Send(It.IsAny<string>()), Times.Once());}
Tickspec: Debugging
RESOURCESPhil Trelford, @ptrelford
DDD North, Sunderland 2013
Try F#: http://tryfsharp.org
Buy the Book
Get the T-Shirt
Show me the money!
Questions?
Twitter:
@ptrelford
Blog: http://trelford.com/blog
F# Foundation: http://fsharp.org