Alternative title: What every new Drupal developer should know Over the past few years I've been teaching various Drupal classes ranging from introductory courses to module development courses for seasoned developers. In fact what lit a fire under me to write up this entry was an upcoming course I'm doing with Chapter Three December 14-18th in San Francisco. I'm my classes nearly every student has asked me a variation of the same question; What do I need to know? If the student was a beginner I'd point them to one of the numerous Top X Drupal modules, such as Lullabot's Top 80, or direct them to review the awesome site showcases up on drupal.org. If the student was a developer (or aspiring developer) the answer was never as concrete. I would explain the concept of a hook, rattle off a few hooks I thought were important, point them to greggle's (or GVS's?) awesome Cheat sheet, tell them about t(), hook_menu, explain how db_query() worked, and then direct them to http://api.drupal.org. Being the geek I am this wasn't good enough for me so I set out to find out what the top hooks and functions were. I wanted something concrete.
I broke out my terminal and used CVS to checkout every module on drupal.org that was listed as stable for Drupal 6 (those in a DRUPAL-6 branch), 3,308 modules. I then wrote a quick and dirty BASH script that went through every function sorting, counting, and ultimately discovering what the most heavily used hooks were. I wrote this script over a year ago at a time when I was living behind the great firewall of China, which made blogging, twittering, and other fun Internet activities a frustrating experience, which is why I have not posted this sooner.
The next 12 significant implementations are:
Most Utilized Functions
My curiosity then led me to answer the question: What are the most frequented used functions in a Drupal module?
For the curious here are the BASH commands I ran to discover this information The completely inefficient but written in roughly ten minutes BASH script I used to discover the top hooks was: --count_functions.sh--
#!/bin/sh
module_dir="/Users/jredding/Downloads/contributions/modules"
for module_name in `find $module_dir -name *.info|xargs basename |awk -F.info '{print $1}'`
do
grep -hr "function * ${module_name}_" *|awk -F${module_name}_ '{print $2}'|awk -F"(" '{print $1}'
done
I then piped the output through sort |uniq -c |sort -nBe aware that this method takes a very long time to process, roughly three to four hours. I later modified the script to the following, which only took about seven minutes to run:
functions_tmp=/tmp/all_functions.txt
module_dir="/Users/jredding/Downloads/contributions/modules"
grep -hR "^function *" modules/* > $functions_tmp
for module in `find $module_dir -name *.info|xargs basename |awk -F".info" '{print $1}'`
do
grep -h "function * ${module}_" $functions_tmp |awk -F${module}_ '{print $2}'|awk -F"(" '{print $1}'
done
rm $functions_tmp
~
Of course I could probably save more time if I saved the data to two arrays and did all of this searching/sorting in memory instead of performing literally thousands of disk hits. I'll save that for another day.
To discover every function used I ran the following command:
find ./modules/ -exec awk '/[a-9]\(/ { for (i = 1; i <= NF; i++) printf "%s\n", $i }' {} \; |awk '/[a-9]\(/ {print}'|awk -F\( '{print $1}' |sort |uniq -c |sort
A few interesting statsI found the following stats interesting.
Raw DataTags:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


I'm a Drupal lover & love
I'm a Drupal lover & love tweaking on it continuously to discover new tricks,but I really appreciate you for your tips here.Thanks.
Cheers
Found this really helpful, especially as I'm fairly new to Drupal. Will definitely be checking out hook_help
Always useful to have these
Always useful to have these big picture analysis of what people are doing. Thanks for taking the time to do this. I would expect form to feature much higher - and impressed by Views making the cut and, yes, good to see hook_help being used so much!
Awesome analysis
This is a really interesting breakdown. I've done developer training myself, and I've always been more likely to introduce hook_form_alter first. I may have to reassess now based on this :)
Thank you!
Thank you for taking the time to share and help, it's very useful!
Note: array() is a language
Note: array() is a language construct used to represent literal arrays, and not a regular function.
true.
true. I left out the others like "if" and jQuery's $ but left this one in because its usage was so high.
Interesting DB functions
If that drupal_result is indeed db_result then there are 3147+6072+1931 = 11150 fetch calls vs 24266 db_query which leads me to think that there are 13116 INSERT/UPDATE/DELETE queries vs 11150 SELECTs. drupal_write_record does not even appear on your list. Conclusion of all: people are writing DB queries all the time when they should not.
763
763 is the number of times drupal_write_record() appears, quite a bit less than db_query. I'm curious what will happen in Drupal 7 with the new db_select, db_merge, etc.
note: yes drupal_result should have been db_result.
Good job
Interesting article, I remember you telling us about this back in the training. I'm glad hook_help is being used that much too. :)
Post new comment