Saturday, January 31, 2015

Book: The Inner Game of Tennis

The Inner Game of Tennis by W. Timothy Gallwey argues that success can result only if you don't try too hard which sounds counter intuitive. Trying too hard means becoming emotionally attached and being judgmental. He gives practical tips on how to achieve relaxation while practicing. First and foremost, you have to be interested in what you are doing.

A very good book for anyone who wants to be a better person by using tennis (or any other practice) as a means to achieve inner peace and perfection.

Thursday, January 15, 2015

Minimal Software Design

A minimal software design effort should include the following:
  • What problem are you trying to solve? Is the problem specified clearly?
  • Comprehensibility: What will you do to help others (or yourself one year later) understand your code/design. Hint: Wiki, coding conventions, KISS.
  • Modularity/dependency: What approach will you take to make your modules independent? Hint: Encapsulation, MVC pattern.
  • Testability: How will you make sure that your implentation will be as unit testable as possible? Hint: Keep methods short. Whenever you can, make objects/methods static.
  • Error handling and logging: What error cases do you foresee and what mechanisms will you have in place to log and recover from errors? Hint: Exceptions.

Friday, November 28, 2014

Difference between a hobby project and a product

One of the most important lessons an engineer learns is that a going from a demonstration prototype (i.e. "hobby project") to a product that other non-engineer people can use requires a lot of additional work. I would say that prototype to product transition requires as much work as creating the protoype.

A product
  • is well tested and can work under a wide range of conditions (this is the main cost difference because additional testing reveals previously unknown weaknesses and will force you to make major design changes)
  • anticipates internal errors / environmental anomalies and has mechanisms in place to recover gracefully
  • anticipates user error and guides the user when he does something wrong
  • has an intuitive user interface (i.e. people don't need to ask an engineer how to operate it)
A novice thinks he almost has a product when he demonstrates basic functionality. The wise one knows that he has only covered half the distance.

Friday, November 21, 2014

Improving java.awt.Polygon contains() method

The contains() method in java.awt.Polygon, which checks if the input coordinate is inside the boundary, might not return true for all the points that you would expect. Example: xPoints = {0, 5, 10, 15, 15}, yPoints = {0, 5, 3, 10, 0}. With the standard Polygon class, contains(5,5), contains(15,10), contains(15, 0) all return false although these points are on the polygon (indicated by arrows in the figure below). If you use Matlab's inpolygon function you will get true for all of them.


The reason is related to the "insideness" definition. A point is considered to lie inside a Shape if and only if:
  • it lies completely inside the Shape boundary or
  • it lies exactly on the Shape boundary and the space immediately adjacent to the point in the increasing X direction is entirely inside the boundary
  • or it lies exactly on a horizontal boundary segment and the space immediately adjacent to the point in the increasing Y direction is inside the boundary.
I have written ImprovedPolygon whose contains() method returns true for the above cases by checking if the input coordinates lie on the edges of the polygon using the line formula y = m*x + n and limits of the line end points. Both ImprovedPolygon and its unit test class ImprovedPolygonTest can be downloaded from GitHub here.

Listening to: Take me to Church - Hozier

Monday, November 17, 2014

Java: Information hiding using interfaces

Typically, the "private" key word is used to hide any methods/attributes from other classes. However, there are cases where a class has one set of methods that is used by class A and another set of methods that are used by class B which means that all these methods have to be public. To prevent class A from accessing methods meant for class B, we can use interfaces as depicted in the following example:


Wednesday, July 23, 2014

Tips for software integration

I have been involved a couple of times in software development efforts where my small module (~20 KLOC) had to be integrated into a larger module (~1 MLOC).
Complicating factors:
  • It was not possible to install the larger module on my development environment. There was no offline version.
  • Interface Control Document (ICD) did not exist or was out of date the minute it was written because the larger module was also in development.

Friday, June 06, 2014

The path of the autodidact

I like learning, be it a new computer algorithm or political history. My problem is that I spend a lot of time looking around, sampling information from different domains but not being able to focus and get deeper. Since I am in need of depth to feel happy about a topic, I always feel that there is something missing. I watch lots of YouTube videos and I am enrolled (but have never finished) in dozens of online courses. There is no end to sampling in this age of easy access to all sorts of information. Since September 2012, I have a second job, namely being a father, which does not leave any time for prolonged concentration.

My plan: Sample for 6 months, then in the final two weeks, decide on what to focus on (at most 2 things). Take a week of off from job and get down and dirty. If it is related to programming, create a working application. Make sure there is a babysitter during the day, i.e. father time = mainly evenings and weekends.