On Mar 23, 2007, at 3:47 PM, Guyren Howe wrote:

> On Mar 23, 2007, at 4:42 PM, Guyren Howe wrote:
>
>>>>> Functions should return one value.
>
> Another comment: this allows us to set up very nice symmetric pairs
> of functions. For example:
>
> Sub DateFromInteger(i As Integer) As Integer, Integer, Integer //
> Year, Month, Day
> Sub IntegerFromDate(Year As Integer, Month As Integer, Day As
> Integer) As Integer
>
> Dim y, m, d As Integer = DateFromInteger(IntegerFromDate(2007, 3, 23))
>
> Again: no-one has given me a downside to this proposal.

Take this example of yours

        Sub CountWords(s As String) As string(), integer()

1) Its poorly named as it does not just count words, it returns a  
dictionary of words and a count of those words.
2) how do I get JUST the count from this ? I suspect I can't so I  
have to write another function to do that anyways that really does  
count words or does the compiler have to have additional "magic" to  
figure out that if I write

        dim i as integer = countWords(someHugeBlobOfText)

that only the integer return value is used and discard the array of  
strings ? (And now it's done all that work to create an array of  
strings that is simply discarded)

In at least THIS case multiple return values, or the need for it,  
suggests to me that perhaps you should be returning something that  
better encapsulates the return value

That's not to say I have not found myself needing to return several  
items from a single function and have used byref to do so
If you run into the need to do this on a regular basis you might re- 
examine the "type" being returned and create a class to contain that  
data or use a dictionary or array.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to