On Feeling Needed
This article in new york times by Dalai Lama was a good one to read. I collected these important points from the article.
A small hint comes from interesting research about how people thrive. In one shocking experiment, researchers found that senior citizens who didn’t feel useful to others were nearly three times as likely to die prematurely as those who did feel useful. This speaks to a broader human truth: We all need to be needed.
Being “needed” does not entail selfish pride or unhealthy attachment to the worldly esteem of others. Rather, it consists of a natural human hunger to serve our fellow men and women. As the 13th-century Buddhist sages taught, “If one lights a fire for others, it will also brighten one’s own way.”
Feeling superfluous is a blow to the human spirit. It leads to social isolation and emotional pain, and creates the conditions for negative emotions to take root.
Indeed, what unites the two of us in friendship and collaboration is not shared politics or the same religion. It is something simpler: a shared belief in compassion, in human dignity, in the intrinsic usefulness of every person to contribute positively for a better and more meaningful world.
Gandhi Jayanthi
Happy Gandhi Jayanthi to all.
Gandhi's thought that I like to remember the most today is Knowledge without character is a social sin.
We are going to Mars!
A very exciting thing happened this week.
Elon Musk laid out a plan for human beings like us to travel to mars and start a civilization there.
This is a multi-year plan, and there will be multiple rockets carrying humans and cargo. It seems it will take 3 months to reach to the destination and it has be done with Earth and Mars are in sync, which happens every 28 months.
Elon Musk's SpaceX team is trying to reduce the cost to a affordable level of 200K USD per ticket. If the ticket happens to be more than 5x this, it will still be worth it.
The design of the rocket, the system architecture and the entire plan was really impressive. Here is the link to the presentation that Elon Musk gave.
If you are truly interested, this whole video for 1 hour gives a good overview.
There are short teaser video as well, like this one.
Things just got real!
Movie Review: Saving Private Ryan
We got the Netflix subscription recently and one of the movies I watched after getting Netflix was "Saving Private Ryan". Surprisingly, I had not watched this movie earlier. Every time I watched the opening scene, I had simply given up and that was enough of the movie for me.
Now, that I completely watched it, this movie just my regard for "Steven Speilberg" as the director. I can think of no other movie that is as brilliant, portraying human emotions, as this one. The war is shown in its brutality. Soldiers holding on religion as the moment of truth is shown dearly.
The characters in the movie include Captain Miller (Tom Hanks) who shows extraordinary leadership and Private Jackson (Barry Pepper), a highly reliable, accurate marksman, who quotes bible, gives himself unto god, as he fights his enemies.
Everything about this movie was great.
Review of The Emerald Route by R.K.Narayan
The Emerald Route is a travelogue written by R. K. Narayan. He details the cultural and mythological history of various cities in Karnataka. Narayan presents the mythological history alongside with the facts about the place, and gives you a glimpse of his character. He presents them as true stories that have happened in those places.
For example, Narayan shares the story that Sankara was born with a definite time of 16 years to live, and thus he studied all the scholarly works by 10, became a monk, and started preaching. When he was 16, a debate between Vyasa and Sankara took place. Vyasa was the original author of the work that Sankara was discussing, and not knowing this, Sankara was still holding on to his stance. When the debate did not end, student of Sankara called for truce. Ved Vyasa impressed by Sankara's knowledge of his own work, granted him the boon to live for another 16 years.
There was another interesting story that at Srirangapatinum, in one of the battles that Tipu Sultan lost, he had give away two of his sons, aged 9 and 11, as hostages to British on conditions of surrender. It seems that he got his sons back after paying huge money to British.
Filled with stories like this, giving the account of history and culture of the various towns in Karnataka, this book was a pleasure to read.
Not praising intelligence
There are many supporting studies on this, and I came another one which explicitly stated that
Praise for Intelligence Can Undermine Children's Motivation and Performance
The study suggests that parents should praise their children for the efforts they put in their tasks instead of praising the accomplishments or their intelligence for accomplishing the task.
Excerpt from the paper.
Praise for ability is commonly considered to have beneficial effects on motivation. Contrary to this popular belief, six studies demonstrated that praise for intelligence had more negative consequences for students' achievement motivation than praise for effort. Fifth graders praised for intelligence were found to care more about performance goals relative to learning goals than children praised for effort. After failure, they also displayed less task persistence, less task enjoyment, more lowability attributions, and worse task performance than children praised for effort. Finally, children praised for intelligence described it as a fixed trait more than children praised for hard work, who believed it to be subject to improvement. These findings have important implications for how achievement is best encouraged, as well as for more theoretical issues, such as the potential cost of performance goals and the socialization of contingent self-worth.
Abstract Factory - Design Pattern Explanation
Design patterns like "Decorator", "Singleton" are common and be easily recognized. The "Builder" pattern is also recognizable whenever you use Java's StringBuilder class.
Some patterns which are commonly used by frameworks are not easily recognizable unless you are a framework author. Recently, I spent time trying to recognize and understand Abstract Factory design pattern.
In this post, we will look at "Abstract Factory" and explain it with an example. I consulted multiple resources, and ultimately to gain confidence, I had to rely upon The Gang of Four [1] design patterns book.
This post is intended as refresher for a reader who has read the Gang of Four chapter on Abstract Factory. This post presents an example which the reader can relate to in the modern world.
Abstract Factory is a Factory for Factories. To understand this, you will first have to understand the Factory Design pattern, which encapsulates creation of objects. Factory pattern is recognized when instead of using new SomeClass() we call SomeClass.createObject() static method. The advantage is SomeClass is independent of your code, it could be supplied as a dependency from someone else and you simply use the factory. The person controlling the factory can modify the object creation process.
For example, SomeClass.createObject() in version1, can be return new SomeClass(arg1) and in version2, it can change to return new SomeClass(arg1, arg2) with you as the caller, invoking the object creation entirely as SomeClass.createObject() unaffected by the change made by the creator of SomeClass.
Factory pattern is easy to understand. The next step comes in dealing with Abstract Factory.
Intent
Abstract Factory provides an interface for creating families of related or dependent objects without specifying the concrete classes.
Canonical Design
Factory is a class that defers the instantiation of the object to the subclass.Factory encapsulates the decision-making that figures out which specific subclass to instantiate. There are three different kinds of Factory patterns observable with respect to object instantiation.
- Simple Factory.
-
The client directly uses a static method of a subclass, to instantiate an object.
- Factory Pattern
-
The client uses a Factory class to create an object. A Factory, is a class that defers the instantiation of an object to the subclasses.Factory method creates only one product
- Abstract Factory
-
Abstract Factory is a constructional design pattern that is used to create a family of related products.
Abstract Factory is applicable when the
System should be configured with one of multiple families of Products.
The family of related product objects is designed to to used together and we need to enforce this constraint.
Design Problem
In this problem, we are trying to design a "Operating System Installer" for Unix family of Operating Systems. We know there are two popular variants of Unix, there popular operating system with Linux kernel and related application stack, and there is BSD systems.
Each Operating System will consists of components like
Bootloader
Kernel
Shell
DisplayManager
WindowManager
Applications
The installer will have to abstract those components and help the client create an Unix operating system choice.
Correspondence with Canonical Design
Let's look at each of these in some detail.
Product Interfaces
Starting with products, these are:
Bootloader
Kernel
Shell
DisplayManager
WindowManager
BaseApplications
We will have Interfaces for the products.
java/abstractfactory/IBootLoader.java (Source)
java/abstractfactory/IKernel.java (Source)
public interface IKernel { /** * Load the kernel on top of the system image. */ void loadKernel(); }
java/abstractfactory/IShell.java (Source)
java/abstractfactory/IDisplayManager.java (Source)
Concrete Products
Each of these can create many difference concrete products. For the different concrete products like
-
Bootloader
BSDBootLoader
LinuxBootLoader
-
Kernel
BSDKernel
Linux
-
Shell
BASH
CShell
-
DisplayManager
X11
WayLand
-
WindowManager
Gnome
KDE
-
BaseApplications
SystemVUnix
GNUApplications
ProprietaryApps
Let's denote these concrete products in code that can be instantiated.
java/abstractfactory/BSDBootLoader.java (Source)
public class BSDBootLoader implements IBootLoader{ /** * Boot up the System Image. */ @Override public void bootUp() { System.out.println("Booting: " + this.getClass().getSimpleName()); } }
java/abstractfactory/BSDKernel.java (Source)
public class BSDKernel implements IKernel { /** * Load the kernel on top of the system image. */ @Override public void loadKernel() { System.out.println("Loading: " + this.getClass().getSimpleName()); } }
java/abstractfactory/Bash.java (Source)
public class Bash implements IShell { @Override public void loadShell() { System.out.println("Loading: " + this.getClass().getSimpleName()); } }
java/abstractfactory/CShell.java (Source)
public class CShell implements IShell { @Override public void loadShell() { System.out.println("Loading: " + this.getClass().getSimpleName()); } }
java/abstractfactory/GNUApplications.java (Source)
public class GNUApplications implements IBaseApplications{ @Override public void installApplications() { System.out.println("Installing: " + this.getClass().getSimpleName()); } }
java/abstractfactory/Gnome.java (Source)
public class Gnome implements IWindowManager { @Override public void installWindowManager() { System.out.println("Installing: " + this.getClass().getSimpleName()); } }
java/abstractfactory/KDE.java (Source)
public class KDE implements IWindowManager { @Override public void installWindowManager() { System.out.println("Installing: " + this.getClass().getSimpleName()); } }
java/abstractfactory/Linux.java (Source)
public class Linux implements IKernel{ /** * Load the kernel on top of the system image. */ @Override public void loadKernel() { System.out.println("Loading: " + this.getClass().getSimpleName()); } }
java/abstractfactory/LinuxBootLoader.java (Source)
public class LinuxBootLoader implements IBootLoader { @Override public void bootUp() { System.out.println("Booting: " + this.getClass().getSimpleName()); } }
java/abstractfactory/ProprietaryApps.java (Source)
public class ProprietaryApps implements IBaseApplications{ @Override public void installApplications() { System.out.println("Installing: " + this.getClass().getSimpleName()); } }
java/abstractfactory/SystemVUnix.java (Source)
public class SystemVUnix implements IBaseApplications{ @Override public void installApplications() { System.out.println("Installing: " + this.getClass().getSimpleName()); } }
Factories
The products are created by Factories
BSDFactory
LinuxFactory
UbuntuFactory
java/abstractfactory/BSDFactory.java (Source)
public class BSDFactory implements IUnixFactory { @Override public IBootLoader installBootLoader() { return new BSDBootLoader(); } @Override public IKernel installKernel() { return new BSDKernel(); } @Override public IShell installShell() { return new CShell(); } @Override public IDisplayManager installDisplayManager() { return new X11(); } @Override public IWindowManager installWindowManager() { return new KDE(); } @Override public IBaseApplications installApps() { return new SystemVUnix(); } }
java/abstractfactory/LinuxFactory.java (Source)
public class LinuxFactory implements IUnixFactory { @Override public IBootLoader installBootLoader() { return new LinuxBootLoader(); } @Override public IKernel installKernel() { return new Linux(); } @Override public IShell installShell() { return new Bash(); } @Override public IDisplayManager installDisplayManager() { return new X11(); } @Override public IWindowManager installWindowManager() { return new Gnome(); } @Override public IBaseApplications installApps() { return new GNUApplications(); } }
Abstract Factory
The factories will implement an abstraction provided by the Abstract Factory
Client
The design is best understood from the view of the client which uses the Abstract Factory to the create the products.
java/abstractfactory/OperatingSystem.java (Source)
public class OperatingSystem { IUnixFactory unixFactory; public OperatingSystem(IUnixFactory unixFactory) { this.unixFactory = unixFactory; } /** * installerClient uses only the interfaces declared by AbstractFactory (IUnixFactory) and AbstractProduct * (IBootLoader, IKernel, IShell, IDisplayManager, IWindowManager, IBaseApplications) classes. */ public void installerClient() { IBootLoader bootLoader = unixFactory.installBootLoader(); IKernel kernel = unixFactory.installKernel(); IShell shell = unixFactory.installShell(); IDisplayManager displayManager = unixFactory.installDisplayManager(); IWindowManager windowManager = unixFactory.installWindowManager(); IBaseApplications applications = unixFactory.installApps(); bootLoader.bootUp(); kernel.loadKernel(); shell.loadShell(); displayManager.installDisplayManager(); windowManager.installWindowManager(); applications.installApplications(); } /** * client will not know the * products the type of bootloader, kernel, shell, display, window manager or applications. * That is encapsulated in factory used by the client. * */ private static void factoryClient(IUnixFactory factory) { OperatingSystem operatingSystem = new OperatingSystem(factory); operatingSystem.installerClient(); } public static void main(String[] args) { IUnixFactory factory; factory = new LinuxFactory(); factoryClient(factory); factory = new BSDFactory(); factoryClient(factory); factory = new UbuntuFactory(); factoryClient(factory); } }
The execution looks like this.
Booting: LinuxBootLoader Loading: Linux Loading: Bash Installing: X11 Installing: Gnome Installing: GNUApplications Booting: BSDBootLoader Loading: BSDKernel Loading: CShell Installing: X11 Installing: KDE Installing: SystemVUnix Booting: LinuxBootLoader Loading: Linux Loading: Bash Installing: X11 Installing: Gnome Installing: ProprietaryApps
Tabulated Correspondence
Mapping of the code with various elements in the design helps us to appreciate this pattern.
Hope this was useful. If you have any comments on this article, please add your thoughts in the comments section of this article.
Thank you for reading!
A Week Of Violence - July 9, 2016
Police shooting of the black men were disturbing. There are videos on the internet, I suggest that you don't watch them, it just does not help. The men were shot for no-good reason and if I have take an alternate stance, it is probably because the police officer had fear and hatred towards the other person that he shot them.
There are no excuses for the police officers who shot the black men. They should be jailed for their life term for this act.
Later, the protest in Dallas to condemn the shooting, some people, who carried guns, which is legal in US, shot at the officers and killed 5 of them. This is equally brutal. In addition, police used a robot to kill the suspect too.
I had to recollect "Gandhi's message of peace" that many Indians have been thought since childhood. It seems to me that folks who cite, "Second Amendment" will really not understand either Gandhi's or Christ's message to mankind.
Movie Review: No Country For Old Men
My Rating: 4/5
There is a decent chance that you must have heard about this movie. I had heard the name too, had a vague idea from reading synopsis what I would expect. But I was totally wrong. After a point, I said to myself, it is no longer good vs. evil story.
It has a very thin storyline but has an excellent performance from the villain, gripping scenes that will keep you absorbed.
I won't the read book, but I enjoyed watching the movie.
Mesosphere Ahoy!
I joined @mesosphere on June 20, 2016. It's exciting as I get to work on some interesting technology in Datacenter Operating System. The container technology and orchestration world is in rage right now. Mesosphere is suitably positioned in that sphere. :)
The most interesting thing for me will be learn the distributed systems concepts well and contributed to this space. Plus, I discovered that our infrastructure tools are completely in Python3. Yay for that!