Name things properly. Don't use the old-fashioned naming conventions that try to minimize the length of names.<p>good: doc_file_parser<p>bad: x<p>bad: dcprsr<p>good: getFlightString()<p>bad: flightstr()<p>bad: myfun()<p>Writing code is <i>writing</i>. Write things in a thoughtful order. Each line is like a sentence, containing a complete idea. Don't write run-on sentences, with too many ideas in one sentence. In other words, if a single line of code is doing too much, break it into multiple lines. String lines together into thoughtful "paragraphs" that are grouped together in a way that makes sense.<p>It's as much (if not more) about communicating with yourself and other humans as with the computer.<p>Find some recent blog posts on code readability, variable naming, organizing code, and breaking code into functions.<p>Next, for whichever language you're using, figure out how to use an automatic formatter and linter. These tools will standardize your code, making it easier to pattern match.<p>Finally, just write a lot of code and continuously learn and get better. Eventually you'll become great at using your chosen language(s) and understand programming in general, and you'll be able to read code just like you can read natural language.
Comment your code. Not just the what it does, but the why as well. Basically document everything in your comments, approaches you tried, what worked, what didn't etc.<p>Also if you get some code from Stack Overflow etc, then leave yourself a comment of the link you found the code/library too.
This is the trick to writing good code. It reads like a novel. I've never written code that well but the closer it gets to that the better I'm doing. I'm also assuming performance and correct code as goals.<p>I'd recommend reading a few opinionated books on code.<p>Some you might want to look at.<p>Clean code
Pragmatic programmer
Domain Modeling Made Functional<p>Anything that gets you thinking about code structure. Explore the ways that work for you. Don't take them as gospel but explore the thinking.
- Be thoughtful with the names you use, variables should have names that represent what they hold, functions/classes should have names that represent their behavior.<p>- Be thoughtful in how you segment you code into functions/classes/modules. Designing well contained and intuitive interfaces is the foundation of computing.<p>- When something isn’t intuitive, consider adding a comment.
In addition to comments and descriptive descriptive variable names, document everything!<p>I constantly wish i wrote more documentation for my old code. Especially those that "i probably won't need to touch this anymore in the future"
Good variable names<p>Add comments explaining exactly what you needed to figure out this time around<p>Pretty soon you'll get the hang of what to put in the comments right away
If you don't quickly understand the code, reread it and look at appropriate documentation until you do. With practice the patterns and idioms will become second nature, but you must practice. It takes years of reading to get to a high level in natural language, and programming languages are no different.
to understand a new codebase, unit tests are the first thing i read. hopefully things are tested in isolation to a sufficient degree that you don't have to spend a lot of effort keeping track in your head very much to follow the flow of code.