<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1639164799743833&amp;ev=PageView&amp;noscript=1">
Keeping Your Code Clean and Organized
Diagram Views

Keeping Your Code Clean and Organized

Published by Mark Jarvis on 09.18.13

There are many reasons to keep your code clean and organized, here are some of those reasons and guidelines to help you create cleaner code along the way.

In a world of pervasive super high speed internet, where stacks of speedy multicore processors and mountains of multi-gigabyte RAM chips abound, why should we bother keeping our code clean? Well, aside from efficiency, there are many reasons, to consider, including your own sanity.

From a purely aesthetic point of view, cleanly laid out code is easier to read through. This makes the debugging process go much more quickly. As a bonus, keeping code organized will help it stick in your memory longer should anything unexpected turn up after the fact, especially after a dozen other projects have shuffled in and out of your brain.

Recycling is good for the environment, and it’s even better for your web project. Let’s face it: after a great many projects, you’re eventually going to be typing out the same lines of code that you’ve typed before. You know you’ve written this function previously, but where? Having a clean code base in past projects can help you greatly. Being able to reference and even reuse chunks of your work can vastly speed up your development and help you keep ahead of the deadline, but only if you’ve written out that code in a clean, well organized structure.

Another important consideration for cleaning up your code is your fellow coders. That’s right, it’s important to remember the golden rule here and help the next person that may need to reference, reuse, or extend your work. At some point in your career, you’re going to look at someone else’s work, and others will look at yours. It’s always a delight to open a file and be able to easily read through and understand some code that someone else has created, making the process of debugging, updating, or reusing that code a straightforward process.

There are many ways to clean up a coding mess. Here are just a few practices that will get you on your way to cleaner code:

Comments are the single most useful tool in the toolbox, but they are all too often skimped or skipped when you’re trying to press on and get things done. Even simple comments at the beginning of a file can go a long way to let you know what is in the file, who wrote it, and when it was last edited. Keep in mind that comments remember so you don’t have to.

Functions / Methods are useful for grouping a complete process in one place and helpful in preventing repetitive code. It’s often easier to go to a function to see its purpose rather than to pick it out of inline code. It will also make locating a block of code a snap.

Code Regions are used in many code practices to group blocks of functions together, allowing them to be collapsed and commented on and making a read through go faster.

Files and Folders. Keeping everything organized within a file is one thing, but it’s also important to consider the organization of the files themselves. Keeping files organized by type and by function will speed up any future growth of the project. Also, be as descriptive with filenames as reasonably possible. It will save you and others a lot of frustration down the road.

In the end, good clean practices will save you a great deal of time and frustration, making you one happy coder. Do you have any tips of your own on how to make sure your code is clean and understandable? Do you have any horror stories about how you’ve had to decipher what you or somebody else was trying to accomplish with their code? Please let us know in the comments, and feel free to contact us if you would like some help with any website development tasks.


Have questions or comments about this post? We'd love to hear from you.