17. “CLR hates Dynamic” “The speed of the current system is so low as to render the current implementation useless for anything beyond demonstration purposes.” – ActiveState’s report on Python for .NET “The CLI is, by design, not friendly to dynamic languages. Prototypes were built, but ran way too slowly.” – Jon Udell, InfoWorld, Aug. 2003
20. Dynamic Languages on .NET IronPython IronRuby Iron? VB.NET C# Common Language Runtime
21. Dynamic Languages on .NET IronPython IronRuby C# VB.NET Others… Dynamic Language Runtime Expression Trees Dynamic Dispatch Call Site Caching Python binder Rubybinder COMbinder JavaScriptbinder Objectbinder
22. .NET ?.? DLR2 The Common Language Runtime Script Hosting Compiler as a Service ??? .NET 4.0 DLR Expression Trees v2 Call Site Caching Dynamic Dispatch .NET 3.5 LINQ Expression Trees Extension Methods Silverlight .NET 2.0 Generics In Runtime Fast Delegates Dynamic Methods .NET 1.0 GC Reflection JIT BCL Dynamic Codegen Verifier Sandbox
27. IronPython “IronPythonis an open-source implementation of the Python programming language which is tightly integrated with the .NET Framework. IronPython can use the .NET Framework and Python libraries, and other .NET languages can use Python code just as easily.” - IronPython.net
28. IronRuby “IronRuby is a Open Source implementation of the Ruby programming language for .NET and Silverlight, heavily relying on Microsoft's Dynamic Language Runtime.” - IronRuby.net
29. IronWhat? True language implementation True to the language True to the community True to the experience Excellent performance Great integration with .NET Easy to use .NET libraries Easy to use other .NET languages Easy to use in .NET hosts Easy to use with .NET tools Implementation Running On .NET
38. [TestClass] public class StackTest{ [TestMethod] public void NewStackHasZeroElements(){ var s = new Stack<string>(); Assert.AreEqual<int>(0,s.Count); } [TestMethod] public void StackPeekTopElement() { var s = new Stack<string>(); s.Push("bob"); Assert.AreEqual<int>(1,s.Count); Assert.AreEqual<string>("bob",s.Peek()); } [TestMethod] public void StackPopTopElement() { var s = new Stack<string>(); s.Push("bob"); Assert.AreEqual<string>("bob",s.Pop()); Assert.AreEqual<int>(0,s.Count); } }
39. describe ".NET Stack Operations" do it "should create an instance with zero elements" do Stack.new.count.should.be 0 end it "should let us peek at the element pushed" do s = Stack.new s.push"bob" s.peek.should.be "bob" s.count.should.be 1 end it "should let us pop the element we pushed" do s = Stack.new s.push"bob" s.pop.should.be "bob" s.count.should.be 0 end end
40. describe ".NET Stack Operations" do ... end defdescribe(description) print "#{description}" yield puts "end" end
41. s.count.should.be 3 class PositiveExpectation definitialize(obj) @obj = objend defbe(other) if @obj != other print "Fail: wanted #{@obj} got #{other}" else print "Pass" end end end class Object defshould PositiveExpectation.new(self) end end
48. // this code assumes language info in app.config varsetup = ScriptRuntimeSetup.ReadConfiguration(); varruntime = new ScriptRuntime(setup); varengine = return runtime.GetEngine("Python"); engine.Execute("2 + 2");
49. // or you can hard code a specific language varpy_engine= Python.CreateEngine(); py_engine.Execute("2 + 2"); varrb_engine= Ruby.CreateEngine(); rb_engine.Execute("2 + 2");
Fashion: Big trend towards Dynamic Programming, (and Functional Programming and Concurrency) – this has come out of the trend for programming languages and frameworks becoming more concerned with productivity (where previously they were concerned with efficiency.)Fame: Lots of well-known people in the community (DHH, Martin Fowler, Charles Nutter, Uncle Bob, etc.)Weight Loss: Do more with less codeConvention over configuration Text Editor is enough (for some)Interest: What is possible, what can I do?Fortune: There are jobs that require skills in dynamic languages. Fortune might be overegging it a bit...Credit: Mark Bloodworth
Dynamic programming language is a term used broadly in computer science to describe a class of high levelprogramming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all. These behaviors could include extension of the program, by adding new code, by extending objects and definitions, or by modifying the type system, all during program execution. These behaviors can be emulated in nearly any language of sufficient complexity, but dynamic languages provide direct tools to make use of them.Dynamic languages and dynamic typing are not identical concepts, and a dynamic language need not be dynamically typed, though many dynamic languages are dynamically typed.A programming language is said to use dynamic typing when type checking is performed at run-time (also known as &quot;late-bindng&quot;) as opposed to at compile-time. Examples of languages that use dynamic typing include JavaScript, Lisp, Perl, PHP, Python, Ruby, and Smalltalk. Compared to static typing (or &apos;early-binding&apos;), dynamic typing is more flexible because of theoretical limitations on the decidability of certain static program analysis problems; these prevent the same level of flexibility from being achieved with static typing. There is also less code to write for a given functionality, but dynamic typing is slower at execution time.When used by itself, dynamic typing relies much more on testing for the discovery of errors. If code is not executed, then only interpreter checks for syntax can be done, as opposed to the additional type checks done in a statically typed language. These static type checks are necessarily simpler than those which can be applied at run time, since less information is available to the language system then. Infrequently executed code, such as error handlers, might take more effort to test in a dynamic typing context, but equally, there is no illusion that parts of a dynamic program are fit for purpose without them being tested, as opposed to being merely type-checked.Some examples of things done at runtime instead of compile time: Parsing type validation type creation method dispatch Field lookup Inheritance lookupIn a dynamically typed language, since those things are done at runtime, they can be changed at runtime too.Credit: Wikipedia / Harry PiersonBut what does all this mean?
Duck Typing / Dynamic TypingContinuations
Higher Order Functions – Højereordensfunktioner, lambdaClosures - the closure is basically a snapshot of the stack at the point that the lambda function is created. Then when the function is re-executed the stack is restored to that state before executing the functionhttp://www.flickr.com/photos/35064820@N00/3950391591/
MetaprogrammingCode as data, data as codeMetaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data, or that do part of the work at compile time that would otherwise be done at runtime. In many cases, this allows programmers to get more done in the same amount of time as they would take to write all the code manually, or it gives programs greater flexibility to efficiently handle new situations without recompilation.Wikipedia
Simplicity – users believe dynamic code to be simpler than static codeExpressive – syntax, readablePerspective - Examples –amazon, linkedin, facebook app, thoughtworks, Google, etc.Pragmatic Programmer advice – learn one new language a yearFamiliarity – can lead us to conclusionsMindset – learning and using new languages can help us to think differentlyCredit: Mark Bloodworth
Eksempler på de sprog vi skal kigge på: Python, RubyCredit: Mark Bloodworth
This is a model definition from Ruby on Rails for a DB table named Customers (emphasize the plural). Assuming we’re following the db schema conventions that Rails expects (and Nwind doesn’t), it can go out and grovel the schema from the database and update the class accordingly at runtime.The LINQ to SQL equivalent of this code is nearly 400 lines of generated C# code spit out of a fancy designer that Microsoft needed to build because it would be really time consuming to write the data context code by hand. Plus, you now have two copies of your DB schema to maintain – one in SQL DDL and on in C# - and it’s very important to keep them in sync. The ActiveRecord class, on the other hand, simply picks up the new DB schema automatically. Credit: Harry Pierson, Devhawk
DSL = Domain Specific Language
Sinatraer et web framework for Ruby. I DSL tankenerDomænet web applikationer.Sintraer ~1400 linier kodeVi prøver at lave en simpel demo først, ogbagefterprøver vi at udvide den til at være en fattigmandsfront-end til en søgemaskine.
SlideCredit: John Lam
Slide Credit: John LamCriticismThere are a number of things that I hear repeatedly about dynamic languagesUsually from people who haven’t really used them.Slow: Dynamic languages aren’t compiledBuggy: Static typed languages prevent bugsDifficult: Maintaining large codebase in languages, tool supportDangerous: There is some inherent safety in static typingSome Notes Credit: Mark Bloodworth
Lad os prøve at opsummere forskellene i opfattelser af dynamiske og statiske sprog.Bevidst meget karikeret!Dynamic: Scripting sprog, hurtige, dynamiske typer, kort udviklingshastighed længere køretid, fortolket, hacker culture, slår op på runtimeStatic: Sprog man skriver flysoftware i, langhåret, lang udviklingstid kort køretid, IDE’er, slår op på compiletimeSlide Credit:Bart De Smet
How could Microsoft have screwed up so badly that the CLR is far worse than the JVM for dynamic languages?Jythonshows that dynamic languages can run well on the JVMSlide credit: Jim Hugunin
http://www.flickr.com/photos/john_lam/2232308534/IronPython was originally created by Jim Hugunin, who also was the original creator of Jython. Jim wanted to write a paper titled “Why .NET is a terrible platform for dynamic languages”Detvarikkesådum en ide, ogdetkomIronPythonudafCredit: Harry Pierson
Efter IronPython fandt man ud af der var nogle fællestræk for sprog implementører der gerne vil have dynamiske sprog på CLR’en. De dele trak man ud af IronPython, og arbejdede videre på, og det er endt som DLR’eren.
De smet
Dynamic Codegen:Reflection.EmitFast Delegates important because used in call site caching, generics makes it easier to program with these virtual functions and callsDynamic methods: Part of the System.Reflection.Emit namespace, the DynamicMethod class allows you to create and execute methods at runtime without creating any dynamic assembly or dynamic type.Expression tree: An expression tree provides a method of translating executable code into data.Extension methods: string.WordCount:Count all words in a given string.Expression Trees v2 adds:- Add assignment- Add control-flow- Add dynamic dispatch nodes
Credit: Jim Hugunin
Modsætningen bryder ned, og der kommer et fælles sprog. De 2 verdener kan sameksistere og kommunikereDe Smet
Slide Credit: Jim Hugunin
Detbetyder Iron Sprog erførsteklassepå .NETplatformen, deterikke et appendix, et stedbarnellernogetandetværk. Deterfuldgyldigtmedlemaføkosystemet.De sprog Microsoft laver hedderIronPythonogIronRuby. Derudoverer der en del open source projekter med sprogimplementationer.“IronPython is an open-source implementation of the Python programming language which is tightly integrated with the .NET Framework. IronPython can use the .NET Framework and Python libraries, and other .NET languages can use Python code just as easily.” - IronPython.net“IronRuby is a Open Source implementation of the Ruby programming language for .NET and Silverlight, heavily relying on Microsoft&apos;s Dynamic Language Runtime.” - IronRuby.netSome parts Credit: Harry Pierson, Devhawk
Python comes with batteries included.Fuld implementation af Python sprog (syntaks + semantik) plus standardbiblioteker
Targets 1.8.6
Efterrationalisering,De smet
MS-PL, OSI ratified licenseIronRuby takes contributions to libraries
IronJS: compiles Jquery 1.4
Vi har set lidt på hvad dynamiske sprog er, og hvrodan det er implementeret i .NET vha DLR’eren.Så hvad skal vi bruge det til, hvorfor er det interessant for os som .NET udviklere?”Wet your appetite for more”
”.NET to the dynamic masses”
”.NET to the dynamic masses””The right tool for the job”Polyglot programmer – den flersprogede programmerhttp://www.istockphoto.com/stock-photo-5245804-carpenter-tool-belt-and-tools-isolated-on-white.php
Easy to extend – skriv udvidelser i .NET/C# i stedet for CEasy to embed – embed som pluginarkitektur, scriptable appsInterop m. Eksisterende .NETDSL”Enterprise apps”Limen mellem den eksisterende investering i Python kode og til .Net til at udnytte de muligheder der er heri.
Credit: Harry Pierson, devhawk
Credit: Harry Pierson, devhawk
Credit: Harry Pierson, devhawk
Credit: Harry Pierson, devhawk
Rails is the killer application for Ruby. Any ruby implementation must be able to run Railshttp://www.flickr.com/photos/mirkogarufi/363286628/
IronPython in https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=475830Python 3 support er MIA.VS support manglerpga legalDevhawk
Jimmy: 95% pass rate on ruby spec, 1,5 times faster than MRIRails: above 95%1.0: when the community thinks it’s ready. Focus is on perf and bug fixes to be as compatible as possible with 1.8.6Credit: Harry Pierson, devhawk
Build a dynamic language with the DLRLearn a dynamic languageIncorporate a dynamic language into your architectureCreate a dynamic library for .NETUse C# 4.0 and dynamicSlide credit: John Lam,Some Notes: Mark Bloodworth