Tips on Writing Better Code

In any given week I can expect to write at least a few hundred lines of code in around four different languages. I can also expect to edit, review, and collaborate on code written by the other developers I work with. Simply put, there’s a lot of code flying all over the place, and things can get very complicated when it’s not organized, managed, and most importantly, written well. Let’s look at a few different ways to improve the overall quality of our code.

  1. Start Building Modules
    One of the best and most important ways to keep code consistent, reusable, and organized, is to group functionality together. For example rather than dumping all of your javascript into one main.js file, consider grouping them into separate individual files based on functionality, then concatenating them once you reach your build step.

  2. Plan Before You Write
    When was the last time you sat down and on paper wrote out exactly how you would approach a project? What frameworks do you plan to use, how many browsers are you expected to support, do you plan to use any automated task runners or build systems?

  3. Use Version Control
    Version control is a system that records changes to a file or set of files over time, allowing multiple users to edit, track changes, and host assets. There are plenty of services that enable version control, including Bitbucket, Assembla, and Github. Github is my personal favorite, being that it promotes social coding, meaning people will be motivated to share code on Github, while improving and learning about code written by other users.

  4. Start A Code Review
    This is way easier to do if you work with a team of developers, but not impossible if you work on your own. The basic idea of a code review is to present some code you’ve written to a group of peers (or superiors) so that you can explain what you’ve written, learn how to write better, and even teach others who may be unfamiliar with the technologies you’ve written. It’s best done weekly, with the goal of learning how to improve what you’ve already written.

  5. Take Coding Challenges
    There are plenty of free resources online that are aimed towards providing challenges for developers looking to get better at languages they use every day. Most of these sites come with a large community willing to help out with needed, so don’t worry about getting stuck and being unable to continue.

Posted on 22 May 2014

comments powered by Disqus