8/10/14

Chronicles of Last six months

As far as you Know it have been long time I have written something

yet here I'm in boring Sunday morning (which used to be a poya day as well) with limited Internet connection try to write down something

lets try to list down some semi professional things  which I was step in to past few months

Framework Vs Matured Framework 

when its comes to an open source framework selection always go for a matured one that means a framework that have been around for at least 3 years which have reasonable numbered user community .

the new framework may have cool features such as XML annotation ,lazy binding etc .. but not the help when you needed them .. or a less documented API .. don't risk your entire project  on that

Process  ... Process and more Process

the way maintain professionalism is getting rid of doing ad-hoc thing .. well at least try to avoid ad-hoc stuff until others recognize you as a professional . define some steps to do a every day task ,maintain communication with relevant people

Small Organizations give you opportunity to expand

we all dreams to work for big company like google , facebook ,microsoft apple but none of those places offer you a chat with CEO over a tea/coffee at 7 AM morning
I think its a best place to start for a fresh graduate . dream big start small pules points of this is you can hear what your organization really want from you . what their plans for you

most of the big companies want you to work 8 hours a day and 3 months salary in advance if they no longer wanted you thats it

Work Hard or Work Smart 

you have to select one of above ether you work hard or work smart .. don't try to do both I have tried and failed .. so select one I have selected work hard .. because I'm not a smart man :-D 

ok those are the things I have to list down after 2 hours of writing hope this will help for you in some how 

3/15/14

Design Patterns : an Introduction

What are Design Patterns?


Design Patterns provide easy to recognize and use OOP solutions to common problems. They're inherently easy to maintain, because many people are familiar with them.
Design Patterns also solve specific programming challenges regarding usability and maintainability.

Why should we use them?

Design patterns are, by principle, well-thought out solutions to programming problems. Many programmers have encountered these problems before, and have used these ‘solutions’ to remedy them. If you encounter these problems, why recreate a solution when you can use an already proven answer?

But Remember …..

‘Design patterns are a double-edged sword, can be both lifesaver and deadly at the same time.’

2/2/14

Test-Driven Development : A practitioner's guide

What is  TDD

Test-driven development is a programming technique that requires you to write actual code and automated test code simultaneously. This ensures that you test your code—and enables you to retest your code quickly and easily, since it’s automated.

The way to Start TDD is the dumb mans approach
  • you write the test first
  • then you write your working code
  • until test  pass you change your code
  • once test is pass .. add more test cases
  • then again change the code
  • repeat above steps as necessary


lets start with a code here i'm try to get the Fibonacci number


first of all you write the test

public class FibonacciTest {

     
    @Test
    public void testGetFibonacci() {
        Fibonacci f = new Fibonacci();
        int result =f.getFibonacci(0);
        assertEquals(result, 0);
        
    }
}

as my test says there should be a class name Fibonacci and a method getFibonacci that should return int value and accept a int parameter

once we pass the value 0 to getFibonacci it should return 0 (since Fibonacci 0 = 0)

lest write the base code

public class Fibonacci {

    public int getFibonacci(int n) {
        return 0;
    }
}

this is not even Fibonacci but all we wanted to to is get the test pass ,.... and now its passing so
lets add one more test case :D

public class FibonacciTest {

     
    @Test
    public void testGetFibonacci() {
        Fibonacci f = new Fibonacci();
        int n[] = new int[2];
        n[0] = 0;
        n[1] = 1;
        
        
        for (int i = 0; i < n.length; i++) {
            
           int result = f.getFibonacci(i);
           assertEquals(n[i], result); 
        }
        
    }
}
in here I'm try to use an int array as the Fibonacci series index is the position and  value will be the Fibonacci value corresponding
        int n[] = new int[2];
        n[0] = 0; -> Fibonacci 0 =0
        n[1] = 1; -> Fibonacci 1 =1

Now the test start to fail so you can go back to code and modify
public class Fibonacci {

    public int getFibonacci(int n) {
        if (n == 0) {
            return 0;
        }
        return 1;
    }
}


Ok now run the test and see its passing

lets add another test case  n[2] = 1; -> Fibonacci 2 =1 too

public class FibonacciTest {

     
    @Test
    public void testGetFibonacci() {
        Fibonacci f = new Fibonacci();
        int n[] = new int[3];
        n[0] = 0;
        n[1] = 1;
        n[2] = 1;
        
        for (int i = 0; i < n.length; i++) {
            
           int result = f.getFibonacci(i);
           assertEquals(n[i], result); 
        }
        
    }
}

well that's not add a much value still test pass
lets add next value of series Fibonacci 3 =2

public class FibonacciTest {

     
    @Test
    public void testGetFibonacci() {
        Fibonacci f = new Fibonacci();
        int n[] = new int[4];
        n[0] = 0;
        n[1] = 1;
        n[2] = 1;
        n[3] = 2;

        for (int i = 0; i < n.length; i++) {
            
           int result = f.getFibonacci(i);
           assertEquals(n[i], result); 
        }
        
    }
}

Ok now test is falling lets move to code and edit
 public class Fibonacci {

    public int getFibonacci(int n) {
       if (n == 0) {
            return 0;
        } else if(n<3) {
            return 1;
        }else{
          return 2;
        }
    }
}

Still I'm using mocking here and now my code have lot of if else and returns
shall we add more test case :D
public class FibonacciTest {

     
    @Test
    public void testGetFibonacci() {
        Fibonacci f = new Fibonacci();
        int n[] = new int[5];
        n[0] = 0;
        n[1] = 1;
        n[2] = 1;
        n[3] = 2;
        n[4] = 3;

        for (int i = 0; i < n.length; i++) {
            
           int result = f.getFibonacci(i);
           assertEquals(n[i], result); 
        }
        
    }
}

Ok test fails that means more space to improve code

let see if you check the values of Fibonacci (0,1,1,2,3,5,8,13,21,34,55,89,144 .... so on) Fibonacci value of n is Fibonacci value of n-1 +   Fibonacci value of n-2
 and all the base a re less than Fibonacci 0 ,1,2, so from Fibonacci 3 and up its summation of two previous consecutive Fibonacci numbers

after n =3 lets call getFibonacci(n)  again with  getFibonacci(n-1) + getFibonacci(n-2)

 public class Fibonacci {

    public int getFibonacci(int n) {
       if (n == 0) {
            return 0;
        } else if(n<3) {
            return 1;
        }else{
          return getFibonacci(n-1)+ getFibonacci(n-2);
        }
    }
}

And add more test to see it working

public class FibonacciTest {

     
    @Test
    public void testGetFibonacci() {
        Fibonacci f = new Fibonacci();
        int n[] = new int[10];
        n[0] = 0;
        n[1] = 1;
        n[2] = 1;
        n[3] = 2;
        n[4] = 3;
        n[5] = 5;
        n[6] = 8;
        n[7] = 13;
        n[8] = 21;
        n[9] = 34;

        for (int i = 0; i < n.length; i++) {
            
           int result = f.getFibonacci(i);
           assertEquals(n[i], result); 
        }
        
    }
}

so here is my way of TDD ... now I have a good test and some how good Code (still have lot of returns in code ) but since I have the perfect test I can refactor my code with out hassle

I will hope this will help you to get the 101 about TDD skill level need for this is Java and junit testing nothing much

in the first few months when I use TDD i was not much a fan of this but once you get it by heart you will feel the awesomeness of TDD

Pro tips
when you writing classes and want to test properly try to stick with hi-cohesion and low-coupling thing
and try to avoid initiate inside methods instead of try to use strategy pattern and getters and setters

then lets see with  Code refactoring : A practitioner's guide :D

1/14/14

Guide in to Girls and How get Zoned .... I do lot

As far as you I was progressive date crashing on past few months (for sure Programmers don't do it well at leas for me)

so far I was wondering why this my fellow opposite gender zone people much 
while my wonders are in my head here a list of zones I have encounter with my day to day social encounters


Friend Zone :

Most common of all zone this is the place where you were put when its come to the interaction .you will be there and you will not get any

Bro Zone :

Here comes the second .. if you didn't break the friend zone or if you make some smooth moves towards her  or even you are too deep on friend zone this will be your next stop . she will call you "Ayiyaa" funny right
I guess Jeremy and Cersei   will like it

No Hang Out Zone :

This is an exclusive zone . just put you there and cut off all means of communication . they say that "we will hang out for next film definitely "
and you can find out later they have dropped you from their plans



Only get work Done Zone :

yes all means of Interaction depend on there work
they will text you like

 "Can you check my presentation due 2moro ? thank you"

"If you are free can you look in to this code and make it work ? I have to submit this 2moro"

well all of this communication ends once job done ! if you want to make sure that text them like  "Hi Can you help with me to buy a gift for girl ?? " dude you will not getting any reply :D

I have crush/Boyfriend keep away Zone:

basically they start with this they start communication with "My boyfriend .... "
seriously come on I don't even make a move there .. simply the mention about there crush / BF every 2 minute of the conversation if in a case you forgot




there are minor zones .. one that I have been is "furniture zone" yes Nipuni you did that she keep telling me that I remind her a old staircase seriously


ok I know I'm kind of a prick .. been single looking for a way to break the ice
may be its look like I'm a predator for relationship

but it doesn't make me away from one valentine  alone
rejection is not a new thing