I've had an office shared with just one other person, as well as working in open plan offices, and working from home.
They all have advantages, such as when working on debugging, with a small team, to a tight deadline, a small open plan office where people can call out problems and you can just shout back "OK, try it again", works brilliantly and the energy and teamwork is great.
When it comes to heads down application programming however a quiet closed office is the best environment, after all when keeping the structure of three or four objects and their complex relationships in your head you nee to get that vision down and into code quickly with no distractions. If someone distracts you, you will drop the balls and it will be harder to get the image back as clearly, if at all.
The best option would be a large space with slide-able walls , where you could create the workspace required for the type of work you are doing.