That's exactly how I do it, and it seems clear enough to me. The
reasoning is that null is the only valid value for variable of type
Void, since Void is not instantiable (without trickery).
Then, you just do VoidMapper instead of RowMapper. (And voidMap
instead of Map.)
--
You received this message because you are subscribed to the Google Groups "Java Posse" group.To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
Generics is involved, and generics is not capable of representing variable arity, so, if the generics say there is a return type.... there's a return type.Void and void have basically zero relation. That's all there is to it, really. Returning no thing is just as impossible as returning 2 things.
A neat thing is how one misfeature (null) is basically saving the functionality of another feature. (See C# for a different, imho less nice solution.)
While I can see how the notion of "it doesn't return anything" for void looks intuitive from a low-level point of view (nothing gets push'ed/pop'ed), it is not intuitive if you view a program purely from an data flow perspective, because there is a difference between "it returns, but with no new information" and "it doesn't return" which Java completely fails to capture.
Additionally, the fact that void is not even a type, but some special, hard-coded language keyword also adds complexity to the whole concept.
(Some newer languages got all of this right from the start.)
I think it is an interesting example how some "pragmatic" and superficially simpler approach tends to break down and cause complexity in both the spec and the implementation compared to the "academic" solution.
(Some newer languages got all of this right from the start.)
On Monday, October 8, 2012 1:33:06 AM UTC+2, Simon Ochsenreither wrote:I think it is an interesting example how some "pragmatic" and superficially simpler approach tends to break down and cause complexity in both the spec and the implementation compared to the "academic" solution.
Yes, java has no type that represents "there is no value that is this type, not even 'null'". It would be cool if this type existed; a method that had this as return type cannot actually return, ever. It has to exit abnormally: Either it runs System.exit(0), which should probably at that point return this special Nothing type (so that you can type: return System.exit(0)), or it has to throw an exception. There are no other ways out.
def method[A](x: A): A = method(x)
Unfortunately, introducing this kind of concept is exactly the kind of thing java does NOT do, and languages like Scala DO do: it's not a matter of superiority, it's a matter of tradeoffs: If this Nothing exists, it cannot actually be a subtype of Object; a List<?> cannot accept an instance of List<Nothing>, because I can still put nulls in List<?>, and nulls are not a valid value for Nothing. Hell, generics in general play havoc with this: Using trickery I can make a List<Nothing> with nulls in it, and then write return thisHackedList.get(0), which means in practice that Nothing needs type checking (i.e. that would lead to a ClassCastException or similar, even if .get(0) returns null).
That's the kind of thing where java has decided that the practical upside of having a 'Nothing' value is not actually that much; it's largely academic, and it definitely "feels bad" that the language is not complete, and that this awesome concept is not actually in your language. However, adding it to the language definitely incurs a cost: The compiler needs to do all sorts of things to treat Nothing specially, and this is going to make the spec much more complicated.
Scala-like design says you accept the complexity hit, and theorizes that if you go whole-hog on this you can actually remove a lot of complexity because the language is much more flexible. So far that seems like it's been working out reasonably well for scala. The java-like design says that these mostly academic features just aren't important enough, and in practice the language will be simpler if you just don't have them. Where people need them, they'll kludge it.
Sounds ugly. Yet, java's popularity and the robustness of java-based apps like google ads and many a server out there suggest it's fine.
(Some newer languages got all of this right from the start.)
Right. I'm saying, well, the jury is still out on this. Is it actually right to burden your language with the Nothing concept?I'm pretty sure that retrofitting Nothing onto java is a grave mistake at this point.
ivory towerRetrofitting concepts into languages where there's little *real* benefit serves only to waste resources that could be better spent elsewhere -- and to risk breaking things, e.g. backward compatibility, that do have real, tangible benefit.
--
You received this message because you are subscribed to the Google Groups "Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
Unfortunately, introducing this kind of concept is exactly the kind of thing java does NOT do, and languages like Scala DO do: it's not a matter of superiority, it's a matter of tradeoffs: If this Nothing exists, it cannot actually be a subtype of Object; a List<?> cannot accept an instance of List<Nothing>, because I can still put nulls in List<?>, and nulls are not a valid value for Nothing. Hell, generics in general play havoc with this: Using trickery I can make a List<Nothing> with nulls in it, and then write return thisHackedList.get(0), which means in practice that Nothing needs type checking (i.e. that would lead to a ClassCastException or similar, even if .get(0) returns null).
That's the kind of thing where java has decided that the practical upside of having a 'Nothing' value is not actually that much; it's largely academic, and it definitely "feels bad" that the language is not complete, and that this awesome concept is not actually in your language. However, adding it to the language definitely incurs a cost: The compiler needs to do all sorts of things to treat Nothing specially, and this is going to make the spec much more complicated.
Scala-like design says you accept the complexity hit, and theorizes that if you go whole-hog on this you can actually remove a lot of complexity because the language is much more flexible. So far that seems like it's been working out reasonably well for scala. The java-like design says that these mostly academic features just aren't important enough, and in practice the language will be simpler if you just don't have them. Where people need them, they'll kludge it.
Sounds ugly. Yet, java's popularity and the robustness of java-based apps like google ads and many a server out there suggest it's fine.
Right. I'm saying, well, the jury is still out on this. Is it actually right to burden your language with the Nothing concept?
I'd like to see more use cases for Nothing, more ways in which it simplifies without changing the meaning of existing code.
One annoyance in Scala is when it infers a type to be, say, List[Nothing], which so far has never been what I intended.
Yes, java has no type that represents "there is no value that is this type, not even 'null'". It would be cool if this type existed; a method that had this as return type cannot actually return, ever. It has to exit abnormally:
Either it runs System.exit(0), which should probably at that point return this special Nothing type (so that you can type: return System.exit(0)), or it has to throw an exception. There are no other ways out.Unfortunately, introducing this kind of concept is exactly the kind of thing java does NOT do
That's the kind of thing where java has decided that the practical upside of having a 'Nothing' value is not actually that much; it's largely academic, and it definitely "feels bad" that the language is not complete, and that this awesome concept is not actually in your language. However, adding it to the language definitely incurs a cost: The compiler needs to do all sorts of things to treat Nothing specially, and this is going to make the spec much more complicated.
Sounds ugly. Yet, java's popularity and the robustness of java-based apps like google ads and many a server out there suggest it's fine.
Right. I'm saying, well, the jury is still out on this. Is it actually right to burden your language with the Nothing concept?I'm pretty sure that retrofitting Nothing onto java is a grave mistake at this point.
Having Nil not need a type parameter is absolutely not necessary for immutability. It just makes code involving Nil a tad more readable. Also cons lists are not our only option in immutable code, just as the mutable world is richer than just having ArrayList everywhere.
One annoyance in Scala is when it infers a type to be, say, List[Nothing], which so far has never been what I intended.
Void isn't quite right though. It corresponds to "return, but with no useful information", which isn't the same thing as not returning at all.
On Monday, October 15, 2012 3:27:20 PM UTC+2, KWright wrote:Void isn't quite right though. It corresponds to "return, but with no useful information", which isn't the same thing as not returning at all.Why the interest in modeling "not returning at all"? Isn't that mostly interesting to people studying the halting problem? I'm strictly interested in modelling "return with nothing" and "return with something", what else is there but blocking the thread or looping indefinitely?
int someMethod(int question) {
final int retval =
question.equals("What is the answer?")
? 42: throw new Exception("that's not the question");return retval;}
A compiler seeing generic capture of Void, could allow an implicit return clause (as is the case with the void keyword) and furthermore optimize stack push/pop away (rather than boxing null). It seems like the issue is going to come up much more, when/if closures are introduced.
Unfortunately, introducing this kind of concept is exactly the kind of thing java does NOT do, and languages like Scala DO do: it's not a matter of superiority, it's a matter of tradeoffs: If this Nothing exists, it cannot actually be a subtype of Object; a List<?> cannot accept an instance of List<Nothing>, because I can still put nulls in List<?>, and nulls are not a valid value for Nothing. Hell, generics in general play havoc with this: Using trickery I can make a List<Nothing> with nulls in it, and then write return thisHackedList.get(0), which means in practice that Nothing needs type checking (i.e. that would lead to a ClassCastException or similar, even if .get(0) returns null).
Is this just theorizing? I'd love to see that code.
That's the kind of thing where java has decided that the practical upside of having a 'Nothing' value is not actually that much; it's largely academic, and it definitely "feels bad" that the language is not complete, and that this awesome concept is not actually in your language. However, adding it to the language definitely incurs a cost: The compiler needs to do all sorts of things to treat Nothing specially, and this is going to make the spec much more complicated.
Did you actually check that? Until now, I have only seen a Java-specific issue which doesn't even exist in Scala. I'd love to see some of this complexity caused by Nothing.
Scala-like design says you accept the complexity hit, and theorizes that if you go whole-hog on this you can actually remove a lot of complexity because the language is much more flexible. So far that seems like it's been working out reasonably well for scala. The java-like design says that these mostly academic features just aren't important enough, and in practice the language will be simpler if you just don't have them. Where people need them, they'll kludge it.
Did you just make that up?
Sounds ugly. Yet, java's popularity and the robustness of java-based apps like google ads and many a server out there suggest it's fine.
See the other recent debate.
Yes, java has no type that represents "there is no value that is this type, not even 'null'". It would be cool if this type existed; a method that had this as return type cannot actually return, ever. It has to exit abnormally:From a programmers perspective, when you return from a method (byte-code 0xb1), you are indeed returning nothing. From the JVM's perspective, you're not returning anything either - the stack is left completely untouched.
Either it runs System.exit(0), which should probably at that point return this special Nothing type (so that you can type: return System.exit(0)), or it has to throw an exception. There are no other ways out.Unfortunately, introducing this kind of concept is exactly the kind of thing java does NOT doExcept when it DOES do so, such as when you omit an explicit return and rely on javac to implicitly paste this in for you at while desugaring.
Complications usually arise from the convoluted interactions of accumulated features (const vs non-const i C comes to mind), not from being consistent about the programming model up-front. Frankly, I couldn't care less about how the compiles does things internally, but I am often forced into this.
Another example where this applies, is with generics and the (for the uninitiated) odd inability to implement Comparable<Fruit>, Comparable<Veggie>
Sounds ugly. Yet, java's popularity and the robustness of java-based apps like google ads and many a server out there suggest it's fine.You're grasping for straws here. I think we can agree it's not quite that simple.
But we already have Void, the compiler probably already uses plenty of places internally.
Promote it to work in tandem with javac's existing desugaring rules, such that a return Callable<Void> results in a non- stack-modifying return which satisfies developer, compiler and JVM.
One annoyance in Scala is when it infers a type to be, say, List[Nothing], which so far has never been what I intended.
While I remember some “interesting” type inference results, List[Nothing] is a bad example. There is only one, single, unique value of List[Nothing] and it is the empty list. And in fact, that's the only possible element type of an empty list.
that's false; a List[String] can happen to be empty.
that's false; a List[String] can happen to be empty.List[String] is a supertype of List[Nothing], just like Object. That's surely not the point I was trying to make.
On Monday, October 15, 2012 2:42:11 PM UTC+2, Simon Ochsenreither wrote:Unfortunately, introducing this kind of concept is exactly the kind of thing java does NOT do, and languages like Scala DO do: it's not a matter of superiority, it's a matter of tradeoffs: If this Nothing exists, it cannot actually be a subtype of Object; a List<?> cannot accept an instance of List<Nothing>, because I can still put nulls in List<?>, and nulls are not a valid value for Nothing. Hell, generics in general play havoc with this: Using trickery I can make a List<Nothing> with nulls in it, and then write return thisHackedList.get(0), which means in practice that Nothing needs type checking (i.e. that would lead to a ClassCastException or similar, even if .get(0) returns null).
Is this just theorizing? I'd love to see that code.What code? It's trivial:List<Nothing> list = new ArrayList<Nothing>();list.add(null); //Barring compiler magic, this will compile and run without error.or:List<Object> list = new ArrayList<Object>();list.add(null);List<Nothing> list2 = (List<Nothing>)list;Nothing aNothingVariableThatContainsValue = list2.get(0); // compiler or VM magic required to throw the needed runtime exception here.or even:Nothing y = null; // Compiler magic required to make this invalid.
Using trickery I can make a List<Nothing> with nulls in it, and then write return thisHackedList.get(0), which means in practice that Nothing needs type checking (i.e. that would lead to a ClassCastException or similar, even if .get(0) returns null).Is this just theorizing? I'd love to see that code.What code? It's trivial:List<Nothing> list = new ArrayList<Nothing>();list.add(null); //Barring compiler magic, this will compile and run without error.
Nothing y = null; // Compiler magic required to make this invalid.
See the other recent debate.'the other recent debate'? - this forum has lots of threads. This thread has lots of posts. You're going to have to be more specific.
What point _were_ you making then?