1 / 25

Dynamic C# - A New World of Possibilities

Dynamic C# - A New World of Possibilities. Aaron Erickson Lead Consultant, ThoughtWorks Author, The Nomadic Developer Co-Author, Professional F# (coming soon!) Microsoft MVP – C#. Crazy Shit We Can Do With the Dynamic Keyword *. The initial name of the talk before it was rejected….

lilac
Download Presentation

Dynamic C# - A New World of Possibilities

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dynamic C# - A New World of Possibilities Aaron Erickson Lead Consultant, ThoughtWorks Author, The Nomadic Developer Co-Author, Professional F# (coming soon!) Microsoft MVP – C#

  2. Crazy Shit We Can Do With the Dynamic Keyword* • The initial name of the talk before it was rejected… *Not all of this is a good idea (remember, use and abuse)

  3. C# - What it resembles now…

  4. C# - A little of everything… Curly Braces (1.0) Generics (2.0) Functional “Lite” with Linq (3.0) And Now, Dynamic (4.0)

  5. Duck Typing

  6. Expando Objects

  7. Treat Method Calls Like Messages

  8. Send Message Receive Message

  9. 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).

  10. Interesting Applications of Dynamic C#

  11. ActiveRecord

  12. “ActiveRecord” for XML

  13. Interop

  14. Abuses… oh yes… You shuddering yet? If not, you should be!

  15. Is dynamic programming the answer to anything and everything?

  16. Case For Case Against Performance – dynamic lookup just can’t be as fast as static lookup. • A lot fewer things are CPU bound than we tend to think. DB lookups? Really? • You were confused with var? dynamic will make your head spin. • Sorry – if you are confused with var, you really need to put down the keyboard and take up something for dummies, like investment banking. • What is so bad about using strings in a lookup (i.e. table[“field”] vstable.field) • 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?) • If you want dynamic, just use a language designed for it, like Ruby! Or JavaScript! • Sometimes language choice is political. But need for dynamic remains.

  17. Demo – Stupid Dynamic C# Tricks

  18. Dynamic Everywhere? My Thoughts Performance 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.

  19. 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 

  20. Questions?

  21. Thank You! aaron.c.erickson@gmail.com twitter.com/aaronerickson http://nomadic-developer.com/

More Related