VB.NET vs C#, round two

I saw on Dan Appleman's blog that a new version of his Visual Basic.NET or C#…Which to Choose? is available, reflecting the latest changes in VS.NET 2005. I immediately bought a copy from Lockergnome, apparently the only vendor that allows instant eBook downloads after purchase.*


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2004/11/vbnet-vs-c-round-two.html

In fact, the IDE has always been the strength of VB. Starting with VB1. That’s why it is not surprising that most advances come in the form of IDE effectiveness. I’ll pick QuickBasic (with no classes, OOP or what have you with a great IDE than C# or Java with Notepad.

My biggest reason for not using C# (I personally like the C language family) and instead work with VB - VB is not case-sensitive.

Why o why does anyone need case-sensitive programming languages today? There is not a single compelling reason for it that I can think of. Especially with an advanced IDE like Visual Studio that can convert the case of identifiers for you.

Amen. Case sensitivity is just plain wrong, as far as I’m concerned.

I was recently editing code where the C# developer used lowercase versions (dostuff) of the methods to indicate private, and uppercase versions (DoStuff) to indicate public…

ugh.

I like C# actually. I’ve used VB, Fox, SQL, Powerscript, Delphi, java, xml, html and more if you consider application scripting.

The primary reason I can see to keep case sensitivity though is for conversions from C++ to C#. I agree that insensitive coding is easier to read, and would not be surprised if down the road we would see a case insensitive version of this product. Perhaps they’ll call it “C-Basic.”

Another reason other than the reason Jeff stated so gracefully is that having things case sensetive makes things easier to read. i don’t use those visual editors. just give me a unix box with vi on it an i am all set.

I’ve been vb.net for 3 years. I decided to use c# for my current project so that I could stick it on my CV (seeing as c# programmers get paid more!)

Yep - I can’t stand case insensitivity. I too was wondering what the hell it was all about. Phonix comments about the primary reason for it’s existance being for c++ conversions makes sense.

The thing that kills me though is those damn curly braces! {}

At the bottom of a complex page I’ve often got a dozen of the things trailing off…
}
}
}
}
}
}

I can never figure out what’s ending what.

The other day, a Java guy at work said “yeah, alot of people put comments after the end elipse”

     } // End foreach
 } // End for j

} // End Method
} // End Class

Um - does this look like BASIC to anyone else?? :wink:

I think that, after this project, I’m going back to VB.

Oh - there’s one other reason I can think of to use C# - it appears that the international community is adopting it more. Most of the opensource projects are in c# (well - for obvious reasons the Java ports are anyway… )

I do not care … i will do whatever my customer wants VB or C#

but rather be Called a Sharp developer than a Basic one

Well, I think it is a matter of history and IT culture. Why is COBOL so bad labeled, I had opportunity to work with it and I found it a great language for business applications. Actually add to it OO and you get perfect business language. But no, academics (professors) want their students to be scientists, science is math, and math is assembly and C language. Computer scientist is scientist so he respects C language and despise easier COBOL for business, along the way came C++ and VB, so scientist naturally choose C++ for really hard math formula programs, complex code gets popular with scientific institutions and the language gets the emperor of the programming languages title. With the hype comes marketing and business people look forward to have C++ top notch programmers as superior race of programmers. On the productivity level, VB amazes the managers, instead of being late, now they have VB coders who produce fancy GUI and fast applications (80% of the world is MS based). However, the hype holds for C++ and even if you can do it in VB in 1 month, give it 3 or 4 months and you have it in C++, bravo (now you got it complex and scientific). Along the way, IT students divide themselves in two camps. Top markers go for C++ with full steam and patiently accept the pointers induced crashes (assembly/C legacy of low level programming), another group of students, ones who got life (and lower marks for time lost on life) adopt easier yet more practical approach, VB is easy to learn, gets the projects done sooner, and GUI is cool. Yet they are lazy labeled, hence not professional, and really complex code still is done in C++. So the natural progression of VB as a language is stuck, what does MS have to solve if VB is used for small to middle range projects and its good for it. Why add to it anything nobody will use anyway. Along came Java and C++ scientific community cheered, no pointers = no crashes (less anyway), no viruses, reduced complexity, more productivity (even academics forgot why they insisted on pointers at first place and now teach Java). C to C++ to Java progression inherited Java scientific hype of C++, MS had to respond and they labeled their Java C# and finally added what they should have long time ago to VB.Net. The syntax of VB and C# is different but funcionality very similar. Yet true scientist is C syntax oriented and everybody respects those good students and not lazy ones so the hype holds, and is properly payed for. I’m currently Java programmer who only casualy worked with VB so for me its C# to adopt (I was C++ student) and Java is great language. Is it slow? not really. Case: Empty loop of 10 000 billion iterations.

Create a simple test class which times a loop. The Java definition is

public class Loop
{
public static void main(String[] args)
{
//10 000 billion iterations
long time = System.currentTimeMillis();
int REPEAT1 = 1000 * 1000;
int REPEAT2 = 1000 * 1000 * 10;
for (int i = 0; i REPEAT1; i++)
{
for (int j = 0; j REPEAT2; j++)
{
//do nothing
}
}
time = (System.currentTimeMillis() - time)/1000;
System.out.println("Time taken: (in seconds) " + time);
}
}

The C# definition is

using System;
class Loop
{
static void Main()
{
DateTime start = DateTime.Now;
int REPEAT1 = 1000 * 1000;
int REPEAT2 = 1000 * 1000 * 10;
for (int i = 0; i REPEAT1; i++)
{
for (int j = 0; j REPEAT2; j++)
{
//do nothing
}
}
TimeSpan time = DateTime.Now - start;
Console.WriteLine(“Time taken: (in seconds) {0}”, time.TotalMilliseconds/1000);
}
}

Result: Time taken to run -

C/C++ == approx. 1 month
C# == approx. 1 month
VB. == approx. 1 month
Java == Under one second

So does all this mean that Java is really faster than other languages? Hundreds of times faster?
No, of course I was joking. If you read the code, you probably assume that the benchmark measures the time taken for any language to iterate a loop counter. In fact the benchmark measures the ability of a language to optimize an application by eliminating inefficient instructions. The Java server mode JIT compiler eliminates the empty loops completely from the JIT-compiled code. So Java really does not execute these loops at all and thats a catch. Can other languages be optimized to do that too? Yes of course, its a matter of compilers.

Advice: Don’t make syntax and compiler ruin your chances of getting bread. If you are good programmer, the code you make is complex to the degree it needs to be. VB code can be very complex according to the requirements, but languages themselves are very similar. So if you are ridiculed cause you are using easy to learn language (as it happened to me when I programmed COBOL) move on and give it some extra time to learn new syntax and let them pay you properly for the hype they created. As for the casing issue C/C++/Java/C# have been a case sensitive language from the very start of it, and how much are you ready to pay me if I take your lower case code and convert it properly for you (if its your only reason not to adopt more paying language then you are probably paying some pretty greenies anually for it anyway).

“Anis” (never study IT my son).

I used to be a VB programmer, VB.NET and later Java and now finally C#. Clear and simple, C# code is easier to read and easier to find and visualize the logic pattern. If you write it in vb.net code, i just feel that the code is sucks, my eyes keep rolling of too much typing. C# is a very natually to code in OO but unlike VB.net, it seem too confusing. Last but not least, I like Java but Java is too slow and not much productivity to code in Java. If i have to choose between java and vb.net, i rather choose vb.net. Luckly, Ms knows that i love C coding standard, then Ms understand and specially design super C for me which is C++++ = C#.

my eyes keep rolling of too much typing

Well, if you dislike the verbosity of VB, you must really hate typing English sentences…

Code will be read many more times than it is written (see pages 841-843 of Code Complete for citations on this) – and verbosity is about producing code that’s easy to read. So erring on the side of { } instead of “End If” isn’t always a reasonable tradeoff.

The compiler may not care if your code is readable, but human beings do.

I personally like the braces and hate the words “End If”. It’s much easier to trace through the code and quickly figure out where the scope begins and ends because of the sharp visual difference that occurs when you have a single { on a line as opposed to a jumble of text.

People who write Visual Basic code also tend to be sloppy with their spacing, line breaks, indenting and case. Call me anal but it bugs me the same way seeing someone misspell the word “you’re” as “your” does. The laziness complaint is a very serious thing when it comes to the business of programming. In my experience, VB.NET developers tend to care primarily about getting the program done whichever way possible instead of worrying about efficiency. C++ and C# programmers are more likely to care about getting it done well.

When I write same code snippet using VB.NET and C#.NET, I found that exe created by VB.NET is less than C#.NET and C# Created exe under \bin\debug folder.

I guess I am in the minority when it comes to casing. I don’t really like to have to declare variables like this: m_ProductID. I rather type productID or productId.

Car car = new Car();

looks cleaner than

Dim m_car As New Car

in my opinion.

How about…

Item 1tem = new Item();

No? I wouldn’t consider this for the same reason I won’t consider

Item item = new Item();

If your variables are that unimportant-- they’re scoped really tightly and used for relatively simple stuff-- then just go with

Item i = new Item();

And avoid the brain damage altogether.

A “Car car” sounds like something my cat would cough up…

As said above, its not the language…

I’m not too sure what you are all going off about, I used to be a VB, Java, C++ developer up until VB 6. When .NET came out I thought i’d give this new fangled C# thing a go… personally I liked it and found it quicker and easier to do things than in VB. (this was a personal choice).

I think what pushed me over the edge was this…
I had to write a serial port interface for an windows service I was writing… try accessing DeviceIoControl in Kernel32.dll from VB.NET… or any of the standard buffers…

I stand to be corrected, and I am not sure if it is available now in 2005 but I know this. I could do this in a single pure C# application instead of having to use someone elses crappy dll…

Something that bothers me also guys… if C# developers get paid more, what are you waiting for, become a C# developer today and GET PAID MORE rather than whining about it (duh!). (it is all the .NET framework as you say and the conversion really is not difficult at all)

It is reasonable to say this much though, from my experience and utilising such tools as BizTalk etc… there is a fairly large amount of support for C#… I believe this much…

  • do what the customer wants
  • do what makes you the most amount of cash
  • do what keeps you more employable than the next guy.

Regards

Ryan

Simple answer, since its very first release.

Delphi has the best IDE of all the RADS out there.

Delphi 2006 takes it two notches up. The bar is set, and in those 4 points that the author gave, it has a A+ in all of them.

I suspect the main reason that publishers release two different books is simply practical - lugging a 1200 page book when it could be 800 pages makes a difference.

Here is another example:

VB.Net

Dim m_car As Car = DirectCast(mapper.GetObject(GetType(Car), Car)
m_car.Model = “Nissan”

C#

Car car = (Car)mapper.GetObject(typeof(Car));
car.Model = “Nissan”;