A characterization of flat spaces in a finite geometry and the uniqueness of the hamming and the MacDonald codes