Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

F# for C# devs - Copenhagen .Net 2015

Slides presented to the Copenhagen .Net meetup at SimCorp's offices.

  • Sé el primero en comentar

F# for C# devs - Copenhagen .Net 2015

  1. 1. Phil Trelford, @ptrelford Copenhagen .Net @SimCorp, 2015
  2. 2.  Founded Feb 2010  1050+ Members  Meets every 2 weeks  Topics include  Machine Learning  Finance  Games  Web http://meetup.com/fsharplondon
  3. 3.  Statically Typed  Functional First  Object Oriented  Open Source  .Net language  In Xamarin & Visual Studio
  4. 4. Kaggle Testimonial “we have a large existing code base in C#, …getting started with F# was an easy decision.” “The F# code is consistently shorter, easier to read, easier to refactor and contains far fewer bugs. …we’ve become more productive.” Source: http://fsharp.org/testimonials/
  5. 5. Phil Trelford, @ptrelford Copenhagen .Net @SimCorp, 2015
  6. 6.  Time to Market  Efficiency  Correctness  Complexity
  7. 7. speed development by 50 percent or more, European IB order of magnitude increase in productivity, GameSys
  8. 8. processes that used to require hours now take just minutes Grange Insurance performance is 10× better than the C++ that it replaces Aviva
  9. 9. leads to virtually bug-free code, Fixed Income I am still waiting for the first bug to come in, E-On
  10. 10. Billion-dollar mistake I call it my billion-dollar mistake. It was the invention of the null reference in 1965. […] I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years. Tony Hoare I call it my billion-dollar mistake. It was the invention of the null reference in 1965. […] I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years. Tony Hoare
  11. 11. everything becomes simple and clear when expressed in F#, Byron Cook, Microsoft Research
  12. 12. Phil Trelford, @ptrelford Copenhagen .Net @SimCorp, 2015
  13. 13. 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
  14. 14. F# type VerySimpleStockTrader (analysisService:IStockAnalysisService, brokerageService:IOnlineBrokerageService) = member this.ExecuteTrades() = () // ... C# public class VerySimpleStockTrader { private readonly IStockAnalysisService analysisService; private readonly IOnlineBrokerageService brokerageService; public VerySimpleStockTrader( IStockAnalysisService analysisService, IOnlineBrokerageService brokerageService) { this.analysisService = analysisService; this.brokerageService = brokerageService; } public void ExecuteTrades() { // ... } }
  15. 15. F# NUnit module MathTest = open NUnit.Framework let [<Test>] ``2 + 2 should equal 4``() = Assert.AreEqual(2 + 2, 4) C# NUnit using NUnit.Framework; [TestFixture] public class MathTest { [Test] public void TwoPlusTwoShouldEqualFour() { Assert.AreEqual(2 + 2, 4); } }
  16. 16. F# Foq let ``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# Moq public 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()); }
  17. 17. open FSharp.Data type Person = JsonProvider<""" { "name":"Name", "age":64 } """> let thomas = Person.Parse(""" { "name":"Thomas", "age":12 } """) person.Age
  18. 18. R – TYPE PROVIDER
  19. 19. Phil Trelford, @ptrelford Copenhagen .Net @SimCorp, 2015
  20. 20. F# Software Foundation http://www.fsharp.org software stacks trainings teaching F# user groups snippets mac and linux cross-platform books and tutorials F# community open-source MonoDevelop contributions research support consultancy mailing list
  21. 21. //--------------------------------------------------------------- // About Let // // The let keyword is one of the most fundamental parts of F#. // You'll use it in almost every line of F# code you write, so // let's get to know it well! (no pun intended) //--------------------------------------------------------------- [<Koan(Sort = 2)>] module ``about let`` = [<Koan>] let LetBindsANameToAValue() = let x = 50 AssertEquality x __
  22. 22.  Twitter  @ptrelford  Blog  http://trelford.com/blog  F# Koans:  http://tinyurl.com/fsharpkoans

×