<!--DEBUG:--><!--DEBUG:dc3-united-states-software-in-english-pdf-2--><!--DEBUG:--><!--DEBUG:dc3-united-states-software-in-english-pdf-2--><!--DEBUG-spv-->{"id":501714,"date":"2017-04-11T17:53:00","date_gmt":"2017-04-11T15:53:00","guid":{"rendered":"http:\/\/nhub.news\/?p=501714"},"modified":"2017-04-11T17:50:43","modified_gmt":"2017-04-11T15:50:43","slug":"an-end-to-co-evolution-with-visual-basic-15","status":"publish","type":"post","link":"http:\/\/nhub.news\/fr\/2017\/04\/an-end-to-co-evolution-with-visual-basic-15\/","title":{"rendered":"An End to Co-Evolution with Visual Basic 15"},"content":{"rendered":"<p style=\"text-align: justify;\"><b>Visual Basic 15 brings with it partial implementations of two important C# features: tuples and ref returns. Neither feature is \u201ccomplete\u201d, but they do offer enough work-arounds that VB applications can consume C# libraries that make use of these features.<\/b> <br \/>Visual Basic 15 brings with it partial implementations of two important C# features: tuples and ref returns. Neither feature is \u201ccomplete\u201d, but they do offer enough work-arounds that VB applications can consume C# libraries that make use of these features. <br \/>Tuples <br \/>The ability to directly return multiple values from a single function call has long been a requested feature in VB. Although you can get the same result using ByRef parameters, the syntax is clumsy compared to what you see in functional programming languages. <br \/>If you aren\u2019t familiar with the term, a \u201ctuple\u201d is just a set of related values. Since. NET 4.0, Visual Basic has had a standard Tuple class , but the user experience has been less than satisfactory. The values have to be manually unpacked from the Tuple using the unhelpful property names Item1, Item2, etc. <br \/>Seven years later, VB 15 finally adds syntax support for tuples. Or rather, the ValueTuple structure, which offers better performance than the heap-allocated Tuple object. Here is an example of a TryParse method written using the new style: <br \/>Public Function TryParse(s As String) As (Boolean, Integer) <br \/>Try <br \/>Dim numericValue = Integer. Parse(s) <br \/>Return (True, numericValue) <br \/>Catch <br \/>Return (False, Nothing) <br \/>End Try <br \/>End Function <br \/>Dim result = TryParse(s) <br \/>If result. Item1 Then <br \/>WriteLine(result. Item2) <br \/>End If <br \/>In this example, the return type of TryParse is ValueTuple. This makes the function a bit cleaner as you never have to explicitly mention the ValueTuple type. But as you can see, the code that calls it isn\u2019t any different. So let\u2019s improve it a bit by renaming the fields on the return type: <br \/>Public Function TryParse(s As String) As (IsInteger As Boolean, Value As Integer) <br \/>\u2026 <br \/>End Function <br \/>Dim result = TryParse(s) <br \/>If result. IsInteger Then <br \/>WriteLine(result. Value) <br \/>End If <br \/>You can create new tuples with named fields using this syntax: <br \/>Dim kvPair = (Key := 5, Value := \u00ab\u00a0Five\u00a0\u00bb) <br \/>Unfortunately there isn\u2019t a way to \u201cunpack\u201d a tuple in VB into multiple variables. So translating this C# code into VB requires one line per variable. <br \/>var (key, value) = kvPair; <br \/>(By)Ref Returns <br \/>Ref returns, known as ByRef returns in VB, are severely limited. You can consume C# functions that return a reference (i.e. managed pointer) to a field or array index, but you can\u2019t create your own. Nor can you create local byRef variables. <br \/>What you can do is a rather complicated work-around. While again you cannot create local ByRef variables, you can create ByRef parameters. Consider this C# function signature and its VB equivalent: <br \/>public ref string FindNext(string startWithString, ref bool found) <br \/>ByRef Function FindNext(startWithString as string, ByRef found as Boolean) As String <br \/>To use this, Klaus L\u00f6ffelmann tells us that we need a helper function: <br \/>Private Function VbByRefHelper(Of t)(ByRef byRefValue As t, <br \/>byRefSetter As Func(Of t, t)) As t <br \/>Dim orgValue = byRefValue <br \/>byRefValue = byRefSetter(byRefValue) <br \/>Return orgValue <br \/>End Function <br \/>You can then pass the result of the ref-returning function as a parameter to the helper function, along with what you want to do with it as an separate anonymous function. <br \/>Dim didFind As Boolean <br \/>&lsquo;Version #2: With a simple generic helper-class: <br \/>aSentence = New NewInCS2017. Sentence(\u00ab\u00a0Adrian is going to marry Adriana, because Adrian loves Adriana. \u00ab\u00a0) <br \/>Do <br \/>VbByRefHelper(aSentence. FindNext(\u00ab\u00a0Adr\u00a0\u00bb, didFind), <br \/>Function(stringFound) As String <br \/>If stringFound = \u00ab\u00a0Adrian\u00a0\u00bb Then <br \/>stringFound = \u00ab\u00a0Klaus\u00a0\u00bb <br \/>Return stringFound <br \/>End If <br \/>Return stringFound <br \/>End Function) <br \/>Loop While didfind <br \/>For reference, this is what it would have looked like had VB fully implemented ref returns: <br \/>&lsquo;THIS DOES NOT WORK IN VB!!! <br \/>Dim aSentence = New Sentence(\u00ab\u00a0Adrian is going to marry Adriana, because Adrian loves Adriana. \u00ab\u00a0) <br \/>Dim found = False <br \/>Do <br \/>&lsquo; !! In C# we can declare a local variable as ref &#8211; in VB we cannot.!! <br \/>&lsquo; This variable could take the result&#8230; <br \/>Dim ByRef foundString = aSentence. FindNext(\u00ab\u00a0Adr\u00a0\u00bb, found) <br \/>If foundString = \u00ab\u00a0Adrian\u00a0\u00bb Then <br \/>&lsquo; but via the reference, so writing would be possible as well, <br \/>&lsquo; and we had a neat find and replace! <br \/>foundString = \u00ab\u00a0Klaus\u00a0\u00bb <br \/>End If <br \/>Loop While found <br \/>So what happened to \u201cco-evolution\u201d? <br \/>The promise of co-evolution and parity between C# and VB was never truly honored. Even when they were still seeing the same features added to both languages, there were several platforms where C# was being offered without VB. Some of the most noteworthy examples include Windows Phone 7,. NET Core, and. NET Standard. We&rsquo;ve covered this before in Visual Basic: The Road Ahead , but here&rsquo;s a recap. <br \/>According to Mads Torgersen, there has been a major change in the way Microsoft approaches VB. Firstly, Microsoft sees VB more as an entry-level programming language than a professional tool- something that is learned first, but then abandoned for C#: <br \/>Visual Basic is used by hundreds of thousands of people. Most are using WinForms to build business applications in Windows, and a few are building websites, overwhelmingly using ASP. NET Web Forms. The majority are also C# users. For many this may simply be because of language requirements of different projects they work on. However, outside of VB\u2019s core scenarios many undoubtedly switch to C# even when VB is supported: the ecosystem, samples and community are often richer and more abundant in C#. <br \/>An interesting trend we see in Visual Studio is that VB has twice the share of new developers as it does of all developers. This suggests that VB continues to play a role as a good, approachable entry language for people new to the platform and even to development. <br \/>As a result, here is how the new strategy for VB is described as: <br \/>We will keep Visual Basic straightforward and approachable. We will do everything necessary to keep it a first class citizen of the. NET ecosystem: When API shapes evolve as a result of new C# features, for instance, consuming those APIs should feel natural in VB. We will keep a focus on the cross-language tooling experience, recognizing that many VB developers also use C#. We will focus innovation on the core scenarios and domains where VB is popular. <br \/>Anthony Green adds some more detail on the shift in strategy. You should read the full text, but briefly summarized they are: <br \/>Green writes: <br \/>A worthwhile observation is that, contrary to how customers often think of the causal relationship between them, the investments we make aren\u2019t the force pushing the languages in these new arenas. The arenas are the forces pulling on them and the investments are responses. It\u2019s not \u201cif you just pushed Visual Basic harder on Linux it would be a huge player there\u201d but \u201cGee, they really want C# on Linux, let\u2019s make it easier for them\u201d.<\/p>\n<p><span>\u00a9 Source: <a href=\"http:\/\/www.infoq.com\/news\/2017\/04\/VB-15?utm_campaign=infoq_content&amp;utm_source=infoq&amp;utm_medium=feed&amp;utm_term=news\" target=\"_blank\">http:\/\/www.infoq.com\/news\/2017\/04\/VB-15?utm_campaign=infoq_content&amp;utm_source=infoq&amp;utm_medium=feed&amp;utm_term=news<\/a><br \/>\nAll rights are reserved and belongs to a source media.<\/span><\/p>\n<script>jQuery(function(){jQuery(\".vc_icon_element-icon\").css(\"top\", \"0px\");});<\/script><script>jQuery(function(){jQuery(\"#td_post_ranks\").css(\"height\", \"10px\");});<\/script><script>jQuery(function(){jQuery(\".td-post-content\").find(\"p\").find(\"img\").hide();});<\/script>","protected":false},"excerpt":{"rendered":"<p>Visual Basic 15 brings with it partial implementations of two important C# features: tuples and ref returns. Neither feature is \u201ccomplete\u201d, but they do offer enough work-arounds that VB applications can consume C# libraries that make use of these features. Visual Basic 15 brings with it partial implementations of two important C# features: tuples and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":501713,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[93],"tags":[],"_links":{"self":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts\/501714"}],"collection":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/comments?post=501714"}],"version-history":[{"count":1,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts\/501714\/revisions"}],"predecessor-version":[{"id":501715,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts\/501714\/revisions\/501715"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/media\/501713"}],"wp:attachment":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/media?parent=501714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/categories?post=501714"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/tags?post=501714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}