IronSprog<br />//kristiankristensen.dk<br />twitter.com/kkristensen<br />kristian.kristensen@microsoft.com<br />
Agenda<br />
Why Dynamic Languages<br />
What makes a language “dynamic”? <br />
http://www.flickr.com/photos/35064820@N00/3950391591/<br />
http://www.flickr.com/photos/janineberben/3219556705/<br />
Why Dynamic Languages<br />
Eksempler<br />C#<br />class Program<br />{<br />    static void Main(string[] args)<br />    {<br />Console.WriteLine(&qu...
class Customer &lt; ActiveRecord::Base<br />end<br />
DSL<br />
http://www.flickr.com/photos/parksy/828680991/sizes/o/<br />
http://www.flickr.com/photos/jamesdale10/2151196493/<br />http://www.flickr.com/photos/pandiyan/1339056452/<br />
The traditional view of the world<br />
“CLR hates Dynamic”<br />“The speed of the current system is so low as to render the current implementation useless for an...
Dynamic Language Runtime<br />
Dynamic Languages on .NET<br />IronPython<br />IronRuby<br />Iron?<br />VB.NET<br />C#<br />Common Language Runtime<br />
Dynamic Languages on .NET<br />IronPython<br />IronRuby<br />C#<br />VB.NET<br />Others…<br />Dynamic Language Runtime<br ...
.NET ?.?<br />DLR2<br />The Common Language Runtime<br />Script Hosting<br />Compiler as<br />a Service<br />???<br />.NET...
Multiple Language Dynamic Dispatch<br />IronPython<br />x.Foo<br />IronRuby<br />x.Foo<br />C#<br />x.Foo<br />VB.NET<br /...
Common Language = CLR + DLR<br />Today’s view of the world<br />
Iron languages arefirst class .NET citizens<br />
IronPython<br />“IronPythonis an open-source implementation of the Python programming language which is tightly integrated...
IronRuby<br />“IronRuby is a Open Source implementation of the Ruby programming language for .NET and Silverlight, heavily...
IronWhat?<br />True language implementation<br />True to the language<br />True to the community<br />True to the experien...
Languages on DLR<br />Pictures<br />
Break<br />
Why<br />
Why Iron* Languages?<br />
Ruby Test Framework<br />
[TestClass]<br />public class StackTest{<br />    [TestMethod]<br />public void NewStackHasZeroElements(){<br />var s = ne...
describe &quot;.NET Stack Operations&quot; do<br />it &quot;should create an instance with zero elements&quot; do<br />Sta...
describe &quot;.NET Stack Operations&quot; do ... end<br />defdescribe(description)<br />print &quot;#{description}&quot;<...
s.count.should.be 3<br />class PositiveExpectation<br />definitialize(obj) @obj = objend<br />defbe(other)<br />if @obj !=...
Enterprisey<br />
http://www.flickr.com/photos/mirkogarufi/363286628/<br />
.NET interop<br />
(Video)<br />
Easy to embed<br />
// this code assumes language info in app.config<br />varsetup = ScriptRuntimeSetup.ReadConfiguration();<br />varruntime =...
// or you can hard code a specific language<br />varpy_engine= Python.CreateEngine();<br />py_engine.Execute(&quot;2 + 2&q...
Bad Paint<br />
Upcoming SlideShare
Loading in …5
×

Iron Sprog Tech Talk

1,457 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,457
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Spørgsmål: Dynamisk/statisk typede sprog, .NET, JVM, JavaScript, PHP
  • 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 &amp;quot;late-bindng&amp;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 &amp;apos;early-binding&amp;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
  • Runtime Introspectionhttp://www.flickr.com/photos/janineberben/3219556705/
  • 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&amp;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/
  • IronBunny. CI with TFS
  • Credit: Harry Pierson, devhawk
  • Credit: Harry Pierson, devhawk
  • http://www.amazon.com/Road-Ahead-Bill-Gates/dp/0453009212/ref=sr_1_2?ie=UTF8&amp;s=books&amp;qid=1264950459&amp;sr=8-2
  • http://www.britannica.com/EBchecked/topic-art/505178/97220/Traffic-sign-indicating-a-winding-road
  • 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
  • Devhawk
  • Credit: Mark Bloodworth
  • Iron Sprog Tech Talk

    1. 1. IronSprog<br />//kristiankristensen.dk<br />twitter.com/kkristensen<br />kristian.kristensen@microsoft.com<br />
    2. 2. Agenda<br />
    3. 3. Why Dynamic Languages<br />
    4. 4. What makes a language “dynamic”? <br />
    5. 5.
    6. 6. http://www.flickr.com/photos/35064820@N00/3950391591/<br />
    7. 7.
    8. 8. http://www.flickr.com/photos/janineberben/3219556705/<br />
    9. 9. Why Dynamic Languages<br />
    10. 10. Eksempler<br />C#<br />class Program<br />{<br /> static void Main(string[] args)<br /> {<br />Console.WriteLine(&quot;Hello World&quot;);<br /> } <br />}<br />Ruby<br />puts “Hello World”<br />
    11. 11. class Customer &lt; ActiveRecord::Base<br />end<br />
    12. 12. DSL<br />
    13. 13.
    14. 14. http://www.flickr.com/photos/parksy/828680991/sizes/o/<br />
    15. 15. http://www.flickr.com/photos/jamesdale10/2151196493/<br />http://www.flickr.com/photos/pandiyan/1339056452/<br />
    16. 16. The traditional view of the world<br />
    17. 17. “CLR hates Dynamic”<br />“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<br />“The CLI is, by design, not friendly to dynamic languages. Prototypes were built, but ran way too slowly.” – Jon Udell, InfoWorld, Aug. 2003<br />
    18. 18.
    19. 19. Dynamic Language Runtime<br />
    20. 20. Dynamic Languages on .NET<br />IronPython<br />IronRuby<br />Iron?<br />VB.NET<br />C#<br />Common Language Runtime<br />
    21. 21. Dynamic Languages on .NET<br />IronPython<br />IronRuby<br />C#<br />VB.NET<br />Others…<br />Dynamic Language Runtime<br />Expression Trees<br />Dynamic Dispatch<br />Call Site Caching<br />Python<br />binder<br />Rubybinder<br />COMbinder<br />JavaScriptbinder<br />Objectbinder<br />
    22. 22. .NET ?.?<br />DLR2<br />The Common Language Runtime<br />Script Hosting<br />Compiler as<br />a Service<br />???<br />.NET 4.0<br />DLR<br />Expression<br />Trees v2<br />Call Site Caching<br />Dynamic<br />Dispatch<br />.NET 3.5<br />LINQ<br />Expression<br />Trees<br />Extension<br />Methods<br />Silverlight<br />.NET 2.0<br />Generics<br />In Runtime<br />Fast<br />Delegates<br />Dynamic<br />Methods<br />.NET 1.0<br />GC<br />Reflection<br />JIT<br />BCL<br />Dynamic<br />Codegen<br />Verifier<br />Sandbox<br />
    23. 23. Multiple Language Dynamic Dispatch<br />IronPython<br />x.Foo<br />IronRuby<br />x.Foo<br />C#<br />x.Foo<br />VB.NET<br />x.Foo<br />Dynamic Language Runtime<br />GetMember<br />Name=“Foo”, IgnoreCase=false<br />ObjectBinder<br />PythonBinder<br />RubyBinder<br />COMBinder<br />
    24. 24. Common Language = CLR + DLR<br />Today’s view of the world<br />
    25. 25.
    26. 26. Iron languages arefirst class .NET citizens<br />
    27. 27. IronPython<br />“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<br />
    28. 28. IronRuby<br />“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.net<br />
    29. 29. IronWhat?<br />True language implementation<br />True to the language<br />True to the community<br />True to the experience<br />Excellent performance<br />Great integration with .NET<br />Easy to use .NET libraries<br />Easy to use other .NET languages<br />Easy to use in .NET hosts<br />Easy to use with .NET tools<br />Implementation Running On .NET<br />
    30. 30.
    31. 31. Languages on DLR<br />Pictures<br />
    32. 32. Break<br />
    33. 33. Why<br />
    34. 34.
    35. 35.
    36. 36. Why Iron* Languages?<br />
    37. 37. Ruby Test Framework<br />
    38. 38. [TestClass]<br />public class StackTest{<br /> [TestMethod]<br />public void NewStackHasZeroElements(){<br />var s = new Stack&lt;string&gt;();<br />Assert.AreEqual&lt;int&gt;(0,s.Count); }<br /> [TestMethod]<br />public void StackPeekTopElement() {<br />var s = new Stack&lt;string&gt;();<br />s.Push(&quot;bob&quot;);<br />Assert.AreEqual&lt;int&gt;(1,s.Count);<br />Assert.AreEqual&lt;string&gt;(&quot;bob&quot;,s.Peek()); }<br /> [TestMethod]<br />public void StackPopTopElement() {<br />var s = new Stack&lt;string&gt;();<br />s.Push(&quot;bob&quot;);<br />Assert.AreEqual&lt;string&gt;(&quot;bob&quot;,s.Pop());<br />Assert.AreEqual&lt;int&gt;(0,s.Count); } }<br />
    39. 39. describe &quot;.NET Stack Operations&quot; do<br />it &quot;should create an instance with zero elements&quot; do<br />Stack.new.count.should.be 0<br />end<br />it &quot;should let us peek at the element pushed&quot; do<br />s = Stack.new<br />s.push&quot;bob&quot;<br />s.peek.should.be &quot;bob&quot;<br />s.count.should.be 1<br />end<br />it &quot;should let us pop the element we pushed&quot; do<br />s = Stack.new<br />s.push&quot;bob&quot;<br />s.pop.should.be &quot;bob&quot;<br />s.count.should.be 0<br />end<br />end <br />
    40. 40. describe &quot;.NET Stack Operations&quot; do ... end<br />defdescribe(description)<br />print &quot;#{description}&quot;<br />yield<br />puts &quot; end &quot;<br />end<br />
    41. 41. s.count.should.be 3<br />class PositiveExpectation<br />definitialize(obj) @obj = objend<br />defbe(other)<br />if @obj != other<br />print &quot;Fail: wanted #{@obj} got #{other}&quot;<br />else<br />print &quot;Pass&quot;<br />end<br />end<br />end<br />class Object<br />defshould PositiveExpectation.new(self) end<br />end<br />
    42. 42. Enterprisey<br />
    43. 43. http://www.flickr.com/photos/mirkogarufi/363286628/<br />
    44. 44. .NET interop<br />
    45. 45.
    46. 46. (Video)<br />
    47. 47. Easy to embed<br />
    48. 48. // this code assumes language info in app.config<br />varsetup = ScriptRuntimeSetup.ReadConfiguration();<br />varruntime = new ScriptRuntime(setup);<br />varengine = return runtime.GetEngine(&quot;Python&quot;);<br />engine.Execute(&quot;2 + 2&quot;);<br />
    49. 49. // or you can hard code a specific language<br />varpy_engine= Python.CreateEngine();<br />py_engine.Execute(&quot;2 + 2&quot;);<br />varrb_engine= Ruby.CreateEngine();<br />rb_engine.Execute(&quot;2 + 2&quot;);<br />
    50. 50. Bad Paint<br />
    51. 51. The road ahead (picture)<br />
    52. 52. The road ahead (picture)<br />
    53. 53. IronPython Roadmap<br />
    54. 54. IronRuby Roadmap<br />
    55. 55.
    56. 56. http://ironpython.codeplex.com<br />http://ironruby.net<br />http://dlr.codeplex.com<br />
    57. 57. Resources<br />Michael Foords bloghttp://www.voidspace.org.uk/<br />
    58. 58. The end.<br />
    59. 59. //kristiankristensen.dk//twitter.com/kkristensenkristian.kristensen@microsoft.com<br />

    ×