How to create a hard straight edge while keeping this sphere's shape?
Start off by adding a cube, giving it a subserf with a level of three, and applying it.


Then tab into edit mode, and use the space bar to search for the "to sphere" operation. Use this operation, press 1, and press enter. This takes our cube which was almost spherical, but not quite, and turned it into a perfect sphere.

Then select the middle 16 faces, and inset them a little bit.


Then extrude those faces back, and scale them along the Y axis to 0 to straighten them out.


Then add a subserf modifer and move the edges closest to the outside of the hole, out to sharpen up the edge, and then add some edge loops around hole to create some sharper edges.


Then tab out of edit mode, and admire your finished result!