It is better to paint the ceiling first, and then paint the walls. This allows you to hide the remnants of paint from the ceiling that was left on the walls.