Let me know when int i = "hello"; is rejected by the compiler and I'll look again.
--
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.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
A much better "plain old" object type, improved collections, and a decent concurrency library
Something that surprised me when I first looked javac's source code was that they had added a cons list (immutable singly-linked list). That opened my eyes a little to the world outside j.u.ArrayList and friends.
The fact that Java's collections have lots of optional methods is a flaw, and we all know about the obsolete but not deprecated classes in there.
j.u.c is heaps better, but I'd say it's not 'reached the ground' yet. Nobody I've interviewed has known that CopyOnWriteArrayList exists, for instance. Executors has some traction but it's thought of more as a thread pool than any higher abstraction.
Try chaining Futures, for instance, to create a workflow, and you'll end up using listeners etc., which just aren't needed in libs like Akka and Functional Java. It's a good set of primitives but we want more!
Sure, I generally do stick with static languages. Groovy was promoted as a step up from Java, though, which until that line of code is rejected, it clearly isn't. A step sideways, perhaps.
Isn't Groovy adding static typing now? Will that line be rejected thereafter?
Java's lack of type inference.. sure. Does Groovy infer types?
Whoops, you added the static typing info while I was replying..
Can that @TypeChecked be added at the class level? Within a typechecked class can you still use all/most of the Groovy features or is it basically Java within there? I might grab a copy and play around, thanks for at least the information you've already provided, Russell.
On Sun, 2012-07-22 at 16:41 -0700, Cédric Beust ♔ wrote:
[…]
> As for the concurrency library... seriously? java.concurrent.util is notSadly though it doesn't look like ParallelArray will make it into Java
> just very powerful, it's very well designed and it's running tens of
> thousands of high volume web sites today. No other library can claim to
> come close to this, except maybe .net's.
8. Unless I missed something recently.
java.concurrent.util is showing more and more high-level features as
Doug et al. work them in, but the problem remains that most Java
programmers still think shared-memory multi-threading is the way to code
up parallel algorithms.
--Cédric
> But it also demonstrates the performance benefit of avoidingI like Clojure's approach in that it generally only copies the small
> locks - which can easily harm performance much more than GC pressure. This
> is the same reason that the asynchronous model also performs so well, even
> in the presence of immutable objects.
amount of data it needs. That said, if you 'need' to operate
concurrently on all 1,000,000 elements in that data structure then
yo'd best learn about GC tuning :-).
Cheers,
Martijn
That can't happen with shared mutable objects.
Hi guys,
just back from holidays sorry if I didn't response sooner.
Ricky:
"Let me know when int i = "hello"; is rejected by the compiler and I'll look again."
Thats such a staggeringly huge, dumb thing to say, I have to assume you are trying to be provocative. But if I was to give it some thought, here's what I would say:
1. That does not say much about you if thats the level of due diligence you are prepared to do before dismissing a technology that many people (some better than you) are saying is worth a look.
2. If you're hoping the compiler will catch errors like that, then I think you have a bigger problem in who you are hiring to write code.
3. As a professional programmer, I thoroughly unit test my code. A piece of code like that won't get far before its caught.
Fabrizio:
"In the end I found that that kind of stuff is the empty set: I found always preferable to do with Java"
Can you elaborate? At the moment I can't think of anything I would ONLY do in Java if I also had Groovy available and could do a mix.
Kevin:
"What ultimately turned me off was the performance hit and the dynamic typing (that, and the existence of Scala). What has your experience been with these in Groovy?"
That statement has the smell of 'Java is slow' that used to get bandied about years ago. I guess the answer is I don't know yet. I've yet to come across a development team where performance of the code was measured during development time. It usually comes afterwards, which can be too late of course.
I attended a presentation this year on Groovy performance at the CloudFoundry Day and the message was with constant improvements in the JVM and the new static checking, you are almost the same as Java.
My gut feel though is that unless you are already measuring your app in terms of tsp then its likely to be fast enough. Even if it isn't, once you isolated the critical parts, rewrite that part in Java. I just think the people bitten by this is small.
Cedric:
"java.concurrent.util is not just very powerful, it's very well designed and it's running tens of thousands of high volume web sites today"
I'm sure it is. However, as Russell and Ricky point out, is does feel as though its too low level.
Over the past week I've been reading up on GPars which is an abstraction layer on top of the concurrency libraries and its definitely way easier to work with and feels at the right abstraction level, especially in Groovy (in Java, it still seems verbose because of the lack of closures and the extra syntax).
I think, to get philosophical for a moment, that software development is a journey. Its also very unique to the individual as well. The journey I am on may well lead me to the promised land known as Scala but I do not feel I am ready quite yet and still have to pay my dues, learn more lessons out in the wild with Groovy. Its like the levels you have to pass through on the way to enlightenment. There's no point saying to people 'just use Scala' as they have to worked their way there. Over the years I've heard Dick talk about Java then he started playing with Python and then he moved to Scala.
Like I said, Groovy feels like a door opening onto a wider world. It has enough bits of other languages that I could well get distracted by:
Functional programming and end up in Haskell land or more likely, Clojure land.
Or maybe the dynamism gets into my blood and I end up moving to Ruby.
We all know people in these camps and it would be foolish to say there is something wrong with their choices.
Also, one last think I want to mention. Groovy says it tries to bring the 'fun' back into programming. I know see what they mean. I actually do get that buzz from writing something elegant that required me to have mastered some previously unknown area.
Rakesh
--
--
To unsubscribe from this group, send email to javaposse+unsubscribe@googlegroups.com.
--
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.
--
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.
--
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.
"you might find that compiler help isn't all that important in the end"
To view this discussion on the web visit https://groups.google.com/d/msg/javaposse/-/P1tShNeGVtEJ.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Java Posse" group.
To view this discussion on the web visit https://groups.google.com/d/msg/javaposse/-/q-A3HxccEmsJ.
--
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.
Java type-system issues:
1. Arrays.asList("foo", "bar") gets the type List<String> when it's the only thing in the expression, but as soon as you pass it to something else the type parameter gets inferred to be Object.
2. No way of saying that an Iterator<String> is an Iterator<Object> even though logically it could be (no covariance or contravariance)
3. Arrays are covariant so the compiler lets you add an invalid item to an array.
4. List<int> doesn't work. Nothing to do with erasure, as Scala manages it.
5. null inhabits every reference type (like in lots of other mainstream languages).
6. foreach is not open for extension, i.e., it only works with Iterables and arrays.
7. try-with-resources is not open for extension, e.g., it can't be made to work with locks without wrapper objects.
8. Varargs use arrays. Given the incompatibility between generics and arrays (caused by arrays' covariance) this just seems a mistake. Again, should be open for extension.
9. No higher kinds. I can't write Monad in Java because there's no way of saying "this type parameter has a type parameter". This occasionally results in either code with warnings or duplication.
10. Definite assignment could use a tweak:
final int x;
try {
x = foo();
} catch (FooException e) {
x = 5;
}
That doesn't compile because x might have been assigned to twice. I suppose that's not really the type system but I've typed out that code on my phone now so it's staying!
11. A culture issue rather than strictly a type system issue but the whole Java community seems to have a collective brainfart and start waffling about complexity budgets when they see Enum<E extends Enum<E>>. Perhaps the type system issue is that Java has no self types so we end up doing that in generics.
What hole do you see in Scala and C# if covariance and contravariance open holes in type safety? There may well be a problem I don't know of.
As for Monad (or higher kinds in general), I'll try to come up with a motivating example at some point but I'm self-trained to avoid it in Java mainly because the missing feature makes it hard.
The basic idea is that if you "insert" an Apple into a collection of Oranges, then you get back a collection of Fruit. Both the new collection and the original are immutable, with the original continuing to be a simple collection of Apples.
This nicely sidesteps a *lot* of problems. Not just thread synchronisation, but also things like the Liskov Substitution Principle.
As for allowing mutability then, sure, it can be done. You simply have to clamp down on your types for the mutable subclass (which is fairly standard practice in polymorphism anyway). The mutator methods introduced in the subclass DON'T permit Co- variance, but you're still free to use the inherited methods which will force you back into immutability.
Casting around that is theoretically possible. Which is why Haskell purists will tell you that casting is unsafe and a lie (tantamount to reflection hacks). This is also why Scala very purposely made casting so verbose and ugly - you really don't need it if you have immutability and you're using the type system correctly.
It's worth pointing out that nobody on this list is criticising the value of unit testing, integration testing, load testing, pair programming, code review, documentation, or any other technique demonstrated help with maintainability and catching defects.
But... given that we use all these techniques, and that they're known to be more effective in combination, why then argue that type checking/static analysis is somehow unique in its ability to be superseded by the others?
Nobody would claim that formal code review obviates the benefits of pair programming. Why, then, is it more acceptable to claim that unit testing can effectively replace static typing?
"This argument is only really useful in this debate if statically typedcodes need no unit tests at all in order to provably correct."
--
You received this message because you are subscribed to the Google Groups "Java Posse" group.
On Mon, 2012-07-30 at 21:52 +0100, Kevin Wright wrote:I have to admit that whilst a lot of programming is about transforming
> The basic idea is that if you "insert" an Apple into a collection of
> Oranges, then you get back a collection of Fruit. Both the new collection
> and the original are immutable, with the original continuing to be a simple
> collection of Apples.
apples to oranges and comparing apples and oranges, the interesting
stuff happens with very big data structures, for example 6GB XML
documents, or 256MB images. You do not deal with these things by value
per se.
val uppernames = names map { _.toUppercase }
The solution at the moment is to switch from a shared memory
perspective to a message passing perspective, a return to
object-oriented programming – which most current Java, Scala, Groovy, C
++, Python, Ruby, etc codes that I have seen do not employ.
Go and Groovy/GPars, and others, are trying to alter this. Immutability is
critically important, the question is at what scale. Functional
programming, actors, dataflow, CSP, all have slightly different
architectural views on this.
The core issue is surely to remove
shared-memory multi-threading as the main applications programmer tool
of concurrency and parallelism. After all locks are designed exactly to
stop parallelism
for(x <- xs) { println(x) }
xs foreach { x => println(x) }
for(x <- xs) yield { x.toUpperCase }
xs map { x => x.toUpperCase }
def lengthyAsyncOp1(): Future[Int] = ...
def lengthyAsyncOp2(): Future[Int] = ...
//this returns instantlyval futureSum = for {int1 <- lengthyAsyncOp1()int2 <- lengthyAsyncOp2()} yield {int1 + int2}... keep doing other stuff ...//this next line blocks the threadval answer = Await.result(futureSum)println("the answer was: " + answer)
Hang on... What's with all this "could" business?
You know full well that it already does!
Actually, I don't. I lost track of all the Java compatibility stuff a couple of years ago. It all sounds good now but I just don't know it.
Back to the Groovy topic, I just found out from a Haskell guy forced into Groovy that it doesn't respect private. I verified this in the bugtracker but saw conflicting ideas about whether it'll be fixed in the upcoming 2.0 or the more distant 3.0.He had some lovely things to say about the language. I must look up 'trainwreck' as applied to programming languages.
--
As for unit testing, I actually use them to design my code:"now I need my code to do this, so I am going to pass these arguments in and expect this back"rather than"if i pass this, then I expect that"Subtle but important point. Its not about exhaustive input testing.
RakeshOn 30 July 2012 11:06, Fabrizio Giudici <Fabrizio...@tidalwave.it> wrote:
On Mon, 30 Jul 2012 11:51:45 +0200, Rakesh <rakesh.m...@gmail.com> wrote:Rakesh, this is not only religious but I think that people have many points here. Kevin just pointed out that unit testing can't be complete. It would be complete only if one submitted to any piece of code all the possible combinations of inputs. Of course, this is theory: in practice, it would suffice to submit all the practical combinations of inputs. This can be quite large. The fact that you didn't experience problems so far is not necessarily a strong point: see the inductivist turkey argument by Russel / Popper. In practice, you might feel strong for a lot of time, until you get burned. Of course, this is still theory, and in practice I'd say that personal experience, given that we have a sufficient bunch of data, is an indicator... for that person.
I am saying, that in practice, this check at not happening at compile time,
based on my personal experience, has not been a show stopper. At all.
Unit testing definitely made this a non-issue for me. That may not be the
only solution.
I seem to have stumbled into a 'religious' issue here and there's not much
I can say to convince you that static compilation hasn't prevented me from
being way more productive than before.
Let's put this in another way. I think it's a very strong point to say that without static typing you loose lots of benefits. Now, we can afford to lose something in change of something more interesting. What's the benefit you get with Groovy. When I answered in the previous mail exchange, my point was that with my experience with Groovy I didn't get much in return: just writing a few less line of code is not enough, and if it was a very important point to me I'd rather consider alternatives such as Scala, which allows less lines of code and it's static.