Things We Love About Visual Basic Dot Net

Things we love about VisualBasicDotNet:

(...sometimes related to ThingsWeLoveAboutVbClassic.)

Not to be confused with ThingsWeHateAboutVisualBasicDotNet.


List:



Discussion:


You can embed XML literals right into your source code:
    Dim xmlVar As XElement = _
        <rootElement>
            <innerElement1/>
            <innerElement2>Constant text here.</innerElement2>
        </rootElement>
and you can embed expressions to dynamically change element and attribute names and values
    Dim xmlVar As XElement = _
        <rootElement>
            <nameElement type=<%= greetingType %>><%= "Hello " + nameVar + "." %></nameElement>
            <<%= dynamicElementName %> <%= dynamicAttributeName %>="static attribute value"/>
        </rootElement>
and VisualBasic automatically does all the appropriate quoting, giving one a high level of protection against SqlInjection attacks.



Query syntax in DLinq (LinqToSql?) is much more like the StructuredQueryLanguage (SQL) syntax we're accustomed to, rather than the "collections library" style syntax in C#.

In VisualBasicDotNet, one might do a DLinq query like this:

    SELECT p2.ProductName?, p1.UnitPrice?
    FROM dbo.ProductsCostingMoreThan?(80.50)
    AS p1 INNER JOIN Products AS p2 ON p1.ProductID = p2.ProductID
Where in the CsharpLanguage (C#), it would look more like this:
   var q =
      from p in db.ProductsCostingMoreThan?(80.50m)
      join s in db.Products on p.ProductID equals s.ProductID
      select new {p.ProductID, s.UnitPrice?};
The VB.NET syntax is much more like the RelationalDatabase's SQL syntax than the C# version. The C# version has all the same clauses, but they're in some other order that's "more natural" for a collections library.

Related: LanguageIntegratedQueryProject



For a VisualBasic subclass to override a superclass method, you must use the Overrides keyword: If the method signatures match and you don't have the Overrides keyword, it's a compile error. The Java 5 @Override annotation is nice, but when it's missing, the program might or might not still be overriding a superclass method, and the original programmer might or might not have been intending to override a superclass method; it can be hard to be sure. But with VisualBasic the intention and implementation are always clear: You see the Overrides keyword IfAndOnlyIf this method overrides a superclass method.



The Shared keyword more clearly expresses that fields and methods are Shared across all instances of a class -- making its usage much less error-prone than the C/C++/C#/Java overloading of the static keyword for this purpose, particularly for relatively less experienced developers.


CategoryVisualBasic CategoryDotNet


EditText of this page (last edited November 4, 2012) or FindPage with title or text search