1 / 32

Dynamic Languages

Extending .NET Applications Philly.NET Code Camp 2010.2 2010-10-09 John C. Zablocki Development Lead, MagazineRadar Adjunct, Fairfield University. Dynamic Languages. 2:00 PM. On a Saturday. Philadelphia, PA. Agenda. Dynamic vs. Static Languages Dynamic Language Runtime (DLR) ‏

Download Presentation

Dynamic Languages

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. Extending .NET Applications Philly.NET Code Camp 2010.2 2010-10-09John C. Zablocki Development Lead, MagazineRadar Adjunct, Fairfield University Dynamic Languages

  2. 2:00 PM

  3. On a Saturday

  4. Philadelphia, PA

  5. Agenda Dynamic vs. Static Languages Dynamic Language Runtime (DLR)‏ Use Cases for Script Hosting DLR Hosting API Sample: Boo Sample: IronRuby Sample: IronPython Questions

  6. Static vs. Dynamic Languages Static Languages Type safety Compile-time checking Runtime performance Dynamic Languages Late bound Loosely typed Highly expressive

  7. “The Gang Learns About the DLR...”

  8. Dynamic Language Runtime(From CodePlex)‏

  9. Dynamic Language Runtime Language implementation services Language interoperability Shared dynamic type system Runtime services Fast dynamic code generation through various caching mechanisms Utilities to allow statically typed objects to share in the dynamic message passing protocol

  10. Script Hosting Use Cases Why would you want to host a scripting language in your application? Provide extensibility (the obvious answer)‏ Replace complicated XML configuration (e.g. NAnt, EntLib, etc.) with meaningful code Remove clutter from core application logic (validation, sanity checks, etc.)‏ Maintain transient logic outside of core application code (rules processing)‏

  11. Hosting API(from CodePlex)‏

  12. Hosting API ScriptRuntime Starting point for hosting Represents global script state (referenced assemblies, available engines, etc.) Bound scopes (named globals)‏ Constructed with ScriptRuntimeSetup, which uses configuration settings

  13. Hosting API ScriptEngine Represents a DLR language implementation (PythonEngine, RubyEngine)‏ One engine, per-language, per-runtime Methods to execute code and create ScriptScope instances

  14. Hosting API ScriptScope Essentially represents a namespace Unit of isolation within a runtime Has language affinity Variables may be set and retrieved at scope ScriptRuntime.Globals is actually an instance of a ScriptScope

  15. Hosting API ScriptSource Represents source code Provides means for code execution and compilation Created from ScriptEngine or ScriptScope instances

  16. “John Demos the DLR Hosting API...”

  17. “The Gang Learns About The (Iron)Python Programming Language...”

  18. Introducing IronPython

  19. The (Iron)Python Language CLI implementation of the Python language Hosted on CodePlex Integration with many common Python libraries Built on top of the DLR

  20. from System import * class Message(object): def __init__(self, message): self._message = message def get_message(self): return self._message message = property(get_message) @property def audience(self): return self._audience @audience.setter def audience(self, audience): self._audience = audience def show_message(self, message_formatter): print message_formatter(self.message, self.audience) IronPython in 60 Seconds

  21. m = Message(“Hello”) m.audience = “World” m.show_message(lambda message, audience: “%s, %s!” % (message, audience)) IronPython in 60 Seconds

  22. “John Demos Some IronPython Code...”

  23. “The Gang Learns About The Boo Programming Language...”

  24. Introducing Boo

  25. The Boo Language Object oriented, statically typed language built for the CLI Has a Python-like feel (whitespace matters)‏ Supports Duck typing (dynamic-like behavior)‏ Flexible syntax, InteractiveInterpreter and extensible compiler makes boo a good choice for DSL implementations

  26. Boo in 60 Seconds import System class Message(object): def constructor(message): _message = message [Getter(Message)] _message as string [Property(Audience)] _audience as string def show_message(message_formatter as callable): print message_formatter(_message, _audience)

  27. Boo in 60 Seconds m = Message("Hello", Audience: "World") m.show_message def(message, audience): print "${message}, ${audience}!"

  28. “John Demos Some Boo Code...”

  29. Resources http://www.codevoyeur.com – my code http://www.dllhell.net – my blog http://www.linkedin.com/in/johnzablocki http://twitter.com/codevoyeur http://www.codeplex.com/dlr http://www.ironpython.net http://boo.codehaus.org

  30. Questions?

  31. “It's Always Sunny At the Philly.NET Code Camp”

More Related