Showing posts with label anders hejlsberg. Show all posts
Showing posts with label anders hejlsberg. Show all posts

Sunday, December 30, 2007

How to make the compiler do your work

Before Christmas I spent a few weeks on a school project in computer science. The choice of technology was up to us, and I naturally took the safe path of .NET and C#. I used Visual Studio 2008 as IDE, as it had just come out, and I wanted to try it out. I also wanted to test C# 3.0, which the new IDE of course facilitated. Later I came to think that my team and I wanted to have the solution running on a web server, so the examiners would be able to see the actual prototype working. As I didn't have any options for running the prototype on a .NET 3.5 server, I had no choice but to make the solution .NET 3.0 compatible. This is no big thing in Visual Studio 2008 – you just change the target framework and recompile. Naturally a lot of compiler errors emerged. But to my surprise, they were all related to references to .NET 3.5 specific assemblies, and not my actual code! This got me thinking, and investigating.

I used "simple properties", which is an easier way of writing simple properties with no get/set logic, other than setting a backing field's value or returning it, a lot. When you write them in C#, it looks like this:

Simple properties

What happens when above is built is that the compiler generates the get_Id() and set_Id(int value) methods as before, but then also generates a backing field that reverse engineered looks something like this:

Backing field

The funny thing is the naming of the generated field. Note the < and > symbols; they are used in order to avoid C# code accessing the field! If I try to get access to the field from a C# method, I will get a compiler error, as < and > are not allowed in the context.

The full property will look like this after being compiled:

Compiled property


I never thought of this, but as all the features of C# 3.0 are "syntactic sugar" changing the target framework while keeping the C# 3.0 compiler, I can have all the features, even though everything is compiled to C# 2.0! Great!

Oh, and by the way: Note the [CompilerGenerated] attribute. I want all of my compiled code to have that!

Thursday, November 23, 2006

LINQ to Desktop Search

Yes! Yet another interview with Anders Hejlsberg on Channel9.

In this one he talks to Chris McConnel who is the architect for the Windows Desktop Search product. It's really cool to hear his takes on the world, and how LINQ fits into it. And as a new thing in Channel9 the person asking questions is actually not the interviewer but the interviewee (ie. Chris McConnell asks Anders questions). It seems like he's asking all the right things, and we get Anders' views on a lot of different problems in the programming world, for example:
- functional programming
- intentional programming
- LINQ to desktop search
- WinFS


Nice stuf...


Well, here's the link:
http://channel9.msdn.com/ShowPost.aspx?PostID=260202#260202

Thursday, November 16, 2006

C#'ing into the future

It's been a week since I was at the Microsoft event, where Anders Hejlsberg addressed the new features in C# 3.0, and better tell you about what he told me about..

I had seen a webast where he talks about C# 3.0 before, and he started the exact same way, by stating that:

Data != Objects

The rest was kinda like that webast, but he seemed to go more into details, which was brilliant. As mentioned I had seen a lot of his stuff before, but there where a few points that, if not supprised me, then made me think. Fx. in my head C# 3.0 == LINQ and nothing more. Anders made it quite clear that that wasn't the case. C# 3.0 is a whole bunch of small things that combined make the developer able to write C# in a query-like syntax. The small features are mainly:
- Extension methods
- Lambda expressions
- Expression Trees

As Anders said, the

var q = from c in Customers
where c.City == "London"
select c.Name

is only "syntactic sugar" translated by the compiler to:

var q = Customers.Where( c => c.City == "London" ).Select( c => c.Name );

ie. method calls! All very simple when it's explained to you like that..


The most important thing, however, was that before we left the lecture Marcus, the technical manager in Composite, got Anders' autograf in the C# 2.0 book :-)




In other news: My G1 school project is finished!! Now I only need the printing part, which I will do tomorrow, so I'm what you could call a free man tonight!! Hmm.. Where did I put that shortcut for Visual Studio ;-)


'Till next time...




Oh yeah, and check this out: http://www.zefrank.com/theshow/gallery/d/8544-1/yeeha.mp3