Ask HN: How do I learn to write better code? | Hacker News

It's a good question, but has multiple components.

The first, and IMHO most important component of your question, is how to improve your actual written code. A few ideas:

~ Pair programming with an experienced programmer, if possible. If not, try to work on a project (even an open source one) with someone who is an experienced software developer and who does comprehensive code reviews. Code reviews from articulate, experienced developers are an excellent way to learn.

~ Write lots of code. Write code in new areas unrelated to your job. Try to find some small project or projects to do. Once you're done, reflect on what you've done and what you could do better next time.

~ Read books like Clean Code. It might also be wise to pick up a book on design patterns, particularly if you'll be working much in object-oriented languages like Java, C#, or C++.

~ Always read source code when possible. Using a new tool at work? If it's open source, go check out the code. Starting a new project? Go find similar projects on Github and browse the code. You could also find some well-known open source projects and read through their code. A good book for ideas on which open source projects to focus on is called The Architecure of Open Source Projects (there are two volumes, shown at the bottom of this page:

~ Learn other programming paradigms, such as functional programming (maybe learn Haskell, or Scheme) or logic programming (learn Prolog). You may never use such languages in your work, but languages in other paradigms will provide you with both a better understanding of computation, and a bag full of useful techniques and ideas for your working language(s).

The next component is how to improve your understanding of data structures, algorithms, and other topics rooted in theoretical computer science.

~ Consider doing problems from sites like and

~ The book _Algorithms_ by Robert Sedgewick and Kevin Wayne is very good, as is their free two-part course algorithms and data structures offered on Coursera (

~ Work all the way through the online book Structure and Interpretation of Computer Programs ( It will not only touch on a number of important theoretical computer science topics, but you'll also get some good exposure to functional programming.

Finally, to learn commonly used technologies you see on HN, such as Docker or Kubernetes, you'll just need to get your hands dirty:

~ Rent a $5 server on Digital Ocean, or set up a home server, running a Linux distro like Debian or Ubuntu (which often makes installation easier), and start experimenting with them.

~ Continue following HN and reading about new technologies and programming languages.

~ Realize that it's critical for software developers to constantly learn new technologies. Otherwise, they very often become unemployable after a decade or two. HOWEVER, it's also critical that devs exercise restraint and good judgment when selecting technologies for important projects. For such projects, it's usually better to choose languages and technologies that have a proven record and that you personally have a good understanding of, over some new technology that's getting a lot of attention on HN.

With respect to all three of these components, it's a very good idea to maintain a blog and write about your experiences and projects. A blog will serve to not only consolidate your new knowledge, but also to improve your writing and help your career (a good technical blog will be a strong positive signal toward potential employers).

Don't worry about not having a traditional education in computer science. Lots of excellent senior devs I've worked with have no formal training in computer science. As long as you're motivated to constantly learn new languages, technologies, and techniques, and master the ones you already know, then few people will care (or even know) whether or not you have a CS degree.