Learn how to read source code
Learn how to read source code. It is an extremely valuable skill.
Everyone who has written software knows that reading source code is generally more difficult than writing it. This is because you have to lower yourself to the level of the (virtual) machine running it. You have to lower your level of abstraction and understand what is probably going on behind function calls that you haven’t written. On top of that, you have to then place yourself in the mindset of the author. This is not easy. Once you can do this, however, you can start truly reading code.
Like all useful skills, the ability to read code comes with practice. Maybe you’ll have to read some really old legacy code - maybe something with syntax in all-caps, or code that has “just worked” chugging along for the past 22 years since the intern who wrote it left. These are the programs that use some kind of miraculous self-modifying state with a use-after-free hack, with more lines that invoke undefined behavior than lines which don’t. (As an aside: if you have not seen these programs yet, wait until you get a job in the Real World ™. They’re everywhere.)
This takes a while. It has to do with time and experience, but moreso an effort and a want to read code. It sucks to do things you suck at. It sucks even more when you’re trying to do things you suck at (reading another person’s code) when you thought you were actually really good at it (reading your own code). It’s like wading through mud - you’re trying to accomplish something useful, doing something you’ve normally been good at, and now you’re working towards this same goal (understanding the program) but at an painfully slow pace, with every mistake reminding you how much you suck at it.
It’s worth it. If you’re looking at horrendously written code - of which you will be reading a lot in your career - there is a very good chance you are in a place where you can make an effort to re-write it. And depending on the size of the codebase, you can probably start fixing horrendous code, if you’re in a position to do so. Or, if you are not so much in the corporate world, or work for a company where you aren’t exposed to horrible code (congratulations!) you can funnel your efforts towards open source. Plenty of open source projects of great significance could use your help. Maybe you’ll look at the source to the program you’re using, and you can figure out why it’s not behaving how you expected it to. If you get REALLY crazy, you may even write up a patch and send it to the author. Think of it as your contribution to society.
After you have learned to read code, I would personally expect you’ve learned a thing or two from what other people have written. You’ve learned how not to do things, but hopefully learned some good design patterns through reading good code. These patterns will be echoed in whatever code you write. If you’ve reached this point then point it’s safe to say: you’ve become a much better programmer as a side effect of being able to read code.