Thursday 9 July 2015

Decision Making and achieving the right attitude

Nobody guarantees what's gonna happen next. It takes enormous patience to achieve that kind of clarity of vision in a day-to-day basis.

We humans were never designed to understand minute things directly, the only way to achieve that kind of understanding is - experience, explore and document. This has been the only way a science got developed. Some day some one will come and add some more documentation and build a community on it. This is the way careers get developed - by mutual help.


1. Don't discard good things of past, try to recollect as much as you can.
2. Don't underestimate any small opportunity around you, it might end up becoming the butterfly effect of your life.
3. Explore, explore explore, document, document, document.
4. Know exactly what you want and keep asking people the same.
5. Wait wait wait, survival days are almost done with and it is time to meet and greet people. Respect every one even one wrong word will ruin others' day.
6. Think about your feet, so that we can be practical about what we want to do and keep moving.

Thursday 18 June 2015

Recursion

Recursion is a wonderful method that saves lots of code writing. So what's new in this post ? I haven't found any proper explanation of how exactly to write a recursive algorithm, what are the modules to be considered in a recursive algorithm or what is the fastest way to understand recursion. When I started developing a quick sort algorithm it took eternity to write my own code without reference. So here is the division

Recursive program has four parts

1. Base case which is the end point where recursion will stop or recursion will boomerang back.
Else case
2. Separate (based on number of recursions)
3. Recurse
4. Merge into one

example, take this code
------
int x = 0;
x = 10;
factorial(x);

public void factorial(int x)
{
     if(x == 1)
         return x;
     else
        return x*factorial(x-1);
}
------
is the usual way, but since there is not data manipulation or division, separate and merge don't make sense here.
Dividing this function as per what I have pointed it looks like this ,

------
public void factorial(int x)
{
// base case
     if(x == 1)
         return x;
// else case
     else
     {
        // separate
        int y = x -1;

        // recurse
        y = factorial(y);

        // merge 
        x = x * y;   

        return x;
     }
}
------

This is the worst case we can get with memory in case we want to make some more operations on y based on the algorithm.

Friday 12 June 2015

Single responsibility principle


Spring framework has been with me since my first day of my work experience. Dependency injection is the main reason why Spring has become so popular. So why is spring considered to be a higher level of OOPs rather than an add-on ? The answer lies in "Single responsibility principle".


When I started with writing a new page with a new approach from the normal CRUD backing beans, first thing came to my mind is implement all the add and modify functionality inside one bean. So in this way we can save some memory by using boolean variables that separate functionality. It is like a single Government office with two doors and only one of them will open based on the type of Token number.

This is a very feasible option and a very good way to make things work, until a door gets closed accidentally.  Now this is where the office needs to be deleted into two offices with another set of officers working. This is where the need for "Single responsibility principle"arises, each class should do only one kind of work. This is a very important principle while creating Objects.

What Spring does is it provides beans whenever needed and since they are dedicated beans, serving single purpose can completely remove dependency.