Wednesday, January 14, 2015

match, rc3

and that was that, last commit/release for the night, needs more testing and loving. But then again, who doesn't. The match in the name stands for a fairly sweet new dsl I put together, the idea being having a sample extending code.

http://xslang.azurewebsites.net/#/project/4

The match construct works as an extended switch the very basic usage so far implemented looks like this:



As you can see, expressions are permitted in the case statement. Including, the > 10 in line 11. Which is pretty sweet, one must admit. In its final form, this dsl will be so much cooler. For instance, match could return a dynamic value. Or use continue and break creatively.

Fun times.

As for the rc3, it means there is a semi-usable version somewhere in the cloud. All samples running and its behaving decently. All in all not a bad day for the unemployed.

So goodnight.

Tuesday, January 13, 2015

Extend programming languages, online

Lets start with a useless construct: a 'pure' class. Defined as a class which does not produce side effects when invoked. Whether truly useless or poorly implemented is irrelevant. What's important is that you would like that feature in your language of choice.

Up until today, you are out of luck. Language design is tightly controlled and version updates take years. Well, no more! Head to http://xslang.azurewebsites.net/#/project/3

What follows is a brief tutorial on how to create your own programming language constructs. Understand that whatever you create is not along in an island but tightly integrated into csharp. First, you will create a project for your dsl:


In here, we're saying the dsl will be referred identified in your code with the keyword "pure". Both the parsing and the linking will be done using Roslyn and it will extends types. A word on extension types:

  • Namespace extension: Your constructs appear at the namespace level, same as classes, etc.
  • Type extension: Types headers will be modified. In this case: pure class MyClass.
  • Member extension: Your constructs appear inside types and look like methods.
  • Code extension: Adds statements, such as the asynch dsl discussed in previous posts.
Once created, editing the project takes you to the main IDE:

DSLs written in Roslyn have two main components: a parser and a linker. Parsing will analyze your extended code, fix (or rewrite, in Roslyn lingo) any problems it can and defer anything else to the linker. Parsing does not have access to any semantic information, hence deferring to the linking stage.

I will not go too much into the code because it is pretty standard Roslyn stuff: the parser will collect all method calls and assignments inside the pure class and it will schedule its linking, The linker makes sure that calls are made only to static or pure classes and assignments only modify internal state.

The only noteworthy snippet is the scheduling of individual linkers instead of the linking process having to again find all troublesome syntax nodes:

return Link(newNode, Linker.CheckAssignment);

This schedules the assigment newNode to be linked by CheckAssignment. This linker will be called as many times as scheduled and with the right syntax nodes.

Then you have all your code written and need to do a little debugging:

Same as in the home page, you get to write some test code and translate it into c# as to validate its correctness. While not the greatest way to debug, we also offer notifications triggered by console.write. But hey, you are extending c# in a few lines of code! 

A long cold angular detour

About ten years ago I decided I wasn't made for cold weather and that I would never ever go back to it. So much for that. So I quit the good old job, packed and before you knew it was 9th and Hennepin and all the donuts have funny names.

So, in order to reintegrate myself into the working force, you know, get a job... I decided to learn the stuff the cool kids do nowadays, namely angular and all that dependency injection jazz. Funny thing, I flunked the question about said injection in every interview. I thought it was something else, more complicated and important. Turns out it is a fancy name for: pass your stuff as parameters. Silly kids.

But hey! After a few weeks using the cheapest laptop I could find as my dev box I find myself knowing kung-fu and with a brand-spanking-new Excess website full of angles and goodies. Its all open sourced now and, while not quite ready for prime-time, quite cool. 

Links!!


I would not look much into the Roslyn code there, as it is so very prototype and about to get nuked in the worse way possible. But it is all there. The web site has a few new features (write and test your own DSLs!!) but that will get its own post.

I also added a few goodies to xs:

constructor ()
{
     //your initializers
}

which should need no explanation but warrants a bit of a rant: some keywords are universally accepted to refer to programming languages constructs (think constructor, method, property) and yet are never used in languages. Why is that?

property myProp = 5;
int property myProp;

which will both translate to int myProp {get; set;} That's something programmer must write continually and is just not as expressive or easy to write.

Check the new site, there are samples for all that. And more!!