DYNAMIC: DONT BE AFRAID Hadi Hariri JetBrains Agenda The What, the - - PowerPoint PPT Presentation

dynamic don t be afraid
SMART_READER_LITE
LIVE PREVIEW

DYNAMIC: DONT BE AFRAID Hadi Hariri JetBrains Agenda The What, the - - PowerPoint PPT Presentation

DYNAMIC: DONT BE AFRAID Hadi Hariri JetBrains Agenda The What, the Why, the How A Tale as Old as Time... A tale as old as time Static vs Dynamic Static vs Dynamic Discussion Threads Blog Blog Posts Posts and more blog posts In


slide-1
SLIDE 1

DYNAMIC: DON’T BE AFRAID

Hadi Hariri JetBrains

slide-2
SLIDE 2

The What, the Why, the How

Agenda

slide-3
SLIDE 3

A tale as old as time…

A Tale as Old as Time...

slide-4
SLIDE 4

Static vs Dynamic

Static vs Dynamic

slide-5
SLIDE 5

Blog Posts Discussion Threads Blog Posts and more blog posts

slide-6
SLIDE 6
  • Types can be implicit or explicit (var)
  • Compiler Safety
  • Early Binding

In the Static World

slide-7
SLIDE 7
  • Types defined at runtime
  • No Compiler (Usually)
  • Late Binding
  • Interpreted (Not always)

In a Dynamic World

slide-8
SLIDE 8

What Dynamic Developers think of Static Developers…

slide-9
SLIDE 9

I need my compiler!

slide-10
SLIDE 10

What Static Developers think of Dynamic Developers…

slide-11
SLIDE 11

http://nimblepros.com/products/software-craftsmanship-2012-calendar.aspx

slide-12
SLIDE 12

"You cannot build serious business applications in dynamic languages"

slide-13
SLIDE 13
slide-14
SLIDE 14
slide-15
SLIDE 15
slide-16
SLIDE 16

They both have Good and Bad Things

slide-17
SLIDE 17

DLR & C# 4

slide-18
SLIDE 18
  • dynamic keyword
  • Classes/Binders and interfaces to work with

dynamic types

C# added...

slide-19
SLIDE 19

Hosting API Debugging API Interop Binders Dynamic Objects Call-Site Caching Expressions Expression Compiler / Interpreter IL Code Generator

DLR added…

slide-20
SLIDE 20

DLR IronRuby IronPython C# VB.NET Bindings .NET Ruby Python Office

The Big Picture

slide-21
SLIDE 21 http://www.flickr.com/photos/bitjungle
slide-22
SLIDE 22

GET YOUR STINKING DYNAMIC TYPES OFF OF MY STATIC LANGUAGE

slide-23
SLIDE 23

IS THERE A NEED?

slide-24
SLIDE 24

Readability

slide-25
SLIDE 25
slide-26
SLIDE 26

Interoperability

slide-27
SLIDE 27

Interoperability with other languages

  • IronPython
  • Interpreted
  • Can be compiled
  • IronRuby
  • Interpreted
  • Your own language
slide-28
SLIDE 28
slide-29
SLIDE 29
slide-30
SLIDE 30
slide-31
SLIDE 31

DEMO

TALKING RUBY

slide-32
SLIDE 32

Interoperability

  • Talking to COM
  • Need a type-library beforehand
  • Use Method Invocation
slide-33
SLIDE 33

DEMO

TALKING COM

slide-34
SLIDE 34

The Case of the DTO

slide-35
SLIDE 35

Creating Dynamic Objects in C#

slide-36
SLIDE 36

Options

  • ExpandObject
  • DynamicObject
  • IDynamicMetaObjectProvider
slide-37
SLIDE 37

Expando Object

  • Built-in Dynamic Object. Works out of the box
  • Benefits over Dictionary
  • More Fluent
  • Support for Methods
  • Supports Hierarchies
  • Implements INotifyPropertyChanged
  • Limitations
  • Index Access
slide-38
SLIDE 38

DEMO

ON THE FLY: BASICS OF DYNAMIC

slide-39
SLIDE 39

DEMO

EXPANDOS

slide-40
SLIDE 40

DynamicObject

  • Moving Beyond an Expando
  • Built-in class which implements

IDynamicMetaObjectProvider

  • Allows easy creation of Dynamic types
slide-41
SLIDE 41

DEMO

MVC – VIEWBAG, DYNAMICOBJECTSIMPLE

slide-42
SLIDE 42

IDynamicMetaObjectProvider

  • Meta Object that performs binding
  • Allows decoupling from class
  • Uses DLR Expressions
  • Returns DynamicObject
slide-43
SLIDE 43

DEMO

DYNAMICPROVIDER

slide-44
SLIDE 44

Undetermined API

slide-45
SLIDE 45

Aspects of MetaProgramming

  • Adding / Removing Methods
  • Creating Instance Methods
  • Creating Static / Class Methods
  • Query Classes
slide-46
SLIDE 46
slide-47
SLIDE 47

DEMO

DYNAMICMETHODMISSING – SIMPLE DATA

slide-48
SLIDE 48

Consuming the ever-changing

slide-49
SLIDE 49

DEMO

CONSUMINGJSON

slide-50
SLIDE 50

DSL's and Fluent API's

slide-51
SLIDE 51

A QUICK LOOK UNDER THE HOOD…

slide-52
SLIDE 52

The backbone of dynamic support

DLR

Language Semantics via DLR EXpression Define Late Binding Logic

slide-53
SLIDE 53

DLR Expression

  • Superset of Linq.Expression
  • Common to multiple Languages
  • DLR Expression is to DLR Languages what IL

is to CLR languages

C#

VB.NET

IL CLR IronPython IronRuby DLR Expression DLR Runtime

slide-54
SLIDE 54

Late Binding

  • We only know the types at runtime
  • We have to figure out how to call those

methods at runtime

  • It’s not embedded in the “IL”
  • It’s potentially slower
slide-55
SLIDE 55

Late Binding

  • Using Binders and Call Sites
  • Using Dynamic Expression (uses former

internally)

slide-56
SLIDE 56

Late Binding

slide-57
SLIDE 57

DEMO

DYNAMICCONVERSION

slide-58
SLIDE 58

SUMMING UP…

slide-59
SLIDE 59

The Disadvantages

  • There is no compile type-checking*
  • Potentially slower (even with caching)
  • There is no Intellisense*

* Partially incorrect – It’s about the tooling

slide-60
SLIDE 60

Reasons to not not use dynamic

slide-61
SLIDE 61

Reasons to not not use dynamic

  • There’s no compiler
  • There’s no intellisense (Emphasis on Unit Tests)
  • You shouldn’t mix dynamic and static languages
slide-62
SLIDE 62

Reasons to use dynamic

slide-63
SLIDE 63

Reasons to use Dynamic

  • Interoperability
  • COM
  • Consuming Dynamic Languages
  • Ruby
  • JavaScript
  • Fluent API’s and DSL
  • Consuming the *unknown*
  • Dynamic Structures
  • Avoiding unnecessary “class explosion”
slide-64
SLIDE 64

Thank you