First you create the sphere, lets say 20x20 segments. Then you select a few adjacent polygons in the middle of the sphere and extrude them inwards. Alternatively, you first make an extrusion along the surface first, to give you a good basis for defining the rim of the extrusion, and then extrude the middle face inwards.
So far, so good. Now, when you smooth this, you'll end up with a circular hole. But we wanted a square hole, with sharply defined corners.
The only two methods through which I've succeeded in doing this is to either smooth and object first, then add the indentation (And while this works fine in such a simple project as the example I made in this post, in more advanced and irregular hard-surface objects it would take an annoying amount of planning to make this work. The other is to smooth first and then do a boolean difference operation with a square object. It goes without saying that this can result in catastrophic results, as especially more advanced meshes will require a massive amount of cleanup, if the boolean even work (Maya's Boolean tools have a track record which is quite unimpressive, at least for me), and the same problem with having to plan ahead is present in this case.
So, how do one go about defining the corners while at the same time preserving the smoothness of the objects surface? Every method I've tried have ended me up with smoothing artifacts at the corners, like bumps or edge-pinches. If you could, please post pictures showing your topology solutions :)