Thursday, October 29, 2009

Eclipse Summit Europe 2009

This year's Eclipse Summit Europe is again a very nice happening. It's so important to meet all the people you're chatting and mailing with in person.
Yesterday, Sebastian and I had the chance to demo some of the new Xtext features we've been working on in the Helios train. It was much fun and we got very positive feedback for both the talk and (more important) the features. We'll post the demos to our blogs very soon.

I'm especially excited about how well Xtext is accepted within the Eclipse Community. Yesterday there were at least three talks about other projects which make use of Xtext:
  • The b3 guys are working on a DSL to describe builds
  • In the new EMF Search implementation the query language is implemented with Xtext
  • The Relax NG tools are as well implemented in Xtext
How about e4? Designing UIs works good in a WYSIWYG style, but there are scenarios where you want to program parts of it. In addition storing the UI descriptions in XMI is not necessarily the best option. You cannot read it and it's very hard to diff and merge them. I can imagine that a programmer friendly textual syntax might please the modeling skeptics a bit. We can still use a WYSIWYS editor on top.

Implementing the CSS functionality with Xtext could be another opportunity to get more for less. To find out, I'll have to attend Kai's talk about the CSS customization in e4 this morning.
There are lots of other interesting sessions to attend today. Unfortunately I have to decide between listening to
because they are both scheduled for 14:40.

Monday, October 05, 2009

Helios M2 of Xtext, Xpand and MWE


The M2 builds are promoted (with Athena!). And here's the promised update on what we've already done for the M2 of Helios.

You can find the details in the bugzilla links. Here I'll only mention new big features.

Xtext (fixed bugzillas)

Quickfix Support

It is now possible to register quickfixes for validation rules. The feature is documented as part of the validation section.

JVM - EMF bridge
This one allows referencing Java elements from EMF models, as it is desired in most DSLs which are used in a JVM context. We already wrote a small MWE prototype (without XML syntax), which makes use of this new component. It took us a day to come up with a neat MWE editor. Our upcoming base language will be based on top of this type system.
Sebastian is going to blog about the details soon.

EMF Index integration
We made some good progress with regards to the index integration. However, as it was not finished by M2 and the changes were too big we decided to hold it back. It will be shipped with M3 and I will write a separate blog about it soon.

Xpand (fixed bugzillas)

Incremental Generation
There's support for incremental generation now. It leverages EMFCompare to find out what has changed and only triggers those parts in a generator which could possibly be affected by the changes. In typical scenarios where one has big models and only very little changes between the builds this can yield a significant performance boost. The implementation is there and the unit tests should be a good starting point (org.eclipse.xpand.incremental.tests). Documentation and an example workflow will follow.

Xpand Profiler
If you want to improve the overall execution performance of your generator, the new Xpand profiler comes in handy. Heiko already blogged about it. There's also documentation available.

MWE (fixed bugzillas)

For MWE only some bugs were fixed. The new MWE syntax we're working on has not yet been checked in. It is primarily meant as a test language for the Java EMF bridge. In order to replace the current parser and infrastructure we need to implement an XML based reader (for backward compatibility) and of course the interpreter needs to work on EMF models. This is not planned for M3 as we have little resources and want to focus on the EMF Index integration as well as the Java EMF bridge. But I'm pretty sure we'll do this during one of the next milestones.

Disclaimer: We encourage everybody to use and test our milestones. It really helps to get as much feedback as possible. However, note that every API we introduce between M1 to M5 might be changed or even be removed completely in future milestones. Also milestones are usually not as stable as releases.

If you want to test the milestones just take the composite updates site from itemis:
http://download.itemis.com/updates/milestones/
Check the Antlr feature ("Xtext Antlr Support 0.8.0 M2" -> "Xtext Antlr Feature") and p2 will do the rest.

Just in case you're interested in what is planned for M3. Here are the bugzilla queries:
  1. Xtext M3 bugzillas
  2. Xpand M3 bugzillas
  3. MWE M3 bugzillas

Tuesday, September 15, 2009

Xtext in wind energy


I've visited the Fraunhofer IWES in Bremerhaven this week. Fraunhofer is a famous german research institute and the IWES department focusses on wind energy. In their current research project they make heavy use of Xtext and other Eclipse Modeling technologies.

The project is about specifying and connecting the different components a wind turbine is made of and simulating real time scenarios using such models.
The problem they want to solve is that today's computers are much too slow to compute structural, fluid, or thermo dynamics of detailed models in detailed surroundings in a reasonable time. Also the components are usually tested and simulated in isolation only.
The general approach to face this is to reduce the level of detail in order to speed up computation. This has of course the drawback that the resulting data gets more imprecise. The goal of the research project is to dynamically change the level of detail for the different components during the simulation. This is modeled using a state machine.
For instance if you want to simulate a storm in order to find out at what wind force a blade breaks you have to start with low wind force and increase it constantly. The system would allow to replace a lower detailed blade with a higher detailed one in certain scenarios. The engineer specifies in what circumstances detailed information is interesting and the system can use fast models with low details for the rest of the time. For instance one would want to replace a low-detailed blade with a high-detailed blade when the wind gets so strong that it is likely that the blade breaks.

The other problem they have to solve is that there are many different tools (e.g. Modelica, NASTRAN, ANSYS) used to model and simulate the different components. Each of them have their strengths and weaknesses so the research team needs to find a universal way to reuse and interconnect all of these tools.

To solve these two issues they have developed a DSL used to model the different components. From that description they generate representations for the different tools in different levels of detail. In addition they have developed Xtext implementations of the most interesting languages they use, that is Modelica (an object-oriented, equation based language), NASTRAN, and ANSYS.

I want to mention that the Fraunhofer IWES are looking for smart software engineers. So if you're interested in wind energy and Eclipse Modeling it might be a good fit. I haven't spent much time in Bremerhaven but on a first glance it looked much nicer than I thought.

Thursday, August 27, 2009

Xtext - Road to Helios

After the Galileo release of Xtext we are now focussing on the next iteration. We've had a face-to-face meeting in Kiel and discussed the different ideas, our process and what the "themes" for our Helios development are.

In this post I want to share our vision of how the road to Helios could! look like. I say 'could' because although we have a rough idea of where we want to go, we know from the past, that the actual road we go will slightly differ. That is things we find useful today might have become less important in six months. "Round And Round The Earth Is Turning" :-).
I'll outline our visions and priorities along the four themes we identified for the Helios development period.

Theme I : Clean Code

Our code base is already comparatively clean but we want it to be even cleaner. Cleanness in code means the following to us:

DRY - Don't repeat yourself

Every information should be kept in one place only. This is as everything I write not meant dogmatic. So, there are of course situations where it is more pragmatic to duplicate a piece of information.

KISS - Keep it small and simple


Solutions should only be as complicated as they need to be. Sometimes it is hard to understand for developers that they have solved a problem but we do not want to check it in in that way. That is of course not because we do not appreciate the effort. It is because we think it is too complex, and we do not want to add superfluous complexity to the code base. Of course opinions of what is superfluous and what is not might as well differ :-).

Keep it testable and have tests

Code needs to be testable. If it is not testable unit testing is either not possible or it is too complicated and therefore is fragile and complex. We want to have sufficient unit tests. Sufficient is again a weak statement. Usually one has too little tests, so having too many tests is very seldom the case. Mature and published code can't have too many tests, as long as each test covers a different case. Note that the code cleanness of unit tests is as important as the code quality of the production code. When we fix bugs we usually do test first. That is we write a failing test reproducing the reported miss behavior and fix it afterwards.
In Xtext we have more LOC in the tests than in production code.

Comments

Any comments need to reflect the code! Wrong comments are far more problematic than no comments.

Inlined comments are a smell. They tell you that your code is not readable. Most of the time the simplest thing to do in order to avoid such comments is extracting a method and naming that method like the comment you wanted to put in front of that code snippet.

JavaDoc comments are important. This is an aspect where we should improve our code base.
JavaDocs should be as small as possible and as verbose as needed in order to understand the contract behind the API at hand. We only add JavaDocs to primary hooks. Internal stuff is seldom commented because we can do a quick view at the code in order to understand what's going on. At least as long as the code fulfills the next requirement.

Readability

Code is read far more often than it is written or edited. So it's especially important to write the code so that your intentions are clear. Small functions and expressive names are good starting points.


Theme II : Usability (UI Quality & Features, API Quality, Documentation Quality)

UI Quality and Features

In Galileo we mainly focused on putting the main abstractions in place and creating a solid framework. Some UI features were therefore postponed.
One of the first things we want to do in Helios is adding the EMF Index and making the usage of it and the corresponding scope provider the default. Based on that we have information about all cross file references, which enables us to not only automatically trigger validation of referencing models, but also provide advanced navigation features and things like rename refactoring.

API Quality

It is our desire that people have fun when working with the abstractions we provide.
The mantra for last year's development was 'We aim to make simple things simple and complex things possible.' (by Alan Kay). Which means to us that what the 80% of things we want to do with a framework needs to be as simple as possible, but at the same time we need to make sure that the other 20% are still possible (and ideally also not too hard to accomplish). Of course there are use cases which simply do not fall into the scope of a framework but that is a different story.

Documentation Quality

Our documentation is in a relatively good shape, but still can be improved. We are convinced that good documentation is key for the overall acceptance of a framework.
So keeping the documentation current and keeping a good quality is part of our development process. That is adding or changing code is always paired with adding and changing tests and updating the documentation.

Theme III : Performance & Scalability

This has been a major theme for last year's development as well.
Given user stories like the talk about Xtext and AUTOSAR proposed for ESE 2009, it seems that we met this non-functional requirement fair enough.
But that does not mean that we don't need to check it from time to time, or that users neverface performance issues. We take this aspect very serious.
But of course we do not write optimized code as along as we haven't measured that optimization is worth the extra unreadability, complexity or what ever.
What we do is having regular profiling sessions and thinking about different use cases when we design concepts.

Theme IV : Increase Applicability (Base Language, Grammar Features)

So far all the themes are more or less about, improving the quality. I haven't talked about many new features (despite the mentioning of EMF Index and what it means for some UI features we want to implement). You will of course see many improvements and new features I haven't mentioned in this post. We decide which bugzillas to work on from milestone to milestone (I'll write about what is coming in M2 in a separate post.)
But there is one huge "feature" we want to do and I want to mention it here:

Base Language

We want to provide a base language, which can be extended and customized by users. The idea is not new: The Intentional Workbench as well as MPS both have similar things. Despite that these frameworks are of a different nature (they are not text-based) we also don't want to implement Java or C# (that is what they do), but come up with a much simpler and nicer language. Actually I like Scala very much, because it has very little concepts in it and allows to define new concepts out of them. But with an Xtext-based language you don't need the syntactical flexibility of Scala or Ruby, because the parser and the compiler are open and you can change the language as it seems fit. Imagine state machines with action implementations, entity models with implementation for operations and derived attributes, validation languages etc. Looking at the current land scape of external DSLs I'ld say that about 90% of all languages would benefit from support for embedding expressions. Some people already have implemented their own expression language others reuse the language of the target platform, i.e. they write the behavior in Java and mix it into the generated code. Sebastian and I gave a talk about this at Code Generation 2009 in June.

In order to show and prove how great such a language is, we plan to implement an EMFatic version that supports adding implementation for EOperations and derived EStructuralFeatures.
With that you'll no longer need to change the generated code (at least most of the time) and you'ld have everything in one place.
In addition DSLs for common viewpoints in Xtext, such as scoping, validation, quick fixes, formatting, etc. would be nice.

The base language is a huge effort and will likely not be finished by next year. As of now I'm not sure if and how much it will be included in the Helios release.

Java adaption

Another really nice thing we're already working on is, having a thin EMF adapter layer to JDT's Java model. This allows for referencing Java elements from within a DSL, which is very often desired. Reimplementing MWE with a nicer syntax will be a matter of a couple of days when we have this feature. We want this to be tightly integrated with EMF Index.
This is also a bigger topic but will definitely be part of Helios (actually we plan to have it finished by M4).

Grammar Features

There are a lot of ideas of additional features for the grammar language. We haven't decided on them yet but things like multiple grammar inheritance might get more important when we ship a base language. But what exactly such a feature would mean and what the consequences are still has to grow on us.

DISCLAIMER

Please don't take any of these ideas as guaranteed. This is what we currently have in mind but our view of the world will change. Also note that developing the base language we have in mind is a big effort, so it might take us more than just one release cycle.
I'll write a post for each milestone in order to tell what we exactly we did and do.

Friday, July 17, 2009

Xtext 0.7.1 available

We've just published a bugfix update to the Galileo release. Actually it is not only an update of Xtext but also of MWE and Xpand. All three projects are now shipped in version 0.7.1.

The update contains a lot of nice bugfixes (see Sebastian's blog for details). Getting it should be pretty easy for everyone this time. It's all available from our update site at itemis :

http://download.itemis.com/updates

Moritz made it a P2 composite site pointing to the corresponding update sites at Eclipse as well as to the highly recommended Antlr generator fragment. So it is just a matter of pressing 'update' if you already had Xtext installed and had added the updatesite above. If you want to install Xtext for the first time, just add the update site above and install the Xtext SDK. This will install everything you need (including MWE UI and the like, which was previously not automatically added). Have fun!

Thank you Moritz, Dennis and Sebastian. It works great! :-)

Wednesday, July 15, 2009

RT @Xtext #webinar #bugfix-release #dsl-contest

Just in case you're not sure what exciting things to do within the next couple of days, here are some suggestions:

First you could attend the Xtext webinar Heiko and I are giving today (at 5:00 pm GMT). There you'll learn something about the general principles and ideas behind this new language framework. We'll also show some examples.
You have to register in advance!

Second you grab the bugfix release (0.7.1) of Xtext which is due this Friday (July 17th). It includes a lot of nice bug fixes. Sebastian already blogged about it.

With that on your box you'll be well prepared to develop a nice, witty language using Xtext and submit it for the DSL contest itemis is running. Creativity wins!


Thursday, July 02, 2009

Xtext scopes and EMF index in action

This is a post about scoping and how to use the EMF index for that. It is in some sense a practical follow up on another blog post about the general idea behind indexing and scoping in Xtext. The topic is somewhat advanced and bleeding edge. This post describes the needed steps to get the current index based default scoping up and running. I've prepared a small screencast demonstrating the result in action. The example language can be downloaded from here.




Today, the common way to do cross resource references in Xtext is to do it via resource URIs. That is if you want to reference a model element (EObject) from another resource, you typically put the whole resource on the scope by adding a corresponding import. Example:
import "platform:/resource/my.project/src/othermodel.dsl"

//.. refer to elements from othermodel.dsl
The corresponding default scoping is very simplistic. Every object in the current resource and in the referenced resources can be referenced by its simple name (as long as it has a 'name').

Although this is very easy to understand, it has it's limitation when it comes to more sophisticated design. If you for instance want to hide some elements or have duplicate simple names in different packages (this can be the case if you use elements, which are developed by others).

In many programming languages we have the notion of namespaces, which are much more flexible and powerful. Java, for instance, is file system agnostic. Although it forces you to put the files into folders which correspond the packages, it ultimately is just based on namespaces (packages, types).
That said Java's namespace mechanism is also a bit limited. For instance I cannot have imports in nested namespaces but only per file. And I cannot nest packages but only classes and interfaces.

Scala and C# both allow to have multiple nested packages within one file and you can put imports per namespace, so that imported names are only visible within that namespace.

In order to demonstrate how to use the index together with Xtext, I've implemented a DefaultIndexBasedScopeProvider which implements a similar semantic. There's a small example I've prepared, where you can see how it can be used. It is mainly a matter of configuring the different implementations with Guice. Programming is not needed as long as you're happy with the defaults.

Here's how it works

The index registeres a builder, which is invoked on resource changes. In order to make your model elements visible, you'll have to contribute a so called Indexer using an extension point.
<extension point="org.eclipse.emf.index.indexer">
<indexer class="org.eclipse.xtext.example.DomainmodelExecutableExtensionFactory
:org.eclipse.xtext.index.DefaultDeclarativeResourceIndexer"
fileextensions="dmodel"/>
</extension>
Please ignore the ExecutableExtensionFactory, which is declared in order to make any executable extension Guice aware, that is you can use dependency injection. This is a different topic and might be covered by another blog post.

The actual class to be instantiated is the one after the colon (':'): The DefaultDeclarativeResourceIndexer, which delegates to an instance of IQualifiedNameProvider, which itself is injected. This means that its implementation can be arbitrarily changed.
The contract of a name provider is very simple: it computes a qualified name for an element, if it returns null, the element is not indexed and hence not referable.

By default we use a DefaultDeclarativeQualifiedNameProvider, which if not otherwise specified looks up a simple name (if there's an attribute 'name') and concatenates it to the qualified name of its parent. It's named 'declarative' because you're able to change the described default behavior per type by just adding a method like this:
String qualifiedName(MyType foo) {
// compute different qualified name for MyTypes
// ...
}
It will automatically dispatch to this method as soon as it has to compute a qualified name for an instance of MyType.

With this in place we'll have our elements automatically indexed as long as they are in a project, which have the index nature enabled. Being indexed means that they are globally visible by their qualified name, which is comparable to how public Java elements are globally visible as soon as they are on the classpath.

What's next?

In order to use the index and have it injected into your components (e.g. your scope provider) you'll have to configure the singleton instance from the index bundle into your Guice module. In the example the corresponding binding goes into the UI module and looks like this:
public IndexStore bindIndexStore() {
return EmfIndexUIPlugin.getDefault().getIndexStore();
}
With that in place you can inject the index store by just adding a dependency in your code:
@Inject
private IndexStore store;
Guice will automatically put the instance into such declared dependencies.
Now that we have a binding for IndexStore we can add the index based scoping to the runtime module:
public IndexStore bindIndexStore() {
return new PersistableIndexStore();
}

@Override
public Class bindIScopeProvider() {
return DefaultIndexBasedScopeProvider.class;
}
Note the additional IndexStore binding, which is overridden by the binding we previously added to the UI module, but is needed in order to use this stuff at runtime (i.e. without running within exquinox). So it gets active as soon as you run without UI.

How the DefaultIndexBasedScopeProvider works

The DefaultIndexBasedScopeProvider
- looks up EAttributes with name 'importNamespace'
- and translates the globally unique qualified name into shorter ones using those import statements.

By default qualified names with or without a wildcard at the end are supported. For an import of a qualified name the simple name is made available as we know from e.g. Java, where
import java.util.Set;
makes it possible to refer to 'java.util.Set' by its simple name 'Set'.
Contrary to Java the import is not active for the whole file but only for the namespace it is declared in and its child namespaces. That is why you can write the following in the example DSL:
package foo {
import bar.Foo
entity Bar extends Foo {
}
}

package bar {
entity Foo {}
}
Of course the declared elements within a package are as well referable by their simple name:
package bar {
entity Bar extends Foo {}
entity Foo {}
}
Of course the following would as well be ok:
package bar {
entity Bar extends bar.Foo {}
entity Foo {}
}
Disclaimer
All this is in a very early stage. The index is not finished and its architecture is not settled down yet. Also the scope provider implementation might be changed in future (I'm sure it will).
Additionally, there are other things around this which we have to work on before considering this mature.

But as I know that there are a lot of bleeding edge users out there, I wanted to share the current state, so you might find a starting point to play with it. The index is an enabler for more advanced functionality in Xtext and in EMF based development in general. So expect it to become an important part in Eclipse Modeling.

Feedback is highly appreciated and should either go to the newsgroup for Xtext (the scoping part) or to the EMFT newsgroup (the index part), because the index project is a component under EMFT.