Read other people code

Writing a software program code is like writing a novel, there’re an art behind it.
We all learn how to write or speak Arabic or English but very few can become novelists. Same thing about programming languages, many know the grammar but very few can write an artistic code.
Attend courses that teach how to write good solid beautiful code (ExpertWave have such courses), read books about how to write professional code, or at least read other people’s code to learn from other’s professional by reading their code and try to find how it’s good and do the same when you write your code.