Open source* can be very appealing. An author of a story often won't feel satisfied until his work is in the hands of the general public. Simiarly, we get some satisfaction when our source code is publicly available.
When a man assumes a public trust he should consider himself a public property.
- Thomas Jefferson
Giving away your source code -- making it "public property" -- should be a very serious decision.
Why to open source your code
There are many reasons to make your code open source.
Open source code can be used widely, freely. If anyone uses your code, then this amounts to a massive peer review. It also means that you can have many people working on it openly (including using a site like google code or github). Collective effort can often result in a superior product; even more important, some software could never have been implemented by one person.
Making your source code open source also means that you are doing something altruistic: making software available to everyone at no cost. This is not to say that charging for software is a bad thing (free market profits are good and drive most innovations), but donating intellectual property is philanthropy in the same sense as donating money.
Why not to open source your code
But what does it mean when something is public property? Simply put: your code has no salable value. Consider the following thought experiment:
Let's suppose that you have a small software development firm with four employees: you build websites. As part of your on-going work, you create your own proprietary CMS. Let's suppose further that this tool is not significantly different than other tools in the market, but it is used critically by your customers. There comes a time when you want to retire or simply move on to do something else, so you want to sell your business. In a scenario when you had open sourced your software, the value of your firm rests solely on you. If you are now gone, what is the remaining value of your firm? On the other hand, if you have a product from all your intellectual effort that you solely own, your firm has an intrinsic value.
Where did that value go? Some small part of it went into your reputation. But most of it is now shared amongst all the people who freely use your software. Making your software open source literally transfers the value from you to the public.
The motivation of having your code used and viewed, which comes from this desire to create a public good and to engage openly in a community, should occasionally be checked. Software that is used widely can be more important than software that can be freely read. And profits can be critical to continued innovation, especially when working in niche field.
* Note that by "open source", I am here referring to things in the vein of GPL. There are many different open source licenses and I am strictly referring to those that allow free and unrestricted usage.