Monthly Archives: June 2013

TrueCaller: App to keep away unwanted calls

A couple of months back I was introduced to truecaller app https://play.google.com/store/apps/details?id=com.truecaller&hl=en.

“Truecaller is the world’s largest collaborative phone directory that makes it easy to get in touch with people across the globe.”

I had tried many similar apps before this which claim to show caller’s info, but none comes close to this one. This app shows location and name of the caller (well 60-70% of the time, else it will show no info available). Most importantly the app has saved me  taking unwanted calls as it shows the info about the caller like “credit card”, “customer care”, which helps me judge if I want to take the call.

Agile Mobile Development

One of the best candidates for agile development I have found is mobile app development. Why?

1. Requirements are usually not very clear as mobile app development itself is relatively new- so client demos and regular feedback helps us not to move away from what is required.

2. The mobile technologies have not been explored as much as we have already explored web technologies, so we still have lot of challenges to be faced. This means peer reviews and pair programming can be very helpful.

3. The apps are generally UI extensive, that means they are good candidates for client feedback. We need to get clarity on look and feel, and specially responsiveness of the app.

4. With frameworks like phonegap available and newly emerging augmented reality libraries, complex mobile apps are normally started in POC (proof of concept) mode. With hit and try approaches, it is good to have daily discussions to float ideas and get feedbacks within the teams.

Refer : http://kamalmeet.com/2013/06/agile-development-what-is-it/
http://kamalmeet.com/2013/06/agile-development-is-it-for-me/

 

Amazon India- Ecom war gets tough

When I had to buy a book last week, the first obvious choice was Flipkart for me. But I knew Amazon has launched recently Indian online e-commerce website with books and movies, so I thought of giving it a hit. And to my surprise the price quoted was 10% lower than what was asked on flipkart. With cash on delivery option available, it was a safe bet to try, so I gave it a shot.

It normally takes 3 to 4 days for stuff ordered online get delivered, so I was not expecting the amazon delivery card on third day itself (as no one was at home). The card stated that they tried delivering the book and will bring it again the next day. Normally with other websites, I have to check status online, in case I do not get the item delivered within expected time period, so the card was a welcome surprise. Anyway, the book got delivered, as promised, the next day.

Overall I will have to say amazon, as always has kept its high standards from the very beginning in India. With just its presence in Books and movies category, I am expecting a takeover in near future. Let’s see how the things will shape up in future, but with so many online e-commerce sites coming up, it is definitely going to be tough to survive unless one comes up with a unique advantage over others. At the end, customers will get benefited with so many quality options.

Interesting Java Facts 3: Cloning a multidimensional Array

Consider the following code

int arr[][]={{10,20,30},{23, 45, 67,}};
int clone[][]=arr.clone();
clone[0][0]=-1;

Q. What should be the value of arr[0][0] and clone [0][0]?

A. It is -1 for both. Why? Let understand 2 things- clone always make a shallow copy of object  & Array is an object in Java.

Shallow copy: When we clone an object in Java, it only creates duplicate copies of primitive types, and for objects, the reference is copied. For example if an Employee object containing an address object is cloned, for address only reference is copied, that is not bot employee and clone are referencing same address object and any change in address is reflected in both.

We can override the clone method for Employee to make sure whenever a clone is made a new object for Address is created as well and all the values are actually copied one by one to new object. This will make sure both the original object and clone are referencing to their own address and changes in one does not get reflected in other.

Array is an object: In java array is an object, so a multidimensional array is actually an object with multiple objects (arrays) in it.

Putting both the above concepts together, we can figure out that while cloning, only the references of array objects  in multidimensional array are copied to cloned object, that means any change in one will get reflected to another.

Agile Development- Is it for me?

Agile practices are becoming popular day by day. In my last post I took up the question Agile Development- What is it? But the important question for a development team or manager should be Agile development- Is it for me? Is it the right choice? Should I use it just because it is working for someone else?

Every coin has 2 sides and so does agile methodology. If there are benefits of using it, it can also hurt the development process if not used intelligently. For example, if a project does not have many UI elements and has more complexity at backend like handling of MDBs and Web Services, having a client demo every week will not be very useful as we will not have anything new to demonstrate. Similarly, if the requirements are mundane and team has already worked on similar requirements already, pair programming will cause a negative impact on productivity.

While going for the agile approach, we will need to analyze if it will work for project in hand, rather than trusting it blindly. Ideally we should be checking each agile practice in detail and see if this is something I can use, and not go for the complete package.

For Example:

Continuous Client Feedback: If my requirements are not very clear, or are prone to changes or software has heavy UI element which needs to be verified by client, I should definitely plan weekly or biweekly demos based on project complexity and requirement.

Test Driven Development: Need to analyze how much automated test scripts will be required. Black box and white box test cases needs to be analyzed. Test cases can be created in parallel of code rather than before coding starts. If requirements are prone to change it might not be useful for me to create automated test scripts beforehand.

Face to Face Communication: if we are working in a model where teams are scattered across globe, we will not be able to follow this. Conference calls might be helpful.

Pair programming: In case we are working on a cutting edge technology which is new to team and having more than one mind concentrate on a problem will help, this is definitely the way to go.

Similarly we will need to take a call on what will work for my project rather than following the herd and going agile mindlessly.

Agile Development- What is it?

Human beings by nature are impatient. That reflects in software development industry as well now. Gone are the days when it used to take years to complete software, now we are talking about software delivery in months and at times in weeks. Due to this impatience, we are seeing a lot of emphasis on agile development practices.

Agile– the term means fast, quick. So we are looking for some way to fasten up our software development process in order to reach the end results quickly. Here are some key components of agile methodology which help us speed up development process

Iterative Development: Rather than following traditional waterfall model, we will get into more spiral mode. The idea is to divide the final requirements into small junks, where each chunk can be delivered one by one, in each iteration.

Continuous Client feedback: This is the most important factor in agile development mode. We do not wait till the end to get the product completed and then get it reviewed from client. The idea is to involve client at every stage by giving weekly or bi weekly demos of the product so that everyone is on the same page and last minute surprises can be avoided.

Test Driven Development: see here.

Emphasis on Face to Face communication: In a normal scenario, where development teams are sitting in different geographical locations, communication will flow through emails. And a query raised from one team will most probably take a day or two to get resolved. This delay can be a killer of agile development, so focus is laid on having team sitting close to each other.

Daily status meets: Generally a short meet of 10 to 30 minutes is scheduled every day where focus is on – previous day’s achievement, today’s plan and any issues being faced. This helps keep the team on track and use knowledge of whole team to solve any issues.

Pair Programming: Slightly controversial practice of2 people sitting together on a machine and writing the code. This is very tricky to implement as if team is not educated on the pair programming activity, we might end up losing productivity that two people are doing work of one.

The list is not exhaustive. Ideally there can be no complete list as every team should invent best practices of its own, of course keeping the tried and tested methodologies as the base.

Revisiting Max Subarray Problem

Sometime back I discussed and solved a problem to find out a subarray from an array which has the maximum sum- here.

I solved the problem using brute force, that is, all the sub arrays were actually created and maximum sum subarray was found. That solution was created in order of N^2 complexity.

Let’s see how can we improve on our solution using divide and conquer approach.

Array: {-1,2,4,60,1,3,-2,-6,7,-9}

If we divide the original array into two half arrays from mid of the array. one of the following must be true

1. Max Subarray is part of first half {-1,2,4,60,1}

2. Max Sub array is part of second half {3,2,-6,7,-9}

3. Max Subarray passes through the mid of array

Array with maximum sum and passes through mid can be easily figured out in order of N. In this we will simply keep moving left and right from the mid until we hit maximum sum array, so first subarray would be 2+4+60+1+3=70

To solve 1 and 2 we will recursively use the approach with the 2 sub arrays (Repeatedly divide the array and find max having mid of the array).

The problem set is getting reduced to half with every iteration, so Log N iterations will be there in total. At max N elements are added (compared to be -ve), in each iteration, hence the total complexity of the algorithm is (N log N), so we are able to reduce the complexity from N^2 to (N log N) with the help of divide and conquer approach.

Merge Sort: Divide and Conquer Approach

Merge sort is classic example of divide and conquer algorithm approach.

Divide and Conquer Algorithm Design approach: The idea is simple, as the term suggest, we try to divide the original problem into multiple smaller problems. These small problems are solved and the solutions then are merged into one final solution.

The concept is used in merge sorting. Input to any sorting algorithm is a random list (array). For sake of this example let’s take a random array of numbers as input.

Divide Phase: Divide the main array into smaller arrays upto a level that it can sorted easily.

Conquer: Merge these entire sorted arrays into the final solution array.

Example – Lets say we have an array

Original: 99, 23, 45, 12, 67, 28, 09, 98, 44, 84

Divide Phase

Arr1: 99, 23, 45, 12, 67                | Arr2:   28, 09, 98, 44, 84

99, 23, 45                    | 12, 67        |28, 09, 98              | 44, 84

99, 23        | 45           |12    | 67     |28, 09        | 98      |44     | 84

99   | 23   | 45           |12    | 67       |28    | 09   | 98      |44     | 84

Merge Phase

23, 99      | 45           |12, 67            |09, 28   | 98           | 44, 84

23, 45, 99                  | 12, 67          | 09, 28, 98              |   44, 84

12, 23, 45, 67, 99                            | 09, 28, 44, 84, 98

09, 12, 23, 28, 44, 45, 67, 84, 98, 99

Complexity Analysis

The Divide phase of merge sort will need log N operations as in every step we are reducing length of array by half.

Merge step will again have log N merges and in each merge step we will have maximum N comparison, so the overall complexity will (N log N)

Test Driven Development

One of the most important practices of Agile development process is Test Driven Development (TDD). It is not a complex term to understand, TDD simply means you are aware of test cases before you actually start development of a piece of code. You are supposed to write test cases, automated test scripts, Junit test suite before you actually went on to write the real code.

Though the concept is simple, but in real world the implementation is not that easy. Why? Lets look at some of the key challenges.

Challenges for TDD

1. How can you create a test plan for something which does not even exist?
2. What if Requirement gets changed or modified? Instead of just making code change, we are making change to test plan as well. If we were creating tests after code completion, we will have saved ourselves from the trouble of making the changes to test plan.

Ok we have talked about the challenges, so why should we take so much pain and not just stick to the regular practice of writing test cases after writing the code.

Advantages of TDD

1. You can test the code implementation the moment you have written it without waiting for the test to be ready as the test was written before code.
2. Errors are caught at the early stage rather than propagating till late stages.
3. Test cases can be confirmed by business team, so that any discrepancy in the requirements can be figured out at an initial stage.
4. Most importantly, a TDD makes sure improvement in code quality. As the test cases are written in advance, it makes sure that all the code written passes the test before getting checked in.

Factory Pattern vs Strategy Pattern

Factory pattern and Strategy pattern might create a confusion if you are using them for the first time. Atleast I was confused, so I tried to analyze the two patterns further.

Let’s relook at the two examples which we used for factory and strategy pattern.

http://kamalmeet.com/2013/06/factory-pattern/

http://kamalmeet.com/2013/03/understanding-strategy-pattern/

Car Factory- A factory for creating Sedan or Hatchback car at the run time based on user need.

Tax Calculator- To pick at run time which type of tax to be calculated (Indian or German).

The difference lies in the usage of two examples above. In first example we are creating object of something, so we can conclude factory pattern is a creational pattern. In second example it is clear we are trying to achieve a goal / execute a method based on input, hence strategy pattern is an operational pattern.