The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,862 other subscribers

Archive for May, 2010

#fail: Facebook has changed their mail domain to facebookmail.com

Posted by jpluimers on 2010/05/28

Recently, facebook started to complain that my email is not valid any more:

Please update your email address
Our systems have detected that valid.email@example.com is no longer a valid email. Facebook requires all users to maintain an active contact email. Please enter and confirm a new contact email below:
New Email: XXXXXXXX
If you believe you have received this message in error, please reconfirm your current email.

Note I changed my facebook email address in the quote above and log below, but the unchanged one is valid, and accepts mail. Read the rest of this entry »

Posted in Opinions, Power User | 11 Comments »

.NET/C#: comparison is a 101, or isn’t it?

Posted by jpluimers on 2010/05/26

In C# (well, actually: .NET), there are a couple of ways to compare things:

  • the built-in equality operator (==) which translates to the IL instruction CEQ
  • an overloaded equality operator (operator ==) that a class or struct can introduce
  • the virtual Equals method that is introduced in System.Object and which you need to call explicitly

Sometimes, this leads to confusion, for instance, given

object one = 0;
object two = 0;
bool same = one == two;

what would you expect the value of same to be?

Actualy, the value is false.

Why?

The reason is that the operator == does not call the System.Object.Equals method.
So the System.Int32.Equals method is never called.

What happens in stead, is that the CEQ instruction is called.
Since both the integer zero values have been boxed into two objects (referred to by one and two), the CEQ will perform the comparison on the object references.
Even though both zero values are the same, both objects have a reference to a different spot in memory (the contents of both memory spots then are the same zero value).
Since one and two refer two different memory locations, the value of same becomes false.

Similar things hold for most types, unless they overload the operator ==.

System.String is a special type.
Even though it not a value type (it is derived from System.Object, not SystemValueType), it behaves like a value type.

One of the things that string does is overload the operator == (and overload the operator !=):

public static bool operator ==(string a, string b)
{
    return Equals(a, b);
}

So even though one and two are potentially* referring to different locations, their content is compared, and same becomes true.

string one = "Foo";
string two = "Foo";
bool same = one == two;

*Now lets see these memory locations:

object one = "Foo";
object two = "Foo";
bool same = one == two;

Surprise! Here too, same becomes true.

What happened here is that when the compiler compiles two identical strings into an assembly, they are interned and end up at the same memory location.

Conclusion:

Comparison in .NET is not always 101.
It depends on the types involved, value types versus reference types, boxing, interning and the overloaded operator ==.

–jeroen

via The Lounge – CodeProject.

PS:
Another special thing about strings is that they are immutable:

A String object is called immutable (read-only) because its value cannot be modified once it has been created. Methods that appear to modify a String object actually return a new String object that contains the modification. If it is necessary to modify the actual contents of a string-like object, use the System.Text.StringBuilder class.

via String Class (System).

PS2:

Some other interesting links on comparison, interning, etc:

Posted in .NET, C#, Development, Software Development | Leave a Comment »

Happy Towel Day

Posted by jpluimers on 2010/05/25

Don’t forget to bring your Towel today

–jeroen

Posted in .NET, About, Delphi, Development, Opinions, Personal, Software Development | 1 Comment »

“Yoda Conditions” (from: stackoverflow – New programming jargon you coined?)

Posted by jpluimers on 2010/05/25

Having done quite a bit of C and C++ work in the past, I often still use “Yoda Conditions”, especially in environments where you have both = and == as an operator.
So, in a boolean expression, I often put the constant to test in front of the test.

I recently learned at stackoverflow that quite a few people call these “Yoda Conditions”:

“Yoda Conditions”— the act of using if(constant == variable) instead of if(variable == constant), like if(4 == foo). Because it’s like saying “if blue is the sky” or “if tall is the man”.

Thanks to dreamlax for helping me find that.

This is a problem in languages that have both the = and == operators, and the result of an assignment itself is also a value (i.e. allowing a = b = true). Read the rest of this entry »

Posted in .NET, C#, Delphi, Development, Java, Ruby, Software Development, Web Development | 22 Comments »

Visual Studio 2010: macro to change Target Framework Version for solution (by Scott Dorman)

Posted by jpluimers on 2010/05/21

Scott Dorman udpated his macro to change the target framework version for all projects in a solution to Visual Studio 2010 and published the new macro on CodeProject.

His new macro now supports these target frameworks:

Notes:

  • The links are to the download pages of the frameworks; look for “Standalone version” or “Full installer” for non-bootstrap download.
    (version 1.1 can be downloaded here, but is not supported in VS2010)
  • The “Client Profile” versions are stripped down versions of their “Full” counterpart.

–jeroen

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Delphi, Development, Prism, Software Development, Visual Studio and tools | 2 Comments »

Telnet for Windows Vista & Windows 7

Posted by jpluimers on 2010/05/20

I wrote about Telnet for Windows Vista & Windows 7.

These steps are even easier:

  1. Press the Windows key
  2. type “turn windows features on or off”
  3. choose “Telnet Client”
  4. press OK
  5. wait a few seconds for the install to complete

–jeroen

Posted in Power User, Windows, Windows 7, Windows Vista | 1 Comment »

Solution for “Error code: 2147500037” while printing in Windows 7

Posted by jpluimers on 2010/05/20

Recently I got the messagebox below with “Error code: 2147500037”  when I used Windows 7 to print some settings (in this case the homegroup password, so I could store it in a safe place).

---------------------------
Your homegroup password couldn't be printed
---------------------------
An error occurred while Windows was trying to print your homegroup password. (Error code: 2147500037)
---------------------------
OK
---------------------------

It seems I am not the only one having this problem, and the solution was simple:
Windows 7 cannot print certain things when Internet Explorer is not the default browser.

Or in other words: this error message means: “Windows 7 cannot print this for you because it needs the default browser to be Internet Explorer“.
Was it that hard for Microsoft phrasing the message in such a way?

Changing the default browser is simple (some of the steps are in screenshots below): Read the rest of this entry »

Posted in Power User | 52 Comments »

Control the VMware VMs from the commandline: vmrun – the successor of vmware-cmd

Posted by jpluimers on 2010/05/19

In the process of upgrading from VMware server 1.0 to 2.0, I found out that vmware-cmd.bat has been replaced by vmrun.exe.

The command-line options are different, and this link explains the vmrun command-line options in detail (well, much better than the vmrun.exe built-in help). The official documentation is available as a PDF.

One of the changes I had to make was from: Read the rest of this entry »

Posted in *nix, Power User, VMware | 2 Comments »

ThinkPads beep during certain key combinations – found the cause

Posted by jpluimers on 2010/05/18

I’ve had an annoying beep on my thinkpad whenever I tried to write CD quickly.

It particularly shows when you press these three keys at the same time:

Shift+CD

Recently, I googled for the symptom to find out the cause.
Below are a few links I found, but this is the actual cause (thanks Kriston!): Read the rest of this entry »

Posted in Keyboards and Keyboard Shortcuts, Power User | Leave a Comment »

sun Java JRE 1.6.0.20 direct download for Windows

Posted by jpluimers on 2010/05/17

Edit:

20110904: Not sure why this MSI file does not work any more, but the comment below is correct: the downloaded MSI fails.
I’ve left the text below as is, just in case someone figures out why it fails.

–jeroen

Got the direct download from the error dialog because the network connection got interrupted:

—————————
Error – Java(TM) Installer
—————————
Download Cancelled by User: from=http://javadl-alt.sun.com/u/ESD6/JSCDL/jdk/6u20-b02/jre/jre1.6.0_20-c-l.msi, to=C:\Users\user\AppData\LocalLow\Sun\Java\jre1.6.0_20\jre1.6.0_20-c-l.msi
—————————
OK
—————————

Always convenient having a direct download URL :-)

–jeroen

Posted in Power User | 3 Comments »