Sujet : Re: New VSI post on Youtube
De : arne (at) *nospam* vajhoej.dk (Arne Vajhøj)
Groupes : comp.os.vmsDate : 22. Aug 2024, 21:25:21
Autres entêtes
Organisation : SunSITE.dk - Supporting Open source
Message-ID : <66c79eb1$0$706$14726298@news.sunsite.dk>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Mozilla Thunderbird
On 8/22/2024 1:39 PM, Simon Clubley wrote:
On 2024-08-21, Dave Froble <davef@tsoft-inc.com> wrote:
On 8/20/2024 1:34 PM, bill wrote:
On 8/20/2024 8:36 AM, Simon Clubley wrote:
In languages with dynamic associative arrays (such as PHP), I simulate
this by returning an associative array from a function call with both
status and value fields. Makes coding _so_ much cleaner and robust.
>
And probably much harder to understand in anything but the most
trivial usage.
>
Would that not be rather clear with adequate comments about what is being done?
Look at the example Arne posted. Very clean and very easy to understand
without having to use comments (and I am actually a fan of the liberal
use of comments. :-) ).
The same example in older VB.NET:
Imports System
Imports System.Collections.Generic
Namespace MR
Public Class Program
Public Shared Function FourOps(a As Double, b As Double) As IDictionary(Of String, Double)
Dim res As New Dictionary(Of String, Double)()
res("plus") = a + b
res("minus") = a - b
res("multiply") = a * b
res("divide") = a / b
Return res
End Function
Public Shared Sub Main(args As String())
Dim a As Double = 3.0
Dim b As Double = 2.0
Dim res As IDictionary(Of String, Double) = FourOps(a, b)
Console.WriteLine("{0} + {1} = {2}", a, b, res("plus"))
Console.WriteLine("{0} - {1} = {2}", a, b, res("minus"))
Console.WriteLine("{0} * {1} = {2}", a, b, res("multiply"))
Console.WriteLine("{0} / {1} = {2}", a, b, res("divide"))
Console.ReadKey()
End Sub
End Class
End Namespace
In newer VB.NET it looks like:
Imports System
Imports System.Collections.Generic
Namespace MR
Public Class Program
Public Shared Function FourOps(a As Double, b As Double) As IDictionary(Of String, Double)
Return New Dictionary(Of String, Double)() From { _
{"plus", a + b}, _
{"minus", a - b}, _
{"multiply", a * b}, _
{"divide", a / b} _
}
End Function
Public Shared Sub Main(args As String())
Dim a As Double = 3.0
Dim b As Double = 2.0
Dim res As IDictionary(Of String, Double) = FourOps(a, b)
Console.WriteLine("{0} + {1} = {2}", a, b, res("plus"))
Console.WriteLine("{0} - {1} = {2}", a, b, res("minus"))
Console.WriteLine("{0} * {1} = {2}", a, b, res("multiply"))
Console.WriteLine("{0} / {1} = {2}", a, b, res("divide"))
Console.ReadKey()
End Sub
End Class
End Namespace
But I suspect that David as a Basic connoisseur consider that dictionary
initializer syntax copied directly from C# an abomination - curly
brackets is not real Basic.
Arne