none
The power, capabilities and industry-usage of Visual Basic.NET, and its limitations? *Discussion*

    General discussion

  • Hi everyone,

    So I've been wondering: how powerful is Visual Basic compared to more flexible and "to-the-metal" programming languages such as C? What do you think are the most complex kinds of application VB could create (could it create advanced 3d video-games to the same level as C++-made games, for example)

    Are there things that Visual Basic simply cannot do - i.e. anybody who's been writing on this forum for a while, have you ever been unable to answer someone's question simply because what they're asking is not possible?

    Of course, there are the well-known limitations:

    • More memory required to work with it
    • Restricted to Microsoft operating systems
    • Quite slow program performance

    Does Microsoft actually use this language at all for any of its programs or OS features?

    When, and why, will Microsoft discontinue Visual Basic.NET in favor of more 'mainstream' .NET languages such as C#?

    Can't wait to hear your thoughts :)

    Thursday, November 9, 2017 12:31 AM

All replies

  • Oh boy -- here we go again. ;-)

    *****

    Do you understand what a "managed" language is? I've used that term a few times now, always assuming that you understood, but if you don't then that's the starting point.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 12:48 AM
  • Oh boy -- here we go again. ;-)

    *****

    Do you understand what a "managed" language is? I've used that term a few times now, always assuming that you understood, but if you don't then that's the starting point.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Yes indeed :-)

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 9, 2017 12:51 AM
    Moderator
  • Yes indeed :-)

    ;-)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 12:53 AM
  • Both C# and VB.NET are powerful yet in the wrong hands, well they can leave an impression that the language rather than the developer is not good enough to do a specific solution.

    For years I used VB.NET in enterprise wide solutions where the only reason they become obsolete is that they are desktop applications and the demand is (at my company) web base solutions. We went to C# mainly because it’s easier to do full stack development easily between C# and JQuery/JavaScript plus there are more code examples in C# now than in VB.NET.

    Now if I was asked which one of the language was better I’d honestly would say that based on Framework 4.5 and C# 6 they are very close to one another. I could go with either language and get any tasked handed to me done thinking database work or business logic.

    First bullet, they are both the same.

    Second bullet, C# is easily ported to other platforms while VB.NET is restrictive.

    Bullet three, without running any kind of professional speed test it’s safe to say they are no different.

    Last question, I doubt VB.NET will be discontinued any time in the near future, VB.NET a extremely robust language, don't let anyone tell you differently. I would expect the same if someone asked about C#.

    Final statement, if you are just starting out coding it would be prudent to learn both languages but have C# as your main language. Don’t be one of those programmers who picks one language and think you have a future in software development. Personally most days I’m coding in C#, JavaScript, Jquery, CSS, Entity Framework, Azure.  I could be called on to write something new (usually a utility or class project) or do an enhancement in VB.NET. Three months from now I may be pulled into a year long VB.NET solution then when finish jump back into C#.

    You must know what customers want as many are bias to a programming language and will not accept another programming language no matter what you say and if the contract or full time job is going to pay well and they say VB.NET, you need to be flexible, same if they ask for C#.

    On top of all of this learn “the gang of four” and good solid database skills.

    Hopefully me siding with C# development in a VB.NET forum does not offend anyone. If you had asked these questions five or ten years ago I would be siding with VB.NET considering what my company was asking for back then but now it’s a 90 percent C# world and ten percent VB.NET while back in the day it was the reverse.

    EDIT

    https://visualstudiomagazine.com/articles/2017/06/13/visual-basic-future.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Thursday, November 9, 2017 12:55 AM
    Moderator
  • Lucy,

    Let's start with this: Managed (in this sense) is done by the CLR and we don't have to deal with things like memory management.

    https://en.wikipedia.org/wiki/Managed_code

    That's a good thing (for us) that we don't.

    - BUT -

    If you had the knowledge and need to, then you're out of luck here. We're a manged (dotNET) language, whether VB Net or C# Net.

    *****

    High level and low level ... where's the umpire when you need one? ;-)

    It's a matter of abstraction. How close are we to actual machine code? Assemly is really close and we're not close to assembly (which is specific to the processor) and you don't *want* to be!

    High Level

    Low Level

    That's a start...


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 12:58 AM
  • Frank,

    Hmmm, I believe I know what "managed" means. i can't really recall you talking about it, I probably dismissed it as, at the time, irrelevant Microsoft jargon. Off the top of my head, correct me if I'm wrong, but is it:

    --------

    Managed code is computer program code that requires and will execute only under the management of a Common Language Runtime virtual machine, typically the .NET Framework, or Mono. The term was coined by Microsoft.

    Managed code is the compiler output of source code written in one of over twenty high-level programming languages that are available for use with the Microsoft .NET Framework, including C#, J#, Microsoft Visual Basic .NET, Microsoft JScript and .NET, while unmanaged code refers to programs written in C, C++, and other languages that do not need a runtime to execute. Managed code in the Microsoft .Net Framework is defined according to the Common Intermediate Language specification.

    The distinction between managed and unmanaged code is prevalent and only relevant when developing applications that interact with the .NET Framework or other Common Language Runtime (CLR) implementations, like Mono. Since many older programming languages have been ported to the CLR, the differentiation is needed to identify managed code, especially in a mixed setup. In this context, code that does not rely on the CLR is termed unmanaged.

    A source of confusion was created when Microsoft started connecting the .NET Framework with C++, and the choice of how to name the Managed Extensions for C++. It was first named Managed C++ and then renamed to C++/CLI. The creator of the C++ programming language and member of the C++ standards committee, Bjarne Stroustrup, even commented on this issue, "On the difficult and controversial question of what the CLI binding/extensions to C++ is to be called, I prefer C++/CLI as a shorthand for "The CLI extensions to ISO C++". Keeping C++ as part of the name reminds people what is the base language and will help keep C++ a proper subset of C++ with the C++/CLI extensions."<sup class="reference" id="cite_ref-Stroustrup_1-0">[1]</sup>

    Microsoft's Visual C++ development environment can produce both managed code, running under the .NET CLR, or compiled binaries, running directly on the Windows platform with the help of its C++ Runtime Library.<sup class="reference" id="cite_ref-Gregory_2-0">[2]</sup>

    Benefits of using managed code include programmer convenience (by increasing the level of abstraction, creating smaller models) and enhanced security guarantees, depending on the platform (including the VM implementation). Drawbacks include slower startup speed (the managed code must be JIT compiled by the VM) and generally increased use of system resources on any machine that is executing the code.

    There are many historical examples of code running on virtual machines, such as the language UCSD Pascal using p-code, and the operating system Inferno from Bell Labs using the Dis virtual machine. Java popularized this approach with its bytecode executed by the Java virtual machine. The WLanguage of WINDEV is also a pCode running on a virtual machine.

    --------

    To be perfectly honest, I am really just guessing here with this definition, but hopefully I'm not mistaken and *managed* to pull off a correct explanation for you.

    Lucy


    • Edited by Lucy Qu Thursday, November 9, 2017 1:00 AM I had to add the pun at the end.
    Thursday, November 9, 2017 12:59 AM
  • So, we've covered one limitation. It's runs on a VM (which I did not know :P). So this will make it slower, right? Any other thoughts?

    • Edited by Lucy Qu Thursday, November 9, 2017 1:02 AM
    Thursday, November 9, 2017 1:02 AM
  • So, we've covered one limitation. It's runs is a VM (which I did not know :P). So this will make it slower, right? Any other thoughts?

    *Please* be clear who you're talking to!

    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 1:03 AM
  • Just to add to this discussion a bit, at the bottom of the Wikipedia page that I covertly copied from without anyone knowing, there's a link to this interesting video:

    https://channel9.msdn.com/Shows/Going+Deep/Singularity-A-research-OS-written-in-C

    Wow! An OS written in CS.NET! As we all know, C# is very similar to VB.NET (only major differences are syntactical), so this is relevant. Wow! Wow, Wow!

    Wow,

    Lucy


    • Edited by Lucy Qu Thursday, November 9, 2017 1:06 AM
    Thursday, November 9, 2017 1:06 AM
  • Lucy,

    Managed - the short course:

    We don't have to worry with memory management; the framework does that for us. We don't have to worry about destructors (we use constructors all the time, never a destructor). The framework does that for us with the built-in garbage collection.

    *****

    All of this is like trying to get a sip of water from an open fire hydrant; the problem isn't the scarcity of water! ;-)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 1:09 AM
  • Karen,

    Very insightful Karen, thank you! It's interesting to hear about its use in business! I kind of get the impression that, when people hear "VB.NET", they think of an extremely limited, basic beginner language without any use. Thanks for addressing this! Great to hear your views.

    Lucy

    Thursday, November 9, 2017 1:12 AM
  • As we all know, C# is very similar to VB.NET (only major differences are syntactical)...

    You're way off base here. That statement isn't correct, no matter who you're quoting.

    There are few things that you can't accomplish in either language and many are "just the syntax" but all of them aren't.

    What I mean is -- you can get the job done with either, but to say that it's only syntax isn't [necessarily] so!

    I will say this though: The IL is remarkably similar and in the end, that's what really matters anyway. That's what the JIT sees, not the language.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 1:14 AM
  • ➽Frank↩Thank you for your input! I've heard about Assembly a lot - given that it's so close to the machine code, I bet you could create really fast applications with that. I've been doing VB.NET for a couple of weeks, I think I'll move on to Assembly next. - Sarcasm, by the way.

    Thanks for the links too, I've only heard "low-level" coined once, by Iron, when he was talking about WinHooks. I always thought that that just meant that it was easy. I guess not.

    So fruitful already! I have amassed terabytes of knowledge!!

    Lucy

    Thursday, November 9, 2017 1:18 AM
  • Frank (addressing dissimilarities between CS and VB)

    Oh, I thought they shared the exact same libraries and classes and such. I was basing this entirely off of my success with Telarik Code-converter in the past when I stumbled across a useful resource, or wanted to experiment with a program.cs.

    I can see clearly now.

    Thanks


    • Edited by Lucy Qu Thursday, November 9, 2017 1:22 AM
    Thursday, November 9, 2017 1:21 AM

  • So fruitful already! I have amassed terabytes of knowledge!!

    Lucy

    Fruitious is never a bad thing. :)

    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 1:22 AM
  • Frank,

    So, does Microsoft still use VB.NET in its products much? I heard they were very involved in BASIC many years ago, but that's a different language?

    Thanks

    Thursday, November 9, 2017 1:23 AM
  • Frank (addressing dissimilarities between CS and VB)

    Oh, I thought they shared the exact same libraries and classes and such. I was basing this entirely off of my success with Telarik Code-converter in the past when I stumbled across a useful resource, or wanted to experiment with a program.cs.

    I can see clearly now.

    Thanks


    Look at Select Case -vs- Switch.

    Accomplishing the same thing but not the same.

    Don't focus so much on the "how to" (learn them both) though. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 1:25 AM
  • Frank,

    So, does Microsoft still use VB.NET in its products much? I heard they were very involved in BASIC many years ago, but that's a different language?

    Thanks

    Let's see if I remember the acronym:

    Beginner's
    All-Purpose
    Symbolic

    ... ok no I don't remember

    *****

    Despite its beginnings, that was then, and this is now.

    Anyway, addressing your question, I don't know but I can't imagine they use *any* high level language, but if they do my guess is that they'd lean to a C-based one (like C# or Java). Totally guessing though.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 1:28 AM
  • Just to add to this discussion a bit, at the bottom of the Wikipedia page that I covertly copied from without anyone knowing, there's a link to this interesting video:

    https://channel9.msdn.com/Shows/Going+Deep/Singularity-A-research-OS-written-in-C

    Wow! An OS written in CS.NET! As we all know, C# is very similar to VB.NET (only major differences are syntactical), so this is relevant. Wow! Wow, Wow!

    Wow,

    Lucy


    Overall syntax is not a big deal nor are slight differences in how a method might be done. For instance in C# 7 TryParse is a good example, we can setup the out variable as shown here. So we have moved away from syntax.

    public void Demo1()
    {
        var input = "12";
        if (int.TryParse(input, out var quantity))
        {
            WriteLine($"Within if {quantity}");
        }
        else
        {
            WriteLine("Quantity is not a valid integer!");
        }
    
        WriteLine($"{quantity}"); // still valid
    }

    VB.NET (Note I had to declare the integer prior to TryParse but not in C# 7)

    Public Sub Demo1()
        Dim input = "12"
        Dim quantity As Integer = 0
        If Integer.TryParse(input, quantity) Then
            Console.WriteLine($"Within if {quantity}")
        End If
        Console.WriteLine($"{quantity}")
    End Sub

    How about creating XML in code, VB.NET makes it so easy while C# is tiresome.

    Does allowing "out parameters" make C# better, heck no but something to consider, VB.NET Framework 3.5 is extremely powerful when working with VB.NET and with that can do great things. At the same time any release of VB.NET lacks in what can be done with web development. Goes back to what do customers demand. 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 9, 2017 1:30 AM
    Moderator
  • Frank (replying to Case + Switch differences comment),

    Right, I can see a lot of people have issues with converting VB cases to C#. Now that I think of it, I've had one instance of a converter not recognizing some code when I was attempting to get my form to house an external process:

    <DllImport("user32.dll")> Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
        End Function

    So, I guess you're right, some differences


    Thursday, November 9, 2017 1:32 AM
  • For the record in regards to assembly language, developing games or business apps there is no need for this.

    I look at C++ and assembler for low level operations but not limited to that either. With C# and VB.NET we can code very fast which even when good with C++ is going to be a slower time to write the same software we do with C# and VB.NET.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 9, 2017 1:33 AM
    Moderator
  • Here is a company that solely uses VB.NET and this company is huge.

    https://www.fastenterprises.com/solutions/gentax/


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 9, 2017 1:35 AM
    Moderator
  • Frank,

    Beginner's
    All-Purpose
    Symbolic

    Instruction

    Code

    - Had to Google, I only knew what the 'B' stood for. The 'B' stands stands for 'me'... beginner.

    Yeah, it's well-known that Microsft uses A LOT of C# (it's well known, I'm not claiming I knew it, haha) - https://www.quora.com/Why-does-Microsoft-use-C-in-most-of-its-teams

    Thursday, November 9, 2017 1:38 AM


  • VB.NET (Note I had to declare the integer prior to TryParse but not in C# 7)

    Public Sub Demo1()
        Dim input = "12"
        Dim quantity As Integer = 0
        If Integer.TryParse(input, quantity) Then
            Console.WriteLine($"Within if {quantity}")
        End If
        Console.WriteLine($"{quantity}")
    End Sub

    Not so!

    If you only want to test *if* it can be cast as an integer, there's nothing else needed:

            Const input As String = "12"
    
            If Integer.TryParse(input, New Integer) Then
                Stop
            Else
                Stop
            End If


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 1:39 AM
  • Here is a company that solely uses VB.NET and this company is huge.

    I remember having a discussion with Jordan back around 2011 or so.

    I said then and will again now: Customers are interested in results; not so much how you got there (ergo, what programming language you used).


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 1:42 AM
  • Frank,

    Beginner's
    All-Purpose
    Symbolic

    Instruction

    Code

    - Had to Google, I only knew what the 'B' stood for. The 'B' stands stands for 'me'... beginner.

    Yeah, it's well-known that Microsft uses A LOT of C# (it's well known, I'm not claiming I knew it, haha) - https://www.quora.com/Why-does-Microsoft-use-C-in-most-of-its-teams

    :-)

    Just to be clear here - you're new and may not know - I'm *not* a developer.

    Karen is - and a good one - I'm a mechanical engineer who likes this stuff so please don't think that I'm a professional at all.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 1:44 AM
  • Karen,

    Thanks again for you input. Looking at the C# code, I guess which language you choose to do a project with may also be down to personal preference too. I for one, would hate to work with all of those curly brackets.

    I'd wait untill I've mastered VB.NET (about 13 years more learning for me), before going onto CurlyBracketSemiColon code.

    Cool to find out that VB's used for web development too!

    Thanks


    • Edited by Lucy Qu Thursday, November 9, 2017 1:52 AM
    Thursday, November 9, 2017 1:44 AM
  • Reply to all, regarding GenTax,

    Oh cool, it's interesting to hear about a company that only uses VB. Thank you everybody for the great discussion - which I have learned a lot from (hopefully it will stick) :) I'm off now as it's getting late.

    Thanks for your time and insightful comments! :D

    Thursday, November 9, 2017 1:49 AM


  • VB.NET (Note I had to declare the integer prior to TryParse but not in C# 7)

    Public Sub Demo1()
        Dim input = "12"
        Dim quantity As Integer = 0
        If Integer.TryParse(input, quantity) Then
            Console.WriteLine($"Within if {quantity}")
        End If
        Console.WriteLine($"{quantity}")
    End Sub

    Not so!

    If you only want to test *if* it can be cast as an integer, there's nothing else needed:

            Const input As String = "12"
    
            If Integer.TryParse(input, New Integer) Then
                Stop
            Else
                Stop
            End If


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    To be perfectly clear, I'm not speaking of TryParse but instead C# out parameters. I can write a void (equivalent to sub in vb.net) method in C# in my project that accepts any type and need not declare it beforehand. Also another new feature in C# is that I can write a function inside a method and is not tied to any internal framework stuff. Another feature would be to have an async method that can float between async and synchronous return values. So TryParse was a simple way to indicate a difference yet we can still use conventional methods that use ref (similar to ByRef yet ByRef you must have a variable declared ahead of time and set to a value to be done right while C# need not). 

    See Out parameters.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 9, 2017 2:01 AM
    Moderator
  • Karen,

    Thanks again for you input. Looking at the C# code, I guess which language you choose to do a project with may also be down to personal preference too. I for one, would hate to work with all of those curly brackets.

    I'd wait untill I've mastered VB.NET (about 13 years more learning for me), before going onto CurlyBracketSemiColon code.

    Cool to find out that VB's used for web development too!

    Thanks


    VB.NET can be used for web development but if you do enough research it's going to be a rough ride as most tutorials and documentation is 98 percent C#. 

    Curly brackets are easy to get use too. 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 9, 2017 2:05 AM
    Moderator

  • See Out parameters.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Inline declarations - interesting idea but how are they figured for scope?

    Block scope?


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 2:08 AM
  • If I read your text it looks like text from Kim Jong-un

    Of course there are well known limitations of English compared to North Korea:

    • More persons required to work with
    • Restricted to those who speak English
    • Quite slow performance of the people

    Those limitations are only in the mind of some persons and they tell it to others as a kind of ideology as the truth. 

    A language has no power, what is made with it that can have power. 

    With VB you can make very easy large solutions with much data because you can simple reuse the same code (and mainly it does that automatically). Which is with many other program languages like C very difficult to manage. Therefore what you write about VB is often the case with what you write about C.

    However, one thing is true, VB, C++, Java, C# are limited to operating systems. C not although then you need a compiler which is able to build machine instructions for the used processor. 



    Success
    Cor


    Thursday, November 9, 2017 8:07 AM
  • Lucy et al,

    "What do you think are the most complex kinds of application VB could create (could it create advanced 3d video-games to the same level as C++-made games, for example)."


    When you consider high performance graphics (and GUI) is where you will find a difference. Not between vb and c#, but between those two and c++ or lower level langs.

    And the difference between managed and unmanaged code as mentioned already.

    In c lets say (I am just going to call c# vb for this discussion. And c++ c), you can control the video display memory with unmanaged code where vb you can not. This means the real high end video games can use c and etc to get better performance of the video display.

    How much better? One can do quite a bit with vb managed graphics. Dont get that wrong. And then I use Directx 9 add in from within vb and get very good 3d graphics from it. Of course Directx is not written in vb. It is written in c(++) and I would guess some is assembly. But I dont really know and I am not an expert.

    So my point is for real high end graphics then you will reach a limit with pure vb. Although the limit is fairly high.

    And my final point is when I was learning vb in the 1980s, which was then qb, I spent a month learning c. It took a month to learn to write my name on the screen. Something I could do in 60 seconds in qb. That was where c and I parted ways.

    That is also what Cor and the others will say, if you are making a business level app you will need a lot more time to write it in c verses vb.

    So finally you need to consider how much $$ in your time and energy you have for the project and balance that with performance of the language and etc.

    PS I forgot to mention with c you get the high performance graphics with unmanaged code, you also get high end errors that can crash and the system. In vb you can not really crash the system, just your app.

    That is one reason vb is managed code. Then the errors are managed and don't constantly crash windows.

    Thursday, November 9, 2017 1:03 PM
  • Tommy,

    That's so, but it depends on the goal. If your goal was to write a driver, for example, you won't get far with that in VB / C#.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 1:13 PM
  • @Frank in regards to scope.

    Here are some simple examples. I commented on scope.

    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    
    namespace WindowsFormsAppEntity
    {
        public class LocalFunctionExample
        {
            /// <summary>
            /// Uses a local function
            /// </summary>
            /// <param name="pCount"></param>
            /// <returns></returns>
            public IEnumerable<int> Numbers(int pCount)
            {
                if (pCount <= 0) throw new ArgumentException();
    
                return NumbersLocal();
    
                // local function, in scope withing Numbers method
                // using yield as an iterator
                IEnumerable<int> NumbersLocal()
                {
                    for (int i = 0; i < pCount; i++)
                    {
                        yield return i;
                    }
                }
            }
            /// <summary>
            /// Local function async
            /// </summary>
            /// <param name="pValue"></param>
            /// <returns></returns>
            public Task<int> PerformWorkAsync(int pValue)
            {
                if (pValue < 0)
                    throw new ArgumentOutOfRangeException("value must be non-negative");
    
                if (pValue > 100)
                    throw new ArgumentOutOfRangeException("You don't want to delay that long!");
    
                async Task<int> AsyncPart()
                {
                    await Task.Delay(pValue * 500);
                    return pValue * 500;
                }
    
                return AsyncPart();
    
            }
            public void SayYourName(string pFirstName, int pMilliSeconds)
            {
                // in scope only in SayYourName
                void Hi(string name, int milliSeconds)
                {
                    Console.WriteLine($"Hi! My name is {name} who waited {milliSeconds}");
                }
    
                Hi(pFirstName, pMilliSeconds);
            }
            public string Address
            {
                get
                {
                    return $@"{GetHouseNumber()}, {GetStreet()},
                      {GetCity()},
                      {GetCountry()}";
    
                    int GetHouseNumber() => 10;
    
                    string GetStreet() => "Liberty St";
                    string GetCity() => "Amsterdam";
                    string GetCountry() => "Jamaica";
                }
            }
        }
    }

    Here is one that combines a local method EmptyAddress in tangent with Tuples. Now the Tuples can be called two different ways, conventional or with discards (a discard skips a param via "_")

    string FirstName, string LastName, string Address1)

    Full method

    public (string FirstName, string LastName, string Address1) LookupByCounty1(string pCountyName)
    {
        using (SandboxEntities Context = new SandboxEntities())
        {
            var results = Context.Contacts
                .Where(contact =>
                contact.ApplicationContacts.Any(ac => ac.Application.Name.ToLower() == "aced") &&
                contact.Organization.Name == pCountyName &&
                contact.AddressContacts.Count > 0 &&
                !contact.IsDeleted).FirstOrDefault();
    
            // local function
            string EmptyAddress()
            {
                var address = results.AddressContacts.FirstOrDefault()?.Address.Address1;
                return address.IsNullOrWhiteSpace() ? "(no address)" : address;
            }
    
            return (results.FirstName, results.LastName, EmptyAddress());
    
        }
    }

    Conventional call

    var (firstName, lastName, address) = ops.LookupByCounty1("Marion");

    With a discard for param 1

    var (_, lastName, address) = ops.LookupByCounty1("Marion");
    Console.WriteLine($"{lastName} at {address}");

    Now some might say cool, others might say "so what". It's all up to whom is coding. Is VB.NET a lesser language because of these C# 7 features, I say no yet someone else may say it is. It's all a matter of perspective and if in a team of developers their opinion matters too. 

    Edit: Tuples are cool now but just because they are cool doesn't mean they should be used just to use them.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Thursday, November 9, 2017 2:56 PM
    Moderator


  • Now some might say cool, others might say "so what". It's all up to whom is coding. Is VB.NET a lesser language because of these C# 7 features, I say no yet someone else may say it is. It's all a matter of perspective and if in a team of developers their opinion matters too. 

    Edit: Tuples are cool now but just because they are cool doesn't mean they should be used just to use them.


    We have tuples and I use them every now and then but they're like a hybrid between an anonymous type (you know how I feel about those) and a real class with properties. Given that I'd rather just make a private class and be done with it. I can then also use names that make sense. ;-)

    As to your other point(s), you missed one - a big one:

    "How would this help me if we had it?"

    That's the question that I'd ask first...


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Thursday, November 9, 2017 3:05 PM


  • Now some might say cool, others might say "so what". It's all up to whom is coding. Is VB.NET a lesser language because of these C# 7 features, I say no yet someone else may say it is. It's all a matter of perspective and if in a team of developers their opinion matters too. 

    Edit: Tuples are cool now but just because they are cool doesn't mean they should be used just to use them.


    We have tuples and I use them every now and then but they're like a hybrid between an anonymous type (you know how I feel about those) and a real class with properties. Given that I'd rather just make a private class and be done with it. I can then also use names that make sense. ;-)

    As to your other point(s), you missed one - a big one:

    "How would this help me if we had it?"

    That's the question that I'd ask first...


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    @Frank, Tulples under C# 7 are strong typed with the name given.

    So here we declare  lastName in the signature then use it in Console.WriteLine. They could be used in a situation where there is a good deal of data crunching e.g. streaming or traversing.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 9, 2017 4:11 PM
    Moderator


  • @Frank, Tulples under C# 7 are strong typed with the name given.

    So here we declare  lastName in the signature then use it in Console.WriteLine. They could be used in a situation where there is a good deal of data crunching e.g. streaming or traversing.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    I don't think you're following what I meant. From this MSDN document:

    "By default, the name of each field in a tuple consists of the string Item along with the field's one-based position in the tuple. For this 3-tuple, the Date field is Item1, the String field is Item2, and the Boolean field is Item3."

    If I create a simple class - private with auto-implemented properties - I can call them any [valid] name I want and use it very easily.

    With a tuple, I'm stuck with "Item" so and so. I'll stick with my way. ;-)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 9, 2017 4:21 PM
  • @Karen and @Frank,

    For me you begin to discuss in an analogy if the word "Elevator" is correct or that it has to be "Lift". 

    Sorry, I was in England a fortnight ago so I have been pointed again with my nose on it. I had biscuits with my thee.  I recognized I became in this forum used to American words. This I see now as it is about VB and C# in a way also in this discussion, it is in my opinion really not important. 

    Karen, as well this becomes to far from a discussion with all those question about VB syntax in it. 


    Success
    Cor


    Thursday, November 9, 2017 4:42 PM
  • @Karen and @Frank,

    For me you begin to discuss in an analogy if the word "Elevator" is correct or that it has to be "Lift". 

    Sorry, I was in England a fortnight ago so I have been pointed again with my nose on it. I had biscuits with my thee.  I recognized I became in this forum used to American words. This I see now as it is about VB and C# in a way also in this discussion, it is in my opinion really not important. 

    Karen, as well this becomes to far from a discussion with all those question about VB syntax in it. 


    Success
    Cor



    Agree :-)

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 9, 2017 4:46 PM
    Moderator
  • The old joke was...

    Is VB as fast as C++?

    Yes, actually 6 months to 2 years faster.


    Mary

    Friday, February 9, 2018 1:04 AM
  • I find the worst part is the parenthesis necessary after methods. I just let the VB editor add them for me and I never know what's wrong when I get a red squiggly on a C# method call. You can cut way down on braces with the right syntax but my old eyes have a terrible time with ([{ and :; and ,. 

    Mary

    Friday, February 9, 2018 1:17 AM