Sei sulla pagina 1di 52

Healthy Code

45 38 32 26 20 14 10 04

April 2015

Contents

Serial Devices and the Raspberry


Pi - A Primer
Code Jugalbandi
Groovy
Working with Collections -1
Dependency Injection
The Functional Way
Interview with
Viral Shah
Introduction to Apache Spark
Reactive Web Programming
Interview with Thushara Wijewardhana

Healthy Code
April - 2015

Healthy Code
April - 2015

From the Editor


Hello readers!
Summer is setting in, and we are back with interesting set of articles.
We have two exciting interviews in this issue. Viral Shah, the
co-founder of Julia programming language and a key man, behind
Aadhar payments talks to us.
Tushara shares her experiences of working in agile projects from Sri
Lanka.
Madhukara Phatak has written a very interesting piece on Apache
Spark that gives you a nice overview of the framework. Code Jugalbandi
team and Naresha continue to impress us with their articles on Pattern
Matching and De-structuring in languages and Groovy collections.
Debashish discusses dependency injection in a Functional language
like Scala.
Charath has written about GPS sensors and interfacing the GPS devices
with Raspberry Pi. Vasanth of Indix, talks about reactive programming
and introduces us to the concept and its implementation using a variety
of frameworks.
We are making our presence felt in a number of conferences. We were
present in Agile India 2015, Bangalore, conference last month. We hope
you attend these conferences too.
Have fun reading and enjoy the summer.

Healthy Code
April - 2015

Article

Charath Ranganathan

Serial Devices and the


Raspberry Pi - A Primer
4

Healthy Code
April - 2015

Assume that you are the average, run-of-the-mill


James Bond-like spy. You need to build a device
that tracks the position of one of your adversaries
using a GPS sensor. Your sensor will interface
with a Raspberry Pi, which will, in turn, save the
data to a disk file. Sounds cool, doesnt it? Lets
find out how to do that, in this article.

The GPS Device


To accomplish our goal, we will use a GPS sensor from
Adafruit Industries (http://www.adafruit.com/). This
sensor is called the "Ultimate GPS Breakout Board." Since
you are the ultimate spy, you will use nothing else but the
"Ultimate" GPS board.

are "Asynchronous" because a clock signal is not transmitted


between the sender and the receiver. Most UART systems,
typically, have the capability to both transmit and receive
data, which explains the words "Receiver" and "Transmitter"
in the title.

The Adafruit "Ultimate" GPS board (called the "GPS board"


from here on out) is based on the MTK3339 chipset. It can
track up to 22 satellites and includes a 3.3V - 5V regulator.
The board communicates with a microcontroller (such as
the RPi) using a UART connection.

In order to learn more about interfacing a serial device to


the RPi using the UART interface, let us implement the GPS
problem.

What is UART?

Before we deep-dive into interfacing the GPS board to


the RPi, let us spend a few moments to understand how
GPS actually works. We take the GPS system for granted
nowadays, especially since GPS receivers are ubiquitous in
our smart phones, but no one actually pauses to think about
how this whole system actually works.

In some of my earlier articles, we looked at various ways


to interface simple electronic circuits to the RPi using the
General Purpose Input/Output (GPIO) interface. While
GPIO interfaces are good for simple interfacing, there are
a few other interfacing options that are available to the
embedded circuit designer.
Out of these, serial communication channels, also called
UART (Universal Asynchronous Receiver and Transmitter)
is very popular, especially for long-haul communications.
Serial communication channels work by transmitting data,
one bit at a time, sequentially. Such transmission generally
requires just one wire for each direction, thereby reducing
cost and complexity in situations where the distance
between two devices is large.
Serial communication protocols have been around for a
long time. Common protocols include RS-232, RS-422 and
USB.
A more generic name for serial communication channels is
UART which stands for Universal Asynchronous Receiver
and Transmitter. Such systems are "Universal" because the
data format and transmission speeds are configurable. They

How does GPS work?

The Global Positioning System (GPS) is a satellite-based


navigation system, which uses a network of 24 satellites
and a ground-based receiver to obtain the position of
the receiver through a process called "trilateration." The
satellites orbit the earth once every 12 hours, and at least 4
satellites are visible to a receiver on earth at any given time.
The GPS signal from the satellite basically consists of a
timestamp of when the signal was generated. The receiver
compares this timestamp to when it actually received the
signal to determine the distance from the satellite. Once it
has this information from at least 3 satellites, the receiver
can triangulate a latitude/longitude coordinate. If the
receiver receives signals from at least 4 satellites, it can also
calculate its altitude.

GPS Receiver Protocol


Most consumer GPS receivers communicate using a
protocol called the NMEA-0183 protocol. This was created

Healthy Code
April - 2015

Identification

Example

Units

Description

Header

$GPGGA

UTC Time

170425.000

hhmmss.sss

17:04:25.000 UTC

Latitude
N/S Indicator

3407.8142
N

ddmm.mmmm
N or S

34 deg, 07.8142 min


North

Longitude

11803.1425

dddmm.mmmm

118 deg, 03.1425 min

E/W Indicator

E or W

Position Fix Indicator

West
0 = Fix not available, 1 = GPS Fix, 2
=Differential GPS Fix

Satellites Used

Number of satellites (0 to 14)

HDOP

1.40

Horizontal Dilution of Precision

Altitude

184.3

Altitude Unit

Geoidal Separation

-33.2

Geoidal Separation Unit

metres

Age of Differential
Correction

0000

seconds

Checksum

6F

Protocol Header - GPS Position Fix

Altitude above Mean Sea Level (MSL)


metres

NULL if not DGPS fix

End of message terminator

Table 1.0. Sentence description


by the National Marine Electronics Association, USA, and
is a general-purpose protocol for marine electronic devices
including echo sounders, sonar locators and GPS receivers.
NMEA-0183-compatible devices use a standard format
for communication. Communication is in the form of
"sentences". The following list describes the sentence:
Each sentence begins with the $ sign.
The sentence ends with an asterisk (*).
The asterisk (*) is followed by a 2-digit hexadecimal
checksum, followed by a carriage return and line feed
(<CR-LF>).
The $ sign, is followed by a 5-letter code.
The 5-letter code is split into two sections. The first
section called the "talker," followed by the data being
sent.
The talker identifies the type of device that is sending
the data. In the case of a GPS receiver, the talker value
is always GP.
The data is a 3-letter code that identifies the type of
data being sent. For example, GPS position fixes
always use GGA for the data type.

Healthy Code
April - 2015

The actual data is a comma-separated list of fields,


with the number of fields, and the content of each field,
being dependent on the data type being transmitted.
There is no comma between the last field and the *
character.
So, a GPS position fix looks like this:
$GPGGA,<some data>*<checksum><CR-LF>
The position fix (GGA) sentence consists of a total of 14 fields
between the protocol header ($GPGGA) and the checksum.
The sentence below is an actual GPS output from my test
program. Let us use it to define what each of the fields are.
$GPGGA,170425.000,3407.8142,N,11803.1425,W,2,5,
1.40,184.3,M,-33.2,M,0000,0000*6F
Table 1.0 describes the sentence in detail.

Setting up the UART on the RPi


By default, the UART ports on the RPi are reserved for
a serial console, and output console messages from the
operating system. This functionality needs to be disabled
before the UART ports can be used for serial communication
with other devices such as the GPS breakout board.

Configuring the UART


1. Remove any mention of ttyAMA0 from /boot/cmdline.
txt.
2. Comment out the line that respawns getty on
ttyAMA0.
3. Reboot the RPi.
Once you have done the above 3 steps, the RPi no longer
sends console messages to the UART ports, and they are
free to be used for serial communication between the RPi
and external devices.

import com.pi4j.io.serial.SerialPortException;
public class GpsTutorial {
public static void main(String args[]) throws
InterruptedException {
System.out.println("=== INITIALIZING
SERIAL " +
"COMMUNICATION ===");
final Serial gps = SerialFactory.
createInstance();
GpsListener gpsListener = new
GpsListener();
gps.addListener(gpsListener);

Connecting the Circuit

try {
gps.open(Serial.DEFAULT_COM_PORT, 9600);
for (; ; ) {
// Loop endlessly. That is our lot in life!
}
} catch (SerialPortException ex) {
System.out.println("*** SERIAL SETUP FAILED: "
+ ex.getMessage());
}
}

The schematic of the circuit to connect the RPi to the


Ultimate GPS Breakout board is given in Figure 1.0.

To set up serial communication, we first create an instance


of the Serial object:
final Serial gps = SerialFactory.createInstance();

We then register a listener object with the serial port that we


just created:
gps.addListener(gpsListener);

Figure 1.0. Circuit Schematic


The main point to note is that the transmit pin of the RPi
(normally labeled "TxD") is connected to the receive pin of
the board, and the receive pin of the RPi (normally labeled
"RxD") is connected to the transmit pin of the board.
The Code
Pi4J includes a package that abstracts serial communication
on the RPi. Rather than polling for data on the serial line,
the package allows interested methods to register a listener
for an event. The listener then gets called back when there
is data waiting on the serial port.
package org.pfactor;
import com.pi4j.io.serial.Serial;
import com.pi4j.io.serial.SerialFactory;

Finally, we loop endlessly while the listener handles any


data that was received over the serial port.

The Listener
As you can see from the listing of the main class, the
GpsListener class is where most of the work is done. Let's
examine how that works.
package org.pfactor;
import com.pi4j.io.serial.SerialDataEvent;
import com.pi4j.io.serial.SerialDataListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
public class GpsListener implements
SerialDataListener {

Healthy Code
April - 2015

private String rawData;


private String line;
@Override
public void dataReceived(SerialDataEvent
event) {
rawData = event.getData();
BufferedReader reader = new
BufferedReader(new
StringReader(rawData));
try {
// valid lines are terminated with CRLF. So,
// readLine() works great.
line = reader.readLine();
// We are interested in a GPS fix.
// Valid GGA lines start with $GPGGA and
// end with * followed by a hex checksum.
// So, some regex fun is warranted to filter
// out corrupted lines.
if (line.matches("^\\$GPGGA," +
"[\\S*,]{13}\\S*\\*\\
p{XDigit}+$")) {
System.out.println(line);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}

In order for the GpsListener class to be called back when the


RPi receives data on the serial port, it needs to implement
the SerialDataListener interface provided by Pi4J. There is
one method that needs to be implemented and that is the
dataReceived method. This method takes a single argument,
the SerialDataEvent, which provides information about the
data that was received.
The most relevant method in the SerialDataEvent class is
the getData() method, which returns a string that contains
the raw characters that were received by the serial port on
the RPi.

Some Java RegEx Fun


When we receive the data, we need to validate that the data
is complete, and syntactically correct. There are, obviously,
many ways of doing this. However, one of the least verbose
methods of doing so is to pattern-match the whole sentence
that we receive. Java provides a regular expression class
that enables pattern-matching.

Healthy Code
April - 2015

We invoke the pattern matcher through a line.matches(...)


call and provide the pattern that should be matched as the
argument to that method.
The pattern that we use is:
^\\$GPGGA,[\\S*,]{13}\\S*\\*\\p{XDigit}+$

Let us examine this regular expression in detail. Firstly,


note that the double backslashes (\\) are used to escape
the backslash character. In a Java String, a single backslash
character escapes the character immediately after. So, a
backslash-backslash (\\) combination delineates a single
backslash in the String.
From the earlier section, we know that an NMEA GPS
position fix sentence:
starts with a $GPGGA
contains 14 data fields that are comma-delimited
(except the last one)
ends with a 2-digit hexadecimal checksum that begins
with an asterisk (*)
In the regular expression above, the caret (^) symbol
represents the beginning of line. We then match the literal
characters $GPGGA, and since the dollar ($) symbol is a
special character in regular expression syntax (it represents
the end-of-line marker), we need to escape it by inserting
the double-backslash before it. So, that gives us:
^\\$GPGGA,

After this, the sentence consists of 13 comma-delimited


fields. The contents of each field are a sequence of nonwhitespace alphanumeric characters. Java regex provides
a simple pattern that can be used to represent such a
character, the \S pattern.
Each field consists of 0 or more such characters followed by
a comma. So, we represent that by the regex \S*, where the
asterisk represents "0 or more" of the preceding sequence
(i.e. the non-whitespace character).
The sentence consists of 13 such fields. That is represented
by the number 13 appended to the regex. This is expressed
as [\\S*,]{13}. Read this as "13 occurrences of a sequence
consisting of 0 or more non-whitespace characters, followed
by a comma."
So, our regex has the following up to this point:
^\\$GPGGA,[\\S*,]{13}

After this, there is one more non-whitespace field, followed


by an asterisk before the checksum. This can be expressed
as \\S*\\*. Note how the literal asterisk (which is a special
character in regex patterns) is escaped by a backslash.
The regex now looks like:
^\\$GPGGA,[\\S*,]{13}\\S*\\*

Finally, the checksum is a combination of one or more


hexadecimal digits. This can be expressed by the regex
pattern \p{XDigit}+ where \p{XDigit} represents a
hexadecimal digit, and the plus (+) asserts that there should
be "one or more" occurrences of that pattern.
Immediately after that, we should be reaching the end-ofline, which is represented by a $ symbol.
So, the final version of the regex is:
^\\$GPGGA,[\\S*,]{13}\\S*\\*\\p{XDigit}+$

The program above merely prints out all received GPS


sentences that match the above patter, i.e. any valid NMEA
GPS position fix sentence.

The Wrap-Up
This article demonstrates basic interfacing of the RPi with
a serial device - in this case, a GPS receiver. We examined
how Pi4J provides a simple event-driven mechanism to
process the received data, and a simple regular-expression
based pattern matcher to validate the received data.
Obviously, we could add significant functionality to
this simple application such as having a threadpool that
processes the GPS data, live plots to Google Maps, etc.

Charath Ranganathan is a technology


enthusiast, especially in embedded systems.
While he dislikes the term "Internet of Things"
he believes very strongly in a world where
networks of intelligent, distributed sensors
and actuators could improve the quality of life
for people. He is currently Vice President of
Engineering at Playtika - the worlds #1 social
casino gaming company. He is an instrumentrated pilot and spends his spare time
flying, both in the real world, and on flight
simulators. He loves to write and publishes a
blog (http://calpilot. wordpress.com). Charath
has an MS in Electrical Engineering from Texas
A&M University, and a BE in Electrical and
Electronics Engineering from the College of
Engineering, Guindy.

Pragmatic

Programmer Quote

Hopefully, something for next time...

The real danger is not that computers will begin to think like
men, but that men will begin to think like computers.

- Sydney J. Harris
There are three kinds of death in this world. Theres heart death,
theres brain death, and theres being off the network.

- Guy Almes
Healthy Code
April - 2015

Article

Ryan and Dhaval

Code
Jugalbandi
In 2013,Dhaval Dalalwas inspired byJugalbandi, an Indian classical music
form in which musicians have an improvised musical conversation, each using a
different instrument, while exploring a shared musical theme together akin to Jazz
in some ways. Dhaval thought, What if we could have a conversation about some
programming concepts in this way? Instead of musical instruments, what if we use
different programming languages?
Code
10 Healthy
April - 2015

This led to the first Code Jugalbandi between us. Code


Jugalbandi inspired and fuelled our learning by focusing
on dialogue and exploration. More languages in the
room meant more perspectives too. Exploring a paradigm
through many languages gave us a better map of the
territory than any single language could. Above all,
Code Jugalbandi was a playful way to learn together!

Creator and Listener

BRAMHA: How does this look in Clojure?

We met regularly with over a period of several months,


exploring some key issues related to Functional
Programming (FP). This culminated in a live Code Jugalbandi
at the Functional Conference in Bengaluru, 2014. During
the FP Code Jugalbandi, we explored nine themes, which
became melodies. Similar to the musical Jugalbandi, there
are two roles: creatorandlistener. We called the creator of
the melodyBramhaand the one who listens and responds
with a different instrument, Krishna. + In the last Code
Jugalbandi Article, we looked at the melody, the Currying
and Partial Function problem. This time we will look atDeStructuring and Pattern Matching.

KRISHNA: Most functional languages provide some level


ofde-structuring:

De-structuring
BRAMHA: In FP, we favour simple data structures over
classes, e.g. instead of a collection ofpeopleobjects, we might
have a collection of person tuples, and containing only the
fields were interested in:
//Tuple with 2 elements - name and age
type Person = (String, Int)
val p = ("alan", 30)

BRAMHA: and then we have some functions acting on


this persondatatype. Whatever well do with person, well
need code to get at the innards of thepersontuple.
def showPerson(p: Person) = p match {
case (name, age) =>
println(s"$name - $age")
}
showPerson(p) //alan - 30

(def a-person ["alan" 30])


(defn print-person [p]
(println (first p) " " (second p)))
(defn print-person2 [[name age]]
(println name " - " age))

KRISHNA: De-structuring gives you a shorthand way of


naming parts of a structure. If we were using a hash-map to
represent our person:
(def h-person {:name "alan"
:age 30 })
;; de-structuring hash-maps looks like this:
(defn print-person3 [{:keys [name age]}]
(println name " - " age))

KRISHNA: There are libraries that allow for even more


compact and sophisticated de-structuring syntax, but lets
leave it at that for de-structuring in Clojure.
BRAMHA: This is interesting, I am not aware of destructuring Maps in Scala, out-of-the-box. However, you can
de-structureLists,VectorsandStreamsin Scala. If Person was
a Vector like you showed in Clojure, I could do the following
val p = List("alan", 30)
def showPerson(p: List[Any]) = p match {
case List(name, age) => println(s"$name - $age")
}
showPerson(p) //alan - 30

Healthy Code
April - 2015

11

Pattern Matching
BRAMHA: So far weve just talked about picking apart the
structure of things, but we can generalize de-structuring into
something even more powerful: Pattern Matching(not to be
confused with string pattern matching)
BRAMHA: Lets explore this by example. Say we have a
journal with some fields.
case class Journal(op: String, amt: Double)

BRAMHA: Lets say, we want to save the journal entries


likedebitandcredit.
def save(j: Journal) = j match {
case Journal("debit" , _) => println("Debit")
case Journal("credit", _) => println("Credit")
case Journal(_
, _) => println("Unknown")
}
save(Journal("debit",
23)) //Debit
save(Journal("credit",
10)) //Credit
save(Journal("transfer", 50)) //Unknown

KRISHNA: Does the underscore "_" here mean wildcard?


BRAMHA: Yes, it means that we dont care about it and is
used as a placeholder during pattern matching.
BRAMHA: We get pattern matching in Scala for free by
usingcaseclasses. Scala compiler implicitly adds a companion
object for thecaseclass and provides an implementation for
theapply()method(basically factory method to create the
classes) and anunapply()method to get the constituents
back.
KRISHNA: Yes, I see, we want to pick only those journals
where the first value isdebitorcredit. So, you cant do this
kind of thing in Clojure.

Pattern Matching - Clojure


KRISHNA: Idiomatic Clojure doesnt have "Pattern
Matching" in that way. But, there is a way to achieve this
(there are libraries that implement sophisticated Pattern
Matching)
(def debit-journal [:debit 25.4])
(def credit-journal [:credit 26.5])

Then one can use multi-methods in Clojure like this.


(defmulti save-j (fn [j] (first j)))
(defmethod save-j :debit [j]
(println "DEBIT: " j))
(defmethod save-j :credit [j]
(println "CREDIT: " j))

Code
12 Healthy
April - 2015

(save-j debit-journal)
(save-j credit-journal)

KRISHNA: Multi-methods allow dispatching on the


arguments in a very flexible way.

Pattern Matching - Haskell


KRISHNA: In Haskell, this would have been expressed
much more directly.
data Journal = Journal String Float
save_j :: Journal -> IO()
save_j (Journal "debit" _ _)
= print ("Debit")
save_j (Journal "credit" _ _)
= print ("Credit")
save_j (Journal _
_ _)
= print ("Unknown")
save_j (Journal "debit"
20.0) Debit
save_j (Journal "credit"
100.0) Credit
save_j (Journal "transfer" 50.0) Unknown

KRISHNA: So, we use pattern matching when we define


a function, that is, embed pattern matching in function
definitions. However, you can also do casedistinctions
explicitly, similar to Scala.
save_j :: Journal -> IO()
save_j jrnl = case jrnl of
Journal "debit" _
-> print ("Debit")
Journal "credit" _
-> print ("Credit")
Journal _
_
-> print ("Unknown")

KRISHNA: In Haskell, we can pattern match on tuples as


well.
showPerson :: (String, Int) -> IO()
showPerson (name, age)
= print (name ++ " - " ++ (show age))
showPerson ("alan", 30)

KRISHNA: In Haskell, pattern matching is a deep part of


the language and we have just scratched the surface here.

Reflections
KRISHNA: There is a difference between De-structuring
and Pattern Matching. In pattern matching, were not
only matching on relative position of elements in the data
structure, were trying to dispatch to different functions
based on a value inside the data structure! This dispatch is
a kind of conditional construct, while with de-structuring
there is nothing conditional about it.

BRAMHA: In Clojure, we saw basic de-structuring, and


then more sophisticated pattern matching made possible
by Multi-method dispatch. In Scala and Haskell, destructuring and pattern matching are unified using
thecaseexpressions.

Pragmatic

Programmer Quote

KRISHNA: Pattern matching with all the case distinctions is


like generalization ofswitchstatements in Java/C#, where we
used Ints, Enums etc., but we can now use class hierarchies
or data types. It so happens that the syntax is different.

Ryan is a software developer,


coach and advisor, based in Cape
Town.He has been working with
code for more than 15 years.Ryan
assists individuals and teams
to manage the evolution and
complexity of their software
systems.Ryan is a passionate
learner and enjoys facilitating
learning inothers.

Dhaval a hands-on developer and


mentor, believes that software
development is first an art and
then a craft. For him writing
software brings his creativity
to the fore. His interests are in
architecting applications ground
up, estabilishing environments,
transitioning
and
orienting
teams to Agile way of working
by embedding himself within
teams.
You can follow them on Twitter @
CodeJugalbandi

In the old days, people


robbed stagecoaches and
knocked off armored
trucks. Now theyre
knocking off servers.
- Richard Power

The inside of a computer


is as dumb as hell but it
goes like mad!
- Richard Feynman

The question of whether


computers can think is
just like the question
of whether submarines
can swim.
- Edsger W. Dijkstra

Healthy Code
April - 2015

13

Article

Naresha

Groovy

Working with Collections-1

Code
14 Healthy
April - 2015

Groovy is a dynamic language on Java platform. It provides


extensive support for working with collection, with native support
for list and map literals. In this article, we will explore the options
for working with collections effectively. We discuss various
collection types, internal iterators, map reduce methods, method
chaining to using Java 8 streams API. Also, we would see how
Java collections get that extra power when they enter the Groovy
world.

Working with index based collections


Creating collection instances
Groovy provides native support for list types.
def numbers = [3, 2, 4, 1]
def developers = ['Raj', 'Reena', 'John']
assert numbers.class == java.util.ArrayList
assert developers.class == ArrayList
def emptyList = []

In the above example, we created a numbersvariable and


assigned a list value to it. In Groovy, lists are created using[]
syntax. Theassertstatements prove that by default, Groovy
creates instances of java.util.ArrayList. If you want to work
with traditionalArray type, the following code shows you
how to achieve it.
def numbersArray = numbers as int[]
assert numbersArray.class == int[]
def namesArray = ['Raj', 'Reena', 'John'] as
String[]
assert namesArray.class == String[]

The as keyword can also be used in situations, where you


want to create other collection types instead of ArrayList,
such asSetor other alternateList implementations, such
asLinkedList.
def setOfNumbers = [1, 2, 3, 1] as Set
println setOfNumbers // [1, 2, 3]
assert setOfNumbers.class == LinkedHashSet
def numbersLinkedList = numbers as LinkedList
assert numbersLinkedList.class == LinkedList

Working with elements


The following code snippet shows how to add elements,
remove elements and access an element of a collection.

def numbers = [1, 2, 3]


numbers.add(4)
println numbers // [1, 2, 3, 4]
numbers << 5
println numbers // [1, 2, 3, 4, 5]
println numbers.get(1) // 2
println numbers[1] // 2
println numbers.remove(1) // 2 - removes item at

index 1
println numbers // [1, 3, 4, 5]

Groovy supports adding elements to a collection


using<<operator. Similarly one can use[]operator to access
the element at a specified index.

Iterating through elements


Groovy provides internal iterators each() and eachWithIndex()
for collections.
def numbers = [3, 2, 4,
numbers.each{ number ->
println number
}
numbers.eachWithIndex {
println "${index + 1}.
}

1]

number, index ->


$number"

The methodeachaccepts a closure with single argument. For


every element in the collection, the closure will be invoked
with the current element as the argument. In the above
example, I have used an anonymous closure. However you
could use the closure that you have already created too.
def printNumber = { number ->
println number
}
def printNumberWithIndex = { number, index ->
println "${index + 1}. $number"
}

Healthy Code
April - 2015

15

numbers.each(printNumber) numbers.eachWithIndex

(printNumberWithIndex)

Since thefindmethod takes a closure an the argument, we


need not restrict ourselves to equality checks.

We have already realized that Groovy uses Java collections


API under the hood. In the above example, numbersis an
instance ofjava.util.ArrayList. However, ArrayList class does
not have methodseachandeachWithIndex defined. Groovy
enriches Java classes with additional methods for the
convenience of developers.

def numbers = [2, 3, 1, 4]


def even = { it % 2 == 0}
def greaterThan2 = { it > 2 }
println numbers.find(even) // 2
println numbers.find(greaterThan2) // 3

Merging collections
Javas Collection interface declares a method addAll, which
accepts aCollectionobject as an argument. Groovy improves
on this by providing three additional flavours of addAll,
which accept an instance ofjava.lang.Iterable,java.util.Iterator,
and array of objectz respectively.
def numbers = [1, 2, 3]
numbers.addAll([4,5])
println numbers // [1, 2, 3, 4, 5]
def moreNumbers = [6, 7] as Integer[]
numbers.addAll(moreNumbers)
println numbers // [1, 2, 3, 4, 5, 6, 7]

In the above example, the original list is getting modified,


which might not be always desirable. In such cases, you
could write your code as follows.
def list1 = [1, 2, 3]
def list2 = [4, 5, 6]
def combined = list1 + list2
println list1
println list2
println combined

Another interesting aspect of +operator is that you could


also use this to add an element to a list, without altering the
original list.
def original = [1, 2, 3]
def newList = original + 4
println newList // [1, 2, 3, 4]
println original // [1, 2, 3

Groovy also provides-operator, which can be used to create


a collection with few elements removed from the original
collection.

Search items in a collection


Often we need to check if our collection contains a specific
element. Groovy provides some convenience methods
likefindandfindAll. Let us go ahead and explore them.
def numbers = [2, 3, 1, 4]
println numbers.find({ it == 1}) // 1
println numbers.find({ it == 10}) // null

Code
16 Healthy
April - 2015

Note that here,findmethod returned the first element from


the list that matched the criterion. If you want to find all the
matching elements, usefindAllmethod.
println numbers.findAll(even) // [2, 4]
println numbers.findAll(greaterThan2) // [3, 4]

Map operations
Groovy provides a method namedcollect for performing
map operations. The collect method applies the specified
transformation operation on each of the items in the
collection and produces a new collection.
def numbers = [3, 2, 1, 4]
println numbers.collect { it + 1 } // [4, 3, 2,
5]
def multiplyBy2 = { number ->

number * 2
}
println numbers.collect(multiplyBy2)
// [6, 4, 2, 8]

Another common use case for collectmethod is when you


want to obtain a collection of property values from the
collection of objects. For example, you might want get the
list of names from a list of Person objects.
class Person{

String name

int age
}
def people = [

new Person(name: 'Raj', age: 30),

new Person(name:'Reema', age: 25),

new Person(name: 'Mark', age: 40)
]
println people.collect {

it. name
} // [Raj, Reema, Mark]

Groovy provides a syntactic sugar for performing such


operations through its spread operator*.
println people*.name
The collect method by default returns a list. You may not
want this all the time. Consider the following example.

def numbers = [ -2, -1, 1, 2] as Set


println numbers.collect { it * it } // [4, 1, 1, 4]

Here,numbersis aSetand if we want the result to be aSettoo,


then we are in trouble. Because the resulting set has fewer
elements (since a Set does not contain duplicate elements).
Groovy provides another flavour of collect method, which
accepts a Collection in addition to a closure. We could apply
it as follows.
println numbers.collect(new HashSet()) { it * it }
// [1, 4]
// OR println numbers.collect([] as Set) { it * it
} // [4, 1]

Since we have passed an emptyHashSet object to collect,


the transformed values are added to that object instead of
creating a newListobject.

Reduce Operations
Groovy supports the most common reduce operations such
assum,min,maxout of the box. Let us see them in action.
def numbers = [3, 2, 1, 4]
println numbers.sum() // 10
println numbers.min() // 1
println numbers.max() // 4

join is another common reduce operation, which is often


helpful is deriving comma separated values from a collection.
def developers = ['Raj', 'Reena', 'John']
println developers.join(", ") // Raj, Reena, John

specifying the initial value as 1, but that would not make


sense as default value for product, when no elements are
present. So ensuring collection isnt empty seems like the
right choice. Groovy collections have a methodany, to check
if the collection has at least one element that satisfies the
specified criterion.
def numbers = [3, 2, 1, 4]
println numbers.any { it > 3 } // true
println numbers.any { it < 0 } // false

Similarly, every method checks if all the elements in a


collection satisfy the specified criterion.
println numbers.every { it > 0 } // true
println numbers.every { it % 2 == 0 } // false

Stack operations
Groovy providespushandpopmethods on a List out of the
box.
def numbers = []
numbers.push(10)
numbers.push(20)
println numbers // [10, 20]
println numbers.pop() // 20
println numbers // [10]

Working with Maps


Creating a map
Groovy has native support for maps too. Following code
examples illustrate how to create maps.

No language can provide all the possible reduce operations


out of the box. But a simpler way to implement custom reduce
operations is appreciated by the developer community.
Groovy providesinject method, which is popular as fold
left in many languages. Let us implement sumoperation
using inject method. Also let us define a custom reduce
operationproduct.

def emptyMap = [:]


assert emptyMap.getClass() == java.util.LinkedHashMap
def capitals = [India: 'New Delhi', France: 'Paris']
assert capitals.getClass() == java.util.LinkedHashMap

println numbers.inject(0){result, number ->



result + number
}
// 10
def product = { result, number ->

result * number
}
println numbers.inject(product) // 24

Accessing elements

While implementing sum, we have provided a default value


0. So even if numbers was an empty collection, we would
have got the result 0. However while implementing product,
we did not specify an initial value and hence collection
cannot be empty here. We can overcome this problem by

Note that when you specify the keys, you dont have to
enclose them in quotes.

println capitals.get('India')
println capitals['India']
println capitals.India

You can access value corresponding to a key using either


subscript notation or using'.'notation.

Add elements
capitals.put('Nepal', 'Kathmandu')
capitals['Singapore'] = 'Singapore'
capitals.UAE = 'Abu Dhabi'

Healthy Code
April - 2015

17

Map Iteration

Healthy Code

Similar to lists, Groovy provideseach method on maps.


Interestingly it can be used in two ways.

April 2015
Vol 2 | Issue 1

capitals.each{ entry ->



println "${entry.key} - ${entry.value}"
}
capitals.each { key, value ->

println "$key -> $value"
}

In the first example, the closure takes one argument,


while in the second example, closure takes two
arguments. each method checks the number of arguments
the closure can take and accordingly sends the data to that
closure. If you provide a closure that accepts single argument,
it would be called withMap.Entry; otherwise closure is called
withkeyandvalueas two distinct arguments.

Publisher:

T. Sivasubramanian
Editor:

S. Prabhu
Production:

New Horizon Media Private Limited


Proof Reader:

Shweta Gandhi

Summary

Publication Address:

In this article we discussed how to work with collections


like lists and maps. We explore various operations on these
collections. Groovy gives you an easy-to-use syntax that
makes working with collections a breeze.

11/6, First Floor,


Fourth Street,
Padmanabha Nagar,

Adyar, Chennai - 600020

Printer: Sakthi Scanners (P) Ltd


7, Dams Road, Chindadripet,
Chennai - 600002.
Contact Phone Number: 044-42337379
Email:
siva@healthycodemagazine.com
Web Site:
http://healthycodemagazine.com
Price: Rs. 150 /-

Naresha works as Chief Technologist at


Channel Bridge Software Labs and has
more than eight years of experience. He is
passionate about learning new technologies
and most of his current works are on Groovy
and JavaScript. Naresha is also an organizer of
the Bangalore Groovy Grails Meetup.
Email:naresha.k@gmail.com
Twitter: @naresha_k
Code
18 Healthy
April - 2015

Disclaimer:
The articles and contents of the Healthy Code magazine
are sourced directly from the authors with their
permission. Healthy Code doesnt assume responsibility
for violation of any copyright issues by an author in
their respective article. We have made sure to the best
of our knowledge that the articles and code presented
here are without any errors. However, we cant be held
liable for any damage or loss that may arise from using
these.
- Publisher

Healthy Code
April - 2015

19

Article

Debashish Ghosh

Dependency
Injection
The Functional Way

Code
20 Healthy
April - 2015

There are a number of ways in which we can implement


dependency injection when we develop domain models.
Frameworks likeSpring[1] orGuice[2] are the two most
popular ways of doing dependency injection in Java. These
frameworks allow you to declare the dependencies upfront
as part of the configuration of your module. When you
instantiate the module these dependencies get wired up and
appropriate instances get supplied to the module. In this
article, we discuss a framework-less approach of solving this
problem from the perspective of a functional programming
language.

Dependency Injection
Separation of concerns is one of the primary goals in
software engineering in general, and modularization of
software, in particular. When we develop a piece of software,
we try to organize the various functionalities into modules.
Each module represents a coherent set of behaviours of the
domain that the software is supposed to model. A module
is composed of a number of artefacts. Some of the artefacts
are intrinsic parts of the module whose lifetimes need to be
controlled entirely within the module itself. But very often
a module may need to interact with some components or
services whose lifetimes are controlled elsewhere. For
example, when the billing module of your domain model
has to interact with a payment gateway service, theres no
way you can control the lifecycle of that service from within
your module.
Its, of course, a recommended approach to keep such
dependencies as decoupled as possible from the core
modules of your application. Dependency injection is a
technique thats often used to achieve such decoupling. The
basic idea is that such dependencies are kept as part of the
environment instead of having them as part of the module
itself.
As has been said of OO design patterns[3], dependency
injection is yet another pattern thats subsumed within the

features that functional programming offers. In the course


of this article, we will see that dependency injection in a
language that offers higher order functions is just another
idiom of the language itself. I will use Scala [5] as the
implementation language and will assume basic familiarity
with the features of the language.

A Domain Service and a Repository


Lets take an example from a domain modelling exercise
where we need to manage dependencies between two
artefacts. The lifecycle of one artefact is not controlled by
the other. Adomain service[4] is an artefact that abstracts
coarse level behaviours of a domain model. Domain
services are mostly structured around modules where we
put related domain behaviours as computational units.
Consider a personal banking system with one of the domain
services offering account management functionalities for its
customers. Listing 1.0 gives an example of such a domain
service defined in Scala. Note we use traits for defining
a Scala module and have the contracts for typical domain
behaviours like opening and closing of accounts, debits,
credits and balance check of client accounts. Each of the
functions return aTryto account for the failures that we may
have for each of them.
trait AccountService {
def open(no: String, name: String, openingDate:
Option[Date]): Try[Account]

Healthy Code
April - 2015

21

def close(no: String, closeDate: Option[Date]):


Try[Account]
def debit(no: String, amount: Amount): Try[Account]
def credit(no: String, amount: Amount):
Try[Account]
def balance(no: String): Try[Balance]
}

Listing 1.0: A Domain Service for Customer Account


Management
One of the issues that we have not yet addressed in the
above design is how each of the service methods will interact
with the underlying database to manage such account
information. One option is to have the entire database
interaction within each method. But as good practices of
modularization suggests, this is an anti-pattern and will lead
to serious coupling of services with the underlying persistent
store. This approach also breaks transaction semantics, as
you need to have a separate database connection for every
method.
Lets use the recommended approach of the Repository
Pattern as suggested in [4]. A repository provides an
interface for aggregates to interact with the underlying
persistent store. An aggregate [4] is a complete coherent
domain object that may consist of entities and value objects.
A domain object likeAccountcan have multiple entities or
value objects as part of its implementation. We can define
anAccountaggregate that offers a single point interface and
a transactionally consistent view of the entire domain object
to the user.
Repositories are where aggregates live though they may
not be in the same form or shape. In the above example,
an account repository will be the storehouse of all account
aggregates. Using the service methods you can store accounts
in the repository, update them and also query them, based
on user defined criteria. With this knowledge, we can have
the following contract for anAccountRepositoryin listing 2.0.
trait AccountRepository {
def query(accountNo: String): Try[Option[Account]]
def store(a: Account): Try[Account]
def balance(accountNo: String): Try[Balance]
def openedOn(date: Date): Try[Seq[Account]]
//..
}

Listing 2.0: Account Repository

Injecting the Repository A Nave Approach


A repository has a different lifecycle than a domain
service. The simplest way to inject the dependency
ofAccountRepositoryintoAccountServicewill be to make the

Code
22 Healthy
April - 2015

repository an argument to each of the service methods. Then


the user can pass in the repository instance while invoking
any of the service methods. This leads to the following
changed definition of the AccountServicemodule in Listing
3.0.
trait AccountService {
def open(no: String, name: String, openingDate:
Option[Date],
r: AccountRepository): Try[Account]
def close(no: String, closeDate: Option[Date], r:
AccountRepository): Try[Account]
def debit(no: String, amount: Amount,r:
AccountRepository): Try[Account]
def credit(no: String, amount: Amount, r:
AccountRepository): Try[Account]
def balance(no: String, r: AccountRepository):
Try[Balance]
}

Listing 3.0: Service with Repository injected as arguments


While this works from the dependency injection point
of view, this approach fails from the compositionality
perspective of API design. Consider the following example
where we would like to perform a sequence of operations on
an account. We call this operationopand have the following
implementation in listing 4.0 with an instance of the
repository passed to every service method that we invoke.
object App extends AccountService {
def op(no: String, aRepo: AccountRepository) =
for {
_ <- credit(no, BigDecimal(100), aRepo)
_ <- credit(no, BigDecimal(300), aRepo)
_ <- debit(no, BigDecimal(160), aRepo)
b <- balance(no, aRepo)
} yield b
}

Listing 4: Composition of abstractions

Here are some issues with the above


implementation:
Verbosity: The user of the API needs to pass the
repository as a mandatory argument to the method.
This is okay when invoking one method of the service,
but clearly looks verbose and boilerplate in the scenario
where we are composing a larger abstraction out of
multiple sequenced invocations.
Coupling: For every invocation of a service method we
pass the instance of the repository, which means that
the repository is strongly coupled with the context of
the API. But in reality, a repository forms the context
of the environment its like a store thats there for

the service method to access and do the required


operations.
Lack of compositionality: Ideally when we compose
functions we would like to defer the injection of
dependencies until the end of the chain. Besides
reducing the verbosity, this also leads to better
compositionality of APIs.

Want compositionality? Curry it!


The solution to all the three issues we saw above is to make the
repository a curried argument to the service methods. When
we sequence the invocations through the for-comprehension
we can thread the repository through the computation and
defer the injection till the final evaluation of the composed
function. This way we dont lose anything on the injection
part and gain a lot on the compositionality of our APIs.
Lets use this technique to our AccountServicemodule and
see how we benefit from it. First we change the algebra of
the methods in Listing 5.0 for AccountServiceto make the
repository a curried argument.
trait AccountService {
def open(no: String, name: String, openingDate:
Option[Date]):
AccountRepository => Try[Account]
def close(no: String, closeDate: Option[Date])
AccountRepository => Try[Account]
def
debit(no:
String,
amount:
Amount):
AccountRepository => Try[Account]
def
credit(no:
String,
amount:
Amount):
AccountRepository => Try[Account]
def balance(no: String): AccountRepository =>
Try[Balance]
}

Listing 5.0: Curry it


Now consider what happens when we write code like the
following:
object App {
import AccountService._
def op(no: String) = for {
_ <- credit(no, BigDecimal(100))
_ <- credit(no, BigDecimal(300))
_ <- debit(no, BigDecimal(160))
b <- balance(no)
}
yield b
}

Now we are almost there. The service methods return


aFunction1and we need to chain this in sequence when we
compose the methods in the for-comprehension above. But for
that, we need to have the power offlatMapwithinFunction1,

which we dont have in the Scala standard library. But we can


do that by transformingFunction1to a monad. In case you
are interested in the details of this implementation, the online
code repository [6] that accompanies this article contains the
whole of it. Assuming we have flatMappedFunction1, what
do you think will the above computation op return when we
invoke the function?
scala> import App._ import App._
scala> op("a-123") res0: AccountRepository scala.
util.Try[Balance] = <function1>

Note that the complete expression has not yet been


evaluated its just the composed function that gets
returned. Now we have to pass a repository explicitly to
the returned value to evaluate the entire computation. Or
we can compose it with any other computation that returns
aFunction1[AccountRepository, _]and defer the evaluation till
we have the whole computation pipeline built. This latter
approach is what we call building abstractions through
incremental composition, a technique used as a norm in
functional programming. And this is a big improvement
over the approach where we passed the repository as a
parameter to the API.
But what if we want to composeopwith some other monadic
computation thats not aFunction1? It can be some other effect
likeListorOption. Our current approach doesnt address this
since we dont have the glue necessary to compose multiple
monadic effects. And thats what we discuss in the next
section.

More Compositionality with the Reader


Monad
The basic purpose of the reader monad is to provide an
environment to the computation from where it can read
stuff. And the technique that we discussed in the last section
does it quite nicely. For all practical purposes you can use
the earlier implementation technique if you need a reader
monad for your repository access.
However, in functional programming, its a very common
practice to compose and build computation pipelines and
defer evaluation till the end. The computation op in the
earlier section is aFunction1that may need to be composed
with a monadic pipeline containing aListor anOption. We
need monad transformers for this kind of composition. But
Function1 doesnt have any transformer that can be used to
stack up our computation into a monadic pipeline. We solve
this by introducing another level of indirection. We wrap
Function1 into another abstraction that we call Reader. And
Reader can have a transformerReader, which can be used to
compose other monads with the Reader.

Healthy Code
April - 2015

23

case class Reader[R, A](run: R => A)

As we just said, its just a wrapper for a function that runs


on an environment R to generate an A. In our use case R is
the repository from where we will read to get an A. The only
thing we need to do now is implement map and flatMap in
order to enable transformation and sequencing of reads in a
pipeline. Heres the Reader Monad in Listing 6.0 ready to be
composed with our domain service APIs.
case class Reader[R, A](run: R => A) {
def map[B](f: A => B): Reader[R, B] =
Reader(r => f(run(r)))
def flatMap[B](f: A => Reader[R, B]): Reader[R,
B] =
Reader(r => f(run(r)).run(r))
}

Listing 6.0: The Reader Monad


And we have the service APIs in Listing 7.0 where we update
the algebra to reflect this change. Each of the service methods
now returns aReaderinstead ofFunction1.
trait AccountService {
def open(no: String, name: String, openingDate: Opt
ion[Date]):Reader[AccountRepository, Try[Account]]
def close(no: String, closeDate: Option[Date]):
Reader[AccountRepository, Try[Account]]
def
debit(no:
String,
amount:
Amount):
Reader[AccountRepository, Try[Account]]
def
credit(no:
String,
amount:
Amount):
Reader[AccountRepository, Try[Account]]
def balance(no: String): Reader[AccountRepository,
Try[Balance]]
}

Listing 7.0: The module API with Reader integration


With the Reader in place, the client code doesnt change at
all from what we had with Function 1 as the reader monad.
The additional abstraction that the Reader gives helps us
integrate our computation with monads downstream using
monad transformers. I will not discuss the details of how this
is done in this article. But I am sure you get the idea using
the Reader monad we not only get dependency injection
for free, but also can make our abstractions compositional
with other monadic computations in the pipeline. As a
final step, you invoke the run function of the Reader and
pass the environment, which in our case is a concrete
implementation of AccountRepository. Runningop(a123).
run(AccountRepository) will give you the balance of
the account at the end of the sequence of deposits and
withdrawals.
Using this policy of compose upfront, evaluate later also

Code
24 Healthy
April - 2015

makes testing quite easy. Since you defer the injection of the
actual repository just before the evaluation stage, you can
supply an alternate implementation for unit testing. May
be your actual repository is based on an enterprise backend
database. But you can swap it out and plug in a simple inmemory implementation for unit testing your services.

References
The Spring Framework -http://projects.spring.io/springframework/
Guice -https://github.com/google/guice
Design Pattern in Dynamic Languages - http://norvig.
com/design-patterns/
Evans Eric, 2003. Domain Driven Design: Tackling
Complexity in the Heart of Software, Addison Wesley.
Scala http://www.scala-lang.org
The complete source code for this articles examples can
be found inhttps://github.com/debasishg/di-article

DebasishGhoshis an independent
software consultant specializing in
functional programming, domain-specific
languages and BigData technologies. A
senior member of ACM and a speaker
in conferences like QCon, CodeMeshIO
and FunctionalConf, Debasish is the
author of DSLs In Action (http://www.
manning.com/ghosh) and is working
on his second book Functional and
Reactive Domain Modeling (http://
manning.com/ghosh2). Debasish pens his
thoughts on programming and related
technologies in his blogRuminations of a
Programmer (http://debasishg.blogspot.
com) and can be reached atdghosh@acm.
org.

Healthy Code
April - 2015

25

Interview
with

Viral Shah
Co-founder of the Julia Language

Hi Viral, you have two very interesting projects


in your profile The Julia Language and the UID
project. Can you formally introduce yourself to
our readers?
You would have seen my LinkedIn profile (http://
in.linkedin.com/in/viralbshah), which should have
given you an idea of what I have been doing all these
years. My interest in scientific computing goes back
to the college days in India, and after my computer
engineering, I got my PhD in Computer Science, where
I worked on building a parallel implementation of
Matlab called Star-P.
A startup, Interactive SuperComputing tried to
commercialize Star-P, and was bought by Microsoft.
For a number of reasons, the product never saw light
of day.
So when the four of us came together: Jeff Bezanson,
Stefan Karpinski, Alan Edelman and I, we didnt want to
do another project that would end up being controlled
or possibly killed by someone. We wanted it to be open
source from day one. Personally, impact on society was
a lot more important to me.
Thats how we started Julia about 5 years back. After
the start-up was taken over by Microsoft, I moved back
to India. We started talking about Julia by email. In
fact Stefan had not even met Jeff and Alan for the first
year of our collaboration. In the first few years of the
project, while I hacked on Julia at night, the days were
spent working on Aadhaar.
It has been a wonderful ride so far.
Lets go back to your interests scientific
computing. Can you elaborate on that?
There are many terms like scientific computing,
numerical computing, technical computing etc.
Traditionally, all these terms referred to just computing
with numbers. This includes doing stuff with floating
point numbers in applications like weather prediction
or climate simulation or oil and gas exploration, or
maybe in the aerospace or dynamical systems or circuit
simulations. Those kind of things come under your
traditional computing.
But in the last 10 years, with the explosion of the
web, and other scientific breakthroughs more and
more things have come under the ambit of scientific
computing. Things like processing text, application
of graph algorithms and combinatorial algorithms,
analyzing genetic sequences are all examples of this
trend.
If you think about economics or psychology, people
never thought these from the computing perspective

Code
26 Healthy
April - 2015

10 or 20 years ago. Even biologists analysing genetic


data were not traditional users of scientific computing.
You never think of them as someone working with
computers. For example, one of my favourite projects
that I have done over the last few years is Circuitscape,
which is in Python (yes, written in pre-Julia days) and
is widely used in landscape ecology for modeling
conservation corridors and gene dispersal.
Everyone wants different things from their
programming environment. Someone wants to run the
code fast. Someone wants to write the code fast. There
are so many things that play on a developers mind.

So, looks like everything finally boils down to


Julia. Your articles on Julia use the word Greedy.
It is very interesting. Can you tell us about that?
We were and continue to be greedy. We wanted Julia to
perform like C, easy and general purpose like Python
and expressive like R or Matlab. This is a chord that
has struck with many, and is the reason why the Julia
community has grown so rapidly in the last three years.

One of the things we can find out is your love for


the C language. Tell us more about it.
All the co-inventors of Julia language share this passion.
The Julia runtime is written in C with the LLVM related
parts in C++. I actually started programming in BASIC
as that was part of my school curriculum, teaching
myself physics by coding up Newtons laws as I learnt
then. After that I did a bit of PASCAL before eventually
discovering C and never looking back.
Surprisingly, my thesis was on parallel processing
in Matlab. C is what the programmers like to work
with. But it is not a productive language for scientific
computing and domain scientists even find it too
esoteric.
During my PhD days, being part of the Computational
Sciences and Engineering program at UC Santa Barbara,
I got a feel for the abstractions that scientists want. The
next round of scientific innovations is going to come
from domain scientists who can program, and not from
computer scientists.
Our role as computer scientists is to build the right level
of abstractions that others can leverage. That is where
the innovation has to happen in computer science. This
is how I believe we can bring about progress in society.

Photo credit: A picture of the Julia creators with Prof.


Kahan taken by Mrs. Kahan at their home in Berkeley

Before getting in to the language, what is the


reason behind calling it Julia?
We have never gone on record why it is called Julia
because there is no real reason.
In fact, Jeff, one of the co-inventors was working in a
project that he kept to himself which was called Julia.
When we started doing this, the first thing Jeff did was
a parser and a little run time, and we wondered, whats
a good name. Jeff told us that he wrote a project called
Julia and we all loved it. Thats how it got its name.

Well said. It is the computer engineers who have


to give the facility to the rest.
You have to understand the other side. It is easiest to
write another language for computer scientists. The
domain scientist is not interested in programming. She
uses programming as a means to solve her scientific
problem.
We believe that until Julia, one had to pick between
productivity and performance. Either get productivity
with Matlab/R/Python, or get performance with C++/
Fortran/Java. With Julias design, we believe that we
can get both, and I personally think that is incredibly
powerful and has the potential to unleash a new level
of scientific innovation.

Ref: http://julialang.org/
Did you start Julia as a fun project or did you have
a clear agenda in mind?
It is a mixture of both.
The motivation did come from having used all other
things that were incredibly annoying and not living up
to the mark. Its like, why cant I have good productivity

Healthy Code
April - 2015

27

and good performance in the same package? Today in


Julia, you can almost get the same performance like
FORTRAN and C and also higher levels of productivity
like your MATLAB or Python.
It was always frustrating doing any numerical work.
Stefan and I went to the same university, University of
California, Santa Barbara. We had been talking about
this for a couple of years, struggling years writing code,
struggling with MATLAB, doing analysis with R, and
writing PERL scripts to clean up data and other stuff.
We thought, why cant we just have one thing? We felt
it was time for something new. Beyond that motivation
we didnt have anything else. The four of us then
started having fun imagining and thinking about what
this thing could be.
We had no idea where things were going to go. We just
started building something that we liked ourselves. For
almost two years, there was just the three of us. We
didnt have even a single user. We then had Why Julia
the Greedy Blog Post, and we got a million hits on
that day. Suddenly, it became a live and kicking project
growing ever since.
Julia is a dynamic language and the general
industry perception is that dynamic languages
perform slowly. So the term fast dynamic language
is like an oxymoron. What makes Julia a dynamic
language but still a fast one?

5. Careful design of the language and standard library


to be amenable to type analysis
6. Metaprogramming
generation, and

for

sophisticated

code

7. Just-In-Time (JIT) compilation using the Low-level


Virtual Machine (LLVM) compiler framework,
which is also used by a number of other compilers
such as Clang and Apples Swift.
Is there any other language that has multipledispatch?
Yes there are many, Dylan being one that took it
seriously. Take a typical numerical example: you want
to add two numbers. The first one is a 64-bit integer
and the second one is a 32-bit floating point number.
What needs to happen is very different compared to
adding, say, two 64-bit integers. Usually, all this is
hard-coded into the guts of the language, but not so in
Julia. Multiple-dispatch makes it possible for functions
to be picked based on the types of all inputs. Consider:
foo(x::Int, y::Int, z::Int) = x+y+z
foo(x::DateTime, y::String, z::String) = println(x, y*z)
When called as `foo(2,3,4)`, it returns the value 9, but
when called as `foo(now(), Hello, , World)`, it
prints 2015-03-12T16:53:34 Hello, World.

There is no argument about the point that dynamic


languages are more productive. Yes, the industrys
perception is that dynamic languages are slow. The
truth is that scientists dont want to be bothered about
the pesky details like types and the finer details of
programming. They want the right abstractions.

With multiple dispatch, the compiler picks the sharpest


function definition among all that are present, and
specializes the generated code for that definition.
This simple idea is what is pervasive throughout
Julia libraries and is one of the things that allows the
compiler to produce high performance code.

So the question is, how do you bring in performance?


We designed Julia in such a way that we could get high
performance right out of the box. It is performance by
design. I encourage anyone curious about these details
to read our paper Julia: A fresh approach to numerical
computing (http://arxiv.org/abs/1411.1607). Julias
performance is a result of carefully chosen features
that work well together. Heres a list of some of those
features.

Is Julia a functional language? Did you design it


taking it into account the multicore environment?

1. An expressive parametric type system, allowing


optional type annotations
2. A dynamic dataflow type inference algorithm
allowing types of most expressions to be inferred
3. Multiple dispatch using those types to select
implementations
4. Aggressive code specialization against run-time
types

Code
28 Healthy
April - 2015

Pure functional is not realistic for scientific languages.


Although LISP has shown how to get there, Julia is
largely functional, but it allows you to do things that
you would not be able to do in functional languages
like in-place operations and such.
We have been parallel from the early days. The design
has always been more of distributed memory. So if
you have a Quad-Core laptop, it will start four Julia
processors in a shared address space. We have some
shared memory routines. We also have a branch right
now that makes Julia thread safe and multi-threaded
so that is on the horizon as well.
We are hopeful that Julia 1.0 will have a good multithreading model and a base library, which is also multithreaded. Developers can already write parallel loops
with Julia that run in distributed memory, and will soon

be possible with threads as well, a bit like the parallel


ForEach in C#.
The parallel computing capabilities are not built into
the language, it is completely written in the user space.
You can read the code and modify it also.
I would also like to say that the core Julia repository
in Github has over 300 committers, which shows how
easy it is to get into the guts of Julia and do stuff.
What is a typical business case for Julia language?
Julia is a general purpose programming language, and
is quite well suited for things like number crunching
and data science as they call it now a days. The
traditional business case is engineering. If you are in
an engineering firm doing simulations using MATLAB
or you are doing statistical computing with R, Julia
could be an alternative. Typically what happens is that
MATLAB code gets translated and deployed in C or
Java, where the process introduces its own bugs and
problems. Julia is a deployable language. Because of
its general-purpose nature and high performance, Julia
can be deployed directly in production. As you can
imagine, this would save a lot of time and cost.
We, the founders of this language, have started a small
company that will provide support for Julia, because
people have started asking for it.
Does Julia compete with R?
Competing with R is a very strong word; because R
is much more mature. R has some 6000+ packages,
whereas Julia has only 500. It is a much younger
language. It is pretty good and usable, but we still
have a long way to go. If you work in data sets what
works in R works in Julia also. But you will move from
R to Julia only if Julia offers you something more. At
the same time, some of the R contributors have also
started contributing to Julia. Rather than compete, we
interoperate with many languages: C, C++, Python,
Java, FORTRAN and R. We want people to solve their
problems in a better, faster, cheaper way, and leveraging
the existing body of robust and stable codes out there is
the best way for us to do so.
Viral, do you have an Aadhar Card?
Hahaha.
Yes. I do. In fact I was lazy about getting it for quite
some time, until I found myself in a meeting with the
RBI Governor, and turned out to be the only person in
the room without an Aadhaar. Naturally, that changed
quickly afterwards.
Can you share some interesting things with respect
to the technologies used in a project of massive
scale like Aadhar and Aadhar-based payments?

I was not really deeply involved in the technical aspects


of Aadhar-based payments, because the National
Payments Corporation of India (NPCI) that issue
the RuPay cards are responsible for it. But they use
amazing scalable systems for processing payments as
a central payment switch. So my work involved the
design that links Aadhar cards with Bank Accounts,
LPG Subsidies etc.
I was designing the platform for Aadhar that will be
useful for linking different applications, not just the
payments. One of the key applications I designed was
eKYC, where my role was to delete two photocopies of
the same document from every bank (proof of address
and proof of ID). Today you can just provide your
Aadhar number and authenticate yourself. The UIDAI
will provide you photo, ID and address proof fully
electronically, online and in real time. It does away
with all the old documents and number of photocopies
as a proof for every person.
My colleague Pramod Varma was the chief architect for
all this stuff. I was more into the policy making and
design. I personally achieved a lot in implementing
these policies in the pubic platform
The underlying technologies for everything are the
open source stack. Everything is Linux-based and there
is very little proprietary software. Even where there
is proprietary software, multiple vendors are used
through common APIs to avoid vendor lock-in of any
kind. It is all cluster-based using a lot of Hadoop and
MapReduce and it is a very large, distributed system
that uses lot of Java toolkits.
I think it was a phenomenal effort implementing all this
from scratch inside a governmental set-up. You know
it is not easy. The credit for all this goes to Nandan
Nilekani himself.
Nandan and I are writing a book, which will hit the
shelves soon. We share all our experiences not just with
Aadhar but all the governmental stuff. It has a lot of
information about technology inside Government. The
working title is Rebooting the Government.
One of your recent projects is Circuitscape. The
premise itself looks very interesting. Can you talk
about it little bit?
Circuitscape is one of my favorite projects. See: http://
www.circuitscape.org/
I collaborated with my colleague Brad McRae and it
was a very interesting collaboration. Circuitscape is a
tool for landscape connectivity.
For example, you have the Bandipur Reserve Forest,
and then nearby is Kabini, where you have all the tigers.
You have a bunch of national parks spread across India.

Healthy Code
April - 2015

29

You have the Western Ghats with all the species. What
happens is that suddenly a town starts growing in the
middle, and so the species lose the connectivity in terms
of their movement.
It so happens that for the wildlife population you need
a large connected landscape for genetic dispersal. Or
if food or water run out in one part, they need to move
to another place where they can find food or escape a
particular disease or find a breeding environment.
Circuitscape uses sophisticated graph theory. If there
is congestion between a place that is good for them and
not good for them, the place gets disconnected and you
lose out all the species. You also lose diversity. The
premise is that in your conservation efforts, how do
you identify what tracks of land the animals are likely
to take. How can one create some sort of highways for
them?
Then they can migrate without clashing with the
humans.
For example, if you see the whole elephant issue
in Karnataka, the elephant migration corridors are
completely taken over by human beings. As the cities
are growing, the elephants run through them and you
get a clash between conservation and development.
Circuitscape takes satellite data and simulates a
landscape. It is like an electrical circuit. It takes every
cell from the image and assigns it a value based on color.
Water and urban areas get high resistance, whereas
vegetation will get low resistance. Thus, you build a
resistive network with millions of resistors.
My colleague Brad showed high correlation between
how current flows through a circuit with mapping
corridors for conservation. And it works incredibly
well compared to many other approaches.
WOW! Extremely interesting!

Ref: http://www.circuitscape.org/_/rsrc/
1360176996173/about-the-authors/SB_surf.jpg

For all the work you have done, dont you think
the environment is very conducive in the US?
How do you compare that with Bangalore?
Interestingly, with email, Github and internet, you can
do all these from anywhere. It is as good as being there.
In fact, all the four co-inventors of Julia had not met
each other for the first two years. You will be surprised
to know that many contributions to Julia come from
Bangalore.
People often like to simplify and say the best
programmers can be found only in Silicon Valley. But
that is not the case. We have contributions coming for
Julia from all timezones, 24 hours a day.

Pragmatic

Programmer Quote

Yes.
Academics, policy makers and researchers use it very
widely worldwide. The first version was in Java. It then
got written in Matlab and eventually in Python, which
is when it really took off. Users want to work with
billions of cells and we may have to rewrite it in Julia.
We hope to find the time sometime! It was an amazing
experience for me as well.
Viral, very curious to know, do you trek?
Outside of programming, I love outdoors, I love
trekking it was useful for Circuitscape, though I
havent trekked a lot after moving back to India. I did
however get a chance to do a one-week trek in the Great
Himalayan National Park, and that was a treat!

Code
30 Healthy
April - 2015

Computers make it easier


to do a lot of things, but
most of the things they
make it easier to do dont
need to be done.
- Andy Rooney

Technology Conferences

April 3-5, 2015, GOA, INDIA


Launched in 2010, RubyConf India is Indias premier Ruby and Rails conference and one of the largest RubyConfs in
the world. Organized entirely by a group of volunteers on a non-profit basis, RubyConf India aims to help connect,
educate and entertain Ruby programmers across the country.
Venue:

Cidade De Goa, Vainguinim Beach, Goa, India


http://rubyconfindia.org/

Conference on enhancing web


experiences on Mobile.
April 16-17, 2015, BANGALORE, INDIA
Venue:

MLR Convention Center


Brigade Millenium Complex,
J.P. Nagar 7th Phase
Bangalore, Karnataka India.
https://metarefresh.in/2015/

April 21-24, 2015, Bangalore


April 25, 2015, Hyderabad
With over 30000 attendees benefiting over seven game changing editions,
GIDS is the gold standard for Indias software developer ecosystem. Join the
2015 edition for cutting-edge content that will squarely put you ahead of the
pack.

Bangalore:
J. N. Tata Auditorium
National Science Symposium
Complex (NSSC)
Sir C.V.Raman Avenue,
Bangalore, India.

Venue:

Hyderabad:
Hyderabad Marriott Hotel &
Convention Centre
Tank Bund Road
Opposite Hussain Sagar Lake,
Hyderabad, India.

May 15-16, 2015, Bangalore


Rootconf is a conference on DevOps and Cloud infrastructure,
Rootconf will help you to plan and develop a strategy map
for infrastructure and devops.
Venue:

MLR Convention Center


Brigade Millenium Complex, J.P. Nagar 7th Phase
Bangalore, Karnataka India.
https://rootconf.in/2015/

Healthy Code
April - 2015

31

Article

Madhukara Phatak

Introduction to

Apache

There is a lot of data everywhere and a part of everything is due to the


growing needs of individuals and changes in technology and lifestyle.
Tools are required to capture, share, store and process this big data.
Apache Spark is one such interesting tool in the big data world. Spark
is an engine for analyzing data stored across a cluster of computers.
A successor of the Apache Hadoop, Apache Spark is driving more
and more big data adoption. This is an introductory article on the
evolution of distributed systems, role of Spark and the state of big
data processing today.

Evolution of distributed systems

First generation distributed systems

Distributed systems are the foundational technology for


important trends from the past decade like cloud computing,
big data etc. They have evolved over the years, in terms of
their approach to data storage and data processing. Their
evolution can be categorized into three generations based
on the architecture of the system and not on the system
usage. Its important to note that all generation-distributed
systems are still in use.

First generation distributed systems evolved in the 1990s.


They were developed to solve very specific problems in
specific industries. Some of the examples are TeraData,
Netezza, Oracle etc.

Code
32 Healthy
April - 2015

Most of these distributed systems are proprietary. Most of


these systems are sold as appliances, which had custom
hardware and custom software. One of the key highlights
of the first generation is that they employed the centralized

data model, where data is stored in one big server using


RDBMS or their own storage and whenever processing is
required, data is brought to the processing nodes from the
server. These systems are quite expensive and are owned
by large-scale organizations.

Second generation distributed systems


With the growing need of big data, there was an explosion
of big data tools in the beginning of 2000s. Apache Hadoop
was the first open source distributed system which brought
the distributed system to the masses. It enabled users to
store and process huge amounts of data at very low costs.
It was different from other available big data tools because
of its ability to run on commodity hardware; plus it was
open source. Also, over the years, there was a prospering
ecosystem which drove Hadoop adoption more and more.

Need for third generation distributed systems


Hadoop, the data processing framework, revolutionized
big data processing. Most of the companies these days
have a Hadoop cluster crunching the data. Now, with the
ubiquity of Hadoop, the question is, Whats next after
Hadoop? Do we need yet another revolution in big data
processing systems? Well, the answer is yes!
Hadoop was not able to keep up with the diversity of use
cases it used. Some shortcomings of Hadoop include the
MapReduce component of Hadoop being slow for real-time
data analysis and iterative type of data loads.
Most of these shortcomings stem from the design and not
from the implementation. The idea of Hadoop architecture
dates back to the 2000s where the first developer was from
Google. Lots of changes have taken place over the last
decade which calls for a better design to be used.

Whats changed in the last decade?

primary source of data. A disk was used as a primary


source to provide fault tolerance, for reliance on persistent
storage of data and shuffling of data etc.
In the last decade, there was a steep fall in the price of
RAM. These days, having 1TB of RAM in a datacenter
node is a very common sight. RAM is a primary storage
medium. It enables faster computation. Having RAM as
a primary source makes computations go 100x faster than
usual, whereas using disk space for computations makes
the systems slower.

Network Speed
In 2000s, most of the organizations had limited bandwidth
inside their data centers resulting in slower processing as it
was expensive to set up effective network.
With the advancement in hardware and software technology,
there was an increase in the network speed. In a latest stat,
Amazon said that it can sync between two datacenters over
the network faster than writing to a SSD (solid-state drive)
disk. Thats the speed we are talking about!

Multi-core environment
According to Moore's law the number of transistors in a
dense integrated circuit doubles approximately every two years.
In the 2000s, his prediction proved to be accurate. There
were systems driving clock speed of single core, which
went from 700hz machines to 1.5ghz and more. So, most of
the software and hardware stack was optimized for a single
core performance.
In the last decade, we stopped at 3.2ghz for a single core.
After that we saw an explosion of multi-core machines.
Multi-core machines usage became widespread. Even the
phone you carry around has more cores than the machine
in 2000s! So, the newer hardware and software stack has to
exploit the multiple cores available in the machine.

The software industry has seen tremendous changes in


terms of both software and hardware. These changes have
shown reflection in the way we design and implement the
software system. Lets discuss some of these important
changes in the distributed system area, which calls for a
new design from scratch.

Software evolution

Hardware evolution

OO vs. Functional programming

Hardware in data centers has undergone a tremendous


change over the last decade. Some of the noteworthy
changes are:

Disk vs. RAM

In the 2000s, OOP (object-oriented programming) was a


de facto standard for software development. Most of the
languages and system encouraged mutable states and
imperative way of doing things. This is the reason why
Hadoop API is implemented in Java and in OO fashion.

In the 2000s, a disk was much cheaper compared to RAM.


So, most of the distributed systems used disks as their

But in the last decade, people have realized that OO is not


the only way of programming. Particularly in a multi-

A powerful hardware stack without a powerful software


stack cannot do much. As there was a tremendous growth
in hardware, there were different changes in the software
too. Some of the noteworthy changes are:

Healthy Code
April - 2015

33

core distributed environment, OO ideas have serious


drawbacks. As a result, functional programming is
gaining popularity. Functional programming in a nutshell
encourages immutability and non-inheritance based
compositions, which can scale to multiple cores or multiple
machines naturally. This is a stark difference compared to
OO philosophy.

Framework
development

for

distributed

system

Distributed systems have two parts. One is distributed


storage and another one is distributed processing. In the
2000s, if you had wished to develop a distributed system,
you had to do everything from scratch, as there was no
open source framework. Thats why it took a considerable
amount of time for Hadoop creators to have a solid
distributed system, as there was no code base to start with.
Things have changed drastically over the last few years.
There are changes in the ecosystem. With open sourcing,
there are more and more frameworks coming up that can
help you to create new distributed systems very rapidly.
In a distributed storage layer, there is HDFS. You can
use HDFS in a non-Hadoop setup also. Its free and open
source. In a distributed storage part, there is Mesos and
YARN. These are generic frameworks, which help you to
create distributed processing system very rapidly.

Need of big data


We can build a great software and a great hardware. But
without a real need, there is no market. So, over the last
decade, there has been a dramatic change in the need for
big data.
In the 2000s, only a few big companies had the need for
big data. Companies like Google, Facebook, IBM, and Yahoo
were investing in distributed systems. Today, the scenario
is different; almost every company needs a distributed
system. Even the startups these days plan to have a big
data strategy.
The evolution of hardware and software tightly coupled
with a big need for big data called for a new design and new
architecture for big data distributed processing system. We
call them as the third generation distributed systems.
One of the first third generation distributed system is
Apache Spark.

Apache Spark
Apache Spark is a fast and general engine for large-scale
data processing system. It is a distributed processing
framework similar to Hadoop Map-Reduce. It uses HDFS
or its relative file systems as storage layer.

Code
34 Healthy
April - 2015

AMPLab, a research lab of Berkeley University, USA,


developed Apache Spark. Now its moved to a commercial
company called Databricks.
Spark is open source and released under Apache Licence.
This makes it attractive to all the enterprise customers. Its
written in Scala, a functional and OO hybrid language on
JVM.

Apache Spark History


A project called Mesos was started as a class project in
UC, Berkeley in 2009. The idea was to create a cluster
management framework which can help in writing
distributed processing frameworks. Mesos inspired the
design of Apache YARN.
After the development of Mesos, the obvious question was
what can you build using Mesos? Spark was a distributed
processing system that used cluster management, so it was
created to test Mesos. This led to the birth of Apache Spark.
But, with time, Spark got popular and more resources went
into the development of Spark than in Mesos.

Goals of Apache Spark


From day one, Spark developers knew that they would
always be compared to Hadoop. Spark is intended to
enhance, not replace, the Hadoop stack. So, the focus was
on the shortcomings of Hadoop. Spark concentrated on
iterative and real time systems. Over the time, there is a lot
of overlap between what Hadoop and Spark can do!

Why Apache Spark or Spark vs. Hadoop?


Apache Spark is the new generation framework for big
data. It not only performs better than Hadoop, it brings
completely new things to the table. In the next section,
we are going to focus on what makes Spark so unique.
Furthermore, we are going to see how Spark exploits the
improvements in software and hardware to the fullest.

1. Unified platform for big data apps


Big data analysis has different data loads. Different use cases
need different kind of analysis. Most of the big data analysis
needs both batch processing and real time capabilities.
Not only that, they have structured, unstructured, graph
analysis and other advanced processing needs too! So, a
full-fledged big data processing framework is needed to
cater to all of these needs.
Hadoop M/R, the currently leading big data processing
framework, is only optimized for batch processing. So,
in Hadoop, you have to use other frameworks like Storm
for real time and Apache Giraph for graph processing
capabilities. Having different frameworks is a pain for
development and maintenance. Though introduction of

cluster. This flexibility of deployment is very attractive to


customers, as it allows them to harness the power of Spark
using their existing infrastructure investments.

4. Small and simple


The original release of Spark contained only 1600 lines of
Scala code. It was designed to be extremely modular. So,
today you can add or remove capabilities to your spark
application simply by changing your build file. Having a
small code base favors to extend the framework at ease.
Figure 1.0: Apache Spark
YARN has solved a few issues, YARN is too low level to be
used in applications.
In the case of Spark, it was designed to cater to multiple
data loads from day one. Batch processing and real time
capabilities are built-in to the core of Spark. Many advanced
graph and machine learning libraries are also built in, so
that it can cater to a wide variety of data analysis needs.

2. Single abstraction across the stack


In Spark, all APIs and libraries talk the same abstraction
called RDD. RDD stands for Resilient Distributed Dataset.
Its just a big collection of immutable data, which resides in
some storage. But whats the advantage if all libraries talk
in RDD?
The advantage is that you can mix and match different

Spark API thrives on its simplicity. If you have ever seen


a Spark word count vs. Map/Reduce word count you
will understand how simple the API is! There is a lot of
thought process that has gone into the API to make it more
approachable and consistent. In contrast, the Java API of
Map/Reduce is a mess. There is too much verbosity. Figure
3.0 shows a comparative chart.

5. Prospering ecosystem
In Hadoop, ecosystem was an afterthought. The ecosystem
projects like Hive and Pig didnt have access to Map/
Reduce abstractions. All they can do was generate Map/
Reduce programs on the fly and run them on cluster. This
severely affected their performance.
With Spark, there was a plan for ecosystem from day
one. The ecosystem libraries like Pregel and MLLib were
developed side by side with core Spark. So, in Spark, all
libraries have access to the same level of abstraction as
the main API. This makes them first class citizens on the
platform.
Figure 3.0. Code-size comparison

Figure 2.0 Processing data


kinds of processing in the same application as shown in
Figure 2.0. You can take a stream of data from Spark real
time system and can run SQL queries using SparkSQL.
Then take the output of SparkSQL and feed it to the
machine learning algorithm, using MLLib. All this is done
without even having to convert or store an intermediate
result. This feature makes it powerful to build complex
data flow systems.

3. Runs everywhere
Spark runs everywhere. It is designed to run on different
platforms and different distributed systems. It can run on
Hadoop 1.0, Hadoop 2.0, Apache Mesos or stand alone Spark

Figure 3.0 depicts the effort required to add a new framework


in Hadoop vs. Spark. To add real time capabilities to
Hadoop, a framework called Apache Storm was developed.
It has around 75,000 lines of code. But in the case of Spark,
it just needs 1.5k lines of Scala to add real time processing.

Healthy Code
April - 2015

35

This ease of extending at underlying platform shows that


Spark was built for an ecosystem citizen from day one.

6. In memory aka Speed


Spark got popular for its efficient use of the RAM. Spark has
the ability to cache data in RAM and run all its processing
from the main memory itself. This capability is very much
desired for iterative algorithms, which requires reading
data multiple times. This caching is done across cluster,
thus giving fault tolerance for the cached data. This is
why the Spark definition says its a fast general processing
engine. The speed comes from the efficient use of the main
memory.

7. Multi language API


Spark officially supports Scala, Java and Python APIs. This
makes it more attractive to many developers compared to
Javas only M/R. Though M/R supported C++ and other
APIs, they are not up to date like Java API. So, Spark is a
great option for developers having different development
background!

Summary
I have given you a simple introduction to Apache Spark
that may ignite the interest in you. Spark has changed
the way we use big data. It allows companies across the
industries to run different kinds of analysis on a single
platform. With the future proof architecture and thriving
ecosystem, Spark is going to be the next milestone in the big
data development.

Madhukara is a big
data consultant. He has
trained more than 2000
people on Hadoop, Spark
and related technologies.
He is passionate about
technology and want to
build software products
to improve people's life.
Madhukara is an open
source enthusiast and
blogs actively at http://
madhukaraphatak.com/.
Code
36 Healthy
April - 2015

Pragmatic

Programmer Quote

Names are deeply


meaningful to your brain,
and misleading names add
chaos to your code.
Andrew Hunt
What kind of
programmer is so divorced
from reality that she
thinks shell get complex
software right the first
time?
James Alan
Gardner
A language that doesnt
affect the way you think
about programming is not
worth knowing.
Alan J. Perlis

Healthy Code
April - 2015

37

Article

Vasanth Gopal

Rea c ti v e
Progra m m ing

Reactive web programming is about building web applications that adapt to


changes in the underlying data. Reactive web apps have the ability to propagate
data changes through a proper channel of messaging. In this article we discuss the
basic concepts of reactive web programming and develop some simple apps using
React.js, Meteor.js and the Elm programming language.

Code
38 Healthy
April - 2015

Reactive web apps


Reactive programming, as shown in Figure 1.0, is defined
by the four principles; Responsive, Resilient, Scalable and
Message-driven.
Responsiveapplication is one of the main goals in modern
day apps. A responsive system is quick to react to the user.
Irrespective of whether its a success or an error scenario, the
system responds consistently to user.
Resilientsystems are about design and architecture of the
application to handle responsiveness. The system doesnt
shut down when external dependencies fail; rather those
failures are handled seamlessly. The design is planned not
just for happy path but also for each of the possible error
path.
Scalable systems respond to data changes by adding or
removing resources. They respond to the user quickly.
Message-driven architecture is the foundation of Reactive
applications. It can be event driven or message-driven.
You can read more about Reactive programming from
the Reactive Manifesto (http://www.reactivemanifesto.
org/).

Let me list down some advantages of reactive web apps.


Pluggable micro-components: A component is
designed to perform only one action. It takes an
input, does some computation and emits an output.
A component can be as small as acheckbox. It takes
user action as an input, reads the user selected value
and sends instant signal to its parents on the action.
Components become easily pluggable and if need
arises tomorrow, checkbox could be replaced with a
radio button component without disturbing the other
portions of the app. Any failure that occurs with the
component, it becomes much easily traceable for a
developer.
Events-flow: Components interacts with each
other through registered events and messages. Any
component that is interested in its subcomponents
output, registers for its signal. When the event
occurs, the subcomponents signal its parent with
appropriate messages. This message flows further to
other components who are dependent on it. Those
components react to the signals and modify their
structure and, if required, emits signal to components
dependent on it.
Data ignorant apps: Developers worry less about what
data they are dealing with and focus more on how to
better present the data. Components react to changes
instantly, the flow of data happens automatically across
the app.
Testable and Themeable components: Since we
design components at the unit level, they become
easily testable and themable. Any future changes can
also be applied with the component level.

Figure 1.0: Reactive applications


We believe that a coherent approach to systems architecture
is needed, and we believe that all necessary aspects are
already recognized individually.
Systems built as Reactive Systems are more flexible, loosely
coupled and scalable. This makes them easier to develop and
amenable to change. They are significantly more tolerant
of failure and when failure does occur they meet it with
elegance rather than disaster. Reactive Systems are highly
responsive, giving users effective interactive feedback.

Adaptive to new technologies: With evolution of


technologies, there may be an urging need to switch
to newer frameworks which has better benefits for
you application model. It becomes much easier to
try out such new frameworks by plugging in certain
components with it without disturbing the architecture.
App architecture easy to bootstrap: Any new members
joining the team will find it easy to follow up on the
architecture of the app as each component performs
only one action and they are clearly modularized.
Lets get hands-on with some reactive web programming to
try out these concepts. I have chosen two frameworks, React.
JS andMeteorand a programming languageElmto explain
the concepts.
Lets take the most commonTODOapp and try to build it

Healthy Code
April - 2015

39

with React, Meteor and Elm. I assume that the reader is well
versed with basics of HTML and Javascript.

React JS
React (http://facebook.github.io/react/) is intended to help
developers build large applications that use data that
changes over time. Its goal is to be simple, declarative and
composable. React only handles the user interface in an
app. It is considered to only be the Viewin the Model
ViewController (MVC) software pattern, and can be used
in conjunction with other Javascript libraries or larger MVC
frameworks.

Whats reactive about React JS?


React JS is about responsiveness. It builds elements in tree
structure and the changes in data navigate through the tree
automatically. Messages flow through the element tree and
get propagated back to parent after its computations.
React uses XML-like syntax calledJSX, which gets compiled
into Javascript. Heres a step-by-step approach of building a
simple React JS application.

Step 1
React views are defined using a render()method which
returns the HTML to display. HTML templates interpret
data objects and render them to DOM. The templates
areresponsive. Any change in the data objects automatically
updates the DOM.
Lets define aReactclass, which renders the container for the
list of Todo items.
// file name: "TodoApp.jsx"
var TodoApp = React.createClass({
render: function(){
return <div>
<header id="header">
<h1>todos</h1>
<input ref="newField" id="new-todo"
placeholder="What needs to be done?"
onKeyDown={this.handleNewTodoKeyDown}
autoFocus={true} />
</header>
<section id="main">
<ul id="todo-list">
{todoItems}
</ul>
</section>
</div>
}
})

Code
40 Healthy
April - 2015

Step 2
The React view is then rendered and inserted into the DOM
usingReact.render()method.
Render the created container into the body of the HTML
page.
//File name: "TodoApp.jsx"
React.render(<TodoApp />, document.getElementById

('body'));

Step 3
Define the Enter keydown event for the input to read and
save the new todo item. Therefsproperty has the all DOM
elements having thereffield. Functions register toeventsand
any application of the event automatically triggersthe
registered function. The function then propagates the
changes across the application.
// File name: TodoApp.jsx
handleNewTodoKeyDown: function (event) {
if (event.which !== ENTER_KEY) { return;}
event.preventDefault();
var val = this.refs.newField.getDOMNode().value.
trim();
if (val) {
// Set the value to model.
this.refs.newField.getDOMNode().value = '';
}
}

Step 4
Define aReactclass which for the individual Todo Item.
//File name: TodoItem.jsx
var TodoItem = React.createClass({
render: function () {
return (
<li>
<input className="toggle"
type="checkbox"
checked={this.props.todo.completed}
onChange={this.props.onToggle}/>
<label>
{this.props.todo.title}
</label>
<button className="destroy"
onClick={this.props.onDestroy} />
</li> );
}
});

Step 5
Implement toggle and destroy functionality for the todoitem
//File name: TodoApp.jsx
toggle: function (todoToToggle) {

//Toggle the completed state in model.
},
destroy: function (todo) {
//Delete the todo model.
}

Thats it. Your react js based TODO app is ready. Compile


your JSX files into JS and run the app by spinning up an
HTTP server usingpython -m SimpleHTTPServer. The app
applies message-driven architecture with components small
enough to handle resilience. The templating structure helps
to couple data changes and DOM; thus the DOM always stay
updated with changes in the model.
A completed version of React JS based TODO app is
available here -https://github.com/Vasanth-Indix/todomvc/
tree/master/examples/react

Meteor
Meteor (https://www.meteor.com/) is an open-source realtime JavaScript web application framework written on top
of Node.js. It integrates tightly with MongoDBand uses
theDistributed Data Protocoland apublishsubscribepattern to
automatically propagate data changes to clients in real-time
without requiring the developer to write any synchronization
code. Meteors goal is to allow developers tobuild apps that
are a delight to use, faster than you ever thought possible

Whats reactive about Meteor?


Meteor is a complete framework and tightly coupled with
Mongo database. It has removed client-server separation
and events in client propagate directly to the database. The
same changes are then broadcasted to all the clients which
listens to messages and update themselves.
Given below is a step-by-step approach of how to build the
TODO app using Meteor.

Step 1
Create a HTML template with nametodoappfor the header
and container of the app. It holds a sub-templatemainwhich
holds the list of Todo items. The individual Todo item
template with nametodois also defined. Here again, HTML
templates interpret data objects and render them to DOM.
The templates areresponsive, and any change in the data
objects automatically update the DOM.

todoapp.html
<template name="todoapp">
<header id="header">
<h1>todos</h1>
<input id="new-todo"
placeholder="What needs to be done?"
autofocus>
</header>
{{#if todos}}
{{> main}} {{/if}}
</template>
<template name="main">
<section id="main">
<ul id="todo-list">
{{#each todos}}

{{> todo}}
{{/each}}
</ul>
</section>
</template>
<template name="todo">
<li class="{{#if todo_completed}}completed{{/
if}}">
<div class="view">
<input class="toggle"
type="checkbox"
checked="{{#if todo_completed}}
checked{{/if}}">

<label>{{title}}</label>

<button class="destroy"></button>
</div>
</li>
</template>

Step 2
Include the container templatetodoapp in the body of the
HTML.
todoapp.html
<body>
<section id="todoapp" data-framework="meteor">

{{> todoapp}}
</section>
</body>

Step 3
Create a new Mongo collection for the list of todos. Any
Mongo DB operation can be directly performed on this
collection. Meteor goes one step ahead of React and makes
sure that the database, server and all clients maintain the
same state of data. This achieves instantresponsivenessand
every user stays updated.
//File name: todoapp.js
Todos = new Meteor.Collection('todos');

Healthy Code
April - 2015

41

Step 4
Bind enter keydown event to the input field to read and
save the new todo item. The events are binded within
theTemplate.<templatename>.events object. The entered value
gets directly inserted into Mongo using the Todos collection
insert option.
//File name: todoapp.js
Template.todoapp.events = {
'keydown #new-todo': function(event){
if (event.which !== ENTER_KEY) { return;}
var title = String(event.target.value || '');
Todos.insert({

title: $.trim(title),

completed: false,
created_at: new Date().getTime()});
}
}

Step 5
Define todos() function which reads and returns the list of
todos from Mongo. Just a single line of code is enough to
read contents from database and pass them to template
which auto renders that.
//File name: todoapp.js
Template.main.todos = function() {
return Todos.find({}, {sort: {created_at: 1}});
}

Step 6
Define toggle and destroy events for the todo item template.
//File name: todoapp.js
Template.todo.events = {
'click input.toggle': function() {
Todos.update(this._id, {$set: {completed: !


this.completed}});
},
'click button.destroy': function() {
Todos.remove(this._id);
}
};

Thats it!. The Meteor based Todo app is ready. To run the
app, you have to install meteor using
curl install.meteor.com | /bin/shRun the app with
keywordmeteor.
While React focuses only on the view part of the app, Meteor
is a complete package offering to keep every module in sync.

Code
42 Healthy
April - 2015

Smaller template structure helps to handle errors within the


template and thus the app becomes resilient.
The completed version of Meteor based TODO app is
available here -https://github.com/Vasanth-Indix/todomvc/
tree/master/examples/meteor

Elm
Elm (http://elm-lang.org/) is a functional programming
language for declaratively creating web browser based
graphical user interfaces. Elm uses the Functional Reactive
Programming style and functional graphical layout to build
user interface.

Whats reactive about Elm?


Elm language is about signals and messages. Observers
subscribe to signals and when events happen, these signals
are triggered. Resilience is achieved by registering observers
to all different possible signals. This makes the system
responsive to changes.

Elm application
An Elm application is broken up into four distinct parts: 1.
Model - a full description of the application as data 2. Update
- a way to update the model based on user actions 3. View
- a way to visualize our model with HTML 4. Inputs - the
signals necessary to manage events
Lets build the TODO app using Elm.

Step 1
Create a model which describes the full application as data.
Filename: Todo.elm
type alias Model =
{

tasks
: List Task.Model

field
: String
,

uid
: Int
}

Step 2
Create a HTML view for the todo container with list of todos.
Each of the DOM element is specified with comma separated
attributes and intended to follow the tree structure. The link
between the model and HTML is established here and any
changes to model, automatically updates the view, resulting
in instantresponsiveness.
Filename: Todo.elm
view : Model -> Html
view model = div


[
class
"todomvc-wrapper",

style [ ("visibility", "visible") ]

]

[ section

[ id "todoapp" ]

[ lazy taskEntry model.field

, lazy taskList model.tasks

]
]
ThetaskEntryis defined as:
taskEntry : String -> Html
taskEntry task =

header

[ id "header" ]

[ h1 [] [ text "todos" ]

, input

[ id "new-todo"
, placeholder "What needs to be done?"
, value task
, name "newTodo"
, Task.onFinish (Signal.send actions
Add) (Signal.send actions NoOp)

]

[]
]
And thetaskListis defined as:
taskList : List
Task.Model -> Html
taskList tasks =

section

[ id "main"
]

[ ul
[ id "todo-list" ]
(List.map (Task.view taskActions) (tasks))
]

13 -> Ok enterMessage
in
on "keydown" (Json.customDecoder keyCode select)
identity

Step 4
Define the view for the individual task. Two actions are
performed here: Thecompletedaction and thedestroyaction.
Events are triggered on user action, which sends signal to
update the dependent views and broadcasts the changes.
Filename: Task.elm
view : LC.LocalChannel (Int, Action) -> Model ->
Html
view channel task =
li
[ div
[ class "view" ]
[ input
[ class "toggle"
, type' "checkbox"
, checked task.completed
, onClick (LC.send channel (task.id,
Completed (not task.completed)))
]
[]
, label
[ text description ]
, button
[ class "destroy"
, onClick (LC.send channel (task.id,
Delete))
]
[]
]
]

Step 3

Step 5

Define the Task.onFinish Signal for new task addition. It


listens for the enterkey event on the input box and calls
theTodomodelsAddmethod which is defined later. Signals
and messages form the architecture of the Elm app and it
ensures that every dependent component automatically
responds.

The actions for the above view are defined here. Each action
calls the Todo models UpdateTask which is defined later
below.

Filename: Task.elm
onFinish : Signal.Message -> Signal.Message
Attribute
onFinish enterMessage escapeMessage =
let select key =
case key of

->

Filename: Task.elm
type Action
= Completed Bool
| Delete
Each action is implemented below.
update : Action -> Model -> Maybe Model
update update task =
case update of
Completed bool ->
Just { task | completed <- bool }
Delete ->
Nothing

Healthy Code
April - 2015

43

Step 6
Finally, define the type of actions which can be performed
on the model. The models are updated when the signals are
triggered. Note that the edge cases like empty descriptions
are handled here.
Filename: Todo.elm
type Action
= NoOp
| UpdateField String
| Add
| UpdateTask (Int, Task.Action)
Each action definition is implemented below.
update : Action -> Model -> Model
update action model =

case action of
NoOp -> model
UpdateField str ->
{ model | field <- str }
Add ->
let description = String.trim model.field in
if String.isEmpty description then model else

{ model |
uid <- model.uid + 1,
field <- "",

tasks <- model.tasks ++


[Task.init description model.
uid]
}
UpdateTask (id, taskAction) ->
let updateTask t =

if t.id == id then

Task.update taskAction t
else

Just t

in

{ model | tasks < L i s t . f i l t e r M a p
updateTask model.tasks
}

Elm takes on HTML and javascript by introducing


immutability and type inference, which helps you write
code that is short and maintainable. The abstraction
boundaries are quite strong which enforces the programmer
to write good code. It also has module system, which breaks
the system into smaller parts of modules. Elm exposes
wholesome graphics and styling helpers which makes it a
good alternative to using multiple frameworks on HTML,
CSS and JavaScript.
A completed version of the Todo app with Elm is available
here -https://github.com/Vasanth-Indix/todomvc/tree/
master/examples/elm

Conclusion
We learned how React, Meteor and Elm provide instant
responsiveness. Modularity helps in better code and makes
it easier to handle errors within the modules. Immutable
components help to scale systems on demand and being
reactive to messages and events make the whole system
responsive, thus providing a seamless user experience.

Thats it. The Elm based Todo app is ready.


To run the app, you have to install elm first and then runelmpackage install. Compile the Elm files to javascript using the
commandelm-make Todo.elm --output build/Todo.js.
Then run the app by spinning up an HTTP server
usingpython -m SimpleHTTPServer.

Code
44 Healthy
April - 2015

Vasanth works as a Software Engineer at


Indix. Indix is building a worlds largest
product database offering insights and
product analytics to retailers and brands,
thus helping them to create a better
commerce experience. Vasanth focuses on
tools which help to automate and scale
the Indix platform. The tools provide user
interface to the components of the platform
and help them to communicate with
each other. The tools are built on reactive
programming using frameworks like React
JS and Meteor.

Interview
with

Hello Thushara! You are working for a C


level job in a global company. How did
you start off your career?
I started my career as a Software Engineer in a
small startup company in Sri Lanka. Typically,
working in a startup gives you various
different opportunities across businesses over
working for a well-established structured
company. There, I got lots of exposure from
all the angles of business, from writing a piece
of code to presenting our new business idea
to venture capitalists. When I think back, I
really cherish the time I spent with a small
bunch of cool developers working towards
some fascinating ideas including developing
our own BI tool. It makes me happy to see
that it has come a long way in the SME market
in Australia. Of course, some of those ideas
worked and many didnt. Still, we learned a lot
from everything we did. That was fascinating.
As the company grew, I moved away from
Product engineering and we started an
offshore software unit in the company. With
this new move, I managed to get lots of
exposure internationally by developing and
managing outsourced software projects.
Ive been taking some tough challenges very
early in my career such as travelling to other
countries and taking over responsibilities of
software implementations on behalf of those
customers. That made me see the world and
learn a lot about various business cultures.
More than anything, I learned how to deal
with challenging situations by myself. This
whole new context helped me a lot to build
self-confidence as a woman as well as a
professional.
Ive met loads of fascinating people around
the world who really influenced my thinking
and Im very thankful to them for that.

Healthy Code
April - 2015

45

What do you do now?


Now, I work as the Chief Project Officer of Exilesoft
by leading our global project operations including
Sri Lanka, Norway, Sweden and Australia. Exilesoft
is totally focused on software engineering in offshore
development context. It is quite different to many
offshore software companies that you find all over
Asia. We are very disruptive when it comes to our
thinking how we model our approaches and day-today business operations. We want to make sure that
offshoring is a pleasant experience to customers as well
as our developers. We want to be very agile in the way
we do everything. I accept that its very challenging to
do but so far we have been very successful with this way
of working. Our business results show that customers
accept us and they see the value of what we do.
During my day-to-day work, I love working with
techies. They inspire me all the time to keep up with
whats going on in the world. I dont write code
today but its extremely important to be technically
sound when you are to lead a technical pool. Most
of the time, our customers also come from highly
technical backgrounds. So without having proper
knowledge about what we do, I cannot do my job.
My main challenge is to facilitate project initiatives and
find new ways of working to do our deliveries better.
This industry is moving very fast and if you need to be
successful you need to drive the change. You need to
lead the industry.
We understand that travelling is a big part of your
job. You travel across Europe and Asia. What
inspires you to do this often?
The most important thing is that I love what I do.
Travel is a big part of my job and thats the reality.
I have lots of support from my family. Without
them, I couldnt have done such a demanding job.
I think Im quite inspired by my mother from my
childhood time. She was a teacher and she always
believed that her job is to make sure her students are
successful with what they do. She was devoted to her
responsibilities and I grew up with that thinking.
You talk a lot about Agile methods in conferences.
You are a great believer in Agile principles and
values. Do you practice them across your global
project organization?
Yes, absolutely.
Can you please tell us why you think Agile is
important to your projects?
As I mentioned to you, we are working in a totally

Code
46 Healthy
April - 2015

remote global team context. Some of the biggest


challenges in such context are the lack of transparency
and the lack of trust. That happens when you dont have
an acceptable level of relationship with the people you
work with. Imagine if you are using heavy waterfall
processes here. We will have big black boxes and small
islands everywhere in the organization. So having all
our engineering and operations built based on Agile
values help us to work as one team across the globe.
Have you come across projects where Agile was
difficult to implement?
Yes, but its not actually about the projects and Agile.
Its usually about the people and Agile. If people are
not open to change and open to ideas, then if you have
a lot of bureaucracy going on in the organization, Agile
will not work in your projects. I see many teams doing
daily Scrum and fooling themselves by believing they
do Agile. I dont think they get the most value out of it.
It was like that in those days when Agile was pretty
new to our organizations, but I think todays scenario is
different. Agile is a common word in projects and is the
norm today. And we dont have a better alternative yet.
While we cant say Agile is the best way to do software
development and it will solve all your problems, we
dont have anything better than Agile either. If you are
working with very large organizations, you may still
have difficulty in convincing them, but that is changing
as we speak.
Do you see Agile implemented differently across
geographies say Europe vs. Australia?
The Europeans (especially Scandinavians) are very
Agile with the way they do things. They are not too
structured and the business culture is very easy going.
At least, thats my understanding. So, its been quite
easy to work with them using Agile methods for project
execution and engineering so far. We are not getting
pushed back due to fixed estimation and are planning
everything upfront.
If you look at Australia, I find the business culture is
a bit different to the Scandinavian culture. Most of
the organizations have strict hierarchies and still work
on big upfront plans. Still, there are very fascinating
companies there too. Things will change and Im
positive about that.
When it comes to Sri Lanka, our developers appreciate
Agile culture a lot. They like to voice their opinions
and challenge each other when necessary. But I cannot
comment on Sri Lankan business culture in general as
Ive not done any business in Sri Lanka. But Im sure,
everyone understands the new ways of working.

Do people in different geographies prefer one


methodology to the other, like Scrum or Lean or
Kanban?
Hmm I dont think the geography matters to select a
method. Its about the nature of the project. Of course, I
would select Scrum over KANBAN in certain scenarios.
But on the other hand, in general, we use a combination
of XP, KANBAN and Scrum at Exilesoft.
What kind of practices promote quality and what
kind of qualities help to stay within the budget?
If the primary focus is the budget, I dont think its a
kind of project that delivers real value. You can get
your developers to always think about money. How
much have I spent; how much do I have left? If you
are in the fixed budget approach, you are only worried
about finishing the project, not about clearing your
technical debt or better usage of features.
Budget is always important; this is a business. You
cant get out of that thinking. However, the primary
focus of everyone who develops software should be
the quality of the product. Thats what we believe at
Exilesoft project organization. How the functionalities
are used, how easy and user friendly it is, is the system
fit to use and is the code clean are what we focus on.
Having the right engineering and project execution
practices from the beginning of the project can help
you to keep control over both quality and budget.
Visibility is the key here. You need to create visibility
of everything you do when it comes to projects.
We notice that you have worked with government
projects in Sri Lanka. Does Agile work well in
government projects?
My exposure to government projects in Sri Lanka is
very limited. During my previous employment, Ive
helped some of the funded projects for the government
as a consultant. At that time, I didnt see any kind of
initiatives taken to introduce Agile practices to execute
those projects. Who knows, the situation may have
changed now. I see Sri Lanka ICTA has done a lot of
initiatives for e-government implementation. I think
Agile project deliveries is a key to success in that kind
of public sector projects as in most of these projects,
scope could be exploratory.
You are a certified SAFe consultant. Do you believe
that SAFe is capable enough to scale Agile and
solve bigger project problems?
There are many frameworks introduced to scale Agile.
SAFe is just one of them but is getting quite popular
among big companies. Let the industry decide the

success or the failure of it. If it doesnt deliver any


value, it will die off soon. But if the framework helps
the organization to deliver better value faster, then it
will survive. Lets be open to new ideas and thinking.
If a few of the developers get together and form a
company, is there a set of Agile practices they can
follow, considering the fact that they are a startup?
Do you have any kind of Agile roadmap for them?
I dont believe in a fixed generic roadmap that leads
to success for all. The people who you hire certainly
play a big part. The very first hires that you do for the
company are extremely key to your success. I always
say that you should have the right skill set, the right
passion and the right knowledge.
Books like Riding the Tiger and Lean Startups can
give you a lot of insight, ideas and guidelines to follow.
Do you think small teams can implement
Continuous Delivery, given the fact that it takes
a few years of experience to be mature to release
software projects?
My belief is that if you are a small team or a big team
you still have to practice Continuous Delivery. The best
part of Agile is doing deliveries all the time. It doesnt
matter whether you are a small team or a large team.
On the other hand, I agree its a journey. You may have
some setbacks when you begin. On the day you start,
you may not have the perfect environment and the
skillset. But you will get there some day. Do not lose
focus. The most important thing is starting.
There are also a lot of maturity assessment services for
continuous delivery. You can use it to find out your
state to the next level. I think these are important
practices. There are a lot of companies that claim they
are Agile, by simply doing stand-up meetings, burndowns, etc. I dont consider them Agile unless they
really start practicing continuous delivery.
Do you have a favorite blend of Agile in your
projects?
We really like XP practices here. We do Scrum and
also do some visualization. At times we use KANBAN
boards. We use lots of automation during our
engineering process. So its a mix of methods and some
common sense too.
What is your favorite Agile tool?
I cant pick one! Honestly, Im not that specific about
tools.

Healthy Code
April - 2015

47

Coming up in the May 2015 issue

Play with Play


- Prabhu Sunderaraman
Play is a framework for building web
applications in Scala. It gives you the
functional style of developing highly
scalable web applications. This article
talks about the Play framework with an
example.

Tips and Tricks


Using Git
- Yokesh Khater
In this article I give you my list of Git
tricks that I have accidentally met
while maintaining some repositories.

Interview with
Fred George
Fred George, who has worked
with more than 70 programming
languages and a proponent of
Microservices Architecture, talks
to Healthy Code on a number of
topics.

RubyConf 2015
- Anisha Narang
Anisha brings you coverage
of the Ruby conference in Goa
this month.

Owned and Published by T. Sivasubramanian. Published from 11/6, First floor, Fourth street, Padmanabha Nagar, Adyar, Chennai 600020 and printed by K. Elumalai, at Sakthi Scanners (P) Ltd, 7, Dams Road, Chindadripet, Chennai - 600002. Editor: S.Prabhu.

Code
48 Healthy
April - 2015

Potrebbero piacerti anche