{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/11324","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/11324/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/11324/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/11324/events","html_url":"https://github.com/dotnet/roslyn/issues/11324","id":154954406,"number":11324,"title":"Enhanced C#: a friendly hello","user":{"login":"qwertie","id":720717,"avatar_url":"https://avatars.githubusercontent.com/u/720717?v=3","gravatar_id":"","url":"https://api.github.com/users/qwertie","html_url":"https://github.com/qwertie","followers_url":"https://api.github.com/users/qwertie/followers","following_url":"https://api.github.com/users/qwertie/following{/other_user}","gists_url":"https://api.github.com/users/qwertie/gists{/gist_id}","starred_url":"https://api.github.com/users/qwertie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qwertie/subscriptions","organizations_url":"https://api.github.com/users/qwertie/orgs","repos_url":"https://api.github.com/users/qwertie/repos","events_url":"https://api.github.com/users/qwertie/events{/privacy}","received_events_url":"https://api.github.com/users/qwertie/received_events","type":"User","site_admin":false},"labels":[{"id":169838071,"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Language%20Design","name":"Area-Language Design","color":"5319e7","default":false},{"id":166672105,"url":"https://api.github.com/repos/dotnet/roslyn/labels/Discussion","name":"Discussion","color":"fbca04","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2016-05-16T03:31:47Z","updated_at":"2016-11-24T03:05:50Z","closed_at":"2016-11-23T02:52:08Z","body":"I'm terribly embarrassed.\n\nFor the last few months I've been working on a tool called LeMP that adds new features to C#. I recently published its \"macro\" reference manual. This month I was going to start publicizing my \"Enhanced C#\" project when I discovered that the design of C# 7 had already started well before C# 6 was officially released - and even more shocking, that this design work was being done \"in public\" right on GitHub!\n\nIt kills me that I didn't realize I could have participated in this process, and that \"my\" C# was drifting apart from C# 7 for over a year. Oh well - it is what it is, and I hope that something useful can still be salvaged out of my work.\n\nSo, this post is to inform you about Enhanced C# - where it came from, and what it offers that C# 7 does not.\n## A brief history\n\nAs a class project in my final year of university, I extended a compiler with a new feature (unit type inference with implicit polymorphism), but (to make a short story shorter) the authors of the language weren't interested in adding that feature to their language. This got me thinking about our \"benevolent dictatorship\" model of language development and how it stopped me, as a developer, from making improvements to the languages I relied on. Since I had already been coding for 15 years by that time, I was getting quite annoyed about writing boilerplate, and finding bugs at runtime that a \"sufficiently smart compiler\" could have found given a better type system.\n\nSo in 2007 I thought of a concept for a compiler called \"Loyc\" - Language of your choice - in which I wanted to create the magical ability to compile different languages with a single compiler, and also allow users to add syntax and semantics to existing languages. This system would democratize language design, by allowing third parties to add features to existing languages, and allowing language prototypes and DSLs to seamlessly interoperate with \"grown up\" languages like C#. But my ideas proved too hard to flesh out. I wanted to be able to combine unrelated language extensions written by different people and have them \"just work together\", but that's easier said than done.\n\nAfter a couple years I got discouraged and gave up awhile (instead I worked on [data structures](http://core.ecsharp.net/collections/) ([alt link](http://core.loyc.net/collections/)), among other things), but in 2012 I changed course with a project that I thought would be easier and more fun: enhancing C# with all the features I thought it ought to have. I simply called it Enhanced C#. It started as a simple and [very, very long wish list](https://github.com/qwertie/ecsharp/blob/master/Doc/EC%23.cs), with a quick design sketch of each new feature. Having done that I reviewed all the feature requests on UserVoice and noticed a big gaping hole: I hadn't satisfied one of the most popular requests, [\"INotifyPropertyChanged\"](https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/2255378-inotifypropertychanged). So at that point I finally went out and spent three weeks learning about LISP (as I should have done years ago), and some time learning about Nemerle macros. At that point (Oct. 2012) I quickly refocused my plans around a macro processor and called it EC# 2.0, even though 1.0 was never written. I realized that many of the features I wanted in C# could be accomplished with macros (and that a macro processor doesn't require a full compiler, which was nice since I didn't have one) so the macro processor became my first priority.\n\nSo \"Loyc\", I eventually decided, would not be a compiler anymore, but just a loose collection of concepts and libraries related to (i) interoperability, (ii) conversions between programming languages, (iii) parsing and other compiler technology, which I now call the \"Loyc initiative\"; I've had trouble articulating the theme of it... today I'll say the theme of Loyc is \"code that applies to multiple languages\", because I want to (1) write tools that are embedded in compilers for multiple langauges, and (2) enable people, especially library authors, to write one piece of code that cross-compiles into many langauges. One guy wants to call it [acmeism](http://acmeism.org/) but that doesn't seem like the right name - I'd call it, I dunno, multiglotism or simply, well, loyc.\n## EC# and Roslyn\n\nRoslyn's timing didn't work out for me. When I conceived EC#, Roslyn was closed source. I researched it a bit and found that it would only be useful for analysis tasks - not to change C# in any way. That wasn't so bad; I wanted to explore \"radical\" ideas, which might be difficult if I had to do things the \"Roslyn way\". That said, I was _inspired_ by Roslyn; for instance the original implementation of \"Loyc trees\" - the AST of EC# - was a home-grown Red-Green tree, although I found my mutable syntax trees to be inconvenient in practice (probably I didn't design them right the first time) and rewrote them as green-trees-only (immutable - I thought I might rewrite the \"red\" part later, but I got used to working with immutable trees and now I don't feel a strong need for mutable ones.)\n\nBy the time MS announced they were open-sourcing Roslyn (April 2014), I had been working on Enhanced C# and related projects (LLLPG, Loyc trees and LES) for well over a year, and by that point I felt I had gone too far down my own path to consider trying to build on top of Roslyn (today I wish I could have Roslyn as a back-end, but I don't think I have time, nor a volunteer willing to work on it).\n## LeMP\n\nEC# still is not a \"compiler\" in the traditonal sense, but it's still useful and usable as-is thanks to its key feature, the Lexical Macro Processor, or LeMP for short. It is typically used as a Visual Studio extension, but is also available as a command-line tool and a Linux-compatible GUI.\n\nThrough macros, I implemented (in the past few months) several of the features that you guys have been discussing for more than a year:\n- Creating ‘out’ variables in-situ, e.g. `int? Parse(string s) => int.Parse(s, out int x) ? (int?)x : null;`\n- Code Contracts via annotations on the method signature\n- Tuples (positional only) with deconstruction\n- Algebraic data types\n- Patern matching\n\n(They aren't as polished as the C# 7 features will be, because of techical limitations of lexical macros and because I'm just one guy.)\n\nIt also has numerous other features:\n- A maximally flexible alternative to \"primary constructors\"\n- Code quotations and code pattern matching (comparable to LISP and Nemerle), which is useful for writing macros, for code analysis, code generation and even (potentially) reading/writing JSON and LES files (a use case I haven't written about yet).\n- Method forwarding, for doing the decorator pattern more easily.\n- Declaring variables and writing code sequences in expressions (like the `;` operator that was sadly not added to C# 6)\n- The \"quick binding\" operator\n- `on_finally` which works like Swift's `defer`, and related macros (`on_return`, `on_throw`)\n- `replace` and `unroll` for generating boilerplate (although after reading about Nim, I think there's a better way to do the `unroll` feature)\n- A `with` statement based on the `With` statement in Visual Basic\n- An LL(k) parser generator called LLLPG\n- And last but not least, users can write their own macros.\n\nThe other parts of EC# that exist - the parser and \"pretty printer\" - support some interesting additional features such as symbols, triple-quoted string literals, attributes on any expression, etc. However, the majority of the syntactic differences between EC# and C# 6 are designed to support the macro processor.\n\nAn important theoretical innovation of Enhanced C# is the use of simple syntax trees internally, vaguely like LISP. This is intended to make it easier to (1) convert code between programming languages and (2) to communicate syntax trees compactly.\n## What now?\n\nWell, I'm not 100% decided about what to do now, knowing that the C# open design process exists and that C# 7 is shaping up to be really nice.\n\nI don't intend to throw the whole thing away, especially since there are major use cases for EC# that C# 7 doesn't address. So in the coming weeks I will change the pattern matching syntax to that planned for C# 7, implement the new syntax for tuple types (minus named parameters, which cannot be well-supported in a _lexical_ macro), and add those \"record class\" thingies (even though I don't think the C# team has taken the right approach on those.)\n\nBut in the long run, is it worthwhile to continue working on EC#, or should I instead devote my time to lobbying the C# team to do the features I want? (beware, I can talk a lot...)\n\nIn fact, those are far from my only options - I've been closely following the development of WebAssembly and I'd like to do something related to interoperability and WebAssembly, mainly because .NET has not turned out to be the cross-language interoperability panacea that the world needs. And I'd love to make the world's most widely useful programming language (which is not EC#, because we all know how hard it is to improve a language given the backward compatibility constraint). The main reasons to keep going with EC# are (1) that I have a large codebase already written, and (2) that after 8 years alone I finally have a volunteer that wants to help build it (hi @jonathanvdc!)\n\nI do suspect (hope) there are some developers that would find value in EC# as a \"desugaring\" compiler that converts much of C# 7 to C# 5. Plus, LeMP is a neat tool for reducing boilerplate, \"code find and replace\" operations, and metaprogramming, so I really want to polish it up enough that I finally win some users.\n\nThere is so much more I could say, would have liked to say, and would still like to say to the C# design team... but in case this is the first you've heard of Enhanced C# or LeMP, you might find this to be a lot to take in - just like for me, C# 7 was a lot to take in! So I'll avoid rambling much longer. I hope that, in time, I can win your respect and that you will not \"write me off\" in a sentence or two, or without saying a word, an eventuality I have learned to emotionally brace for. I definitely have some opinions that would be opposed by the usual commentators here - but on the other hand, I think the new C# 7 features are mostly really nice and I'll be glad to have them.\n\nSo if this wasn't TLDR enough for you, I hope you'll enjoy learning about EC# - think of it as how C# 7 might have looked in a parallel universe.\n\nLinks:\n- [EC# for normal coders](http://ecsharp.net/ecs/for-normal-coders.html) (because [EC# for programming language nerds](http://ecsharp.net/ecs/for-programming-language-pundits.html) is a bit old)\n- [LeMP macro reference manual](http://ecsharp.net/lemp/reference.html)\n"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/262680060","html_url":"https://github.com/dotnet/roslyn/issues/11324#issuecomment-262680060","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/11324","id":262680060,"user":{"login":"CyrusNajmabadi","id":4564579,"avatar_url":"https://avatars.githubusercontent.com/u/4564579?v=3","gravatar_id":"","url":"https://api.github.com/users/CyrusNajmabadi","html_url":"https://github.com/CyrusNajmabadi","followers_url":"https://api.github.com/users/CyrusNajmabadi/followers","following_url":"https://api.github.com/users/CyrusNajmabadi/following{/other_user}","gists_url":"https://api.github.com/users/CyrusNajmabadi/gists{/gist_id}","starred_url":"https://api.github.com/users/CyrusNajmabadi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyrusNajmabadi/subscriptions","organizations_url":"https://api.github.com/users/CyrusNajmabadi/orgs","repos_url":"https://api.github.com/users/CyrusNajmabadi/repos","events_url":"https://api.github.com/users/CyrusNajmabadi/events{/privacy}","received_events_url":"https://api.github.com/users/CyrusNajmabadi/received_events","type":"User","site_admin":false},"created_at":"2016-11-24T03:05:50Z","updated_at":"2016-11-24T03:05:50Z","body":"> Someone on one of the Roslyn teams. \r\n\r\nThat would be me :)"}}
{"actor":{"display_login":"CyrusNajmabadi"}}