Skip to content

Commit

Permalink
Java 8 workshop blog post
Browse files Browse the repository at this point in the history
  • Loading branch information
sjumilli committed Feb 16, 2015
1 parent 27945b6 commit 1dec0b8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_site/
.sass-cache/
.DS_Store
.DS_Store
.idea/
71 changes: 71 additions & 0 deletions _posts/2015-02-16-java-8-workshop-at-finnno.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
layout: post
comments: true
date: 2015-02-16 08:50:16+0100
authors: Sjur Millidahl
title: "Java 8 workshop at Finn.no"
tags:
- java
- java8
- functional
- lambda
- workshop
---

<figure>
<img src="/images/2015-02-06-java-8-workshopp-at-finnno/DSC_0091.JPG" alt="Pondering on the right lambda for the job" />
<figcaption>Pondering on the right lambda for the job</figcaption>
</figure>

With Java 8 comes a whole new set of language features. It even challenges the imperative coding-style of the Java programmer.

Java is a core language in Finn.no. More and more of our java-modules are being built with Java 8, adopting new features of the language.
A workshop was warranted, with the goal of bringing every developer up to speed on the functional paradigm of Java 8.

In Finn.no, we want programmers to do stuff like this

```java
db.fetchLastDayAds()
.stream()
.filter(ad -> "bap-webstore".equals(ad.getAdType()))
.flatMap(ad -> ad.getContacts().stream())
.distinct()
.flatMap(per ->
Optional.ofNullable(contact.getEmail()).map(Stream::of)
.orElseGet(Stream::empty))
.peek(contact -> LOG.trace("Sending notification to "+per))
.forEach(this::sendNotification);
```

While avoiding stuff like this


```java
IntStream.iterate(0, i -> (i + 1) % 2)
.parallel()
.distinct()
.limit(10)
.forEach(System.out::println);
```
(Locking up all cores on a CPU is bad, and should only be done when the machine is right about to become self-aware and turn against you.)

<figure>
<img src="/images/2015-02-06-java-8-workshopp-at-finnno/DSC_0092.JPG" alt="Several lambda-arrows pointing in the right direction here"/>
<figcaption>Several lambda-arrows pointing in the right direction here</figcaption>
</figure>

We split the workshop into two half days. The first day was dedicated to streams and lambdas. Everyone seemed keen on getting those tests green (a rhyme!).

Day 2 we raised the bar with Optional<T> and our in-house version of Either<L,R>. With these structures, much more code can be written functionally in a world where values might not exist (be null), and things may go wrong (throw exceptions).

<figure>
<img src="/images/2015-02-06-java-8-workshopp-at-finnno/DSC_0095.JPG" alt ="We need power.. lots of power!" />
<figcaption>We need power.. lots of power!</figcaption>
</figure>

Both the word "monad" and the phrase "monadic domain" was uttered several times, but we still saw very few making the swoooosh-sound while flying a hand over their head (the internationally recognized sign of communicating that a topic is beyond mental capacity).

This might mean that the timing was good, and developers are interested in the new features of Java 8.

You may [checkout the project and do the tasks yourself](https://github.com/mariatsji/java8-workshop.git), by making the failing tests green

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1dec0b8

Please sign in to comment.