Things a Drupal dev should know part 2

That is, things a drupal developer might benefit knowing or doing.

I started writing this post a few weeks ago and when clicking submit, my internet connection dropped off and I subsequently lost it all. I'll try and capture the essence of my first post but with added readability.

Comments, comments, comments

As a rule I try and comment every function as I go along. It is of course possible to reach the point of overkill with comments. If I am implementing a hook I say so with the simple line Implementing hook_something()

Another thing I like to do is section my files up. Like this:

//===================================================
// DRUPAL HOOKS
//===================================================


//===================================================
// DRUPAL CALLBACKS
//===================================================


//===================================================
// PROCESSING FUNCTIONS
//===================================================


//===================================================
// THEMING
//===================================================


//===================================================
// HELPER FUNCTIONS
//===================================================

Naming Conventions

I know that sometimes I slip up but generally I like to keep a simple structure to the function names and variables. Firstly I tend to keep my helper functions prefixed with an underscore: e.g. _my_helper_function()

Next, camel-case or underscores? I seem to have ended up using underscores but the choice is yours. If you pick one and stick to it, at least for that whole module, you should be able to easily remember your function names.

I always keep my constants defined right at the top of my document and in upper case. This is something that I am very strict on. It's not hard to do but can make things so much easier.

I use my constants to define the items in the hook_perm array. This means I can assign a simple name to the constant and then a human readable string for the value shown on the permissions page.

Instructions are helpful

Even if you are a bloke
Make sure you have an easy to reach bookmark of the api pages (http://api.drupal.com) You'll find them invaluable. There are changes you might not be expecting between versions 5 and 6 and I think radical changes when we get to version 7. You'll need to use the api to find these differences. There is also a section in the main drupal developer handbook online that highlights some of the key changes (see: http://drupal.org/node/114774)

Keeping track of things

I use subversion (see: http://subversion.tigris.org) to keep all my sites in check. There are often multiple developers on the same project and trying to keep the code base in sync was a pain before I started using it. Basically I never lose anything now. I use the subversion server as the master copy, the working copies that people have are used to develop on and then we have our live/test servers. Using this method, even if someone decides they want to work on the same file at the same time you can easily combine changes and prevent losing one dev's changes. I recommend it.

It's good to talk

If you are beginning drupal I recommend getting a good book on the subject. I have a few but I keep referring to the "Pro Drupal Development" book by John K. VanDyk published by apress. It covers a lot and will help you to get your head around the concepts of what happens under the skin of drupal.

the other thing I would suggest is to get on to the IRC channel (see: http://en.wikipedia.org/wiki/Irc) which is based on irc.freenode.net. Join the #drupal channel and ask away. Please bear in mind that there is an unwritten etiquette in the channel. Try not to annoy people and be patient, most users are holding down their day job and might not have time right away. If someone knows, they will answer.