It depends on what you're looking for.
Buying a duplex and renting out the other half can be a good deal, *IF* prices in your area support it. Be sure to do the research on the area and going rent rates. The upside is that if you buy a $150,000 duplex - your monthly payments might be $1300 a month... if you can rent half of the duplex out for $700 a month, you're basically making a profit. (and only paying $600 a month for your own place to live). The downside is, any month that the duplex is NOT rented, you're shelling out $1300 a month for your own rent. Also remember that being a landlord involves responsibility - you'll be the one they call when the fridge breaks or the plumbing leaks, etc. If you're a handy fix-it-yourself kind of guy that may be fine - but if you're the kind of guy who would immediately call a plumber, then you could have some months where you LOSE money on the deal.
Also don't forget you can have situations where tenants don't pay, you have to evict them (!), they skip town, etc. You want to make sure you interview people carefully to live there and reject anybody you aren't 100% comfortable with. Even with those that seem great, you never know when the police will show up on your front lawn and next thing you know everyone is watching you on COPS standing around in your boxers going "they seemed like nice people..."
;-)
But, yes, if you can afford it, and you think you're looking in an area where you'd be able to rent it out to the kind of people you're comfortable with - not a bad idea at all.
Edit: I forgot the best possible scenario - if you own a duplex in an area where rents are going up, and continue to go up, eventually you may be in a situation where one half of the house rents for almost as much as the mortgage. IE let's say you can rent half the house out for $1000. That's when you should move out - rent both halves for $2000 a month, and now you're actually making $700 a month profit on the investment. That should easily cover unexpected repairs and upkeep. Then, in 30 years (or earlier) you'll own the property outright - and somebody else paid the mortage for you every month. Again, that's the "best case".... YMMV.