5. Tech reasons
Moore's law - the observation that
the number of transistors in a dense
integrated circuit doubles
approximately every two years
We’re moving to more cores ...
6. Human reasons
● Working memory only holds 7 +- 2 items at the same time
● But we’re able to use Chunking
“Chunking in psychology is a process by which individual pieces of information are
bound together into a meaningful whole (Neath & Surprenant, 2003)”
7. We need greater abstractions
“The power of the unaided mind is highly overrated. Without external aids,
memory, thought, and reasoning are all constrained. But human intelligence is
highly flexible and adaptive, superb at inventing procedures and objects that
overcome its own limits” - Donald Droman, in “Things that make us smart”
Examples:
Assembly -> Fortran -> C -> C++ -> Java -> Groovy -> ?
Traditional IT -> Iaas -> Paas -> Saas -> XaaS (microservices like Amazon
lambda, Google Cloud Functions)
10. What is Functional
f(x) = x + 2
int f(int x) { return x + 2 }
● Does not keep state
● For same input, always same output
● Everything the function needs is provided as a parameter
● Immutable:
○ Integer f(Integer x) { return new Integer(x.intValue() + 2) }
○ x.setInt(7)
12. What is Reactive
Reacts to events / Hollywood pattern
Iterator -> pull Observer -> push
interface Iterator<T> {
boolean hasNext();
T next();
}
interface Observer<T> {
onNext(T t);
onCompleted();
onError(Throwable e);
}
13. Why reactive
Easy Threading
No callback hell
Function composition
A ton of operators
Easier to reason about
Common vocabulary across languages and platforms (java, swift, etc)
14.
15. Rx Example
// print every item in the array [1,2,3]
Observable.from(Arrays.asList(1,2,3)).subscribe(new Action1<Integer>() {
@Override
public void call(Integer i) {
System.out.println(i);
}
}); // in java
Observable.from(Arrays.asList(1,2,3)).subscribe((Integer i)->{ println(i) })//(Java 8)
Observable.from([1,2,3]).subscribe { println(it) } //(in Groovy)
21. What is Groovy
JVM language
Born in 2003
Inspired by Java, Python, Ruby, Perl, Smalltalk, Objective-C
“Superset” of java
Apache license
Dynamic by default, but also Static if you want to (and I do !)
22. Why groovy
Already using it for the build system (although Kotlin in the future ?)
Looks like java
Easier to transition to
Good IDE support
Much less verbose
Array and map literals, closures, null safe navigation
More functional
Apache Project and License
23. Closures, multiline string & interpolation, safe nulls
new AlertDialog.Builder(context)
.setMessage(Html.fromHtml("""
<small><font color='#$worker.categoryColor'>
${worker.category?.toUpperCase()}
</font></small><br /><br />
<b>${worker.devicesText}</b><br /><br />
${worker.description}<br /><br />
<font color='#99a7aa'>
<i>This is an advanced automation and cannot be edited</i></font>
"""))
.setPositiveButton("Got it", { DialogInterface dialog, int which -> gotIt()})
.show()
24. Switch and casts on steroids
Closure onAction(Object action){
switch (action){
case String: return {startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(action as String)))}
case Closure: return action as Closure
default: return {startActivity(new Intent(activity, action as Class))}
}
}
25. Much, much more ...
● Safe null navigation, boolean cohersion:
If (myObj?.myInnerCollection) { doStuff() }
groups?.each { group ->areas.find { it.id == group.parent }?.children?.add(group) }
● AST Transformations == Compile time meta-programming
@CompileStatic, @InheritConstructors, @EqualsHashCode, @ToString,
@Immutable, and many more
● Operator overloading
26. Groovy caveats
Debugger looses its bearings
Compiler sometimes gets confused when dealing with inner classes (in groovy)
Java preprocessors might not work (YMMV), although Dagger works fine