<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:osnews="http://osnews.com/rss2#">
	<channel>
		<title>OSNews: </title>
		<link>http://www.osnews.com/story/20076/Multiple_Return_Values_in_Java</link>
		<description>Exploring the Future of Computing</description>
		<language>en-us</language>
		<copyright>Copyright 2001-2009, David Adams</copyright>
		<webMaster>adam+nospam@osnews.com</webMaster>
		<lastBuildDate>Mon, 09 Nov 2009 10:20:15 GMT</lastBuildDate>
		<image>
			<url>http://www.osnews.com/images/osnews.gif</url>
			<title>OSNews.com</title>
			<link>http://www.osnews.com</link>
		</image>
		<item>
			<title>tuples</title>
			<link>http://osnews.com/thread?323462</link>
			<guid isPermaLink="true">http://osnews.com/thread?323462</guid>
			<description>This approach is usually generalized into tuples, which are useful in a number of situations. Examples would be:<br />
<br />
for java: <a href="http://javatuple.com/" rel="nofollow">http://javatuple.com/</a><br />
for c++: <a href="http://www.boost.org/doc/libs/1_35_0/libs/tuple/doc/tuple_users_guide.html" rel="nofollow">http://www.boost.org/doc/libs/1_35_0/libs/tuple/doc/tuple_users_gui...</a></description>
			<pubDate>Thu, 17 Jul 2008 17:02:00 GMT</pubDate>
			<author>donotreply@osnews.com (averycfay)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Obvious...</title>
			<link>http://osnews.com/thread?323463</link>
			<guid isPermaLink="true">http://osnews.com/thread?323463</guid>
			<description>Return object array, object, char separated values? How hard could it be?</description>
			<pubDate>Thu, 17 Jul 2008 17:02:00 GMT</pubDate>
			<author>donotreply@osnews.com (Flipper)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323465</link>
			<guid isPermaLink="true">http://osnews.com/thread?323465</guid>
			<description>but couldn't you just return an array of pointers to the multiple data values you want to return?</description>
			<pubDate>Thu, 17 Jul 2008 17:05:00 GMT</pubDate>
			<author>donotreply@osnews.com (FishB8)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323470</link>
			<guid isPermaLink="true">http://osnews.com/thread?323470</guid>
			<description><div class="cquote">but couldn't you just return an array of pointers to the multiple data values you want to return? </div><br />
<br />
1.) Java doesn't have pointers.<br />
2.) There's no type safety in that approach (meaning it's not a good idea for C++ too)</description>
			<pubDate>Thu, 17 Jul 2008 17:13:00 GMT</pubDate>
			<author>donotreply@osnews.com (averycfay)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[2]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323476</link>
			<guid isPermaLink="true">http://osnews.com/thread?323476</guid>
			<description>With C++ you'd just pass multiple values by reference, rather than muck about trying to &quot;return&quot; multiple values.</description>
			<pubDate>Thu, 17 Jul 2008 17:30:00 GMT</pubDate>
			<author>donotreply@osnews.com (Vanders)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[2]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323478</link>
			<guid isPermaLink="true">http://osnews.com/thread?323478</guid>
			<description><div class="cquote">"<i>but couldn't you just return an array of pointers to the multiple data values you want to return? </div><br />
 <br />
 1.) Java doesn't have pointers.<br />
 2.) There's no type safety in that approach (meaning it's not a good idea for C++ too) </i>"<br />
 <br />
 My first thought in C++ would be to have a templated ReturnTriple struct along the lines of:<br />
 <br />
 template<br />
 struct ReturnTriple<br />
 {<br />
     A first;<br />
     B second;<br />
     C third;<br />
 };<br />
 <br />
which is cheap, type-safe and reusable.<br />
<br />
EDIT: Or, as another poster pointed out, just pass parameters by reference. Is this not possible in Java?Edited 2008-07-17 17:37 UTC</description>
			<pubDate>Thu, 17 Jul 2008 17:31:00 GMT</pubDate>
			<author>donotreply@osnews.com (tristan)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Good...I have a comment ready...</title>
			<link>http://osnews.com/thread?323482</link>
			<guid isPermaLink="true">http://osnews.com/thread?323482</guid>
			<description>I've commented on this before ;-)<br />
<a href="http://www.osnews.com/thread?318611" rel="nofollow">http://www.osnews.com/thread?318611</a></description>
			<pubDate>Thu, 17 Jul 2008 17:37:00 GMT</pubDate>
			<author>donotreply@osnews.com (FunkyELF)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE: tuples</title>
			<link>http://osnews.com/thread?323483</link>
			<guid isPermaLink="true">http://osnews.com/thread?323483</guid>
			<description>That java link was nice...thanks.  Once you start using tuples in other languages like Python you want to use them in everything.  I looked at the code hoping it wouldn't be a big mess and it seems pretty clean.  Its not a hard concept.<br />
 <br />
 I didn't see a mention of a license in the download though.  The site does say <div class="cquote">You can compile the source into a jar, or make it part of your project directly. </div> ... so it might be public domain?<br />
<br />
EDIT: Just saw it on the bottom.... Creative Commons Attribution 3.0 United States License.Edited 2008-07-17 17:53 UTC</description>
			<pubDate>Thu, 17 Jul 2008 17:50:00 GMT</pubDate>
			<author>donotreply@osnews.com (FunkyELF)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>not really</title>
			<link>http://osnews.com/thread?323485</link>
			<guid isPermaLink="true">http://osnews.com/thread?323485</guid>
			<description>in Java, if you need multiple return values in your application &quot;most of the time&quot; it is an indication of bad design.</description>
			<pubDate>Thu, 17 Jul 2008 18:17:00 GMT</pubDate>
			<author>donotreply@osnews.com (ahmetaa)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[3]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323487</link>
			<guid isPermaLink="true">http://osnews.com/thread?323487</guid>
			<description><div class="cquote">With C++ you'd just pass multiple values by reference, rather than muck about trying to &quot;return&quot; multiple values. </div><br />
<br />
Then there is no &quot;contract&quot; in the function prototype.  It is nice to know by looking at the arguments what can be changed and what can't be changed.  You wind up looking at the code to see what is really going on, or actually reading the documentation which nobody wants to do.<br />
<br />
Pointers are an ugly hack.  The output variable is an input to the function?</description>
			<pubDate>Thu, 17 Jul 2008 18:26:00 GMT</pubDate>
			<author>donotreply@osnews.com (FunkyELF)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[3]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323488</link>
			<guid isPermaLink="true">http://osnews.com/thread?323488</guid>
			<description>Java doesn't have data structs so it would have to be a class but the same concept works.  <br />
 <br />
 In fact it makes sense... if you're returning multiple values, they have a relationship.  Chances are that that relationship will be studied elsewhere in the code.  For instance other methods will take as input both of those pieces of data.  Or there will be methods that specifically massage that data.  What better place to put them than in this return value class?  So in the end such a class almost always pays off by making code easier to read and more organized.Edited 2008-07-17 18:31 UTC</description>
			<pubDate>Thu, 17 Jul 2008 18:29:00 GMT</pubDate>
			<author>donotreply@osnews.com (saucerful)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[2]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323489</link>
			<guid isPermaLink="true">http://osnews.com/thread?323489</guid>
			<description><div class="cquote">Java doesn't have pointers. </div><br />
Sure java has pointers. You just can't manipulate them.<br />
E.g.:<br />
Object a=new Object(), b=a;<br />
Here a and b are pointers to the same object.</description>
			<pubDate>Thu, 17 Jul 2008 18:29:00 GMT</pubDate>
			<author>donotreply@osnews.com (msundman)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE: Good...I have a comment ready...</title>
			<link>http://osnews.com/thread?323490</link>
			<guid isPermaLink="true">http://osnews.com/thread?323490</guid>
			<description>Reading Your last argument in the linked post - not convinced.<br />
 <br />
 As it is stated in the next thread, returning multiply results from function absolute most of the time means bad design.<br />
 <br />
 Applied to the example you gave.<br />
 You should spend some time and understand what are these tables used for and for how long. If these hashtables are used often I see no reason why shouldn't you use a wrapper. This wrapper may have some of the fetch and common processing logic loaded into to break data and computation apart. If they are short lived - why do you need a separate getter for them anyway?Edited 2008-07-17 18:32 UTC</description>
			<pubDate>Thu, 17 Jul 2008 18:30:00 GMT</pubDate>
			<author>donotreply@osnews.com (v.alexeev)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Poor design = Poor code = Poor blog posts</title>
			<link>http://osnews.com/thread?323491</link>
			<guid isPermaLink="true">http://osnews.com/thread?323491</guid>
			<description>I think it's pretty clear from reading this article that you have very little experience in solid object oriented design. No developer worth his salt would implement a generic &quot;two return value&quot; wrapper like that. If you have a set of related information that gets returned, the proper way to handle it is to design a class that represents that object, and contains methods to analyze its data. <br />
<br />
The solution you suggest is an arbitrary pairing of potentially unrelated data in a too-generic fashion, from which no meaning can be derived - and is therefor a horrible design.<br />
<br />
I may also point out that if you NEED multiple return values (which you don't, you want them, but noone ever needs them), and another languages supports them, then clealy Java was the wrong choice in the first place.</description>
			<pubDate>Thu, 17 Jul 2008 18:33:00 GMT</pubDate>
			<author>donotreply@osnews.com (timneedscoffee80)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[3]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323492</link>
			<guid isPermaLink="true">http://osnews.com/thread?323492</guid>
			<description><div class="cquote">My first thought in C++ would be to have a templated ReturnTriple struct along the lines of:<br />
 <br />
 template<br />
 struct ReturnTriple<br />
 {<br />
     A first;<br />
     B second;<br />
     C third;<br />
 };<br />
 <br />
which is cheap, type-safe and reusable.<br />
 </div><br />
The first poster on here gave a nice link for javatuple which does something very similar.  I just looked and it seems real nice.  it has classes for Single, Pair, Triple etc. up to Decuple.<br />
I'm not sure if your C++ example retains type safety but this javatuple package does.<br />
<br />
<br />
<div class="cquote">EDIT: Or, as another poster pointed out, just pass parameters by reference. Is this not possible in Java?<br />
 </div><br />
<br />
Java has Objects and primitives (because back in the day people were bitching about performance).  Primitives are pass by value, Objects are passed as a reference.  This means that if you pass a Vector to a method, because it is an Object, if you add or remove from that Vector in the method the changes will be visible after the method is called.  However, even though Integer is a class, there are no methods to change the value of one.  So, a method that needs to return two integers could return a List or an Integer[], but things get ugly when you need to return an Integer and a String.</description>
			<pubDate>Thu, 17 Jul 2008 18:43:00 GMT</pubDate>
			<author>donotreply@osnews.com (FunkyELF)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[4]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323494</link>
			<guid isPermaLink="true">http://osnews.com/thread?323494</guid>
			<description>C++ allows you to declare constant references and pointers, just for this purpose.</description>
			<pubDate>Thu, 17 Jul 2008 18:54:00 GMT</pubDate>
			<author>donotreply@osnews.com (ValiSystem)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Comment by wigginz</title>
			<link>http://osnews.com/thread?323496</link>
			<guid isPermaLink="true">http://osnews.com/thread?323496</guid>
			<description>Reading the RSS summary I was just going to say write a class that encapsulates all the data you want to return... problem solved. I Guess that's the solution you were advocating, never mind!</description>
			<pubDate>Thu, 17 Jul 2008 18:56:00 GMT</pubDate>
			<author>donotreply@osnews.com (wigginz)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[2]: Good...I have a comment ready...</title>
			<link>http://osnews.com/thread?323499</link>
			<guid isPermaLink="true">http://osnews.com/thread?323499</guid>
			<description>If you don't see a reason why I should use a wrapper object, then why don't you see a reason for multiple return values?<br />
 It is doing the exact same thing logically.<br />
 <br />
 It isn't often that I need to return multiple things.  Hardly ever.  I just mentioned one case where it made sense.<br />
 <br />
 If I wanted to be &quot;object oriented&quot; using getters I could call one method compute() like so...<br />
 public void compute(){<br />
 Â Â SomeClass a = someExpensiveDBOperation();<br />
 Â Â // h1 and h2 are class members<br />
 Â Â h1 = new HashTable<br />
 Â Â h2 = new HashTable<br />
 Â Â while(a.hasMoreCrap()){<br />
 Â Â Â Â Row r = a.next();<br />
 Â Â Â Â List list = new ArrayList();<br />
 Â Â Â Â list.add(r.getString(1));<br />
 Â Â Â Â list.add(r.getString(2));<br />
 Â Â Â Â list.add(r.getString(3));<br />
 Â Â Â Â list.add(r.getString(4));<br />
 Â Â Â Â h1.put(r.getString(1), list);<br />
 Â Â Â Â h2.put(r.getString(2), list);<br />
 Â Â }<br />
 }<br />
 <br />
 Then, when I want h1 or h2, I'd have to call a method like...<br />
 public HashTable getH1(){<br />
 Â Â HashTable ret = h1;<br />
 Â Â // so we're not hanging onto it forever...<br />
 Â Â h1 = null;<br />
 Â Â return ret;<br />
 }<br />
 <br />
 What an absolute pain in the ass.Edited 2008-07-17 19:06 UTC</description>
			<pubDate>Thu, 17 Jul 2008 19:04:00 GMT</pubDate>
			<author>donotreply@osnews.com (FunkyELF)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[5]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323500</link>
			<guid isPermaLink="true">http://osnews.com/thread?323500</guid>
			<description>Cool... a hack around a hack ;-)</description>
			<pubDate>Thu, 17 Jul 2008 19:05:00 GMT</pubDate>
			<author>donotreply@osnews.com (FunkyELF)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Comment by YEPHENAS</title>
			<link>http://osnews.com/thread?323501</link>
			<guid isPermaLink="true">http://osnews.com/thread?323501</guid>
			<description>Just introduce a new class.<br />
<br />
As you said:<br />
<div class="cquote">Java is object-oriented! If you are afraid of creating single objects then you shouldn't use Java at all. </div><br />
And the next one will come along and demand more horrible things like out parameters, structs and pointers for Java.</description>
			<pubDate>Thu, 17 Jul 2008 19:21:00 GMT</pubDate>
			<author>donotreply@osnews.com (YEPHENAS)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>What's the purpose of a method?</title>
			<link>http://osnews.com/thread?323503</link>
			<guid isPermaLink="true">http://osnews.com/thread?323503</guid>
			<description>I definitely second everybody who suggested that the author needs a better design rather than having the programming language to implement something non-sense.<br />
<br />
If you need multiple return values, that means your method is coding too much logic into it and why don't you code everything in main and if that is the case, you don't need Java or even OO, just go back to any procedural language and even in those you only need main method.<br />
<br />
A method (no matter it's in object or procedural) is a unit that serves a unique purpose.  You code minimum logic into one method and this is why you unit test your method (some suggests you unit test on object, not method).  A method is following a simple processing model:<br />
<br />
Input-&gt;Process-&gt;Output<br />
<br />
If you identify only one output and you will know what you need from input and process.  In this case, if you need more than one return value, I guess you should start again to understand the fundamental of programming.<br />
<br />
No offense but just my 2 cents.<br />
<br />
:)</description>
			<pubDate>Thu, 17 Jul 2008 19:32:00 GMT</pubDate>
			<author>donotreply@osnews.com (andyleung)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE: Poor design = Poor code = Poor blog posts</title>
			<link>http://osnews.com/thread?323504</link>
			<guid isPermaLink="true">http://osnews.com/thread?323504</guid>
			<description><div class="cquote">I think it's pretty clear from reading this article that you have very little experience in solid object oriented design. No developer worth his salt would implement a generic &quot;two return value&quot; wrapper like that. If you have a set of related information that gets returned, the proper way to handle it is to design a class that represents that object, and contains methods to analyze its data. <br />
<br />
The solution you suggest is an arbitrary pairing of potentially unrelated data in a too-generic fashion, from which no meaning can be derived - and is therefor a horrible design. </div><br />
Right. Classes like Point, PairOfShoes, Triangle, ... instead of TwoReturnValues and ThreeReturnValues. And if the values don't relate the method should get refactored.</description>
			<pubDate>Thu, 17 Jul 2008 19:47:00 GMT</pubDate>
			<author>donotreply@osnews.com (YEPHENAS)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Alternatives</title>
			<link>http://osnews.com/thread?323505</link>
			<guid isPermaLink="true">http://osnews.com/thread?323505</guid>
			<description>If I understand, your main idea was to have a function return an object as well as some boolean status of success. Here are my alternatives.<br />
<br />
1. Pass the object you want manipulated, and return a boolean. Example: boolean populateObject(ObjectRef objectToPopulate)<br />
<br />
2. Return an object reference, and test for null. Example: ObjectRef populateObject(). A null return means it failed. This is one reason I rarely use int as a return, but instead use an Integer. Then I can just test for null.<br />
<br />
3. The best approach to do what you want (have a function return both a value and some status flag) is to use exceptions. Example: ObjectRef populateObject() throws ObjectPopulationException. Then your external code would use a try/catch to call this function. This is the norm with languages that supports exception handling.<br />
<br />
Just my 1/50th of a falling dollar.</description>
			<pubDate>Thu, 17 Jul 2008 19:47:00 GMT</pubDate>
			<author>donotreply@osnews.com (fretinator)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Be clear to the caller</title>
			<link>http://osnews.com/thread?323506</link>
			<guid isPermaLink="true">http://osnews.com/thread?323506</guid>
			<description>From the article:<br />
<br />
Having a solution alone is sometimes not enough and you also need to add some parameters which measure the quality of the computed outcome. Most of these accompanying parameters can or have to be computed within the algorithm itself, but Java allows you to return only one value either an object or a primitive type. [...] But as a Java programmer you are pretty much stuck here and need to consider some other means to come out of this situation.<br />
<br />
Actually, you are mistaking a inherent property of Java and other static-typing languages as a disadvantage. If used properly, it is an advantage: the person implementing the caller code can exactly see by looking up the function or method declaration what to expect. This is a potential downside of dynamic languages, that can usually return anything, as long as it is (usually) a reference to something.<br />
<br />
With the proposed solution, there's a risk of returning something that is potentially meaningless to the caller. Therefore, in such situations it's normally best to either: use more getters (where appropriate), or if the data in strongly coupled (which appears to be the case in the example mentioned in the article) return it as a class with its own getters.<br />
<br />
Sure, there are situations where tuple-like classes can be useful. A good example is std::pair in C++, which is used for data stored within a map. The first element of the pair is used as the key, the second element as the value. Most if not all (since std::map provides ordering guarantees) implementations of std::map store these pairs in a binary tree that is ordered by the key. It's also convenient for iteration.<br />
<br />
But for what my opinion is worth, this article makes a design error, it's the kind of approach you'll want to avoid in a static-typing OO language.</description>
			<pubDate>Thu, 17 Jul 2008 19:54:00 GMT</pubDate>
			<author>donotreply@osnews.com (danieldk)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[3]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323508</link>
			<guid isPermaLink="true">http://osnews.com/thread?323508</guid>
			<description><div class="cquote">"<i>Java doesn't have pointers. </div><br />
Sure java has pointers. You just can't manipulate them.<br />
E.g.:<br />
Object a=new Object(), b=a;<br />
Here a and b are pointers to the same object. </i>"<br />
<br />
To a C++ programmer, <b>a</b> and <b>b</b> look a lot more like references than pointers...</description>
			<pubDate>Thu, 17 Jul 2008 19:58:00 GMT</pubDate>
			<author>donotreply@osnews.com (tristan)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[2]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323509</link>
			<guid isPermaLink="true">http://osnews.com/thread?323509</guid>
			<description><div class="cquote">1.) Java doesn't have pointers. </div><br />
Java works with references and a reference is a typed pointer. So if you use Object you kind of are using pointers...<br />
<div class="cquote">2.) There's no type safety in that approach (meaning it's not a good idea for C++ too) </div><br />
Exactly: that's why Java made them type-safe.</description>
			<pubDate>Thu, 17 Jul 2008 20:03:00 GMT</pubDate>
			<author>donotreply@osnews.com (IvoLimmen)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[3]: Good...I have a comment ready...</title>
			<link>http://osnews.com/thread?323510</link>
			<guid isPermaLink="true">http://osnews.com/thread?323510</guid>
			<description>I don't see your problem, then again I don't know what you are trying to achieve in your program. <br />
I never had the urge to use a multi-value return and I also came from a C++ environment, I never used it because good OO design never needed it.<br />
Sorry to point this out but the fact that you nullify the class field 'h1' before returning the (reference) copy, tells me that you either do not fully understood how Java works or you need some serious OO design classes.</description>
			<pubDate>Thu, 17 Jul 2008 20:10:00 GMT</pubDate>
			<author>donotreply@osnews.com (IvoLimmen)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE: Alternatives</title>
			<link>http://osnews.com/thread?323511</link>
			<guid isPermaLink="true">http://osnews.com/thread?323511</guid>
			<description><div class="cquote">1. Pass the object you want manipulated, and return a boolean. Example: boolean populateObject(ObjectRef objectToPopulate) </div><br />
 <br />
 I usually try to avoid this, since Java does not codify your intention in the method signature. The obvious danger is that if it happens more than once in a library that you will confuse the library user. If it happens only a few times, you will suprise the user. It's a solution, but be careful!<br />
 <br />
 Actually, I am happy C++ allows pass by value (where a value can also be a pointer), and pass by reference. If you really want to modify variables or instances provided through a parameter list, you can make this more explicit by using a pointer (without constness).<br />
 <br />
 <div class="cquote">2. Return an object reference, and test for null. Example: ObjectRef populateObject(). A null return means it failed. This is one reason I rarely use int as a return, but instead use an Integer. Then I can just test for null. </div><br />
 <br />
 That's usually not a good idea for math-intensive code due to all the boxing/unboxing that takes place. At other places this can be a good solution, if documented.<br />
 <br />
 If the return type is a floating point type, and the parameters cause an invalid result, returning NaN is an option.<br />
 <br />
 <div class="cquote">3. The best approach to do what you want (have a function return both a value and some status flag) is to use exceptions. Example: ObjectRef populateObject() throws ObjectPopulationException. Then your external code would use a try/catch to call this function. This is the norm with languages that supports exception handling. </div><br />
 <br />
 Be careful there as well. Exceptions are for when... something exceptional happens. The danger is misusing exceptions as a mechanism to return values. Of course, Java does provide some good exceptions for common exceptional occasions. For those cases, prefer one of the exceptions that Java defines.Edited 2008-07-17 20:21 UTC</description>
			<pubDate>Thu, 17 Jul 2008 20:13:00 GMT</pubDate>
			<author>donotreply@osnews.com (danieldk)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[4]: Good...I have a comment ready...</title>
			<link>http://osnews.com/thread?323514</link>
			<guid isPermaLink="true">http://osnews.com/thread?323514</guid>
			<description><div class="cquote">Sorry to point this out but the fact that you nullify the class field 'h1' before returning the (reference) copy, tells me that you either do not fully understood how Java works or you need some serious OO design classes. </div><br />
 <br />
 People should also stop using returning implementation types rather than interfaces <img src="/images/emo/wink.gif" alt=";)" />  (in this case HashTable).Edited 2008-07-17 20:20 UTC</description>
			<pubDate>Thu, 17 Jul 2008 20:19:00 GMT</pubDate>
			<author>donotreply@osnews.com (danieldk)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE: not really</title>
			<link>http://osnews.com/thread?323515</link>
			<guid isPermaLink="true">http://osnews.com/thread?323515</guid>
			<description>Yeah...<br />
<br />
I do .Net in C# for my job which also doesn't allow multiple returns and I have never wished that I could return multiple values.  I just make a struct.<br />
<br />
I suppose I could also use output parameters (not sure if that is in Java), but they always seemed ugly to me.</description>
			<pubDate>Thu, 17 Jul 2008 20:22:00 GMT</pubDate>
			<author>donotreply@osnews.com (eggs)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[4]: Good...I have a comment ready...</title>
			<link>http://osnews.com/thread?323519</link>
			<guid isPermaLink="true">http://osnews.com/thread?323519</guid>
			<description><div class="cquote">I don't see your problem, then again I don't know what you are trying to achieve in your program. <br />
I never had the urge to use a multi-value return and I also came from a C++ environment, I never used it because good OO design never needed it.<br />
Sorry to point this out but the fact that you nullify the class field 'h1' before returning the (reference) copy, tells me that you either do not fully understood how Java works or you need some serious OO design classes. </div><br />
<br />
It is client server.  The client needs the HashTables two different ways.  Nullifying it on the server and returning it to the client makes it a candidate for garbage collection on the server where I didn't want it hanging around.<br />
<br />
All I'm saying is that there are places where multiple return values would be nice.  It is basically returning a tuple but without creating meaningless wrapper classes.</description>
			<pubDate>Thu, 17 Jul 2008 20:57:00 GMT</pubDate>
			<author>donotreply@osnews.com (FunkyELF)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[2]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323520</link>
			<guid isPermaLink="true">http://osnews.com/thread?323520</guid>
			<description><div class="cquote">1.) Java doesn't have pointers. </div><br />
<br />
Where do you get that assert from???<br />
<br />
Everything in Java but the primitive data types are referred via pointers (ok, let's call them &quot;references&quot;, but in Java they are the same).<br />
<br />
When you declare <br />
<br />
MyObject obj = new MyObject();<br />
<br />
you are creating an instance of class MyObject and you are assigning a pointer to that instance.<br />
<br />
The only difference here is that you cannot do pointer arithmetic (as in C).</description>
			<pubDate>Thu, 17 Jul 2008 20:57:00 GMT</pubDate>
			<author>donotreply@osnews.com (ebasconp)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[5]: Good...I have a comment ready...</title>
			<link>http://osnews.com/thread?323521</link>
			<guid isPermaLink="true">http://osnews.com/thread?323521</guid>
			<description><div class="cquote">People should also stop using returning implementation types rather than interfaces <img src="/images/emo/wink.gif" alt=";)" />  (in this case HashTable). </div><br />
<br />
I know it should have returned Map.  I just wrote that quick and dirty...there are probably syntax errors too.</description>
			<pubDate>Thu, 17 Jul 2008 21:01:00 GMT</pubDate>
			<author>donotreply@osnews.com (FunkyELF)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[4]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323522</link>
			<guid isPermaLink="true">http://osnews.com/thread?323522</guid>
			<description><div class="cquote">"<i>[q]Java doesn't have pointers. </div><br />
Sure java has pointers. You just can't manipulate them.<br />
E.g.:<br />
Object a=new Object(), b=a;<br />
Here a and b are pointers to the same object. </i>"<br />
<br />
To a C++ programmer, <b>a</b> and <b>b</b> look a lot more like references than pointers... [/q]<br />
<br />
<br />
No, they are not references, they are pointers. The code above is identical to:<br />
<br />
Object* a = new Object(), *b = a;<br />
<br />
a and b are pointers to the same object.<br />
<br />
References in C++ are stuff defined as:<br />
<br />
const Object&amp; a = Object::GetSingleton();<br />
<br />
a is a const reference to an instance of a class.</description>
			<pubDate>Thu, 17 Jul 2008 21:01:00 GMT</pubDate>
			<author>donotreply@osnews.com (ebasconp)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Er... weak</title>
			<link>http://osnews.com/thread?323524</link>
			<guid isPermaLink="true">http://osnews.com/thread?323524</guid>
			<description>Very weak argument.<br />
<br />
You want multiple return values?  Use an array, then you have as many return values as you like, no objects required.<br />
<br />
Making Java as dynamic as JavaScript would be a mistake and it's this kind of dynamic feature creep that could lead to that.</description>
			<pubDate>Thu, 17 Jul 2008 21:11:00 GMT</pubDate>
			<author>donotreply@osnews.com (FreeGamer)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Think about you software design!</title>
			<link>http://osnews.com/thread?323529</link>
			<guid isPermaLink="true">http://osnews.com/thread?323529</guid>
			<description>If you are in the need of returning more than one value by a method, you should probably think about your software design!</description>
			<pubDate>Thu, 17 Jul 2008 22:11:00 GMT</pubDate>
			<author>donotreply@osnews.com (Ralf.)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[2]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323530</link>
			<guid isPermaLink="true">http://osnews.com/thread?323530</guid>
			<description><div class="cquote">1.) Java doesn't have pointers. </div><br />
<br />
If Java does not have pointers, why is there a &quot;NullpointerException&quot;? ;-)</description>
			<pubDate>Thu, 17 Jul 2008 22:14:00 GMT</pubDate>
			<author>donotreply@osnews.com (Ralf.)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>easiest solution... Map</title>
			<link>http://osnews.com/thread?323538</link>
			<guid isPermaLink="true">http://osnews.com/thread?323538</guid>
			<description>Man, do I hate complications.<br />
<br />
If you really must have multiple return values, just use a map and return it.  Better than that, you can have named values:<br />
<br />
Map Foo()<br />
{<br />
    Map ret = new Map;<br />
    Map[&quot;return1&quot;] = X;<br />
    Map[&quot;return2&quot;] = Y;<br />
    Map[&quot;return3&quot;] = Z;<br />
<br />
    return ret;<br />
}<br />
<br />
<br />
There you go.  Problem solved.  BTW... I haven't used java in a while, so that may not be syntactically correct, but the point is the same <img src="/images/emo/smile.gif" alt=";)" /> <br />
<br />
If you think this is too slow due to the lookup, you can be annoying and use a Vector instead <img src="/images/emo/smile.gif" alt=";)" /> .<br />
<br />
So... why add more crap to a language?</description>
			<pubDate>Thu, 17 Jul 2008 23:10:00 GMT</pubDate>
			<author>donotreply@osnews.com (Yamin)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[6]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323539</link>
			<guid isPermaLink="true">http://osnews.com/thread?323539</guid>
			<description>Er, not really. const is a standard feature in C++ for declaring, well, constants. Same as it is in C, and it's been that way forever. It's hardly a hack: certainly no more than inventing silly ways to return multiple values from a function.<br />
<br />
Also, who said anything about pointers here? C++ supports proper bona fide pass by reference.</description>
			<pubDate>Thu, 17 Jul 2008 23:11:00 GMT</pubDate>
			<author>donotreply@osnews.com (Vanders)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Common Lisp Usage</title>
			<link>http://osnews.com/thread?323542</link>
			<guid isPermaLink="true">http://osnews.com/thread?323542</guid>
			<description>I think what the poster needs is really what's in  Common-Lisp (I don't know whether something similar exists in other languages too).<br />
<br />
Let's take as an example the standard floor mathematical function, that would return the integer portion (and in Common Lisp it might return additionally the remainder portion).<br />
<br />
Normally people are only interested in getting the integer part, so all they are doing is this:<br />
<br />
(setf some-var (floor some-other-var))<br />
<br />
In &quot;C&quot; this would be:<br />
<br />
some_var = floor( some_other_var );<br />
<br />
The user is not even aware that floor can actually return two values, because it's still used as if it was returning one (in such cases the CL compiler might be smart enough and optimize it).<br />
<br />
Now if you want 2 values to be returned - the integer part of floor, and the rational (floating in other languages) remainder, here's what you'll have to do:<br />
<br />
;; Let's put in some-other-var the rational 3/2<br />
(setf some-other-var 3/2)<br />
<br />
;; Now get the two values<br />
(multiple-value-bind (a b)<br />
                (floor some-other-var)<br />
              (format t &quot;A=~a B=~a&quot; a b))<br />
<br />
---&gt; A=1 B=1/2<br />
<br />
The long-ish MVB multiple-value-bind form is going to assign local variable 'a' to 1 and 'b' to 1/2, format is printing them.<br />
<br />
Documentation: <a href="http://www.lisp.org/HyperSpec/Body/mac_multiple-value-bind.html#multiple-value-bind" rel="nofollow">http://www.lisp.org/HyperSpec/Body/mac_multiple-value-bind.html#mul...</a> <br />
<br />
In Common-Lisp there are 4 or 5 such operators specifically for getting multiple return values - some can accumulate the results directly in local variables, others in lists, etc.</description>
			<pubDate>Thu, 17 Jul 2008 23:53:00 GMT</pubDate>
			<author>donotreply@osnews.com (malkia)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[3]: Good...I have a comment ready...</title>
			<link>http://osnews.com/thread?323555</link>
			<guid isPermaLink="true">http://osnews.com/thread?323555</guid>
			<description><div class="cquote">If you don't see a reason why I should use a wrapper object, then why don't you see a reason for multiple return values?<br />
 It is doing the exact same thing logically. </div><br />
No and no. First - no sequence of variables covered in obscure &quot;tuple&quot;. This defy the very basic ideas of OO programming like encapsulation.  Second - I've suggested not a wrapper object but rather an entity on it's own aware of how to fetch the data, how is it encoded, how it needs to be pre-processed etc. This will allow you to decouple supplier from consumer.<br />
<br />
 <div class="cquote">It isn't often that I need to return multiple things.  Hardly ever.  I just mentioned one case where it made sense. </div><br />
<div class="cquote">If I wanted to be &quot;object oriented&quot; using getters I could call one method compute() like so... </div><br />
And the case may point out to a deeper design problem.<br />
I suggest you look once again at each and every case you think you must use more then one return value and try to avoid this at all cost.</description>
			<pubDate>Fri, 18 Jul 2008 04:08:00 GMT</pubDate>
			<author>donotreply@osnews.com (v.alexeev)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[5]: Good...I have a comment ready...</title>
			<link>http://osnews.com/thread?323560</link>
			<guid isPermaLink="true">http://osnews.com/thread?323560</guid>
			<description><div class="cquote">People should also stop using returning implementation types rather than interfaces <img src="/images/emo/wink.gif" alt=";)" />  (in this case HashTable). </div><br />
You are sooooo right!</description>
			<pubDate>Fri, 18 Jul 2008 05:03:00 GMT</pubDate>
			<author>donotreply@osnews.com (IvoLimmen)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[5]: Good...I have a comment ready...</title>
			<link>http://osnews.com/thread?323561</link>
			<guid isPermaLink="true">http://osnews.com/thread?323561</guid>
			<description><div class="cquote"><br />
It is client server.  The client needs the HashTables two different ways.  Nullifying it on the server and returning it to the client makes it a candidate for garbage collection on the server where I didn't want it hanging around.<br />
All I'm saying is that there are places where multiple return values would be nice.  It is basically returning a tuple but without creating meaningless wrapper classes. </div><br />
This this does not explain this piece of code. When there are no references to a object then the garbage collector will reap it. Nullifying an object only helps if you have the only reference to an object but you just passed a copy as return value, hence: there is still a reference.<br />
As for the fact that it is a client-server application, when the protocol you use is done sending the stuff over, the protocol will release it's reference and it will most likely kick in the garbage collector. Still: an experienced Java programmer would never write code like this. And: an experienced Java programmer would never NEED multiple return values.</description>
			<pubDate>Fri, 18 Jul 2008 05:16:00 GMT</pubDate>
			<author>donotreply@osnews.com (IvoLimmen)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Comment by asgard</title>
			<link>http://osnews.com/thread?323563</link>
			<guid isPermaLink="true">http://osnews.com/thread?323563</guid>
			<description>I am getting depressed from this discussion. All this &quot;if you want to return multiple values, your design is wrong&quot; nonsense. It's useful! Try it in Python, at least once. <br />
<br />
The reason why Java (and C and it's predecessors) didn't support it is historical and comes from mathematics. In mathematics, functions that return multiple objects are useless, because you can just have multiple functions. <br />
<br />
However, in programming, you often need to compute something and you get some other useful result as a side-effect of that computation. Classic example is the quotient/remainder example in the integer division. To split it into two functions, you would have to do the division twice, which would be silly. Sure, you can also wrap them into an object or struct or whatever, but compare this to Python, where you just &quot;return them&quot; and it's completely natural.<br />
<br />
So please, stop saying that just because your language of choice doesn't support it, it's not useful. Because it is.</description>
			<pubDate>Fri, 18 Jul 2008 06:55:00 GMT</pubDate>
			<author>donotreply@osnews.com (asgard)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Multiple Return Types??</title>
			<link>http://osnews.com/thread?323565</link>
			<guid isPermaLink="true">http://osnews.com/thread?323565</guid>
			<description>Hi!<br />
<br />
I'm in Java programming for 9 years now, but never really seen a problem with multiple return types.<br />
Normally I would prefer the data object style to return multiple values, because the data returned from one method is often related. So the object groups the data and dealing with the related informations is much easier. Changing the information is much easier, too. Think about: <br />
Position calculatePosition(), goTo(Position pos), runFrom(Position pos)...<br />
instead of:<br />
int[] calculationPosition(), goTo(int x, int y, int z), runFrom(int x, int y, int z)...<br />
<br />
If the data one method returns is not related, you should double-check your code, because it smells (see &quot;code smells&quot;).<br />
<br />
/Nyarla</description>
			<pubDate>Fri, 18 Jul 2008 07:24:00 GMT</pubDate>
			<author>donotreply@osnews.com (nyarlathotep)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE: Comment by asgard</title>
			<link>http://osnews.com/thread?323567</link>
			<guid isPermaLink="true">http://osnews.com/thread?323567</guid>
			<description><div class="cquote">Classic example is the quotient/remainder example in the integer division. To split it into two functions, you would have to do the division twice, which would be silly. Sure, you can also wrap them into an object or struct or whatever, but compare this to Python, where you just &quot;return them&quot; and it's completely natural. </div><br />
<br />
I don't see any problems in creating an object for that. Even if you think it will overhead, when you pass it as an arguments to another method, you'll find the object very usefull, because you only have manage one variable per result. Additionally I like the idea of not changing method signatures (and thus breaking backward compatibility), just because I need another argument.</description>
			<pubDate>Fri, 18 Jul 2008 07:44:00 GMT</pubDate>
			<author>donotreply@osnews.com (nyarlathotep)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[2]: Comment by asgard</title>
			<link>http://osnews.com/thread?323570</link>
			<guid isPermaLink="true">http://osnews.com/thread?323570</guid>
			<description><div class="cquote">I don't see any problems in creating an object for that.  </div><br />
<br />
Well, Python also creates an object (a tuple), so you can actually retrieve and manipulate the return values together. So this is a solved problem.<br />
<br />
Anyway, my point is it's not always quite useful to define an object. In some cases yes, for example, if you have a point in 3D, then you probably want to have it as an object.<br />
<br />
But in some cases, it is pointless to have an object &quot;result of integer division&quot;. So why even bother? <br />
<br />
Imagine a language where you can only have functions with one argument. Sounds silly? But it is exactly what you are defending. You could also say, well, you can always construct an object from the arguments, and it will be helpful in many cases. You could also say that it would be good because the function signature would never change. <br />
<br />
In fact, I don't see any reason why it couldn't be completely symmetric. Thus, why cannot we have multiple return values, default return values, keyword return values and unlimited number of return values. The only reason I see is historic - we are used to notation that doesn't allow all of this stuff.</description>
			<pubDate>Fri, 18 Jul 2008 08:07:00 GMT</pubDate>
			<author>donotreply@osnews.com (asgard)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>I guess you never tried Python</title>
			<link>http://osnews.com/thread?323573</link>
			<guid isPermaLink="true">http://osnews.com/thread?323573</guid>
			<description>All those who claim that it's &quot;useless&quot; have never tried Python. If Java would borrow Python's multiple return types, it would look like this:<br />
<br />
<br />
public (String, int) findName(List names)<br />
{<br />
    String name;<br />
    int number;<br />
<br />
    // do some searching inside the list...<br />
    // ...<br />
<br />
    // finally return the name and the amount of<br />
    // data that has been searched through (just an example)<br />
<br />
    return (name, number);<br />
}<br />
<br />
<br />
String name, int number = getName(someList);<br />
<br />
System.out.println(&quot;Found: &quot; + name);<br />
System.out.println(&quot;I had to search through &quot; + number + &quot; items&quot;);<br />
<br />
<br />
Now tell me that ain't useful? Of course it's not something you need everyday (and it might really be bad design in many cases), but there are cases where you want to return two things that are not so closely connected to each other that they really belong into the same class.<br />
<br />
I have used it in Python before and it's very useful. I wish Java had this.</description>
			<pubDate>Fri, 18 Jul 2008 09:31:00 GMT</pubDate>
			<author>donotreply@osnews.com (Glynser)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Holy crap</title>
			<link>http://osnews.com/thread?323581</link>
			<guid isPermaLink="true">http://osnews.com/thread?323581</guid>
			<description>People should really spend more time with the fundamental parts of computing.<br />
<br />
For instance - there is a HUGE cluebyfour in understanding the fundamental parts of LISP (S-expressions).<br />
<br />
If someone, for an instance of a second, thought that this was a real problem with Java they should take a break and google up some fundamental LISP-knowledge and be a lot wiser.<br />
As an added benefit you'll understand why those LISP/Scheme nutters (they are, really) are correct when they say that their language is beautiful.</description>
			<pubDate>Fri, 18 Jul 2008 10:40:00 GMT</pubDate>
			<author>donotreply@osnews.com (pel!)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Nice discussion :)</title>
			<link>http://osnews.com/thread?323585</link>
			<guid isPermaLink="true">http://osnews.com/thread?323585</guid>
			<description>Maybe I better clearify some parts.. Some claiming it is bad design. Could be, but design is always nice in theory but hard in practice. The intention of this article was for cases when multiple values are needed. I agree when implementing some UI, stuff like this is a bloat. But when using (misue) a language like Java for say number crunching algorithms the algorithms are itself messy and hard to read. There is no good design just from the beginning. Asgard gave a example. Do stuff like linear integer programming, data mining and you want multiple return values. One could argue: Why then Java? - use Matlab or Lisp. Yeah sure, I would like to. But sometimes the decisions are not yours to make and you have to reuse stuff your colleagues worked with.</description>
			<pubDate>Fri, 18 Jul 2008 11:20:00 GMT</pubDate>
			<author>donotreply@osnews.com (raupach)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>Right tool, right job</title>
			<link>http://osnews.com/thread?323586</link>
			<guid isPermaLink="true">http://osnews.com/thread?323586</guid>
			<description>Multiple return values are fantastic, but Java as a language doesn't really need them. It's built in a way that demands their absence.<br />
<br />
I'm primarily a Perl hacker but I've done some lisp, too. It's not really about returning two things from a function, it's about the way your code is structured.<br />
<br />
In Java of course you'd just wrap things in an object. Preferably your code would not suck and the things would be related.</description>
			<pubDate>Fri, 18 Jul 2008 11:21:00 GMT</pubDate>
			<author>donotreply@osnews.com (sorpigal)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE: I guess you never tried Python</title>
			<link>http://osnews.com/thread?323606</link>
			<guid isPermaLink="true">http://osnews.com/thread?323606</guid>
			<description><div class="cquote">All those who claim that it's &quot;useless&quot; have never tried Python. </div><br />
   <br />
   Oh, please. <img src="/images/emo/wink.gif" alt=";)" /> <br />
   <br />
   <div class="cquote">Now tell me that ain't useful? Of course it's not something you need everyday (and it might really be bad design in many cases), but there are cases where you want to return two things that are not so closely connected to each other that they really belong into the same class. </div><br />
   <br />
   Sure you can do the same thing. Return an immutable list of 'Object's. Because that's what Python actually does (it returns a tuple). That's different than allowing for multiple return types (viewed from a static language).<br />
 <br />
 People don't do this, because it sacrifices type safety. Of course, you will have to cast it back to some class type to make its methods visible again. (And you can't apply some of the syntactic cleverness that some dynamic languages offer in the calling code.)<br />
   <br />
   If you don't want to do that, you are picking the wrong language. Java is a statically typed language, Python is dynamically typed. If you want a dynamic language for a particular job, use a dynamic language. Don't expect a static language to act as a dynamic or vise versa.Edited 2008-07-18 14:20 UTC</description>
			<pubDate>Fri, 18 Jul 2008 14:16:00 GMT</pubDate>
			<author>donotreply@osnews.com (danieldk)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>C#</title>
			<link>http://osnews.com/thread?323610</link>
			<guid isPermaLink="true">http://osnews.com/thread?323610</guid>
			<description>In C#.NET you could doâ¦<br />
<br />
SomeObject one = new SomeObject();<br />
SomeObject two = new SomeObject();<br />
<br />
private void ReturnTwo( out SomeObject objone, out SomeObject objtwo )<br />
{<br />
     objone = whatever;<br />
     objtwo = whatevertwo;<br />
}<br />
<br />
(It's been a while since i used c# thoâ¦ but there was out and ref, out needed the parameter pre-initialized and ref allows you to initialize it inside the meethod)<br />
<br />
Or something like that.</description>
			<pubDate>Fri, 18 Jul 2008 14:28:00 GMT</pubDate>
			<author>donotreply@osnews.com (Gryzor)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE: C#</title>
			<link>http://osnews.com/thread?323611</link>
			<guid isPermaLink="true">http://osnews.com/thread?323611</guid>
			<description>I think it is about time OSNews supports Unicode properly.</description>
			<pubDate>Fri, 18 Jul 2008 14:29:00 GMT</pubDate>
			<author>donotreply@osnews.com (Gryzor)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[7]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323613</link>
			<guid isPermaLink="true">http://osnews.com/thread?323613</guid>
			<description><div class="cquote">Er, not really. const is a standard feature in C++ for declaring, well, constants. </div><br />
Except that const are not always constants in C++.<br />
<br />
<br />
<div class="cquote">It's hardly a hack: certainly no more than inventing silly ways to return multiple values from a function. </div><br />
I find much more readable to have the input variable on one part of the function and the output variables on another part, of course readability isn't C++ strong point.</description>
			<pubDate>Fri, 18 Jul 2008 14:58:00 GMT</pubDate>
			<author>donotreply@osnews.com (renox)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[3]: Comment by asgard</title>
			<link>http://osnews.com/thread?323614</link>
			<guid isPermaLink="true">http://osnews.com/thread?323614</guid>
			<description><div class="cquote">Imagine a language where you can only have functions with one argument. Sounds silly? </div><br />
At first glance, yes. But let's think this some further: Normally you just put &quot;something&quot; and &quot;something&quot; into a method and getting a &quot;something&quot; and maybe another &quot;something&quot; back. Like this:<br />
<br />
(c,d) = divide(a,b);<br />
<br />
If you find this call in a sourcecode: How do you know, what's the divisor, remainder, etc.? You have to look at the documentation and interpret the call.<br />
Now imagine this example in a one-parameter-,one-return-value-language:<br />
<br />
DivideParameter params = new DivideParameter();<br />
params.dividend = a;<br />
params.divisor = b;<br />
DivideResult result = divide(params);<br />
c = result.quotient;<br />
d = result.remainder;<br />
<br />
Ok, it's much more to code, but it's much easier to understand, without looking at the documentation.<br />
A good solution in the middle of this, would be named parameters/return values, so you can easily see what's going in and out.<br />
If you just want multiple &quot;somethings&quot; as return values, define the return value as Object[].</description>
			<pubDate>Fri, 18 Jul 2008 15:02:00 GMT</pubDate>
			<author>donotreply@osnews.com (nyarlathotep)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[4]: Comment by asgard</title>
			<link>http://osnews.com/thread?323616</link>
			<guid isPermaLink="true">http://osnews.com/thread?323616</guid>
			<description>So, you basically agree with me that the situation with input and output values is symmetric.<br />
<br />
However, I don't agree that the second example you give is more readable. In a large program, every line and every technicality obscures the high-level structure. To show you the types of parameters of function you are looking at is a job for IDE or some source code browsing tool, and it should not be needed to write it up again and again endlessly in the source itself.</description>
			<pubDate>Fri, 18 Jul 2008 15:38:00 GMT</pubDate>
			<author>donotreply@osnews.com (asgard)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[8]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323617</link>
			<guid isPermaLink="true">http://osnews.com/thread?323617</guid>
			<description><div class="cquote">"<i>Er, not really. const is a standard feature in C++ for declaring, well, constants. </div><br />
Except that const are not always constants in C++.<br />
 </i>"<br />
<br />
Agree, &quot;const-ness&quot; defines a set of properties and behaviors over our methods and variables.<br />
<br />
Let's say:<br />
<br />
const Attribute&amp; GetAttribute() const;<br />
<br />
A method marked with &quot;const&quot; says: &quot;I will not modify the object state, I will only provide information&quot;; this feature prevents a lot of errors and undesired access because it is hardly viral (for this example, you cannot invoke to a &quot;non-const&quot; method defined in Attribute).<br />
<br />
The &quot;const Attribute&amp; &quot; returns a reference to an attribute defined inside our object (a really nice approach to avoid object copy or memory management &quot;ambiguity&quot;) If I get a const Attribute&amp; I'm getting a working state and I have not to worry about its memory handling.<br />
<br />
&quot;const-ness&quot; should be implemented in other C-like (I knew D implements it partially) languages because provides nice behavior and improves the code readibility too.</description>
			<pubDate>Fri, 18 Jul 2008 15:40:00 GMT</pubDate>
			<author>donotreply@osnews.com (ebasconp)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[9]: Never programmed in Java before...</title>
			<link>http://osnews.com/thread?323625</link>
			<guid isPermaLink="true">http://osnews.com/thread?323625</guid>
			<description><div class="cquote">Agree, &quot;const-ness&quot; defines a set of properties and behaviors over our methods and variables. </div><br />
Bleah, I don't like C++'s overloading of keywords for type and method signature..<br />
<br />
<div class="cquote">If I get a const Attribute&amp;amp; I'm getting a working state and I have not to worry about its memory handling. </div><br />
Not always: if there's another reference with read-write access to the same object, it can be modified or the const may be casted away.<br />
<br />
<div class="cquote">I knew D implements it partially </div><br />
Yup, but it caused many, many discussions: head vs tail const, const vs invariant.. Const is a concept really hard to design properly.<br />
<br />
And the solution retained is ineleguant as for C++ compatibility's sake, the name const is retained for read-only views (which may not be really constant!), and true constants are named 'invariant'.<br />
IMHO 'const' should be replaced by 'view' as in &quot;view but don't touch (others may do it though)&quot;<br />
and true constant named const.</description>
			<pubDate>Fri, 18 Jul 2008 19:45:00 GMT</pubDate>
			<author>donotreply@osnews.com (renox)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>How about a Pointer object</title>
			<link>http://osnews.com/thread?323647</link>
			<guid isPermaLink="true">http://osnews.com/thread?323647</guid>
			<description>How about simulating a C pointer with an object?  Then you can do it just like the C people do it.<br />
<br />
public class Pointer&amp;lt;T&gt; {<br />
 public Pointer(T val) {<br />
  value=val;<br />
 }<br />
 public T value;<br />
}<br />
<br />
<br />
Pointer&amp;lt;Type1&gt; a;<br />
Pointer&amp;lt;Type2&gt; b;		<br />
myfun(a, b);<br />
<br />
public void myfun(Pointer&amp;lt;Type1&gt; a, Pointer&amp;lt;Type2&gt; b) {<br />
		a = null;<br />
		b = new Pointer&amp;lt;Type2&gt;(new Type2()));<br />
		<br />
}</description>
			<pubDate>Sat, 19 Jul 2008 00:33:00 GMT</pubDate>
			<author>donotreply@osnews.com (Tron)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE: How about a Pointer object</title>
			<link>http://osnews.com/thread?323654</link>
			<guid isPermaLink="true">http://osnews.com/thread?323654</guid>
			<description>Sorry for replying to myself, but the preview doesn't seem to work quite right with angle brackets.  <br />
Let's try this again:<br />
<br />
public class Pointer { <br />
public Pointer(T val) { <br />
value=val; <br />
} <br />
public T value; <br />
} <br />
<br />
<br />
Pointer a; <br />
Pointer b; <br />
myfun(a, b); <br />
<br />
public void myfun(Pointer a, Pointer b) { <br />
a = null; <br />
b = new Pointer(new Type2())); <br />
<br />
}</description>
			<pubDate>Sat, 19 Jul 2008 04:46:00 GMT</pubDate>
			<author>donotreply@osnews.com (Tron)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE: I guess you never tried Python</title>
			<link>http://osnews.com/thread?323683</link>
			<guid isPermaLink="true">http://osnews.com/thread?323683</guid>
			<description><div class="cquote">All those who claim that it's &quot;useless&quot; have never tried Python. If Java would borrow Python's multiple return types, it would look like this:<br />
<br />
<br />
public (String, int) findName(List names)<br />
{<br />
    String name;<br />
    int number;<br />
<br />
    // do some searching inside the list...<br />
    // ...<br />
<br />
    // finally return the name and the amount of<br />
    // data that has been searched through (just an example)<br />
<br />
    return (name, number);<br />
}<br />
<br />
<br />
String name, int number = getName(someList);<br />
<br />
System.out.println(&quot;Found: &quot; + name);<br />
System.out.println(&quot;I had to search through &quot; + number + &quot; items&quot;);<br />
<br />
<br />
Now tell me that ain't useful? Of course it's not something you need everyday (and it might really be bad design in many cases), but there are cases where you want to return two things that are not so closely connected to each other that they really belong into the same class.<br />
<br />
I have used it in Python before and it's very useful. I wish Java had this. </div><br />
<br />
First of all, I would like to give you a very basic exam on how to call a method:<br />
<br />
<div class="cquote">String name, int number = getName(someList); </div><br />
<br />
Where did you get that method from when your method defined before was findName(...)?<br />
<br />
Besides, you really need to learn what is OO.  Even this example is not enough to proof you have enough OO knowledge.  Let's say your example is to show that customer name with total number searched.  You create an object that wraps these two values and pass it back to the caller until you reach your &quot;View&quot; and show it.  This is value object pattern and if you create Frontend application, this becomes, somehow in web sense, your &quot;Model&quot; in &quot;MVC&quot;.  Tell me, if you have 5 layers (caller methods) between this &quot;findName()&quot; method and the frontend.  During development cycle your requirement is changed 3 times for return value to include &quot;long searchedInMilliSeconds, int listSize&quot;, you have to change all 5 layers (may be more than 5 caller methods) because they all return multiple values.  I don't think this makes any of sense.<br />
<br />
In the end, if you like the way of returning multiple values, why do you want &quot;List&quot; as parameter? You simply extract all values from this list, pass them all as parameters like the following:<br />
<br />
public (String, int) findName(String name1, String name2, String name3, String name4, String name5...[until all names are passed]){<br />
...<br />
}<br />
<br />
If you really like this way of programming, then I guess you don't even need/like to use array.  If this is the case you may want to find out where your strength is really in instead of programming.</description>
			<pubDate>Sat, 19 Jul 2008 13:34:00 GMT</pubDate>
			<author>donotreply@osnews.com (andyleung)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>The Scala way</title>
			<link>http://osnews.com/thread?323684</link>
			<guid isPermaLink="true">http://osnews.com/thread?323684</guid>
			<description>Scala solves this in a manner that actually preserves the nice design principle.<br />
<br />
Here's an example:<br />
<br />
object MultipleReturnValues extends Application {<br />
  <br />
  // Define a class for the return value<br />
  case class RetVal(intPart: Int, fracPart: Double)<br />
  <br />
  // Define a function returning values of that type<br />
  def floor(value: Double) : RetVal = new RetVal(value.floor.toInt, value - value.floor)<br />
  <br />
  // Extract the parts of the return value and declare vals to hold them<br />
  val RetVal(i,f) = floor(10.4)<br />
  <br />
  // Print the result<br />
  Console.println(i + &quot; &quot; + f)<br />
}<br />
<br />
The nice thing with scala is that it can easily be mixed with Java code.</description>
			<pubDate>Sat, 19 Jul 2008 13:40:00 GMT</pubDate>
			<author>donotreply@osnews.com (John Nilsson)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[2]: I guess you never tried Python</title>
			<link>http://osnews.com/thread?323686</link>
			<guid isPermaLink="true">http://osnews.com/thread?323686</guid>
			<description>You have never tried Python.</description>
			<pubDate>Sat, 19 Jul 2008 14:51:00 GMT</pubDate>
			<author>donotreply@osnews.com (j-kidd)</author>
			<category>Comments</category>
		</item>

		<item>
			<title>RE[2]: I guess you never tried Python</title>
			<link>http://osnews.com/thread?323790</link>
			<guid isPermaLink="true">http://osnews.com/thread?323790</guid>
			<description>Well, I am SOO sorry that I once wrote getName und once findName - this was an EXAMPLE, it's likely to make such a mistake if you're writing this stuff into that comment box here...<br />
<br />
<br />
And don't tell me I don't know about OO. This actually hasn't got anything to do with OO, it's just a tiny, tiny EXAMPLE of why multiple return types CAN actually be useful, or - maybe better - how an actual implementation would look like in Java. Cases where it might actually be useful should be made up by everyone themselves, I think every programmer should have just about enough phantasy to do that.<br />
<br />
And yes, it's not useful for EVERY case (remember the sentence: &quot;When you've got a shiny new hammer, every problem looks like a nail&quot;). But there ARE some cases where it is indeed useful.<br />
<br />
Python implements that feature. What do you think is the justification for this - widely used - feature in this - widely used - language, if it ain't useful and hasn't got anything to do with OO and and and...<br />
<br />
Also, it hasn't got anything to do with type safety (not sure if it was you who mentioned that or someone else), because as you can see in my example, it would be actually VERY typesafe indeed. Because the types &quot;String&quot; and &quot;int&quot; are actually written there. And if you would return some other stuff instead, a good compiler _might_ tell you about that. Yes, Python just returns tuples, but they can be immediately assigned to seperate values (JUST like in my Java example) and if it would be included into a statically typed language, who would claim that it would be necessary to use some kind of Tuple internally? No one, because it would be bullshit. And I didn't say that either. It would be no problem for static types (JUST like in my Java example).</description>
			<pubDate>Sun, 20 Jul 2008 19:11:00 GMT</pubDate>
			<author>donotreply@osnews.com (Glynser)</author>
			<category>Comments</category>
		</item>
	</channel>
</rss>
