dynamic don t be afraid
play

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


  1. DYNAMIC: DON’T BE AFRAID Hadi Hariri JetBrains

  2. Agenda The What, the Why, the How

  3. A Tale as Old as Time... A tale as old as time…

  4. Static vs Dynamic Static vs Dynamic

  5. Discussion Threads Blog Blog Posts Posts and more blog posts

  6. In the Static World • Types can be implicit or explicit (var) • Compiler Safety • Early Binding

  7. In a Dynamic World • Types defined at runtime • No Compiler (Usually) • Late Binding • Interpreted (Not always)

  8. What Dynamic Developers think of Static Developers…

  9. I need my compiler!

  10. What Static Developers think of Dynamic Developers…

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

  12. "You cannot build serious business applications in dynamic languages"

  13. They both have Good and Bad Things

  14. DLR & C# 4

  15. C# added... • dynamic keyword • Classes/Binders and interfaces to work with dynamic types

  16. DLR added… Hosting API Debugging API Dynamic Call-Site Interop Binders Expressions Objects Caching Expression Compiler IL Code Generator / Interpreter

  17. The Big Picture VB.NET IronRuby IronPython C# DLR Bindings .NET Ruby Python Office

  18. http://www.flickr.com/photos/bitjungle

  19. GET YOUR STINKING DYNAMIC TYPES OFF OF MY STATIC LANGUAGE

  20. IS THERE A NEED?

  21. Readability

  22. Interoperability

  23. Interoperability with other languages • IronPython • Interpreted • Can be compiled • IronRuby • Interpreted • Your own language

  24. DEMO TALKING RUBY

  25. Interoperability • Talking to COM • Need a type-library beforehand • Use Method Invocation

  26. DEMO TALKING COM

  27. The Case of the DTO

  28. Creating Dynamic Objects in C#

  29. Options • ExpandObject • DynamicObject • IDynamicMetaObjectProvider

  30. 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

  31. DEMO ON THE FLY: BASICS OF DYNAMIC

  32. DEMO EXPANDOS

  33. DynamicObject • Moving Beyond an Expando • Built-in class which implements IDynamicMetaObjectProvider • Allows easy creation of Dynamic types

  34. DEMO MVC – VIEWBAG, DYNAMICOBJECTSIMPLE

  35. IDynamicMetaObjectProvider • Meta Object that performs binding • Allows decoupling from class • Uses DLR Expressions • Returns DynamicObject

  36. DEMO DYNAMICPROVIDER

  37. Undetermined API

  38. Aspects of MetaProgramming • Adding / Removing Methods • Creating Instance Methods • Creating Static / Class Methods • Query Classes

  39. DEMO DYNAMICMETHODMISSING – SIMPLE DATA

  40. Consuming the ever-changing

  41. DEMO CONSUMINGJSON

  42. DSL's and Fluent API's

  43. A QUICK LOOK UNDER THE HOOD…

  44. The backbone of dynamic support DLR Language Semantics Define Late Binding via DLR EXpression Logic

  45. DLR Expression • Superset of Linq.Expression • Common to multiple Languages • DLR Expression is to DLR Languages what IL is to CLR languages C# IronPython IronRuby VB.NET IL DLR Expression CLR DLR Runtime

  46. 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

  47. Late Binding • Using Binders and Call Sites • Using Dynamic Expression (uses former internally)

  48. Late Binding

  49. DEMO DYNAMICCONVERSION

  50. SUMMING UP…

  51. The Disadvantages • There is no compile type-checking* • Potentially slower (even with caching) • There is no Intellisense* * Partially incorrect – It’s about the tooling

  52. Reasons to not not use dynamic

  53. 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

  54. Reasons to use dynamic

  55. 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”

  56. Thank you

Recommend


More recommend