Browsing All Posts filed under »Tech/Hacks«

C# compiler optimizations and empty “try” block

April 28, 2008

2

There is some misinformation you’re likely to stumble upon via Google when searching for “C# compiler /optimize+”. Interestingly, the following snippet can be seen on various forums. The following is a response from a developer on the C# compiler team: We get rid of unused locals (i.e., locals that are never read, even if assigned).… [Read more…]

Switch is just If-Else-If

April 24, 2008

0

In an internal meeting of a bunch of developers at my current company, someone made the assertion that the Switch statement in C# (or Select Case in VB.NET) is just a compiler short-cut for writing a chain of If-Then-Else statements. What do you think? Is that statement – true or false? Take the following C#… [Read more…]

On assigning null to value-types in VB.NET

April 16, 2008

0

Problem: Consider the following generic function written in VB.NET: What message do you expect to be shown by the following bit of code? Would the “Foo” method even compile? It doesn’t make sense to assign a Nothing (VB.NET equivalent of C#’s null) to a value-type, right? Solution: Well, the code compiles just fine. When synthesizing… [Read more…]

WPF equivalent of InvokeRequired

January 10, 2008

8

If you’re reading this article, you’re most probably familiar with the InvokeRequired property on Windows.Forms.Control class which we have to use whenever setting a property on a Windows Forms control from a thread other than the one it was created on. Here is what the MSDN page about InvokeRequired says: Controls in Windows Forms are… [Read more…]

Something about .NET string interning

December 11, 2007

0

Look at the following piece of code: Note how we are first assigning “Hello”, then appending ” “, and then appending “World”. The C# compiler generates the following IL code for our method named Test.   From the IL you can see that the compiler did some optimization. The compiler saw what we were actually… [Read more…]

When not to optimize

December 3, 2007

0

So anyway, this compiler group discovers that they no longer have 32K, or 128K, or 512K. Instead, they now have a 4GB virtual address space. “Hey, let’s use a really big hash table!” you can hear them saying, “Like, how about 1 MB table?” So they did. But they also had a very sophisticated compiler… [Read more…]

A look at DoEvents

November 19, 2007

2

Why did I write this article, and why should you read it I have heard blanket statements lately that assert that DoEvents is evil but then I have also seen code that relies on DoEvents. In this article I will attempt to shed some light on why you might want to use DoEvents, possible problems… [Read more…]

Workarounds

July 13, 2006

7

As we go about creating abstractions on top of other abstractions to get stuff done we cannot avoid inventing workarounds for quirks and bugs in lower level abstractions. But it is important that those workarounds be incorporated in such a manner that they do not come and bite in the back when the quirks in… [Read more…]

TagyuLib – Tagyu .NET Client Library

March 25, 2006

0

I have finished writing a .NET client library for Tagyu's REST Web-Service. Tagyu is a hosted service that uses human intelligence to suggest tags and categories relevant to a block of text. TagyuLib (that’s my creative name for the .NET API) supports everything that the REST API of Tagyu allows you to do as of… [Read more…]

Tagyu::Search v0.03

December 9, 2005

2

I have incorporated support for two new features in my Tagyu::Search module and learnt a lot about HTTP in the process. 1. Support for HTTP Basic Authentication With this in place, it is now possible for Perl code using my module to break the one request per IP barrier imposed on anonymous users by Tagyu.… [Read more…]

Follow

Get every new post delivered to your Inbox.