Illness, Nemerle

    imageNemerle is a .NET language that supports three programming paradigms: one that most programmers consider OOP a paradigm, a functional paradigm (algebraic data types, pattern-matching) and metaprogramming (AOP, quasicitation, syntax extension of nemerle itself through a-la macros lisp). All this is laid on the tracks of strict static typing and seasoned with a powerful type inference system.


    In a single whole, this is combined as follows: the program structure is defined by classes, that is, the code looks similar to the good old C #, but the FP is responsible for life inside the method. It is difficult to notice metaprogramming - it can be disguised as an attribute of the class or a “standard” while construct, which is actually a macro, which when compiling the macro expands into tail recursion, which in turn is converted into a loop on IL by the "pure" nemerle compiler . I say clean, since almost all control commands in nemerle, such as if, when, unless, while, for, are implemented as macros. Thus, you can write code in nemerle, not know anything about metaprogramming, but use it in its entirety and not be aware of it. Briefly, if you have not heard anything about him, then this will not stop you from coding to nemerle. This also applies to FP - no one bothers you with using functions with side effects. But even if you start to write code in nemerle, as if it is C # and hammer on meta, FP, you may be pleasantly surprised - nemerle supports tuples, default parameters and replaces delegates with functional types, that is, it solves the problem of compatibility of delegates with the same signature - instead Funcjust write the signature, for example, int-> int.

    I learned this from the articleson RSDN, blogs and documentation, but always wanted to try to pee on nemerle myself. Unfortunately, I did not do this before for various reasons - either working with people who did not share my point of view on what a convenient programming language should be, or was afraid to start a large project in a new language; but honestly it was just laziness. A couple of days ago, the flu hit me and I decided to realize the dream - to write on nemerle. An experimental rabbit was my long-running sharpe project, which has been my hobby for several months. Maybe someday I’ll write about it on a hub, but so far without details: one of the main functions is analysis of expressions and work with trees representing these expressions. This part was easy to cover with tests, so I stuck with TDD during development, as a result, I had 73 tests on 71 files. Such a complete test coverage gave me confidence and I decided on such refactoring as changing the language. For three days I completely rewrote the code on nemerle, this expanded my understanding of it.

    The language seemed very convenient to me, because where I didn’t want to rewrite the nemerle-style code, I turned off the brain and mechanically transferred the code from sharpe to nemerle, but where I thought it was reasonable to use the FP style, I used it, and it helped reduce project size up to 38 files. I was able to achieve this result due to the fact that I used the FP where its place is, namely, parsing expressions and working with trees: it is natural to represent a tree in functional languages ​​as an algebraic data type, which greatly simplifies working with it. After my acquaintance with nemerle, I reviewed the list of my favorite universal programming languages, now nemerle takes the first place as a representative of static typing and hotcl, which represents a dynamic squad.

    With this article I would like to remind once again that testing is cool, and to draw the attention of the habrasociety to nemerle.

    Below is a small collage that reflects the level of integration of nemerle and MS VS 2008, as well as the syntax of the language.

    image

    Also popular now: