Date post: | 05-Apr-2018 |
Category: |
Documents |
Upload: | anjaneyulu-savilla |
View: | 223 times |
Download: | 0 times |
of 18
8/2/2019 Ph 2010 Dynamic Languages
1/18
Dynamic LanguagesExtending .NET Applications
John C. ZablockiDevelopment Lead, MagazineRadar, Inc.
Adjunct, Fairfield University
April 10, 2010
8/2/2019 Ph 2010 Dynamic Languages
2/18
Platinum and Gold Partners
8/2/2019 Ph 2010 Dynamic Languages
3/18
Agenda
Dynamic vs. Static Languages
Use Cases for Script Hosting
Dynamic Language Runtime (DLR) DLR Hosting API
Tips and Techniques
Samples: IronPython, IronRuby and Boo Questions
8/2/2019 Ph 2010 Dynamic Languages
4/18
Static vs. Dynamic Languages
Static Languages
Type safety
Compile-time checking
Runtime performance
Syntactic Sugar
Dynamic Languages Late bound
Loosely typed
Highly expressive
8/2/2019 Ph 2010 Dynamic Languages
5/18
Script Hosting Use Cases
Why would you want to host a scriptinglanguage 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)
8/2/2019 Ph 2010 Dynamic Languages
6/18
Dynamic Language Runtime(From CodePlex)
8/2/2019 Ph 2010 Dynamic Languages
7/18
Dynamic Language Runtime
Language implementation services
Language interoperability
Shared dynamic type system
Runtime services
Fast dynamic code generation through variouscaching mechanisms
Utilities to allow statically typed objects to sharein the dynamic message passing protocol
8/2/2019 Ph 2010 Dynamic Languages
8/18
Hosting API(from CodePlex)
AppDomain - #1
ScriptRuntime
Application ScriptHost
ScriptEngine
default
ScriptHost
ScriptScope
ScriptScopeScriptScope
.NET component loaded by Application
ScriptRuntime
ScriptEngine
defaultScriptHost
AppDomain - #2
ScriptRuntime
LocalScriptHost
default ScriptHost
ScriptEngine
ScriptScopeScriptScope
ScriptScope
8/2/2019 Ph 2010 Dynamic Languages
9/18
Hosting API
ScriptRuntime
Starting point for hosting
Represents global script state (referencedassemblies, available engines, etc.)
Bound scopes (named globals)
Constructed with ScriptRuntimeSetup, whichuses configuration settings
8/2/2019 Ph 2010 Dynamic Languages
10/18
Hosting API
ScriptEngine
Represents a DLR language implementation
(PythonEngine, RubyEngine)
One engine, per-language, per-runtime
Methods to execute code and createScriptScope instances
8/2/2019 Ph 2010 Dynamic Languages
11/18
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 ofa ScriptScope
8/2/2019 Ph 2010 Dynamic Languages
12/18
Hosting API
ScriptSource
Represents source code
Provides means for code execution andcompilation
Created from ScriptEngine or ScriptScopeinstances
8/2/2019 Ph 2010 Dynamic Languages
13/18
Hosting Tips and Techniques
The script is an extension of the application,not core application logic
Treat the script as if it were a plugin orprovider implementing an interface.
Create a simple object graph to act as thecontroller between the script and model
Provide the script with function referencesto work indirectly with model objects
8/2/2019 Ph 2010 Dynamic Languages
14/18
The IronPython Language
CLI implementation of the Python language
Hosted on CodePlex
Integration with many common Pythonlibraries
Built on top of the DLR
Sample: Hosted IronPython
8/2/2019 Ph 2010 Dynamic Languages
15/18
The IronRuby Language
CLI implementation of the Ruby language
Hosted on RubyForge
Built on top of the DLR
Sample: Hosted IronRuby
8/2/2019 Ph 2010 Dynamic Languages
16/18
The Boo Language
Object oriented, statically typed languagewritten for the CLI
Has a Python-like feel (whitespace, blocks) Supports Duck typing (dynamic-like behavior)
Flexible syntax, extensible compiler andInteractiveInterpreter make it strong choice forDSL implementations
Sample: Hosted Boo
8/2/2019 Ph 2010 Dynamic Languages
17/18
Resources
http://www.codevoyeur.com DLR + BooSamples, other OSS samples, presentations
and articles http://www.dllhell.net My blog
http://www.codeplex.com/dlr
http://www.codeplex.com/IronPython
http://boo.codehaus.org
http://www.ironruby.net
8/2/2019 Ph 2010 Dynamic Languages
18/18
Questions?