Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create C# language modifications as did LINQ?

I've been looking quite a bit at Mr. Skeet's blog on how to re-implement LINQ.

In particular, he states that the code:

var list = (from person in people
        where person.FirstName.StartsWith("J")
        orderby person.Age
        select person.LastName)
       .ToList(); 

is translated to methods that are extension methods that are provided by the LINQ library:

people.Where(person => person.FirstName.StartsWith("J"))
  .OrderBy(person => person.Age)
  .Select(person => person.LastName) 

BY THE COMPILER.

My question is, how does one impress the bigwigs enough with a library to cause them to allow the language to change to support the library? Or were those words already reserved before LINQ came along?

like image 446
user420667 Avatar asked Aug 30 '11 17:08

user420667


People also ask

How is C created?

The origin of C is closely tied to the development of the Unix operating system, originally implemented in assembly language on a PDP-7 by Dennis Ritchie and Ken Thompson, incorporating several ideas from colleagues. Eventually, they decided to port the operating system to a PDP-11.

Is C still developing?

The world of computers is filled to the brim with high-level programming languages, but even today, an age-old computer language like C is still around in the computer world. Even today, there are multitudes of systems that still make use of C as the main programming language in many parts of the world.

Does C have future?

Future-proof code (as long as current operating systems will be used) is therefore written in C. The portability of C is best demonstrated by the fact that C++, Java and Python are part of the C-family of programming languages which also include Julia, Perl, and many other languages.


2 Answers

Grab the Mono C# Compiler - it's open source and you can do whatever language modifications you want and which .net supports, e.g., use enums as generic constraints, create methods that return references to value types (public ref int Max(ref int x, ref int y) { if (x>y) return ref x; else return ref y; }), that have protected or internal visibility etc.

Of course, you are then creating an incompatible derivate of C#, but if you push it hard enough then people might like it.

The other option: Start a blog, come up with some really good use cases for it, possibly a sample implementation in a .net language or using a customized compiler, show what problem it solves and why this would be a big win that justifies the cost that goes into specifying, designing, developing, testing and documenting of the feature.

like image 54
Michael Stum Avatar answered Sep 19 '22 15:09

Michael Stum


I highly doubt the compiler developers would implement syntax extensions for just any library. If you really wanted language-level integration, you could develop a pre-processor that transforms your custom syntax into valid C#. That's essentially what the compiler does with LINQ anyway (as you pointed out in your question).

Of course, you would lose things like auto-complete and syntax highlighting in Visual Studio, but that could be fixed with an extension.

like image 41
David Brown Avatar answered Sep 20 '22 15:09

David Brown