Tuesday, March 20, 2012

How to save VB and piss off the rest of the world

Visual Basic is a dying language.

People are mostly switching to C#, either due to their familiarity with Java, C++ or just because every sample on the planet is in C#, including the ones provided by Microsoft.

The way things are going, some day VB will go the way of Pascal and COBOL. Languages that are still around to some extent, but people don't really use unless they're supporting an old system.

How could they save VB?

Here's my idea:

***** Make VB recognize similar syntax from other languages *****

If the VB compiler accepted this:

If ((x = 1) And Not(y < 0)) Then
    sTmp = "Test"
End If

AND this:

if ((x == 1) && !(y < 0))
    sTmp = "Test";

Then all of the C# syntax in the world could just be copied & pasted into VB apps, PROBLEM SOLVED.

Here are some of the main things that would need to be allowed:
1 - Semicolon to end a line
2 - Curly braces to open & close constructs (if, while, for)
3 - &&, ||, ! % in place of And, Or, Not, Mod
4 - Brackets for arrays, [] instead of ()
5 - Declarations with type first versus last (string sTmp; vs. Dim sTmp As String)
6 - // and /* */ for comments

Some things that would cause problems:
1 - C# ONLY ends a line of code with a semicolon.

So you can have a statement that spans multiple lines and is only ended when the compiler hits the ;
In VB to extend your program to another line you have to use the _ symbol.

Sample C#:

x = y
+ 7;

Sample VB:

x = y _
+ 7

2 - C# string syntax uses \ escape sequences instead of "" for quotes.

Sample C#:

sTmp = "Fail \\, what\" hey";

Sample VB:

sTmp = "Fail \, what"" hey"

Honestly though I think if there was like a compiler setting like "Allow compatible C# syntax" then you would basically be doing it at your own risk and have to take the risky things into account, but the benefits would WAAAY outweigh the drawbacks!