+ All Categories
Home > Technology > F# Eye for the C# Guy - DDD North 2013

F# Eye for the C# Guy - DDD North 2013

Date post: 06-May-2015
Category:
Upload: phillip-trelford
View: 3,591 times
Download: 3 times
Share this document with a friend
Popular Tags:
22
F# Eye 4 the C# Guy Phil Trelford, @ptrelford #dddnorth, Sunderland 2013
Transcript
Page 1: F# Eye for the C# Guy - DDD North 2013

F# Eye 4 the C# GuyPhil Trelford, @ptrelford

#dddnorth, Sunderland 2013

Page 2: F# Eye for the C# Guy - DDD North 2013

Visual F#

Page 3: F# Eye for the C# Guy - DDD North 2013

The F in F# stands for FUN!

Page 4: F# Eye for the C# Guy - DDD North 2013

Halo 3 with F# Skills

Page 5: F# Eye for the C# Guy - DDD North 2013

XBLA: Path to Go – F# AI

Page 6: F# Eye for the C# Guy - DDD North 2013

Facebook: Monopoly

Page 7: F# Eye for the C# Guy - DDD North 2013

F#

• Statically Typed• Functional First• Object Orientated• Open Source• .Net language• In Visual Studio

& Xamarin Studio

Page 8: F# Eye for the C# Guy - DDD North 2013

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.

Page 9: F# Eye for the C# Guy - DDD North 2013

LIVE DEMOSPhil Trelford, @ptrelford

DDD North, Sunderland 2013

Page 10: F# Eye for the C# Guy - DDD North 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; } }}

Page 11: F# Eye for the C# Guy - DDD North 2013

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() { // ... }}

Page 12: F# Eye for the C# Guy - DDD North 2013

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); }}

Page 13: F# Eye for the C# Guy - DDD North 2013

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());}

Page 14: F# Eye for the C# Guy - DDD North 2013

Tickspec: Debugging

Page 17: F# Eye for the C# Guy - DDD North 2013

RESOURCESPhil Trelford, @ptrelford

DDD North, Sunderland 2013

Page 18: F# Eye for the C# Guy - DDD North 2013

Try F#: http://tryfsharp.org

Page 19: F# Eye for the C# Guy - DDD North 2013

Buy the Book

Page 20: F# Eye for the C# Guy - DDD North 2013

Get the T-Shirt

Page 21: F# Eye for the C# Guy - DDD North 2013

Show me the money!


Recommended