Mps Presentation


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Mps Presentation

  1. 1. Extending Java And Developing DSLs With JetBrains MPS Konstantin Solomatov JetBrains Lead Developer for JetBrains MPS Project
  2. 2. Agenda <ul><li>Extending languages. Why bother? </li></ul><ul><li>Problems and solutions </li></ul><ul><ul><li>Composability </li></ul></ul><ul><ul><li>Language support </li></ul></ul><ul><li>MPS’ approach </li></ul><ul><ul><li>Idea behind it </li></ul></ul><ul><ul><li>Hands-on demo </li></ul></ul><ul><li>MPS & domain-specific languages </li></ul>
  3. 3. Why Bother? <ul><li>Specific domains = specific entities </li></ul><ul><li>Drawbacks of general-purpose languages: </li></ul><ul><ul><li>Limited set of generic constructs </li></ul></ul><ul><ul><li>Domains are described too verbosely </li></ul></ul><ul><ul><li>Low code maintainability </li></ul></ul><ul><li>Domain-specific extensions </li></ul><ul><ul><li>Higher abstraction level </li></ul></ul><ul><ul><li>Higher maintainability </li></ul></ul>
  4. 4. Implicit Language Extensions <ul><li>Domain-specific constructs in Java: </li></ul><ul><ul><li>synchronized block in Java </li></ul></ul><ul><ul><li>enhanced for in Java </li></ul></ul><ul><ul><li>typesafe enums in Java </li></ul></ul><ul><li>Desired constructs: </li></ul><ul><ul><li>closures </li></ul></ul><ul><ul><li>yield </li></ul></ul><ul><ul><li>better support for regexps </li></ul></ul><ul><ul><li>whatever else you are missing </li></ul></ul>
  5. 5. Language Extensions <ul><li>Existing extensions </li></ul><ul><ul><li>Cover domain-specific needs </li></ul></ul><ul><ul><li>Are built into existing languages </li></ul></ul><ul><li>Further extensions </li></ul><ul><ul><li>Hard to integrate </li></ul></ul><ul><ul><li>Too long to wait until JCP accepts them  </li></ul></ul><ul><ul><li>Risks of incompatibility </li></ul></ul>
  6. 6. MPS DEMO <ul><li>Closure & UI Language samples. </li></ul>
  7. 7. Agenda <ul><li>Extending Languages. Why bother? </li></ul><ul><li>Problems and Solutions </li></ul><ul><ul><li>Composability </li></ul></ul><ul><ul><li>Language support </li></ul></ul><ul><li>MPS’ Approach </li></ul><ul><ul><li>Idea behind it </li></ul></ul><ul><ul><li>Hands-on Demo </li></ul></ul><ul><li>MPS & Domain-Specific Languages </li></ul>
  8. 8. Composability <ul><li>Definition: </li></ul><ul><li>Components are composable when they can be used together even if created by different parties </li></ul>
  9. 9. Composability Desired Goal <ul><li>Java Libraries </li></ul><ul><li>Hibernate </li></ul><ul><li>Spring </li></ul><ul><li>Joda Time </li></ul><ul><li>Java Extensions </li></ul><ul><li>DB Language </li></ul><ul><li>DI Language </li></ul><ul><li>Dates Language </li></ul>
  10. 10. Composability Libraries vs. Extensions <ul><li>Libraries are composable: </li></ul><ul><ul><li>Java + Hibernate => OK </li></ul></ul><ul><ul><li>Java + Spring => OK </li></ul></ul><ul><ul><li>Java + Hibernate, Spring => OK </li></ul></ul><ul><li>Language extensions are not </li></ul><ul><ul><li>Java + extension A => OK </li></ul></ul><ul><ul><li>Java + extension B => OK </li></ul></ul><ul><ul><li>Java + extensions A, B => possible ambiguity </li></ul></ul>
  11. 11. Composability Grammar Ambiguity Sample With String Interpolation <ul><li>Extension “A”: </li></ul><ul><li>int resultsCount = <some_code>; string s = “Found ${resultCount} results”; </li></ul><ul><li>Extension “B”: </li></ul><ul><li>int resultCount = <some_code>; string t = “Found {resultCount} results”; </li></ul><ul><li>“ A” + “B” => ambiguity for the compiler: </li></ul><ul><li>string a = “Account balance is $ {balance} ”; </li></ul>
  12. 12. Language Support Requirements <ul><li>Generic infrastructure </li></ul><ul><ul><li>Abstract grammar </li></ul></ul><ul><ul><li>Type system </li></ul></ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Etc. </li></ul></ul><ul><li>IDE infrastructure </li></ul><ul><ul><li>Editor </li></ul></ul><ul><ul><li>Error highlighting </li></ul></ul><ul><ul><li>Refactoring </li></ul></ul><ul><ul><li>Version control </li></ul></ul><ul><ul><li>Etc. </li></ul></ul>
  13. 13. Language Support Problems <ul><li>Time- and resource-consuming task </li></ul><ul><ul><li>Complicated algorithms for processing code </li></ul></ul><ul><ul><li>Highly qualified developers required </li></ul></ul><ul><li>Resulting infrastructure composability </li></ul><ul><ul><li>Type systems to be compatible with different extensions </li></ul></ul><ul><ul><li>Refactorings should support potential extensions </li></ul></ul><ul><ul><li>Etc. </li></ul></ul>
  14. 14. Existing Solutions Pros & Cons Composability Language Infrastructure LISP Yes No Internal DSLs in Ruby / Groovy Yes No XText Framework No Yes
  15. 15. Common Problem <ul><li>Existing solutions provide: </li></ul><ul><ul><li>Either composable language extensions </li></ul></ul><ul><ul><li>Or a decent infrastructure </li></ul></ul><ul><ul><li>Not both </li></ul></ul>
  16. 16. Agenda <ul><li>Extending Languages. Why bother? </li></ul><ul><li>Problems and Solutions </li></ul><ul><ul><li>Composability </li></ul></ul><ul><ul><li>Language support </li></ul></ul><ul><li>MPS’ Approach </li></ul><ul><ul><li>Idea behind it </li></ul></ul><ul><ul><li>Hands-on Demo </li></ul></ul><ul><li>MPS & Domain-Specific Languages </li></ul>
  17. 17. Our Solution to the Problem <ul><li>JetBrains MPS </li></ul><ul><ul><li>Workbench for defining and extending languages </li></ul></ul><ul><ul><li>IDE for new languages and extensions </li></ul></ul>
  18. 18. Idea Behind It <ul><li>Text-based grammars lead to ambiguities </li></ul><ul><li>Another approach needed </li></ul><ul><li>MPS works with Abstract Syntax Tree directly </li></ul>
  19. 19. Idea Behind It Editing Abstract Syntax Tree <ul><li>Former attempts </li></ul><ul><ul><li>Diagram-based editing </li></ul></ul><ul><ul><li>Limited domain of application </li></ul></ul><ul><li>MPS solution </li></ul><ul><ul><li>Keeps user in habitual environment </li></ul></ul><ul><ul><li>Supports text-like editing </li></ul></ul>
  20. 20. Idea Behind It Projectional Editor <ul><li>Each node of a syntax tree has its projection in the MPS Editor </li></ul>
  21. 21. Idea Behind It Projectional Editor <ul><li>Each node – in a dedicated cell </li></ul><ul><li>A node is shown in its text/symbol representation </li></ul><ul><li>Instantly synchronized editor and syntax tree </li></ul>
  22. 22. Idea Behind It Projection vs. Text <ul><li>Text-like projectional editor </li></ul><ul><li>Has its pros & cons </li></ul><ul><li>Reasonable learning curve: approx. 2 weeks </li></ul>
  23. 23. MPS DEMO <ul><li>Projectional editor in use. </li></ul>
  24. 24. Idea Behind It Language Support <ul><li>User-defined language infrastructure </li></ul><ul><ul><li>Abstract grammar </li></ul></ul><ul><ul><li>Type system </li></ul></ul><ul><ul><li>Editor </li></ul></ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Etc. </li></ul></ul><ul><li>Programming assistance </li></ul><ul><ul><li>Completion </li></ul></ul><ul><ul><li>Find usages </li></ul></ul><ul><ul><li>Rename </li></ul></ul><ul><ul><li>Etc. </li></ul></ul>
  25. 25. Idea Behind It Existing Languages & Extensions <ul><li>Java™ re-implemented with MPS + Extensions </li></ul><ul><ul><li>Collections language </li></ul></ul><ul><ul><li>Dates language </li></ul></ul><ul><ul><li>Closures language </li></ul></ul><ul><ul><li>Regexp language </li></ul></ul><ul><ul><li>Etc. </li></ul></ul><ul><li>Language definition languages </li></ul><ul><ul><li>Implemented with themselves i.e. bootstrapped </li></ul></ul><ul><li>Misc languages (XML, etc.) </li></ul>
  26. 26. Hands-On Demo Goal <ul><li>Java </li></ul><ul><li>ReadWriteLock l = … </li></ul><ul><li>l.readLock().lock(); </li></ul><ul><li>try { </li></ul><ul><li>//code </li></ul><ul><li>} finally { </li></ul><ul><li>l.readLock().unlock(); </li></ul><ul><li>} </li></ul><ul><li>Java + Extension </li></ul><ul><li>ReadWriteLock l = … </li></ul><ul><li>read (l) { </li></ul><ul><li>//code </li></ul><ul><li>} </li></ul>
  27. 27. Hands-On Demo Workflow <ul><li>We will define </li></ul><ul><ul><li>Structure </li></ul></ul><ul><ul><li>Editor </li></ul></ul><ul><ul><li>Typesystem </li></ul></ul><ul><ul><li>Generator </li></ul></ul>
  28. 28. MPS DEMO <ul><li>Adding lock statement to Java </li></ul>
  29. 29. Agenda <ul><li>Extending Languages. Why bother? </li></ul><ul><li>Problems and Solutions </li></ul><ul><ul><li>Composability </li></ul></ul><ul><ul><li>Language support </li></ul></ul><ul><li>MPS’ Approach </li></ul><ul><ul><li>Idea behind it </li></ul></ul><ul><ul><li>Hands-on Demo </li></ul></ul><ul><li>MPS & Domain-Specific Languages </li></ul>
  30. 30. Domain-Specific Languages <ul><li>MPS suits nicely for creating DSLs </li></ul><ul><li>Common language parts can be reused </li></ul><ul><li>(e.g., expression language) </li></ul><ul><li>You can embed general-purpose languages (e.g., Java) inside DSLs </li></ul>
  31. 31. Domain-Specific Languages Example
  32. 32. Existing Applications <ul><li>Charisma – bug tracking system </li></ul><ul><ul><li>Completely developed with MPS </li></ul></ul><ul><ul><li>Used internally </li></ul></ul><ul><ul><li>EAP program </li></ul></ul><ul><li>Languages for Web Development </li></ul><ul><ul><li>DNQ </li></ul></ul><ul><ul><li>Webr </li></ul></ul><ul><ul><li>Spring language </li></ul></ul>
  33. 33. Licensing/Pricing <ul><li>Almost fully open-sourced </li></ul><ul><li>Apache 2.0 License </li></ul><ul><li>MPS is absolutely FREE </li></ul>
  34. 34. Q & A
  35. 35. More info <ul><li> - MPS page </li></ul><ul><li> - MPS blog </li></ul>
  36. 36. Konstantin Solomatov [email_address] Lead Developer for JetBrains MPS Project Thank You