Oren Eini

CEO of RavenDB

a NoSQL Open Source Document Database

Get in touch with me:

oren@ravendb.net +972 52-548-6969

Posts: 7,565
|
Comments: 51,184
Privacy Policy · Terms
filter by tags archive

C# vNext

time to read 3 min | 435 words

Jeremy Miller asks what we want in C# vNext. I have only real one request, to have meta programming of sufficent power, after which will be able to add all the required semantics without having the compiler team to argue with.

I am not holding my breath on that one, though. I can just imagine the arguments against it (let us start from the potentail for abuse, move to version and backward compatability hell, and then move forward).

I  want to go over Jeremy's list, and see what I can add there.

  1. Mixin's - Agree 102%. This is something that would so useful, I can't realy understand how it is not already there. Make it a magic attribute, something like [Mixing(typeof(IFoo), typeof(FooImpl))], and you can get away with it with just compiler magic, no changes required to the CLR.
  2. Symbols - I am ambivelent on that one. Syntatic sugar is important, but I have other things that I would value more.
  3. Make hashes a language feature - I think that you can do it right now with this syntax:
  4. var hash = new Hash(
    	Color => "red",
    	Width => 15
    );
  5. Automatic delegation ala Ruby or Objective C - Um, isn't this just mixin?
  6. Metaprogramming! - absolutely. This is something that I have gotten to consider as basic. I am getting tired of having to fight the compiler to get the code that I want to have. The code should express my meaning, I shouldn't have to dance to the compiler's tune.
  7. Everything is virtual by default to make mocking easier - I certainly would like that, but I fear that this is not something that will be changed. AOP as a platorm concept, now that is something that I want to see.

My own request covers:

  1. memberinfo() - the CLR already has this concept, so we just need the syntax for it.
  2. Method Interception - let us start with the easy stuff, I want to be able to intercept methods from any type. I can do it now if I want to mess with the profiler API, but that is not something that I can really make use of for production.
  3. IDynamicObject - I want method missing, damn it! It is just the scratch of meta programming, but this is something that you could probably add to the compiler in a week.
  4. Static interfaces. Since we already has generics to allow us to treat types as interchangable types, I want to extend this concept by just a bit, to get it to work in a more reasonable manner.

I have a few more, but they just called my flight.

time to read 2 min | 257 words

So, as I mentioned, I was doing low level binary IO stuff today, and I started the class going on doing stuff using BitConvertor, FileStream.Write, etc.

After they finished the first exercise, I started to show them how they can replace this tedious code with BinaryReader / BinaryWriter. That was much easier, except that we had strings going into the binary files, and I stopped in the middle to try to read the file written using BinaryWriter with the code that manually manipulated the file stream.

I got consistent results for numbers, but for strings it was giving weird results. I used the method of write string len (int) and then write string, but the BinaryWriter didn't need that, and when I tried to just use the code that used it, it gave obvious shift errors.

I pulled out reflector and checked out the code.  The magic is in Write7BitEncodedIntit handles splitting an integer into 7 bits, and use the last bit as a progress indication. After reading that and Read7BitEncodedInt, it was clear, and very clever.

I was good to get down on such a problem, at least I haven't lost all sense for bit twiddling code.

Can't say the same for my UI / JavaScript code, however, spent nearly the whole week doing nothing of value, as far I as feel. I am considering moving to C++ again, hibernate++, anyone? :-)*

* For the humor impaired, the last paragraph is a joke, I don't really intent to port hibernate to C++.

time to read 1 min | 169 words

This is a big biggie for me, because it enables a much nicer syntax for a lot of stuff. But first, let us show this:

using(new ExceptionDetector())
{
	if(new Random().Next(1,10)%2 == 0)
          throw new Exception();
}

How can you tell, from the ExceptionDetector, if an exception was thrown or not? Well, conventional wisdom, and what I thought about until 15 minutes ago, says that you can't. I want to thank Daniel Fortunov, for teaching me this trick:

public class ExceptionDetector : IDisposable
{
    public void Dispose()
    {
        if (Marshal.GetExceptionCode()==0)
            Console.WriteLine("Completed Successfully!");
        else
            Console.WriteLine("Exception!");
    }
}
Amazing!
time to read 2 min | 235 words

Partial is a MonoRail term to a piece of UI that you extract outside, so you can call it again, often with Ajax. This is something that is harder to do in WebForms. Yesterday I found an elegant solution to the problem.

ASPX code:

<div id="UserDetailsDiv">
   <ayende:UserDetails runt="server" ID="TheUserDetails"/>
</div>

User Control:

<div>
Name: <asp:label ID="Name" runat="server"/> <br/>
Email: <asp:label ID="Email" runat="server"/> 
</div>

Client Side Code:

function changeUser(newUserId, div)
{
	var srv = new MyApp.Services.UserDetails();
	srv.GetUserDetailsView(newUserId, onSucccessGetUserDetailsView, null, div);
}

function onSucccessGetUserDetailsView(response, userContext)
{
	var div = $(userContext);
	div.innerHTML = response;
	new Effect.Highlight(div);
}

Web Service Code:

[WebMethod(EnableSession = true)]
public string GetUserDetailsView(int userId)
{
	User user = Controller.GetUser(userId);
	//there may be a better way to do this, I haven't bothered looking
	UserDetails userDetails = (UserDetails)new Page().LoadControl("~/Users/UserControls/UserDetails.ascx");
	userDetails.User = user;
	userDetails.DataBind();
	using(StringWriter sw = new StringWriter())
	using(HtmlTextWriter ht = new HtmlTextWriter(sw))
	{
		userDetails.RenderControl(ht);
		return sw.GetStringBuilder().ToSTring();
	}
}

C# 2.0 is done

time to read 1 min | 93 words

At this point, I believe that there really isn't anything that can be done any more with C# 2.0, I have taken it to the very limits of its expressiveness, and now I hit a wall.

C# 3.0 adds some interesting features, and extension methods, initializers, etc will significantly improve the expressiveness of the language. Even now, I can see the limitations that even C# 3.0 will give us. But on the other hand, I fully expect some interesting developments in taking the capabilities of the language and pushing them forward.

time to read 1 min | 156 words

It looks like a lot of people are not familiar with this, and that is a shame.

Recently we have run into several instances where we wanted to do some things that are not supported out of the box by the repeater. Specifically, render an empty template and render markup after each row, except the first one, etc.

After some time thinking about how easy it would be to do this in MonoRail, I decided to implement it in the same way I would in MonoRail. WebForms has the concept of an ITemplate, a piece of markup/code that can be handed to a control for later processing. For the MonoRail guys, think about it like a section in a component.

By defining <EmptyTemplate> and <NotFirstRowTemplate> - I have been able to get it to work very easily. The only problematic part was where to render the template, but some reflectorring has given me the answer to that.

time to read 1 min | 86 words

My main pain point with R# is very simple, when it generates properties or methods, it doesn't generate virtual ones. Since I tend to generate quite a few properties at one go, it is a pain to have to go and add it to all of them.

Currently the issue is marked as "Not for 3.0", which is something that I would like to change, please visit the issue and vote for it: http://www.jetbrains.net/jira/browse/RSRP-26697

 

FUTURE POSTS

No future posts left, oh my!

RECENT SERIES

  1. Production Postmortem (52):
    07 Apr 2025 - The race condition in the interlock
  2. RavenDB (13):
    02 Apr 2025 - .NET Aspire integration
  3. RavenDB 7.1 (6):
    18 Mar 2025 - One IO Ring to rule them all
  4. RavenDB 7.0 Released (4):
    07 Mar 2025 - Moving to NLog
  5. Challenge (77):
    03 Feb 2025 - Giving file system developer ulcer
View all series

RECENT COMMENTS

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats
}