Dynamic C# - A New World of Possibilities<br />Aaron Erickson<br />Lead Consultant, ThoughtWorks<br />Author, The Nomadic ...
The initial name of the talk before it was rejected…<br />Crazy Shit We Can Do With the Dynamic Keyword*<br />*Not all of ...
C# - What it resembles now…<br />
C# - A little of everything…<br />Curly Braces (1.0)<br />Generics (2.0)<br />Functional “Lite” with Linq (3.0)<br />And N...
Duck Typing<br />
Expando Objects<br />
Treat Method Calls Like Messages<br />
Send Message<br />Receive Message<br />
And More…<br />Metaprogramming - take the expression tree called by the caller and do something with it.<br />Interop– cal...
Interesting Applications of Dynamic C#<br />
ActiveRecord<br />
“ActiveRecord” for XML<br />
Interop<br />
Abuses… oh yes…<br />You shuddering yet?  If not, you should be!<br />
Is dynamic programming the answer to anything and everything?<br />
Case For<br />Case Against<br />Performance – dynamic lookup just can’t be as fast as static lookup.<br />A lot fewer thin...
Demo – Stupid Dynamic C# Tricks<br />
Dynamic Everywhere?  My Thoughts<br />Performance argument has merit.  Sometimes.  No pretending Twitter didn’t happen.  <...
So you wanna do dynamic…<br />You will do TDD.  Without it, you are a mess of runtime errors and maintenance nightmares<br...
Questions?<br />
Thank You!<br />aaron.c.erickson@gmail.com<br />twitter.com/aaronerickson<br />http://nomadic-developer.com/<br />
Upcoming SlideShare
Loading in …5
×

Dynamic C# and a New World of Possibilities

1,509 views

Published on

Aaron Erickson's presentation about the dynamic features introduced in C# 4.0.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,509
On SlideShare
0
From Embeds
0
Number of Embeds
57
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • You may not eliminate state in your more traditional OO system, nor will you in an FP/OO hybrid – but you will likely make sure that things that manipulate state are seperated from things that ask questions. Question for audience – what are some common exceptions?
  • You may not eliminate state in your more traditional OO system, nor will you in an FP/OO hybrid – but you will likely make sure that things that manipulate state are seperated from things that ask questions. Question for audience – what are some common exceptions?
  • You may not eliminate state in your more traditional OO system, nor will you in an FP/OO hybrid – but you will likely make sure that things that manipulate state are seperated from things that ask questions. Question for audience – what are some common exceptions?
  • You may not eliminate state in your more traditional OO system, nor will you in an FP/OO hybrid – but you will likely make sure that things that manipulate state are seperated from things that ask questions. Question for audience – what are some common exceptions?
  • Dynamic C# and a New World of Possibilities

    1. 1. Dynamic C# - A New World of Possibilities<br />Aaron Erickson<br />Lead Consultant, ThoughtWorks<br />Author, The Nomadic Developer<br />Co-Author, Professional F# (coming soon!)<br />Microsoft MVP – C#<br />
    2. 2. The initial name of the talk before it was rejected…<br />Crazy Shit We Can Do With the Dynamic Keyword*<br />*Not all of this is a good idea (remember, use and abuse)<br />
    3. 3. C# - What it resembles now…<br />
    4. 4.
    5. 5.
    6. 6. C# - A little of everything…<br />Curly Braces (1.0)<br />Generics (2.0)<br />Functional “Lite” with Linq (3.0)<br />And Now, Dynamic (4.0)<br />
    7. 7. Duck Typing<br />
    8. 8.
    9. 9. Expando Objects<br />
    10. 10.
    11. 11. Treat Method Calls Like Messages<br />
    12. 12. Send Message<br />Receive Message<br />
    13. 13. And More…<br />Metaprogramming - take the expression tree called by the caller and do something with it.<br />Interop– call other people’s libraries written using real dynamic languages (Ruby, JS, Python).<br />
    14. 14. Interesting Applications of Dynamic C#<br />
    15. 15. ActiveRecord<br />
    16. 16. “ActiveRecord” for XML<br />
    17. 17. Interop<br />
    18. 18. Abuses… oh yes…<br />You shuddering yet? If not, you should be!<br />
    19. 19. Is dynamic programming the answer to anything and everything?<br />
    20. 20. Case For<br />Case Against<br />Performance – dynamic lookup just can’t be as fast as static lookup.<br />A lot fewer things are CPU bound than we tend to think. DB lookups? Really?<br />You were confused with var? dynamic will make your head spin.<br />Sorry – if you are confused with var, you really need to put down the keyboard and take up something for dummies, like investment banking.<br />What is so bad about using strings in a lookup (i.e. table[“field”] vstable.field)<br />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?)<br />If you want dynamic, just use a language designed for it, like Ruby! Or JavaScript!<br />Sometimes language choice is political. But need for dynamic remains.<br />
    21. 21. Demo – Stupid Dynamic C# Tricks<br />
    22. 22. Dynamic Everywhere? My Thoughts<br />Performance argument has merit. Sometimes. No pretending Twitter didn’t happen. <br />Dynamic readers for things like Json, XML, Text, Excel, etc – will be really wicked cool!<br />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”.<br />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.<br />Linq + Dynamic in C# is mostly unexplored territory. Some amazing things could come out of that intersection.<br />
    23. 23. So you wanna do dynamic…<br />You will do TDD. Without it, you are a mess of runtime errors and maintenance nightmares<br />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.<br />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.<br />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.<br />There is a good chance that schmuck will be me <br />
    24. 24. Questions?<br />
    25. 25. Thank You!<br />aaron.c.erickson@gmail.com<br />twitter.com/aaronerickson<br />http://nomadic-developer.com/<br />

    ×