Because of so many good comments on my previous post about Multiple Return values (Tuples) I need to write a new post, I think this kind of discussion is relevant to the .Net Community and I’m so glad that so many have spend the time about their thoughts and ideas etc about this topic. People can call me stupid, that I can’t develop apps, or have a bad design if I need multiple values, well it’s my idea of a replacement for out parameters, and also avoid creating some kind of container to hold more values to only support single point of return. My new post will probably make more people upset ;)
So many people that don’t like Multiple Returns (Tuples), I can sort of understand why. But have you ever tried to use it in a real project and also together with Agile? I hated the multiple returns when I first saw it, but after using it in a project, or at least the Framework I used which had several helper methods where they use multiple returns, I started to like it. The main reason I liked it was that I could avoid creating different type of structs, arrays, using hashtables and create objects which only should hold few information and in some cased never been reused. The problem with an Array and Hashtable is that I need of extra documentation, like what value is in index 0 and in index 1 of the returned array (An Array with different type of objects aren’t typed), and what keys do I use to fill the Hashttable etc. A method which will return multiple values need of course some documentation too, but the same with a method that returns a struct or object etc, or use out parameters. If we create objects, structs etc to hold info, to not make the code plotter with different type of structs we need to reuse them. But some methods which should only return x,y can’t use a struct which have x,y and z. Because the developer that uses this method don’t know if the z shouldn’t be used etc. So in this case multiple return values can be useful. Multiple values are often not logically related, so you can't define a sensible class to pack the values into. And if you did define such a class, it might only be used once. I know that some of you don’t agree with me, but hey everyone can’t like everything another people like ;) But I think you are going to like it (or at least some of you), when you use a language which will support it. I have worked with OOP since 1994, and think I know the concept now ;) and how to write code. For 2 years ago I first started to work with LUA, which is a dynamic language which uses the Multiple Returns, and by using it in a real project, I started to like it. The multiple returns can for example be used in functional programming. And remember that C# is a Hybrid. I read an interesting book where two developers uses TDD and eXtream Programming. When the project was done, they didn’t even used OOP at all, it was functional based. There was no need of using OO. Once again there is no Silver Bullet.
Today I notice that other people have blogged about Multiple Returns and came across some articles, you can read their thoughts here:
Take a look at this forum, some C# developers are also talking about Tuples, it seems they have adiscussion if JAVA Should support Tuples or not, don’t know if they have add it, or will not add it. But it was interesting to see that a language like JAVA have it under consideration.
http://forums.java.net/jive/thread.jspa?messageID=16969&tstart=0
This one was good ;):
“Something I have never seen is an argument why a method should only return one value, when nobody argues that a method should only take one parameter. Why should there be a difference?”
http://cairographics.org/manual/bindings-return-values.html
http://onthethought.blogspot.com/2004/12/multiple-return-statements.html
http://www.informatik.uni-kiel.de/~scheme/doc/mzscheme/node7.htm