19
Sep 11

Unusual but Achievable: Running 0 to 10K in 60 days

First of all it’s not difficult, if you are actively involved in some level of sports or other physical activity.

My background

My profession does not facilitate me to do any physical activity nor I was involved any kind of games in my life time. Before running I usually walk (3-4K) as exercise for few times in month.

How I started

My wrist size was increasing and it makes me worried, so I started doing walk in morning almost 2-3 days in a week. To cover 3-4K walk I have to spend around 1 hour.

First Month

I want some quick exercise, so I have started jogging. First few days was difficult.  Running was quicker so I keep running every day. After two weeks I started enjoying the whole process. Listening music while running was also great feel. I started  increasing distance and within one month I was able to complete around 3K.  I had a great feeling about my progress.

Second Month

I thought now I should have some target and practice it with some schedule.I discovered http://www.halhigdon.com/ and selected training for your first 10-K.

I never follow this because my schedule of going for running based upon lots of things. Having day job, father of a 2 year old daughter and staying with parents; all these does not allow me to follow the schedule.

But one thing was very clear from schedule that, if I have to do long run than only running will not going to help me. I have to do other exercises as well. So I created my own schedule according to my need. My schedule was 1) Having less time – Lets do some Stretch & strength through body weight or try to run 3-4 200m sprints.  2) Miss  – don’t worry today is a break ;) . 2) Enough time, do complete running with Stretch.  Idea was -  “keep going.

Every time I go for running I try to increasing my distance by 200-500 meter. After around one month I have reached the level of 10K though timing was not so great but who cares at this level (10K in 1 hour 6 mins). As a side effect I have loose around 5Kg weight and improved eating habits because it helps me in running.

Why running

It require nothing. You just need a pair of shoes and that’s it. You don’t need training, expensive gym membership, people etc. Except rain in morning there is no problem . There is no age  sex bar.

Running on treadmill

I have tried treadmill at gym for couple of days and believe me it sucks big time. 1) Its boring; running on same place every day is not going to motivate you for long distance running. Running on ground or on road keeps your mind engages with activity surround you. 2) It will not as effective as running on ground because your base is moving through motor and it makes running less effective. 3) Cannot enjoy morning freshness at gym.

Things you need for running

1. Shoe

I used basic nike jogger and I don’t think anybody need any expensive shoes until they are professional runner  So far I am not facing any problem with related to my shoes.

2. Body outfit

I used adidas running shorts and believe me these running shorts are worth. Before that I used normal shorts which have two side pockets and it was uncomfortable to keep your cell phone and keys in side pocket while running. Running shorts are design for running so they fit and there is only one small pocket with zip on the backside for cell phone and other small stuff.

3. Music

Initially I used music while running; latter I discovered running without music is more employable. Running without music helps me to think about various tasks. This whole blog post I have thought while running.

4. Running Track

Park where I run in morning having cemented 1400 meter track as well as 1600 meter grass track. I use grass track.

5. Time

Now as I am running 10K and I have to spend around 1.5 hours on park. I have changed couple of things in my lifestyle a) I Try to sleep on same time very night between 9:30 – 10:30. b) I have cut down all the time waste activity.
To satisfy both the condition I have stopped watching TV. Also promote my family members not to watch TV after 9pm. It works very well. It helps to go for sleep on same time. Second I get more time in my life to do running and spend with my family.

I try not to miss a single day. Some time when I have no time for running I just go to park run one 200 meter sprint and come back to home. It give me a feeling o f get going and not stopped.

I have read somewhere

If you miss today there is highly chance that you miss next day as well.


02
Aug 11

Does writing good content is good enough for reaching out people

This article is a personal note from Ask HN: How to be successful online without SEO bullshittery?

Three things to consider before write any content
1. Something worth saying.
2. The ability to say it in an intelligible manner.
3. The ability to promote it to right audience.

To start with always focus on some clear topic; it will give readers a signal. Writing everything will confuse the readers and probably they don’t subscribe you. People looking for geeky articles won’t follow you because they don’t want to be spammed with your movie reviews, so having a focus topic is necessary condition to any blog or content site.

Some self promotion is required, share it through facebook, twitter or send mail to your friends and family.

Personal distribution channel - Post your articles on social news sites. Feedback is necessary to improve the content. Relentlessly put your site out there, on Twitter, on Facebook, everywhere. Post comments on other people’s blogs to make connections. Submit your articles to Slashdot. Keep at it until you get through. It might take months, or even years. If you don’t actively do it, though, it will never happen.

You need to answer the following questions. If you can answer them satisfactorily, your blog readership will increase substantially:
1) Why should anyone care about my blog?
2) Who should care about my blog?
3) Will these people be annoyed by any part of my blog?
4) How am I promoting my blog to get to these people?
5) How am I connecting with these people as human beings rather than just readers?

Google _loves_ sites that are tightly focused on a specific niche that update frequently containing well written text.

If you want to succeed, look at all the genuinely successful sites. They all have a thread of personality, a pattern, a rhythm, and a predictable-ness — that doesn’t mean boring, it means they are graspable.

SEO for most startups isn’t about doing all sorts of trickery to rake in tons of traffic, it’s about letting people find you easily.

If your site includes embeddable widgets for users you probably give yourself some kind of back link.

Google primarily focuses around a site’s authority. You get authority by incoming links from reputable sources, for a startup these would be places like Techcrunch, Mashable, RWW, etc. And it’s not a numbers game, it’s a quality game.

The Internet isn’t a store front that people are forced to walk by. Without a marketing strategy your site does not exist.

Writing the article is half the job, if that. You’ve got to let people know it exists. Simply having google index it doesn’t mean shit.

you’re never going to become the next Kottke with a general interest weblog, but if you find a niche you’re passionate about, you don’t need to do any SEO douchebag stuff to attract readers.
Example – onethingwell – is a tightly-focussed, single topic blog, committed to writing three posts every week day.

Nice slides about SEO recommendations for web developers Search-Friendly Web Development


25
Jul 11

Readonly and const in C#

There are two type of constant in C#

  1. const – Compile time constant.
  2. readonly – Runtime constant.

const (Compile time constant) are bit faster but less flexible where readonly (runtime constant) are bit slower in comparison with const but more flexible. (If you change value of const in your class then every client code which using the reference of that class.)

If you define any const and use in you code it actually it replace with the value to const instead of holding the reference of const. Which makes const bit faster in comparison with readonly. But it also make less flexible.

  1. const can only be primitive type (numeric and string) because it has to replace the value to const where it used in code that’s why and any runtime evaluation is not allowed.
  2. If you change the value to const in you code then every assemblies which using that const must be recompile otherwise changes would not be reflect.

readonly can only be initialize while declaration or in constructor but not after that while const can declare in method as well. That make readonly flexible enough to create different constant for each instance of class which is not possible with const. Another flexibility with readonly is it can be any type.

If readonly is refrence type then reference is immutable but actual object is not; means we can change the reference but we can change the same object (like changing the data for its properties or data member).


25
Jun 11

Initialization of variables in C#

If we initialization of variable while declaring it then compiler generates the initialization code at beginning of each constructor. If there is no constructor then compiler generates the default constructor for that class. This initialization code execute before base class constructor and execute in order they declare.

Initialization of member variable while declaring it get rid of the problem of put member variable initialization code in constructor.

If you have to initialization your variable null then do do this because it will automatically initialize to null variable is not initialize.

Only do initialization of those variables which you want to initialize in constructor. If you have to initialize your variable somewhere else then previous initialize object will going to collect by the garbage.

If you do initialization while declaring the variable then you can not catch any exception if there is any. In that case use constructor.

To initialize static variable static constructor are the best place. Static constructor execute before any other method, properties or data member access first time and static constructor are called by CLR so they will be always parameter less.


26
May 11

VSS to Mercurial

Note: I was using VSS around 2 year back and move to mercurial when i have started my own company. Few days back I had discussion with one one of my ex colleague who is still using VSS and does not feel they required to move to new source control. This blog post is all about the discussion I had with him about VSS, distributed source control especially mercurial (because I am using it) and people who are not using any source control.

Why to use source control

Do you know “The Joel Test” – The first requirement of good software development is source control. If you or your company are not using it then change that; either company or way of work.

Now a days people don’t ask “do you use source control?”. They ask which all source controls you have used so far and what is your workflow.

Some people argue that I am alone developer and I take backup every night to my code (through some automated system or manual) and I don’t need source control complexity in my life. This project can be in your organization or your pet project in your free time.

My argument is; any serious source code should be in source control otherwise it is not serious. Backup is not primary reason to use source control it is a bi product of using source control.

Around two year back we used VSS as a source control. Its seems nice because I never used any other source control system. I heard about CVS, SVN etc but never get chance to using it. VSS had lots of problems like

  • It damage often. Once In past we even lose all the history from VSS due to damage.
  • Lock – VSS work on lock mechanism; where developer have to locked the file before start the work. So developer have to keep in mind before doing any changes with the code base. In locking mechanism no two developer can work on the same file at same time. There are lots of time when developer goes on leave and he locked couple of file in VSS.
  • Over internet VSS (Till the time i used) is not reliable. We use paid third party plugin to use VSS over the internet.
  • VSS required IT guy to manage the server.

When I have started in new organization, one of the first few things which I required is source control. My wish list for source control was

  • Free or less license fee
  • Reliable
  • Easy manageable (Till date we don;t have any server administrator guy.)
  • Work well on over the internet.
  • Good support on windows.
  • Reliable hosted solution.

I had couple of options a) SVN, b) Git (A big buzz word in source control due to github) c) mercurial.

All above are free and open source. github.com (for git) and bitbucket.org (for mercurial) was my favorite one because of distributed source control buzzword. After little bit of research I found that mercurial have better support on windows, bitbucket.org have option to create free account with private repository for life time and 5 users allowed with free account.

So I have decided to use mercurial because

Using distributed source control require only mental shift from client server source control system and that shift is really worth.

In distributed source control every developer holds complete repository on his local machine. so every time developer commit any change it commit on his local repository. Once he finish his changes then he push his changes to other repository. Because every developer holds copy of repository on his machine it gives following advantage.

  • Speed -It makes day to day task very speedy because it holds complete repository on his had drive and there are no network latency. He required network only for pull or push the changes form other repository. So It can be used online and offline. Distributed source control was design with the mind set that developer not necessary connected to internet/internet every time.
  • Separation of work by branching and merging - Branching is another reason to use mercurial. I never use SVN and there are no concept of branching in VSS. Consider the scenario- You and your team have just release the code base to QA and then you have start working on future version of app and same time QA is raising bugs. I don’t know about the SVN but in VSS handling these type of situation is not possible. In VSS days we all are not allowed to write new code until QA have finished all the testing and there are no more bugs. Once everything is fixed we label the codebase in VSS and start working on new version. In mercurial we create new branch and start working on new version with other team mates. If QA raised any bug we simply switch to main branch and fix the bugs. Once QA done with testing we marge newly created branch with main branch. Switching between branch in mercurial is super easy and pain less.
  • Reliability – Due to distributed nature it really hard to destroy. As each developer machine have complete repository creating new centerlize repository is pretty easy.
  • Easy to learn – I have started using mercurial after 2 hour of learning.
  • Collaborative – Distributed source control allows developer to communicate directly without affecting the central server.

Only mental shift you require while working with team in organization is; you need to have one centralize repository. Every team member will pull or push changes from centralize repository when they are ready to. It don’t mean that you can’t pull or push changes with your team mate. Centralize repository will don’t have working directory because nobody will going to work on centralize server. Every team member will only push his latest finish changes to centralize server and take latest changes from centralize server. Just as we do with VSS or SVN . So distributed source control have all the advantage as client/server source control with addition to speed, reliability and high level of celebration with other team mate without affecting the central server.

Our setup

We have pretty simple setup. Every developer machine have configured a free account of dropbox (2 GB is so far sufficient for source code backup). We use bitbucket.org as a central repository. Every developer have it own repository and working directory in dropbox folder.

Resource

I have used http://hgbook.red-bean.com/ for mercurial.

http://hginit.com/ is also a nice tutorial about mercurial and distributed source control.


20
May 11

Non-sense tips for start-up

Startup founder

We have been running a service-based start-up organisation for the past 18 months. In this article I am going to highlight on some points I learnt while managing this start up.

We are now a team of approximately 18 people and I am the person responsible for infrastructure, HR and technical concerns. So in this article I am going to write about recruitment, team management and infrastructure.

Infrastructure

1. Power backup

Before you decide on an office location, please make sure that it has enough power backup for power cuts of longer duration. I have had some bad experiences in the past. We had power backup for 3-4 hours for all PCs, light and fans, but not for air conditioners (AC). Working without AC in summer was almost impossible and sometimes these power cuts were so frequent and longer that small power backup systems would not suffice.

Availability of less space is acceptable. However, this kind of power cut not only interrupts the work atmosphere but also demotivates employees. Sometimes it would be embarrassing if the power is cut during a client visit.

Try to occupy a rental building where the complete building has power backup plans with generators, which will make you feel that there is no power cuts at all. For such buildings, you have to pay more, but believe me, it will be worth paying.

2. Office Boy

When we start a business we think that office boys can be replaced often, but we are wrong. If you have decided to hire your first employee, then the first choice should be to hire office boys who can do the following activities:

  • He should make good tea/coffee.
  • He should open the office on time and make sure office is cleaned before any other employee comes to office (remember that the workstation should be neat and clean on all working days).
  • He should get lunch/dinner from nearby hotels for the office staff (it would be better if he knows some of the best nearby food places).
  • He should handle office administration work such as posting couriers, taking printouts, scanning, photocopying, etc.

These small activities might add burden on you and make you frustrated.

3. Internet

For any web-based start up, internet is the life line. We started with a plan from Airtel that seemed good for a couple of months until we faced a huge downtime for 3 days due to some maintenance work. At the time, I realized that having another internet connection with some other provider is a must. At least one big failure in a month, leading to couple of hours of downtime is usual with every provider. Having another connection with less bandwidth is essential.

4. Office Size

I don’t know what to say about this. A number of people told us that having bigger offices is a huge advantage. But I believe that they either gave us an incomplete picture or we understood them wrong. According to me, a well-managed office space is more important than a bigger office space. For our organization, it was enough to have 20-30% extra space but we went for around 60% extra space, which added a lot of burden on me to manage that space. If you are really planning a larger space, then make sure you hire some infra guy who can manage that space.

Recruitment

This is the single most important thing for a start up. Steve Jobs said the

first 30 employees would define the future of the company.

But I would say that the first 5 or first 3 or even the first employee can define the future of the company.

One of our valuable unofficial advisers, who had great experience in recruitment shared his experiences:

Hiring the first person is important if you are hiring for some area where you do not have some experience. He will bring other people according to his taste and if something does not goes well then you never understand; what is wrong—people, market or something else.

This is quite true. We also had similar experience with our different department. The first thing you should know when to hire. According to Peldi (Founder of awesome mockup tool http://balsamiq.com/) – “You should hire somebody once you see you are going to die just because of work”. This is correct because it gives you a clear picture of what you are looking for and once you hired somebody you can assign a good amount of work.

1. Job Sites Suck

Yes, recruitment websites suck big time, not because they are bad but because they are not designed for start ups. People who post their resume on Naukri/Monster don’t know about you and your company and you end up with lots of resume which don’t fit the needs of your company.

I would suggest you go for reference. Ask your friends, family members, employees for reference. It will solve two problems a) Most of the time they portrait the right picture in front of candidate b) You will end up with resumes which are in less in count and more relevant. Searching candidates to come-up for interview is a time taking process and you save time on that with references.

2. Age, Marital Status and Start Up Passion

First of all I am not making any judgment about a person based upon their marital status, sex and their age. But I am sharing my experience. You should look for candidate who is a) Passionate about your start up b) Passionate about the skills for which he/she has been hired c) Can work extra hours if needed d) Can take less salary ;) .

A & B is the most essential element you should look for in that order. We had some bed experience with hiring very experienced and skilled persons who leave us without adding any value because they do not have the attitude to work in a start up. You lose money, time and energy and its add only frustration. OK now let’s talk about C & D. A person who is not married and is younger can easily spend more time on work and live with less salary. I am not underestimating older and married guys, but it is little bit more difficult for them.

3. Hiring Friends

There are some really serious pros and cons of the same. If he meets all the above four criteria of an employee, then you should consider yourself lucky because you don’t have to put in efforts towards recruitment. Its like winning the lottery without buying the tickets. But if does not turn out to be a good, then it is very difficult to get rid of him. So don’t go with gut feeling while hiring any friend/relative as an employee. Make sure you have seen his work in the past and know his strengths and weakness and discuss it with him/her as well.

4. Make Sure the Person is Eager to Join You

This leads to point number A. If he is not eager to join you and you use some other technique like paying a big salary or giving a better position, the person is not going to last.

5. Never Hire a Person in the First Interview

People have multiple faces and you can see only one face at a time. Try to call a person for an interview at least 2-3 times and make him meet different people each time. It will give you good perspective about the person. It will also test the seriousness of the person. If he did not show up the second time, he probably was not interested.

6. Don’t Hire Too Many People at Once

Hiring too many people at the same time can become difficult to manage because every new hire requires attention to get familiar with your company. If you hire too many people at the same time, you are splitting your attention between all the new hires. In start ups your attention towards your employee is considered important.

All above points are too idealistic about recruitment. We have learned some hard lesson in past. The biggest challenge in a start up is to find time to get recruitment done because you are always so busy with current execution. But it is the most serious thing you can do in your start up while scaling it. Every founder and employee of the company should be involved with this process. If you hired the right person for the right job, you are almost done. People management becomes difficult when the person is not right or the task is not assigned to the right person.

Team management

1. Party

One of our advisers has suggested a great tip: “In a start up you should know each and every employee’s family, not just the employee”. You can achieve this only though un-official discussions where there is no boss and no employee. Have small, cheap frequent parties in your office. Have lots of un-official discussions about people. Make sure not a single employee feels lonely. Everybody is not a party animal. So make sure every employee feels like he is in the company of friends.

2. Work & Work culture

If you want to hire and retain good people make sure you have adequate work culture. As a programmer, I never want to be around non programmers. Everybody loves to stay with similar kind of people because dealing with them is easy and that’s where culture begins.

Developers want to work quietly, while business people want a lot of discussion. Developers think business people are wasting time in discussions and business people think developers are boring, but both are right in their own place. Developers require quite and longer time to finish their task and business people requires meetings to get things done. If both people will work on the same location without any physical boundary, then it will be difficult for them to work and create appropriate work culture.

Another point is that every employee should have enough work to keep them busy. When an employee comes in morning, he should feel that there are a lot of things to finish. It gives you couple of benefits a) Employee starts feeling that company is growing b) Finishing the task or deals are most important feeling for any professional. It gives a good feel when we leave for home. Employees gain a sense of achievement and learning in such a scenario. That leads to the point where I said hire people at a time when nothing can move without them.

Even if employees have free time, do something that benefits the company as well as employees. Think of free time as scrap and try to sell it as high as possible. Whatever something comes out of it, it is a benefit to the company and the employee. If nothing comes of it, then it was scrap. But try to use this free time seriously, there might be a gold mine.

Summary

All the above points are our learning through lots of failures and some successes. I want to thanks people who have shared some wonderful tips for certain problems from their experience. Implementing the above points are challenging as far as our experience is concerned. It requires a hell lot of time, money, energy and motivation.


25
Feb 11

Properties in C#

Properties are methods but accessed as a data member.


class TimeMachine
{
private double seconds;

public double Hours
{
get { return seconds / 3600; }
set { seconds = value * 3600; }
}
}

class Program
{
static void Main()
{
Timemachine t = new TimeMachine();
// Assigning the Hours property causes the 'set' accessor to be called.
t.Hours = 24;
// Evaluating the Hours property causes the 'get' accessor to be called.
System.Console.WriteLine("Time in hours: " + t.Hours);
}
}
// Output: Time in hours: 24

It makes easier to add any small logic with properties. In above example we have converted seconds in hours within properties.
Most of the time adding validation logic in get and set are handy.
Compiler generates get and set method for the properties. That’s why properties have all the language features of method.

In C# 4 you can declare implicit properties


class TimePeriod
{
public double Hours
{
get;
set;
}
}

In above example compiler will automatically generates the private filed for Hours (also known as backing fields).
There are some problem with implicit properties:
1. We can not initialize the properties as we can do in explicit properties.
2. While debugging you can not put break point on get or set, but with explicit properties we can set break point on get and set.

Both get and set can have different access modifiers which helps us to make read only and write only properties. It is not possible with data member.

Properties looks like data member but generates different MSIL, so if you change any data member to properties you must recompile all the assemblies which using that class.

As properties are method but we should always avoid any computation which take long time, because properties are made for holding data. It is replacement of public data member with some extra capabilities.


18
Jan 11

Excel: Unable to drag cell corner to auto increment

I am not a big user of Excel but I know I can write 1,2 in two cells and drag my mouse to auto generate rest of numbers.

But somehow it was not working on my Excel 2007 after 10-15 minutes of struggle I was able to fix that.

To fix that click on the office icon on top left and then click on the “Excel Options” then go to “Advance”.

Under “Edit Options” there is a check box named “Enable fill handle and cell drag-and-drop”. Select the check box to enable the auto increment.

Hope this help!!!


06
Dec 10

Redmine installation on dreamhost shared hosting [for windows users]

I want to setup simple bug tracking system for our internal use, which don’t require any kind of training before start. After evaluating couple of free, open source systems (Bugzilla, Trac, Pivotal Tracker, BugTracker.NET) I found redmine was good, simple and build upon rails. As I also want to learn ruby and rails so I thought it could be good exercise. Redmine also includes wiki, which makes it more attractive.

After 5-6 hours of adventures ride, finally I was able to install it on dreamhost shared hosting.

Following are the steps I have taken to install it.

If you don’t have shell account, you must create a shell account before start through dream host panel, or you can enable SSH access to your current user.

Go to the User -> Manage Users

Click on the “edit” link of the user which you want to give SSH access.

On the Edit user screen, there is an option of user account type. Select “Shell account”. Click on the Save Changes button. That’s it. Your user is ready with SSH access.

Create a sub-domain, or you can install it on the root domain. In my case I want to install on sub domain (your-sub-domain.your-domain.com) suppose you want to install redmine on you-sub-domain.

Make sure your SSH account must have right on this folder.

Make sure the domain supports “Ruby on Rails Passenger (mod_rails)?”

Specify your web directory: /home/username/ your-sub-domain.your-domain.com /public (add public folder if it does not add by default.)

Also create new database though MYSQL database for redmine. Keep database hostname, user name and password handy.

Now you need a SSH client. For windows PuTTY is an option.

Following are the steps to access SSH through PuTTy

  1. Download and install the “Windows-style installer” from the PuTTY Download Page. [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html].
  2. Open PuTTY, under the category tree select Session, on the right side enter the host name [full path of your domain] and click on the open.
  3. Command prompt type of screen will open and asking for “login as”. Give you SSH user name and press enter. Then it will asking for the password.

That’s it you are now accessing your server through SSH account.

Now go to the http://www.redmine.org/wiki/redmine/Download see which stable version available to download through SVN in my case it was svn://rubyforge.org/var/svn/redmine/branches/0.9-stable

SSH into your dreamhost account run following command

cd  your-sub-domain.your-domain.com

Now we need to import the latest redmine code on to the server through svn

svn export  --force svn://rubyforge.org/var/svn/redmine/branches/0.9-stable

for permission run following command

chmod -v -R 755 ./

go to the config directory

cd config

change the database.yml.example to database.yml

cp database.yml.example database.yml

now we have to put database details into database.yml

vi database.yml

It will open the vi editor. Press “I” to come into the “Insert” mode. Change following details


production:

adapter: mysql

database: yourdatabasename

username: yourusername

password: yourpassword

host: mysql.yourdomain.com

After adding your details press “Esc” to exit from insert mode. Press Shift +q to come into the command mode. Now enter :x in command for save and exit the database.yml.

Go into your-sub-domain.your-domain.com/public

cd ~/ your-sub-domain.your-domain.com /public

cp dispatch.rb.example dispatch.rb

cp dispatch.fcgi.example dispatch.fcgi

cp dispatch.cgi.example dispatch.cgi

vi .htaccess (replace with following text)

Options +FollowSymLinks +ExecCGI

RewriteEngine On

RewriteRule ^$ index.html [QSA]

RewriteRule ^([^.]+)$ $1.html [QSA]

RewriteCond %{REQUEST_FILENAME} !-f

ErrorDocument 500 "H2Application errorH2 Rails application failed to start properly"

replace the H2 with the proper HTML tag when you place it in the .htaccess

cd ~/ your-sub-domain.your-domain.com

* rake generate_session_store

This will generate a file (config/initializers/session_store.rb) with a random secret used to secure session data.

from application root type

* rake db:migrate RAILS_ENV="production"

also type the following to load config defaults

* rake redmine:load_default_data RAILS_ENV="production"


* choose "en" for english

browse to http~/ your-sub-domain.your-domain.com

Happy bug tracking!!!


07
Oct 10

Association, Aggregation, Composition object relationship

Association → Whenever two object are related with each other the relationship is called association between objects.
According to wiki

“Association represents the static relationship shared among the objects of two classes.”

So any relationship between object of two classes is called association.
Example - “University offers courses” where university have association with courses.

Aggregation → Aggregation is specialized form of association. In aggregation objects have their own life-cycle but there is ownership and child object can not belongs to another parent object. But this is only an ownership not the life-cycle control of child control through parent object.
According to wiki

aggregation is an association that represents a part-whole or part-of relationship.

Most of the time aggregation used when a class is a collection or container of other classes, but where the contained classes do not have a strong life cycle dependency on the container—essentially, if the container is destroyed, its contents are not.
Let’s take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers but there is no ownership between the objects and both have their own life-cycle. Both can create and delete independently.

Composition → Composition is again specialize form of aggregation and we can call this as a “life and death” relationship. It is a strong type of aggregation. Child object dose not have their life-cycle and if parent object deletes all child object will also be deleted.
Let’s take again an example of relationship between house and rooms. House can contain multiple rooms there is no independent life of room and any room can not belongs to two different house if we delete the house room will automatically delete.
Another example; think about relationship between questions and options. Single questions can have multiple options and an option can not belong to multiple questions. If we delete questions options will automatically delete.
According to wiki

“Composition is a way to combine simple objects or data types into more complex ones”

To remember composition you can think of “has a” relationship between parent object and child object.
Look at a bicycle as a object which is a composition of wheel, handle and other building block of bicycle. So bicycle “has a” composite type of wheel.
The basic difference between aggregation and composition is the life cycle of object.
During implementation of composition parent object is also responsible for creating the child object. We can not create child object independently. If I am having questions and options. Question will be associate with options. But there is no existence of options without questions. So question object will be responsible for creation and deletion of option object.

Some other examples from different article (Following are not my words, got them from another site)

Association:
1. Create a folder called “Links”.
2. create a shortcut inside this folder and link it to www.yahoo.com
3. create another shortcut inside this folder and link it to www.google.com
4. Ask your friend to do the same on another machine using same links (www.yahoo.com and www.google.com)
5. Delete the “Links” folder, and open your browser to check if www.yahoo.com and www.google.com still exist or not ;)

Briefly, Association is a relationship where all the objects have different life cycles. There is no owner.

Aggregation:
1. Create a file called file.txt
2. make a simple application to open the file.txt, but don’t close the connection.
3. Run an instance of this application (it should work OK and can open the same file)
4. Keep the first instance, and run another instance of this application (In theory it should complain that it can’t open the file in read-write mode because it is already used by other application).
5. Close the 2 instances (make sure you close the connection).
From the above application, we knew that the Application and the file has a separate life-cycles, however this file can be opened only by one application simultaneously (there is only one parent at the same time, however, this parent can move the child to another parent or can make it orphan).

Composition:
1. Open a new Document name it as test.txt
2. Write this sentence in inside this document “This is a composition”.
3. Save the document.
4. Now, delete this document.

This is what is called composition, you can’t move the sentence “This is a composition” from the document because its life-cycle is linked to the parent (the document)

Book recommendation → Code Complete is an excellent book which I Recommend to every programmer. If you don’t have please have it.