Archive for August, 2007

Book Review: Pro Drupal Development

Book Site | Sample Chapter: The Theme System | Table of Contents

Many of you are aware of my current total infatuation with Ruby, and that I’ve
used PHP for about 6 years and at one point decided I hated PHP…until, I
needed it for a quick one-off page and then realized that PHP had its place.
Then again, I was totally frustrated with Ruby when making my moms bakery site and then turned to Drupal and Gallery (another fine PHP project), which saved my bacon and I got a website and photo gallery up in a weekend. So, PHP and I have had our moments but I’m not abandoning it!

Drupal powers some big sites, its not just for joe smoe’s blog. This is an interesting page about Is Drupal Right For You? and if you are wondering if its something that would even work for you.

I was excited to get my hands on a review copy of Pro Drupal Development. Its no
secret that coders hate documentation and Drupal has one of the most complete
online documentation I’ve seen for an Open Source project, but its almost too
hard to find what you need amongst so much. The Pro Drupal Book is a godsend for
the drupal programmer, new and experienced alike. I wish it was written a year
ago!

The book starts off with a quick overview of how Drupal is structured and
defines terms such as hooks, node and blocks in just 10 pages. Chapter 2 is a A
step-by-step tutorial with making a module. That is a great idea to start off
quickly writing code. It get the reader involved and hands on. I really tire of
books that have to start off with the history of the internet, html and how
things have evolved. Get to the code dangit!! Kudos to the Authors for that!
Chapter 3 gets into module specific settings, like how to get your module to
show up on the admin page and storing user settings that your module needs.

After you’ve had some experience with the code then the book goes into details
on the specific parts of Drupal:

  • Menu System
  • Databases
  • Users
  • Nodes
  • Themes
  • Blocks
  • Form API
  • Filter System
  • Searching and Indexing
  • Files
  • Taxonomy
  • Caching
  • Sessions
  • JQuery
  • Localization
  • Using XML-RPC

Drupal is a pretty amazing framework, when I read the code I say “why didn’t I think of that?” … the module and hook system is genius.

Then some more general topics:

  • Writing Secure code
  • Development Best Practices
  • Optimizing Drupal
  • Installation Profiles

One of the chapters I skipped ahead to read was The Form API. In my years of PHP
I’ve often tried to come up with a framework for doing forms and I wanted to see
how they did it. This chapter follows a tutorial style as well. The Form API
allows you to define fields, their label, their value, description. Some
frameworks take the template approach, where you hammer out your HTML. Some are
more configuration based like Drupal making a multi-dim array with keys and
values. I can see advantages to both. There is a hook function for validation
which allows you to write your validation checks.

PHP gets a bad wrap for security, partly because its pretty easy to learn
PHP and newbies don’t always realize what they are doing. There is a
chapter devoted to security and includes even some things I didn’t know about –
encoding mail headers. The Form API is very secure,  one thing it does is
check values that come from dropdowns were actually in the options and it wasn’t
something that the hacker made up.

Developer Best Practices are great for the new developer, it talks about using
cvs, tags, branches. It talks about how to create and apply patches (hint - you
can contribute back to drupal). That is awesome. Alot of open source projects
are like “HELP us, submit patches!” and the new user is left with uhhhhhh..how?

Caching is another interesting chapter. You will learn  how caching works
and how Drupal Core uses it. There is a Cache API that has methods for module
creators to make their modules faster.

JQuery … I am not sure if I like it or not, but its part of Drupal 5! I
skipped ahead to this chapter to see what its all about. There is a javascript
hook built into Drupal making it easy to add, thats pretty cool.

One thing I found lacking in the book is anything about Testing. There are few
pages on debugging and some modules to help with testing, but I would like to
see more. At least some talk about selenium, which is great for a site made with
any framework/cms.

Over all, Thanks APress for another great book!

Comments (1)

Beautiful Ruby: Learning the -isms

I did PHP for 6 years.... sometimes its hard not to do PHP in ruby...

Today i was testing a url to see if it contains a certain string:

RUBY:
  1. response = Net::HTTP.get_response(URI.parse("http://myawesomesite")
  2. if response.body.match("my awesome text") == nil  then
  3.       return false
  4. end

and remember to do:

RUBY:
  1. response = Net::HTTP.get_response(URI.parse("http://myawesomesite")
  2. return "false" if response.body.match("my awesome text").nil?

Another thing I was working on was I had to do a multiple if statement

I will simplify it for this example:

RUBY:
  1. color = red
  2.   if (color == "red") or (color =="green") or (color == "yellow") then
  3.     print "its valid)
  4. end

In PHP I might have actually made the values into an array, and then did in_array ... but in reading the code, you see below, if in the valid values, print something. I don't want to see array!

This is more elegant:

RUBY:
  1. color = red
  2. valid_values = ["red","green","yellow"]
  3. puts "its valid" if valid_values.include? color

This seems to only work for values you'd do == on, not ===

See... programming in ruby just makes me grin :)

Comments (3)