Meta Programming System
Anders Bech Mellson
I am very new to model driven development and currently looking at xtext and of course MPS. I have two beginner questions for MPS.
Is it possible to create a language in MPS that extends Java. Export it as an IntelliJ plugin that will work in the Java editor of IntelliJ? Or is it restricted to the MPS model editor?
If number 1 is doable, is it possible to export a complete plugin and not have the users need to install all the MPS plugins as well?
Thanks in advance,
1 - yes, you can extend Java, but within IntelliJ you have to use the MPS editor. This isn't so bad, because the projectional editor is very good. The main restriction I've found in doing this is that sometimes it's harder to integrate your MPS language with other parts of IntelliJ, for example I haven't been able to get it working with Maven-based projects.
2 - N/A, since you have to use the MPS plugins, mainly for the projectional editor. This will be the same with Eclipse when they add support for it later this year.
I've used both Xtext and MPS quite a bit, so if you have further questions I would be glad to help. You can post here or drop me a line at txmikester at gmail dot com.
A few general observations/comparisons between the two (these are just my opinions based on moderate-heavy usage of each, others may not agree):
1) MPS has a lot more capabilities overall. Many of the language extension mechanisms available for MPS are just not possible with Xtext.
2) On the surface, MPS seems to have a higher learning curve. I'm not completely convinced that's the case, however. Granted, Xtext makes it pretty easy to get up and running with simple languages, probably easier than MPS. But to do substantial work, I found Xtext required as much learning of the intricacies as MPS did.
One thing I like about MPS in this area is the consistency of their approach - everything is a model, and learning it mostly involves learning the modeling languages for all the various aspects. Xtext isn't as consistent in this way.
One thing I like about Xtext in this area is Xtend, which is used for a lot of the things you need to implement with Xtext, such as code generators and model transformations, but the knowledge can be applied to any Java development you do (in Eclipse anyway). Xtend has some nice features to make you more efficient without investing in learning Scala or Clojure (although I recommend learning those languages anyway). I use Xtend a lot for general-purpose programming, generally whenever I have to write Java and use the Eclipse environment.
3) The biggest objection in my mind that I had to overcome to adopting MPS was the model format being stored in XMI, vs. being able to have a plain-text DSL with Xtext. Of course, that's the reason MPS is so powerful, because it's storing a representation of the actual AST, which allows you to do things you just can't do with a context-free parser. But I'm an old-timer, so the idea of "just text" has been drilled into my head from the early days, and it was only after running into limitations of Xtext on a particular project that I was able to overlook that and embrace MPS. I still would prefer to have everything text-based and buildable from the command-line, but the power of MPS was compelling enough to me to make an exception.
4) Both MPS and XText are great at Java integration (MPS is better at Java extension, though). If you need to target other languages, I think MPS is a better fit. It is certainly possible to do that in Xtext, but if you take away XBase you lose a lot of the value-add of that tool. The architecture of MPS makes it cleaner to create new "base" languages - look at the mbeddr project as an example. I've also created an XQuery base language using MPS for a project, and it was relatively straightforward.
This opens up the possibility for some really powerful stuff - like creating higher level abstractions that map down to different implementations. For example, I've been toying around with an XSLT language to swap out for the XQuery language I wrote. The higher-level language just maps to whichever base language you need. There are tons of places this is useful besides just implementation languages - think UI frameworks, ORM mapping frameworks, etc.
All of this is certainly possible with Xtext, but based on my usage of the tools I think it would be quite a bit more work than it was with MPS.
5) There's no denying that there is a larger community around Xtext, and of course it is Eclipse based, so those both may be important considerations for you. It will be interesting when MPS adds Eclipse support later this year - hopefully by bringing MPS to the Eclipse platform, it will help to grow the MPS community even more.
Conclusion - both are very capable tools, and we are lucky to have access to both of them as open source. For the things I am trying to do, I have been leaning towards MPS as the favored tool, but depending on your needs, either one will serve you well. Ultimately, if you're really into this stuff, you'll want to learn both! Another one to keep an eye on is Stratego/SDF, which looks to be a nice middle ground between the MPS and Xtext approaches (disclaimer - I haven't used it yet, I've only read about it in Markus Volter's book, but I plan to look into it when time allows).
Anders Bech Mellson
This far exceeded my expectations for a reply. Thank you very much.
I really like MPS so far including the editor.
But my aim is about creating a DSL that is easy to use for the user.
I think for my current project I will use Scala to build it - since the user can just import the library and use the "normal" editor.
I will however keep playing with MPS (and XText) to keep up with the development of both.
Thanks again for the helpful input and thoughts on the subject.
No problem, always glad to help. If an internal DSL suits your needs, then I think Scala is an excellent choice. The static type system gives you more help in the IDE compared to other DSL-capable options like Groovy or JRuby, and the performance is very respectable. I like Scala in general - I think it may be well positioned to be the "successor" to Java as the main JVM language used for general purpose development.
FYI, I'm in the process of setting up a blog dedicated to DSL development. I want to cover all aspects, but since my experience so far has mainly been with external DSLs, I will probably try to find some guest bloggers to write on other topics, such as internal DSLs in Scala and Ruby. Perhaps down the road you could write about your experiences with creating an internal DSL in Scala, if you don't mind sharing what you learn. Or just post here and let us know how it goes - I'm always interested in hearing other people's experiences with DSLs, and I think many others here feel the same.
go to parent
Incomplete generation (model to model, not model to text) - is it possible in MPS?
Inheritance of abstract concepts and IF intention
Build #178 (Dec/17/2014 3:47PM)