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,828 other subscribers

Archive for the ‘Software Development’ Category

Example.[com|net|org] Web Page

Posted by jpluimers on 2010/06/01

After years of doing web-development, I just stumbled on example.com/example.net/example.org second level domain names.

Those are domains meant for documentation or example purposes.
And there is RFC 2606 that documents them.
There are even these first level domain names:
.test/.example/.invalid/.localhost

You’re never too old to learn something new :-)

–jeroen

Posted in Development, Software Development, Web Development | 1 Comment »

.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 »

Duplicate Shortcuts IE8 configuration dialog – Alt-N binds to “No” and “Next”. Are UI designers ever going to learn to be nice to keyboard users?

Posted by jpluimers on 2010/05/17

Duplicate Alt-N shortcut: No / NextFor every (re)install, IE8 is usually part of the installation.
So, for the upteenth time, I came across the dialog on the right.
This time Alt-N is bound to both the “No” choice as well as the “Next” button.

–jeroen; wishing UI designers would learn to pay more attention to keyboard users…

Via: 20100516-UI-Duplicate-Shortcuts-IE8 on Flickr – Photo Sharing!.

Posted in Development, Keyboards and Keyboard Shortcuts, Power User, Software Development, UI Design | Leave a Comment »

.NET – Putting a base in the middle (Eric Lippert – Fabulous Adventures In Coding)

Posted by jpluimers on 2010/05/14

I always tend to recompile assemblies when something changes they depend upon.

But now I’m even more careful after reading Fabulous Adventures In Coding : Putting a base in the middle.
Especially his checklist is important.

When you use a newer version of an assembly you depend on:

(1) at the very least test your derived types with the new base type — your derived types are relying on the mechanisms of the base types; when a mechanism changes, you have to re-test the code which relies upon that mechanism.

(2) if there was a breaking change, recompile, re-test and re-ship the derived type. And

(3) you might be surprised by what is a breaking change; adding a new override can potentially be a breaking change in some rare cases.

–jeroen

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Delphi, Development, Prism, Software Development | Leave a Comment »

.NET/C# – determining the hardware acceleration support for your WPF apps

Posted by jpluimers on 2010/05/13

When you want to deploy WPF, it is important to check if you have sufficient hardware acceleration for your apps.

The most important things to check is the RenderCapability.
It gives you the  Tier on which graphics is rendered.

The Tier tells something about hardware acceleration support, including a broad estimate of the pixel shader and vertex shader levels and DirectX versions.

Currently, there are 3 tiers: Read the rest of this entry »

Posted in .NET, C#, C# 3.0, C# 4.0, Development, Software Development, WPF | 1 Comment »

Reading tea leaves – Danny Thorpe

Posted by jpluimers on 2010/05/12

A short while ago, [WayBack] Danny Thorpe posted an answer about multithreading issues on StackOverflow.com [WayBack] which reminded me a lot about a BorCon session he did.
That session is called [WayBack] “Reading Tea Leaves: The Fine Art of Debugging“, it is still very current (a lot of it is not Delphi specific at all: it can be applied to a broad range of platforms), and I was glad to find that [WayBack] Joe White made [WayBack] some great notes and posted them on his blog.

Edit 20100513T0830: (thanks Mario!) Don’t you love 404 :-)
The blog from Joe White seem to be down, and the web archive of his blog didn’t have that particular page, but the google cache has.

–jeroen

PS:
Danny is a great writer; I’m really glad he [WayBack] showed up at StackOverflow.
Here is another very [WayBack] nice answer from him on concurrency in software using read-write, locking, interlocked increment and more.

He found back his slides:

Consolidating a dusty box of ancient DVDRW archive disks this weekend (uploading them to multi-redundant NAS) and looky what I found! I’d given up all hope of ever finding this again. #digitalpackrat ftw!

Hope this brightens your day @jpluimers :) https://t.co/saqq7JA46e

Posted in Debugging, Delphi, Development, Software Development | 3 Comments »

Why SizeOf for character arrays is evil: stackoverflow question “Why does this code fail in D2010, but not D7?”

Posted by jpluimers on 2010/05/11

This Why does this code fail in D2010, but not D7 question on stackoverflow once again shows that SizeOf on character arrays usualy is evil.

My point in this posting is that you should always try to write code that is semantically correct.

By writing semantically correct code, you have a much better chance of surviving a major change like a Unicode port.

The code below is semantically wrong: it worked in Delphi 7 by accident, not by design:
Like many Windows API functions, GetTempPath expects the first parameter (called nBufferLength) number of characters, not the number of bytes. Read the rest of this entry »

Posted in Delphi, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi XE, Delphi XE2, Delphi XE3, Development, Encoding, ISO-8859, Software Development, Unicode | Leave a Comment »