Tuesday, April 24, 2012

& versus +

I've pretty much switched over to C# programming, and while I do like some aspects of it, there are some that I think are just silly.

Type conversion is SOOOO easy in VB versus C#.

Ex:
Dim x As Integer
Dim s As String

s = "7"

x = s 'Since x is an Integer, it automatically converts s to an Integer

x = 5

s = x 'Since s is a String, it automatically converts x to a String

In C# you have to EXPLICITLY cast everything.Kind of a pain.

Ex:
int x;
string s;

s = "7";

x = Convert.ToInt32(s); //Explicitly converts s to an int

x = 5;

s = Convert.ToString(x); //Explicitly converts x to a string

I understand that VB allows for some "sloppy" programming by making the compiler assume the type conversions, but as programmers shouldn't we be able to depend on the programming language to be smart enough to perform the default type conversion based on the type of the variable on the left?

It just makes things kind of silly sometimes, and I was thinking that maybe the root of it all is that C# doesn't have a separate operator for string concatenation.

In VB you use + for arithmetic, and & for string concatenation.In C#, + is for both. (& is for bitwise operations)

Ex:
Dim x, y, z As Integer
Dim s As String

s = "Results: " & x & ", " & y & ", " & z


Ex:
int x, y, z;string s;

s = "Results: " + Convert.ToString(x) + ", " + Convert.ToString(y) + ", " + Convert.ToString(z);

Wouldn't it be sweet if C# defined a string concatenation operator?

And if your response is "Don't be a lazy VB programmer, C# rules!"I say bite me, and if less typing makes you lazy then why are you all so excited about lambda expressions? :P

I really despise the religious war between VB and C# programmers. I've programmed in so many different languages that I think it's just silly because really VB and C# are more similar to each other than to they are to so many other languages.
*sigh*