Day one of JAX London...
The opening keynote (by Jeff Sussna) was a review of how the software business is increasingly one of accelerating change driven by disruptive new technologies. Kodak lasted 100 years until it was disrupted, Microsoft is under heavy disruption after 30 years and current new players can expect a lifespan of only a few years before the rug gets pulled from under their feet.The continuous delivery of new products leads to seamless changes in the physical world. Example: Tesla released an upgrade, via the cloud and without user intervention, that increased the battery lifetime. Complex systems cloud responsibilities. A faulty car radio; is it the problem of Honda, Spotify or the ISP?
Agile response the only way to survive: Observe, Orient, Decide, Act.
Streams in Java 8 (Angelika Langer)
Inspired by the sequence paradigm from functional programming, the stream separates the "how to do it" from the "what to do":myStream.forEach( s -> func(s) );
func() - responsibility of programmer
forEach() - responsibility of Library
Following fluent programming, the stream allows chaining:
stream.filter(...)
.map(...)
.forEach(...);
By default, the stream is sequential, but can be declared .parallel().
Parallel has an overhead. Using the fork-join framework, the payload (e.g., Collection) is split in two several times (splitting phase) to arrive at leaf nodes. These are executed (execution phase) and the outputs re-assembled (join phase). The cost of splitting and joining must be less than the gain from parallel execution for it to be worthwhile.
Is parallel faster? Depends on the use case:
- for primitive types (e.g., sorting ints), the execution is so simple that a simple for-loop is always faster.
- Some collections are better than others; LinkedList does not split well so is worse than ArrayList.
- for CPU-intensive functions, parallel overheads wash out and are insignificant compared to execution time saved.
- for I/O intensive (HTTP uploads?), the latency clogs the common pool and there is no advantage in parallel.
Java Generics (Urma & Warburton)
The programming trilemma: Can only have two from:- simplicity
- concision
- type safety
static <I extends A & B> myMethod{...}
the method accepts arguments of type A or B.
Wildcards:
Suppose we have objects like:Email extends Message
SMS extends Message
Then we make an array of emails:
Email[] e = {new Email()};
And copy this to an array of SMSs:
SMS[] s = e; // ok - both extend Message
However if we have a method,
logList(Email[] e)
this will fail at runtime if we give it the SMS array.
fix it with wildcard:
logList(List <? extends Message> list)
Now it works with anything that extends Message.
SQL or Java (Lukas Eder)
Self-described geek from Zürich. He started with the porblem of how to write SQL in Java - illustrated with some amazing examples from Stackoverflow... Have a look at www.annotatiomania.com and the QW@RTY keyboard - I LOLed...No SQL preaches Big Data, Mongo DB and the end of the relational DB. But - these are all about storing data. Relational DB allows complex querying...
Did you know that SQL hasn't really changed since 1992 (who still uses Windows 3.1?). He supports
jOOQ as and SQL writing tool for Java. Queries are objects and clauses become methods. It looked very intuitive and would be worth exploring.
As the talk wore on, we learned about nested selects, window functions and model clauses. This was not to show how easy SQL is, but rather to show how powerful it is. I especially liked the Mandelbrot Set drawn with SQL. His conclusion was always, push all logic into SQL.
I asked him if there was a systematic way to optimise a query when the explain-plan shows an N-squared dependency. Disappointingly, it seems there isn't (try an index?).
We should get this guy in for a talk.
No comments:
Post a Comment