Category Archives: Java

Watching/Reading – Reactive Design Patterns – Cont.

https://www.manning.com/books/reactive-design-patterns

Continuing to read the book and additional notes are,

  • Asynchronous interfaces helps decoupling modules and provides horizontal scalability.
  • Location transparency – By writing the application in a distributed manner, even for the local processing, your application can become resilient to the failure. It makes writing tests easier too.
  • Akka’s Actor systems (http://doc.akka.io/docs/akka/snapshot/scala/actors.html) provides simple interface for message passing between components. It provides simple interface and it makes it easier to tests through stubs/mocks on the interface.
  • You need to work with non-determinism in distributed systems. One approach is explicitly synchronize for avoiding ordering issue. The other is to avoid/isolate computations which will be affected by the computation order.
  • Back-pressure and flow control becomes required between components. Reactive stream (http://www.reactive-streams.org/) is one way to control flow.
  • Netflix is building Chaos Monkey which randomly disabled production instances for ensuring system resiliency (https://github.com/Netflix/SimianArmy).

This book covers various concepts and methodologies for building solid system in a distributed manner. Also, the examples written with Scala is relatively simple and good to understand.

Also, the following coursera courses covers similar topic and would help gaining knowledge on this topic too.

Advertisements

Scala and Monad Tutorial

Scala Monads: Declutter Your Code With Monadic Design

I had been staying out of the keyword “monad” as it’s often described as difficult. But, this tutorial video nicely explains it with concise and clean examples.

It’s interesting to explain monad as “design pattern” in the functional programming world. Also, the example compares normal Java-way of handling null and exceptions with monadic-way ones in Scala.

[Java]

if (foo != null) {
  Bar bar = foo.getBar();
  if (bar != null) {
    Baz baz = bar.getBaz();
    if (baz != null)
      return baz.computer();
    else
      return null;
  }
  else
    return null;
}
else
  return null;

[Scala]

for {
  foo <- maybeFoo
  bar <- foo.bar
  baz <- bar.baz
} yield baz.compute

Pretty much concise. When I was learning Scala at coursera course, I could understand the basics (for statements, Option with Some/None and map/flatmap concepts), but I wasn’t thinking about its underlying concepts like monad. It would be worthwhile to dig-deep a little more.

Functional Way of Thinking

Functional Thinking with Neal Ford

It’s a nice talk about functional way of thinking. The “functional” provides a different way of programming style from the object-oriented and imperative ones. The concept is not about specific language or syntax, but rather a different paradigm to think on problem solving.

The Functional Java is one example to apply this paradigm in the Java through libraries.

The library provides functional data-operations like map, filter, etc., and it can be applied into the familiar object-oriented and imperative Java syntax.

Also, Java is now equipped with lambda expression and streams. Along with Scala, the functional style seems getting into the mainstream gradually.

I was yet a little skeptical about the paradigm of functional programming, mostly because it is difficult. It requires more abstracted way or mathematical thinking, rather than more concrete and basic imperative way of thinking. However, recent adoption of functional paradigm in the popular languages would be a good indicator that certain paradigm shift in the majority area is now happening.

The Play Framework @ YouTube

The Play Framework at LinkedIn: Productivity and Performance at Scale

The “Play” seems an interesting Java/Scala framework that absorbed the nice feature-sets of other popular script language frameworks. It has simple Rails-like app bootstrapping commands (“play new”) and view/controller structures with concise route files. Also, Node.js-like event driven non-blocking I/O is supported, and it can be executed in parallel through the concept of “promise”, which is popular in the JavaScript world.

As the non-blocking I/O pattern is gaining popularity, the Java framework that supports in simple mechanism would be nice rather than struggling on thread pools.

Introduction to Play Framework for Java developers

This tutorial video covers simple todo-list type of application, which is often seen as tutorials. Though there’re some Java related redundant notations (compared with the script-language ones like AngularJS), its concept is simple. Considering the static-type checking and detailed error messaging, it would be a good option especially for large applications. Also, it seems the Play has built-in testing-framework for application/integration tests along with stubbing/mocking features. Nice.