Implement chainability to VB

Topics: C# Language Design, VB Language Design
Apr 22, 2014 at 11:17 PM
Edited Apr 22, 2014 at 11:19 PM
Chainablity allow to streamline nested function calls and avoid to declare temporary variables.
Instead of:
Dim x = GetData(0)
Dim y = GetData(1)
Dim res = Proc2 (x, y, Proc1 (x, y))
we can chain it into:
Dim res = GetData(0) : GetData(1) : Proc1(E1,E2) : Proc2(E1, E2, E3)
where EX is auto generated variable that carry result of indexed chain. These variables are scoped only to chain.
Apr 23, 2014 at 1:03 AM
I think that the first version is much more readable than the second one, especially if you give x and y decent names.
What compelling benefit would this bring? Saving few characters?
Coordinator
Apr 28, 2014 at 9:17 PM
C# had been considering two features called "declaration expressions" and "expression sequences" that more or less achieved this...
   var res = (var e1=GetData1(); var e2 = GetData2(); var e3 = Proc1(e1,e2); Proc2(e1,e2,e3));
F# has allows inline declarations, which we considered for VB as a sort of combination of declaration-expressions and expression-sequences...
   Dim res = Let e1 = GetData1()
             Let e2 = GetData2()
             Let e3 = Proc1(e1,e2)
             In Proc2(e1,e2,e3)
That is a bit more readable than the expression-sequences and declaration-expressions, but it just doesn't seem worth it. In the end, the only place where we wanted to have "variable declarations within expressions" was as Out parameters, e.g.
   If Integer.TryParse(Out s) Then Console.WriteLine(s)
May 8, 2014 at 12:36 PM
Edited May 8, 2014 at 12:36 PM
Chained expression could by very useful in aspx/ascx files, when mixing VB with HTML, without need to create helper functions with <script runat="server">...</script>