My 9 Best Coding Tips
Over the last few years, I’ve learned a lot about programming and coding sites. Some of this knowledge came from books, but the majority of the really good things I’ve learned came from simply “doing it” – trying things, experimenting, and just learning what works best and what doesn’t work. In other words, experience really is the best teacher.
So here are nine “tips” – short but helpful things that can make your life easier when you develop a web app, website, or script. I will list these in no particular order – hopefully at least on thing in this list will be of use.
Create a wireframe, sitemap, or content matrix before you ever start coding. Unless you’re hacking something out really quick – plan your programs. Seriously. I see many people just sit down and start coding, but in my opinion they waste far more time doing things that way. It’s far better to plan out your program first, work out the flow of events and logic, and then start coding. And you don’t need to use Omnigraffle or any tools to do this: I map out database structures, navigations, and wireframes on yellow legal pads. So plan your projects in the way that works for you best – but do it.
Use a good text editor or IDE. I personally prefer Crimson Editor. If you’re on a Mac, Textmate is supposed to be good. But I would not recommend trying to code in Dreamweaver as I’ve seen some people attempt. You really need to get into the code – and I recommend this for HTML, CSS, as well as scripting.
Group all “like” files. Have a directory for images, one for CSS, etc. Don’t throw it all in your main directory and expect to keep things in order. Grouping files that belong together will make maintenance much simpler.
Name all include files with a leading underscore. Someone wrote this on their blog (I don’t remember who) and it’s helped me keep things organized for some time. I often have a file such as “__header.php”, “__footer.php”, or “__nav.php” and I can always tell which files are includes for other “main” files or template files by merely glancing at them. Also, by using the underscore character to name them, they will appear at the top of my directory listing by default.
Indent your code with tabs, instead of spaces. It keeps the structure of your code consistent, and it takes less characters to make one tab than to make four spaces. I know it might seem insignificant, but I like to make my files as small as possible.
Use comments, “stubs” and pseudocode when developing – liberally. There’s no reason that you can’t delete/replace this stuff later if you don’t need it. But initially, I find it useful to “jump right in” and actually create the file(s) for my program and make myself notes where things are missing or where I haven’t yet implemented something.
Don’t use inline styles. This is a general rule that I’ve found should rarely be broken. Learn how to control all your pages with a stylesheet. You’ll see the beauty and simplicity of it if you’ve ever had to hunt through multiple pages for stray inline styles when you needed to make a change.
When you begin to get unproductive, go for a walk. I find that there are three activities where I can really think creatively and productively: mowing the lawn, taking a shower, and going for a walk. Seriously, many of my best ideas come to me in the shower! But taking a walk usually clears my head, as well. The essential ingredient here is the “zoning out” factor paired with no interruptions.
If you can’t think of a way to solve a problem, present the situation to a non-programmer. This might sound like it’s the wrong way to approach a coding problem, but it works very well. (Of course, you have to strip the problem down to its essentials and present it in non-technical terms.) But if you have someone you can bounce problems off of and they have no pre-conceived ideas about how you’re “supposed to do it”, you might be surprised at the insights you’ll get from them.
There you have it: nine very specific ideas to help programmers. Whether you code in Perl, Ruby, or PHP or if you’re making small web sites or huge web applications one of these ideas is sure to crop up in the near future. I hope you find at least one of these tips helpful when that time comes!