Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency:...

21
Intro to F# and DAXIF# Talk by Ramón Soto Mathiesen @ Mødegruppe for F#unktionelle Københavnere 2013

Transcript of Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency:...

Page 1: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

Intro to F# and

DAXIF#Talk by Ramón Soto Mathiesen

@ Mødegruppe for F#unktionelle Københavnere 2013

Page 2: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

Contents

• About me

• What is F# and why use it?

• F# on a daily basis: DAXIF#

• Live demo (DAXIF#)

• How to get started with F#

• Summary

Page 3: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

About me

• MSc. Computer Science from DIKU

• CRM Architect @ Delegate A/S

‣ ER-modeling, WSDL, OData (REST API)

• F# / C# / JavaScript / C++

Page 4: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

F# - What is it?

• Is an open-source, strongly typed, multi-paradigm programming language encompassing functional, imperative and object-oriented designed by Don Syme (MS Research Cambridge UK) and maintained by Microsoft, F# Software Foundation and open contributors

• F# derived from OCaml: http://caml.inria.fr/ocaml/

• It’s a mature language that is part of Visual Studio and the .NET Framework (+Mono)

Page 5: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

F# - Why use it?

• Conciseness

• Convenience

• Correctness

• Concurrency

• Completeness

Page 6: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

F# - Why use it?

• Conciseness:

‣ F# is not cluttered up with coding noise such as curly brackets, semicolons and so on

‣ You almost never have to specify the type of an object, thanks to a powerful type inference system.

‣ And, compared with C#, it generally takes fewer lines of code to solve the same problem

Page 7: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

F# - Why use it?

• Convenience:

‣ Many common programming tasks are much simpler in F#. This includes things like creating and using complex type definitions, doing list processing, comparison and equality, state machines, and much more

‣ And because functions are first class objects, it is very easy to create powerful and reusable code by creating functions that have other functions as parameters, or that combine existing functions to create new functionality

Page 8: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

F# - Why use it?

• Correctness:

‣ F# has a powerful type system which prevents many common errors such as null reference exceptions.

‣ Values are immutable by default, which prevents a large class of errors

‣ In addition, you can often encode business logic using the type system itself in such a way that it is actually impossible to write incorrect code or mix up units of measure, greatly reducing the need for unit tests

Page 9: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

F# - Why use it?

• Concurrency:

‣ F# has a number of built-in libraries to help when more than one thing at a time is happening. Asynchronous programming is very easy, as is parallelism. F# also has a built-in actor model, and excellent support for event handling and functional reactive programming

‣ And of course, because data structures are immutable by default, sharing state and avoiding locks is much easier

Page 10: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

F# - Why use it?

• Completeness:

‣ Although it is a functional language at heart, F# does support other styles which are not 100% pure, which makes it much easier to interact with the non-pure web sites, databases, other applications, and so on. In particular, F# is designed as a hybrid functional/OO language, so it can do virtually everything that C# can do

‣ Of course, F# is part of the .NET ecosystem, which gives you seamless access to all the third party .NET libraries and tools.

‣ Finally, it is well integrated with Visual Studio, which means you get a great IDE with IntelliSense support, a debugger, and many plug-ins for unit tests, source control, and other development tasks

Page 11: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

C# vs. F#

‣ no coding noise

‣ fewer lines of code

‣ no type specification

‣ Immutable (threadsafe)

‣ Records don’t have identity

Page 12: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

F# on a daily basis:DAXIF#

• DAXIF#: Delegate Automated Xrm Installation Framework

‣ One-click-deployment

‣ TFS commit DEV DEV-BUILD TEST PROD

‣ Web resources synchronization

‣ Data management (Import/Export with Parallelism)

‣ Data migration: 1:1 between source and target Created by/on + Modified by/on (only for On-premise)

‣ Only one programming language (to rule them all)

‣ Type Strong script files

‣ Unit tests executed before building assembly

Page 13: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

F# on a daily basis:DAXIF#

• Why F#? less code, error-free projects,

only one code base, big data, parallelism,

concurrency, asynchronous (buzzwords)

• Delegate A/S is the new kid on the block

small teams, less time to spend on

side projects

Page 14: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

F# on a daily basis:DAXIF#

• DAXIF# started out as DAXIF (C#, .BAT files, almost no time for unit test, …, you know the drill)

• Now, all modules are less than 100 lines of code. Easy to read again, and again, and again …

Page 15: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

F# on a daily basis:DAXIF#

• Unit test are executed before building the final assembly file. F# interactive for add-hoc testing (is able to interact with C# assemblies)

• Documentation is generated on the Markdown headers of the functions (HTML/Latex)

Page 16: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

Live demo:DAXIF#

Page 17: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

Live demo:C# vs. F# (CRM Parallelism)

Page 18: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

How to get started

with F#• Tryfsharp http://www.tryfsharp.org

Page 19: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

How to get started

with F#• Project Euler and Emacs http://projecteuler.net/problems

Page 20: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

Summary

• The language is mature and you can do awesome stuff in less

time that you would spend on other languages

• Jump into it, the only way to master something is by try/error

on a daily basis

• Be pragmatic about it. If you can use a Dictionary (mutable

data structure) don’t use a sequence/list for the sake of purity

Remark: Pragmatic ≠ sloppy

• A lot of the cool stuff is licensed under a very lightweight

Open Source license (Apache License). Try, as much as

possible, to give back to the community in small

modules/libraries that are also open source

Page 21: Intro to F# and DAXIF#files.meetup.com/10193032/Ramones_F#_and_DAXIF#_MF#K2013.pdf · Concurrency: ‣ F# has a number of built-in libraries to help when more than one thing at a

Questions?