Download - Dynamic C# - A New World of Possibilities
![Page 1: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/1.jpg)
Dynamic C# - A New World of Possibilities
Aaron EricksonLead Consultant, ThoughtWorksAuthor, The Nomadic DeveloperCo-Author, Professional F# (coming soon!)Microsoft MVP – C#
![Page 2: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/2.jpg)
Crazy Shit We Can Do With the Dynamic Keyword*
*Not all of this is a good idea (remember, use and abuse)
The initial name of the talk before it was rejected…
![Page 3: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/3.jpg)
C# - What it resembles now…
![Page 4: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/4.jpg)
![Page 5: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/5.jpg)
![Page 6: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/6.jpg)
C# - A little of everything…
Curly Braces (1.0)
Functional “Lite” with Linq (3.0)
And Now, Dynamic (4.0)
Generics (2.0)
![Page 7: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/7.jpg)
Duck Typing
![Page 8: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/8.jpg)
![Page 9: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/9.jpg)
Expando Objects
![Page 10: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/10.jpg)
![Page 11: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/11.jpg)
Treat Method Calls Like Messages
![Page 12: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/12.jpg)
Send Message
Receive Message
![Page 13: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/13.jpg)
And More…
Metaprogramming - take the expression tree called by the caller and do something with it.
Interop – call other people’s libraries written using real dynamic languages (Ruby, JS, Python).
![Page 14: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/14.jpg)
Interesting Applications of Dynamic C#
![Page 15: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/15.jpg)
ActiveRecord
![Page 16: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/16.jpg)
“ActiveRecord” for XML
![Page 17: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/17.jpg)
Interop
![Page 18: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/18.jpg)
Abuses… oh yes…
You shuddering yet? If not, you should be!
![Page 19: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/19.jpg)
Is dynamic programming the answer to anything and
everything?
![Page 20: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/20.jpg)
Case ForCase Against
Performance – dynamic lookup just can’t be as fast as static lookup.
You were confused with var? dynamic will make your head spin.
What is so bad about using strings in a lookup (i.e. table[“field”] vs table.field)
If you want dynamic, just use a language designed for it, like Ruby! Or JavaScript!
A lot fewer things are CPU bound than we tend to think. DB lookups? Really?
Sorry – if you are confused with var, you really need to put down the keyboard and take up something for dummies, like investment banking.
table.field looks cleaner, survives a rename refactoring, and can just take the shape of a static object later if introduced (introduce class refactoring for R# someday?)
Sometimes language choice is political. But need for dynamic remains.
![Page 21: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/21.jpg)
Demo – Stupid Dynamic C# Tricks
![Page 22: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/22.jpg)
Dynamic Everywhere? My ThoughtsPerformance argument has merit. Sometimes. No pretending Twitter didn’t happen.
Dynamic readers for things like Json, XML, Text, Excel, etc – will be really wicked cool!
End-user definition of objects. I can finally envision systems, based on C#, where you can have user defined fields on CRUD objects from databases, where an end user adds a field, names it, and binding just “works”.
This does not belong in your math or stats library. That is what Clojure, Scala, Erlang, F# - or where C# is your given language, LINQ, are for.
Linq + Dynamic in C# is mostly unexplored territory. Some amazing things could come out of that intersection.
![Page 23: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/23.jpg)
So you wanna do dynamic…You will do TDD. Without it, you are a mess of runtime errors and maintenance nightmares
You will respect that with great power comes great responsibility. Programs using dynamic programs tend to be smaller, but metaprogramming to extremes can end up becoming “write-only” code.
You will need to consider that vast parts of .NET-land have never seen this stuff before. You will be ready to explain and justify why and how this stuff improves things.
In 2020, you will curse, and maybe throw a chair or two, because of some abuse of dynamic some schmuck did in 2010 in that 10 year old code base.
There is a good chance that schmuck will be me
![Page 24: Dynamic C# - A New World of Possibilities](https://reader035.vdocument.in/reader035/viewer/2022070422/568163ad550346895dd4c269/html5/thumbnails/24.jpg)
Questions?