Margarine often has a lower saturated fat content and higher water content than butter does causing it to be much softer when cold. Because of it softer property, margarine can cause cakes to be less tender and cookies will generally spread out more and be less crisp when compared to the same recipe using butter. Generally, it is not recommended to replace butter for margarine if a recipe calls for it- unless you’re OK with a slightly different final product.

How does butter stand up against other fats?

Baking with butter has two major advantages over other fats:
1. Flavour. Shortenings are flavorless, but butter has a smoother and more desirable flavour, adding more taste to baking and pastries.
2. Melting qualities. Butter melts in the mouth. Shortenings or lards do not. After eating pastries or icings made with shortening, you might find and unpleasant film or coating in your mouth.

When used in pastry, butter makes it more flavourful and creamy on the tongue than other fats, but might not be as flaky.

Dairy Goodness has some further information about using butter (and some drool worthy recipes too!).