Help, This Code Doesn't Work (Tip #5)
Study Great Code!
One of the ways people learn a craft is to watch experts do the craft. Watching a painter teaches one how to paint, watching a chef teaches one how to cook, and studying great code teaches one how to code well.
I got my first look at good code in school when a professor did some close out on our lab project. (BTW - closeout is a topic onto itself) The professor said - I want to share one possible solution to the lab which I feel is very elegant.
Later, while attending code reviews on the job, I was able to see some really great ways to write code. Coding is like traveling from Maryland to California. There are many paths and lots of options for lodging, eating, vehicle, etc. Discussing plans with someone who has previously made the journey is valuable - to repeat the good choices and avoid the bad choices.
Repeat other's good choices and avoid other's bad choices
When doing something new for the first time - why skip the opportunity to see how someone else accomplished a similar goal? My son installed a flag pole for his Eagle Scout project - we found someone who completed a flag install and we just listened to them. It's all about installing the tube securely and level. The pole itself is easy - and the pole can be reinstalled easily if not done right the first time. Surprise, the pole is held in place by sand.
For first year programmers, I strongly recommend getting yourself to a code inspection (code review, code walk-through, etc) of a senior developer. Your horizons will expand and you'll most definitely learn something. Study great code.
Attend a code review
If you have the opportunity to actually watch an experienced programmer work - that's even better. Or, work under the wing of a grey haired coder. Ask questions - why did you do that?
If you have the opportunity, watch an experienced coder work