Structured functions

Topics: VB Language Design
Apr 22, 2014 at 10:26 PM
Edited Apr 22, 2014 at 10:28 PM
Make new possibility to join functions with structures. This greatly reduce redundant formalization, and provide more compact code.
Functiom GetCar () as {Name as String, Speed as Integer}
    return {.Name = "SomeText", .Speed = 200} ' or return {"Some text", 200}
End Function

Function GetLength () as {Length as Integer}
    return 20
End Function
Apr 28, 2014 at 9:21 PM
That's an interesting idea. At last week's VB Language Design Meeting we actually discussed another similar feature...
Class GetCarResult(Name as String, Speed as Integer) : End Class

Function GetCar() As GetCarResult
    Return New GetCarResult(Name := "SomeText", Speed := 200)
End Function
The advantage of this is that it's made up of smaller orthogonal language features (e.g. primary constructors). The disadvantage is that it's not as slick as your inline-declarations...
May 8, 2014 at 12:22 PM
I suggest that compiler shold create structure GetCarResult or GetCarOut for function GetCar. So we can use this structure explicitly like:
Dim res as GetCarResult
res = GetCar()