domingo, 9 de octubre de 2016

[Discussion] Compile-Time Metaprogramming

This time I listened the Software Engineering Podcast, Episode 57: Compile-Time Metaprogramming[1] where Laurence Tratt was present as guest.

Although the episode focuses in the Converge programming language (created by Tratt), it has some significant topics of general interest for the listeners. To explain this, we have to know what Converge is. It is a programming language that supports compile-time metaprogramming for implement DSLs. In common words, it has a macro built-in system that allows you to implement custom DSLs using the same language.

The main reason for creating such language is to provide a generic way to build DSLs and so to create easily ASTs from any grammar specified.
Tratt said that using a host language is very useful because you have already many common tasks solved for you out-of-the-box.

I really don’t know much about why building ASTs in runtime would be useful because this is a topic that we are currently starting to learn in the school but it seems that is a very complex stuff that Converge solves easily.

As Tratt explained, the language provides a function that lets you parse a grammar and build an abstract syntax tree for any input given by the user, you only have to specify the input, the grammar and your DSL so it sounds such a powerful tool. Another thing that he said is that you can program how the AST is created using the same Converge language. Again, I don’t know how this could be useful but it seems to be a nice feature of the language.

I liked that they explained some basic concepts such like the difference between a parse tree and a AST (i.e., parse is a two state process, first you take the input and tokenize, then you try to make sense in the language, while the purpose of the AST is only to get what the user tells you).
A interesting topic they talked about was error reporting. Although in Converge you can embed macros, it doesn’t suffer from the main errors that many programming languages have while trying to report an error where a macro is present. For example in C, when you have a macro and there is an error, because of the macro-expansion the exact place where the language is reporting the error could be wrong because the expansion is not considered in the report. This is solved in Converge so it is a great feature it has.

Personally I enjoy DSLs because in Ruby you have a lot of them coming to the surface very often. I have not tried yet to create one, only a simple one for a programming activity in a past course, but thanks to this activity now I know some useful tips for creating Domain Specific Languages.

The main quote I saved is: start small, evolve according to your user's needs.

References

[1] http://www.se-radio.net/2007/05/episode-57-compile-time-metaprogramming/

0 comentarios:

Publicar un comentario