Posted on June 21, 2007

Q: Why is non-virtual the default in C#?

Anders Hejlsberg: There are several reasons. One is performance. We can observe that as people write code in Java, they forget to mark their methods final. Therefore, those methods are virtual. Because they’re virtual, they don’t perform as well. There’s just performance overhead associated with being a virtual method. That’s one issue.

—–
Fuck. Number one reason is performance. Well, if performance is so crucial then mark them as final, most of the time it is not an issuse. I’m using a virtual machine and JITed code, if speed was so crucial I would have used C.  And Java has reasonable performace once it is running, I never had to complain about method call overhead.

They could have asummed that the method is non-ovewriteble by default and deoptimised the code in run-time first time it is overwriten. Or something like that.

In one book they said not to have an empy constructor because of the performance. Well couldn’t compiler detect an empty  constructor? Doesn’t it create one by default? Fucking premature optimizations.

I’m so glad that my next project will be in Ruby.

Filed Under Uncategorized | Leave a Comment

Vs.net 2005 lock.

Posted on June 19, 2007

VisualStudio puts an exclusive lock on files.
In my case it lib\Rhino.Mocks.xml file that contains documentation for lib\Rhino.Mocks.dll.

msbuild scripts fails to read this file and I can not test my project. This is retarded.

Filed Under Uncategorized | Leave a Comment

C# problem

Posted on June 19, 2007

I have Microsoft and their bastard child C#.

I really want to start using test triven developement and have unit test.
Their proved to be invaluable when I modify code.

In one of my classes I use System.Net.WebClient.

public WebCamera(WebClient client, Uri uri)
{
this.client = client;
this.uri = uri;
}
public string CaptureFrame()
{
string location = Path.GetTempFileName();
client.DownloadFile(uri, location);
return location;
}

WebClient is a concrete class, it implements IComponent, but IComponents does not have DownloadFile mathod.

At first I tried to use Rhino Mocks, to mock the Webclient. I’m probably not familliar enougth with
this tool but it was calling GetWebResource(uri) i.e concrete implementation, instead of just returning.

So, next I deciced that I can just pass my impementation of WebClient

class StubWebClient : WebClient
{
public Uri m_uri;
public string m_path;
override public void DownloadFile(Uri uri, string path)
{
m_uri = uri;
m_path = path;
}
}

I got this nice message:
Error Cannot override inherited member ‘System.Net.WebClient.DownloadFile(System.Uri, string)’ because
it is not marked virtual, abstract, or override

Allrighty then, we will provide new DownloadFile mathod.

override public void DownloadFile(Uri uri, string path)
{
m_uri = uri;
m_path = path;
Consle.Write
}

Well I would not write this post if it worked. C# ignored my method and called the one from the base class.

I can do
StubWebClient webClient = new StubWebClient();
webClient.DownloadFile(uri, “file.tmp”);

but I don’t want my camera to care what type of webclient i pass.

Now I’m just started programming in C# this mounth, and I probably don’t know what I am supposed to do. But so
far it look like C# is broken.

Anyone knows how to fix this?

Filed Under Uncategorized | Leave a Comment

© Copyright 0xDEADBEEFCAFE • Powered by Wordpress • Design by Sebastin.

free web hit counter