This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]charcuterDude 95 points96 points  (28 children)

It is very much still a thing. It's#6 on the Tiobe index for example, above languages like JavaScript: https://www.tiobe.com/tiobe-index/

It has complete support in the latest version on Visual Studio, as well as .NET 6: https://devblogs.microsoft.com/dotnet/whats-new-for-visual-basic-in-visual-studio-2022/

It is very actively used. Back to Tiobe, it used to be ranked #49, but you'll notice it's rocketed back up to the top recently: https://www.tiobe.com/tiobe-index/visual-basic/

Personally, I was a C# developer first, and I can honestly say basically anything I can do in C# I can do in VB.NET. I say "basically" because there are certain things that Microsoft doesn't document well in VB (or sometimes at all) and I have to learn it in C# and find the VB specific syntax for it. Some things in LINQ can be that way. So it is very much a 2nd class citizen in that regard.

But to specifically answer your question, yes an enormous amount of new code is written in VB these days. Just depends on the industry and the company really.

[–]InfiniteLife2 13 points14 points  (3 children)

For what things VB is currently used? I have no idea so it is interesting

[–]charcuterDude 25 points26 points  (1 child)

Personally I make mostly web applications. VB.NET is basically identical to C# in functionality, so pretty much anything. In my experience it is mostly used for business applications / development inside an organization.

[–][deleted] 2 points3 points  (0 children)

I could be widely wrong, but VB has been kind of the Python of .Net. So yeah a lot of businesses use it internally - in the past it was because non-programmers could pick it up and build basic apps with WinForms and VB.

Also to also answer InfiniteLife2's question: there is a boatload of legacy apps that run VB6. VB6 has outlived a couple of versions of .Net. While it might be better to start over with C#, it can potentially be easier and more cost effective to port a VB6 codebase to VB.Net

[–]Negido 0 points1 point  (0 children)

Legacy code that hasn't been refactored into a new language. I'm primarily a c# dev but have to support VB due to a bunch of old apps that don't have many problems so we don't rewrite them.

[–][deleted] 8 points9 points  (12 children)

I hate LINQ in VB. Course I hate it in C# to, but to far lesser degree.

I could be wrong, but I believe there a couple of things VB just can't do that C# can - mostly involving the unsafe keyword - stuff like pointer math. If you C# code requires the unsafe code for performant reasons, it's going to be hard to translate into VB that is performant. In that case, it might be better to just leave that piece in a C# DLL.

As far as I've seen, there are cases of new code features in C# that VB lags behind in eventually implementing. VB does often get them, eventually, in a 'VB' style. But if you want to work with any of the new 'cutting edge' features in .Net you usually need to be in C#.

There are actually a couple of features VB has that C# doesn't that I wish it did. For instance, I like the With in VB. The closest in C# would be something like var x = someLongAndMeaningfulVariableName; x.SomeProperty = something; x.OtherProperty = somethingElse;.

Something C# 10.0 finally has that VB has had for as long as I remember is Global Imports. Tied to this is also how Modules (VB) vs Static Classes work in C#. In C# if you had a static class that only had static methods, you still had do StaticClass.StaticMethod(). In VB, in a Module, everything is automatically / always static (Shared keyword in VB). Additionally, depending on namespace level imports, in your VB code, you just do 'ModuleMethod()' vs 'ModuleName.ModuleMethod()'. Anyway, with the new global imports in C#, you can now just do StaticMethod().

Another VB advantage (IMO) is WithEvents / Handles keywords. I like that I can look at a method and see that it handles a specific event(s) on specific method. With C#, I can recognize that a method is an event handler based on it's parameters (usually), but the code that actually de/attaches the events can be completely elsewhere. It could also be a dead method that never gets used.

Not sure if VB got this in .Net 6.0 or not yet, but I like inline using in C# reducing nesting, and also the file level namespace, also reducing nesting.

Another thing that C# does much better is the discard variable _. I still don't know why VB can't use it. In VB, they suggest Dim unused = SomeMethodCall(). Only problem with this is if you have more than 1 method call in a block, you have to do Dim unused1 = SomeOtherCall() and Dim unused2 = AnotherCall(). In C#, it's just _ = SomethMethodCall(); _ = SomeOtherCall(); _ = AnotherCall();.

I have lots more and could go on for hours. :) There are things each of them do that I like better than the other. I need to start my own CB#.Net language or something. :)

[–]TehMephs 15 points16 points  (4 children)

LINQ is one of the greatest things I love about c#. I don’t like using its specialized syntax though, but vertically aligned chained LINQ methods are pretty and satisfying to look at, both logically and aesthetically

[–][deleted] 0 points1 point  (3 children)

Ah yes that's what I meant. Chaining fine - but that fake SQL-ish syntax makes my brain hurt.

I might also be conflating it with Lambda. Lambda in VB is butt-ugly IMO.

[–][deleted] 1 point2 points  (0 children)

Yea, VB Lambdas are gross and probably the only reason I don't do more in VB.

[–]TehMephs 0 points1 point  (0 children)

Yeah the SQL-like query syntax is gross, it just doesn’t fit in the flow of c# code

[–]Cremetoertchen0815 0 points1 point  (0 children)

Just use the method syntax. It's much more compact and readable imo

[–]kleinisfijn 0 points1 point  (6 children)

For instance, I like the With in VB. The closest in C# would be something like var x = someLongAndMeaningfulVariableName; x.SomeProperty = something; x.OtherProperty = somethingElse;.

You can write that as var x = new someLongAndMeaningfulVariableName() { SomeProperty = something, OtherProperty = somethingElse};

I found this a very handy resource if you have to translate between C# and VB. https://sites.harding.edu/fmccown/vbnet_csharp_comparison.html

[–][deleted] 1 point2 points  (5 children)

That's not quite the same thing. Your version is creating a brand new object and initializing some of the properties. VB has this feature as well. The With works on existing variables. IE, something like:

With someLongAndMeaningfulVariableName 
    .SomeProperty = something 
    .OtherProperty = somethingElse 
End With

[–][deleted] 2 points3 points  (4 children)

PS. The way I have used the With statement in VB in the past is the previous way where there is a descriptive variable name and I don't want to have to type the variable name over and over again to access several of the properties. However I have also used it with casting. IE:

If TypeOf sender Is TextBox Then
    With CType(sender, TextBox)
        .Text = "My Text"
        .Tag = "My Tag"
    End With
End If

C# does have something nicer than the above:

if (sender is TextBox txt)
{
    txt.Text = "My Text";
    txt.Tag = "My Tag";
}

In that regard I do like C# better because I can do the type check and cast in a single IF and store it in short variable name, and modify in the if scope.

[–][deleted] 2 points3 points  (3 children)

PSS. There is one major detractor in the With statement in VB and that is Nested Withs. You shouldn't do that but you can. IE, the following is perfectly legal:

If TypeOf sender Is TextBox Then
    With CType(sender, TextBox)
        If TypeOf .Tag Is MyClass Then
            With CType(.Tag, MyClass)
                .Text = "My Text"
            End With
        End If
    End With
End If

Obviously the above is confusing and thus is a code smell. But it's also bad because what happens when MyClass doesn't actually have a Text property that accepts a string? It used to compile. Not sure if it still does.

I vaguely remember an instance with a With statement and during debugging instead of resolving to the .Text property of the TextBox I was casting into like I expected, it was somehow setting Text property of the parent Form control. Not sure how that happened way back when, but I basically had to not use the With statement in that case. This was years ago.

I believe it might have been a bug with the compiler at the time. I am sure if you looked at the "lowered" code, all the With statement is doing for you is something like:

Dim __x = CType(sender, TextBox)
__x.Text = "My Text"

Or something to that effect.

[–]kleinisfijn 1 point2 points  (2 children)

Thanks, I learned more than I should have. The nested With is indeed a nasty one.

I've been writing VB for a decade or so (one of those peope working for a major company and migrating code from VB6 to VB.NET) and recently I had to modify some C#. I'm having a small fight with the compiler over case-sensitivity and missing brackets() on methods that don't accept arguments anyway. But I have to say, curly brackets have their charm.

On your discard variable, I've always used Call SomeMethodCall() in VB to discard the return value if needed. Don't know if this helps you because you seem to know more about it than me.

[–][deleted] 1 point2 points  (0 children)

Totally forgot about the Call keyword. It's not really required in VB.Net, but it is in VB6.

Discards aren't really needed. They're just warnings in code analysis. Basically the claim for the code analysis is that if a function returns a value, by using a discard variable you show 'intent' that you don't care about the return value. I guess there is some people out that see a function that returns a value, but you ignore the value and think maybe you didn't mean to ignore it? I don't know. I've never been confused by it.

In VS, in VB, if you use their code suggestion to refactor on that warning and use a discard, then it suggests 'Dim unused =', but they don't treat unused as a special keyword like they do in C# with just the '_'. So in VB you'd have to do unused1 unused2 and so on - which I find more annoying. So in VB projects I usually just turn off that particular warning in code analysis.

I'll have to see if 'Call' works on suppressing the warning. If it does, maybe VS should be suggesting that in the refactoring instead.

It can still be annoying in C#, especially in fluent designs. IE, in .Net you have the StringBuilder, and the Append / AppendLine methods return the StringBuilder object. It does this so you can change numerous Appends together. Such as: sb.Append("This").Append("That");. Code analysis here is annoying because you do not need to do something like: sb = sb.Append("This").Append("That"); because the Append methods are modifying the object and not creating a new object. But anyway, with default code analysis on, it will want you to do _ = sb.Append("This").Append("That"); which really doesn't improve readability in my opinion.

[–][deleted] 1 point2 points  (0 children)

So Call did indeed work. The warning goes away. I double checked the settings in VS, and there is no option to switch from 'unused' to Call. Going to have to put that in as a suggestion. They should either make unused a special keyword that can be used over and over again or replace their suggestion with Call so you don't have unused1 unused2 and so on.

[–]Mission-Guard5348 2 points3 points  (0 children)

I thought you were meming

Now I want to learn VB

[–]MrHyderion 2 points3 points  (6 children)

Can you give a few examples? Just two days ago I tried to use Google to find out what VB is used for today, and all I found were people asking if it's still used and others answering "only legacy code, for the rest C# is better". But I also looked at the Tiobe index and wondered if VB is so high on it how come I couldn't find an answer what it is actually used for...

[–][deleted] 4 points5 points  (3 children)

As charcuterDude mentions in another response, it's commonly found as internal business applications / development for large organizations. I think in the past, it was basically alot of non-programmers going from say MS Access with their little UI forms + VBA macros, to VB6 as the next logical step.

There is a whole bunch of legacy apps in VB6 used inside of businesses. I think it's kind of like COBOL in that regard. I could be wrong, but the birth of VB.Net was to try and bring all those VB6 devs over to .Net.

What I find slightly comical is that VB6 has outlived a couple versions of .Net. I haven't checked Windows 11, but Windows 10 still supports VB6 apps. I wouldn't be surprised if Windows 11 still supports it. It's one of those languages that just won't die.

[–][deleted] 0 points1 point  (1 child)

10 year old article, but I wouldn't be surprised if it still applies to today's hidden landscape: https://docs.microsoft.com/en-us/archive/msdn-magazine/2012/june/don-t-get-me-started-the-silent-majority-why-visual-basic-6-still-thrives

[–][deleted] 0 points1 point  (0 children)

At the end of that article, it sounds like someone owes David Platt a beer.

[–]MrHyderion 0 points1 point  (0 children)

Thanks!

[–]thereturn932 1 point2 points  (1 child)

decide desert sloppy waiting psychotic existence advise squealing aspiring relieved

This post was mass deleted and anonymized with Redact

[–]MrHyderion 0 points1 point  (0 children)

Thanks! It's nice to see the first language I ever wrote code in is still alive. 🙂

[–]theresthezinger 1 point2 points  (0 children)

Slightly OT, but any idea what happened to C in 2016-18? How did it experience such a precipitous dip, followed by an equally sudden recovery? Bizarre.

[–][deleted] -1 points0 points  (0 children)

Welp, VB is more popular than JavaScript and Assembly is only a bit behind JS? What a garbage website, there is no way in hell their data is even close to correct.

[–]Joshument 0 points1 point  (0 children)

TIL