Monday, November 10, 2008

Mixing Static and Dynamic Languages

Kevin Hazzard presented at the Philly Code Camp about mixing DLR (Dynamic Language Runtime) based languages with statically typed languages like C#.
"The gist of this presentation is that it's possible to mix the Dynamic Language Runtime (DLR) into statically-typed, early-bound languages like C# to make them much more flexible. In this talk, I demonstrated how a ShoppingCart being filled with Products can adjust discount rates based on marketing rules written in an external Domain Specific Language (DSL). In this case, my DSL was really just Python. I chose to use Python because the syntax is so simple and clean. It's so light, it doesn't get in the way. It's not a real DSL, of course, but by injecting .NET objects into a ScriptScope on a ScriptRuntime (all DLR hosting terms), the Python syntax acting on those injected types looks an awful lot like a language for managing product discounts."

Slides and code examples are linked to from the blog entry.

UPDATE: Kevin has done a 'November Update' to this presentation, for an upcoming Raleigh Code Camp talk. The new blog entry has screenshots and updated code to download:
I like a couple of comments on this entry:

"Python code is pretty easy to read isn't it."

"One of the most often asked questions I get when talking about IronPython is, "How do I convince my boss to let me write that application in Python?" My answer is, "You don't have to write the whole thing in Python. With the fantastically rich hosting APIs in the .NET Dynamic Language Runtime (DLR), you can write the portions that need dynamism in Python and write the rest in C# or VB.NET."

No comments:

Post a Comment

Note: only a member of this blog may post a comment.