Nanoinhomogeneities in glasses and relaxors: How, when, and why they arise?