This is the P2PU Archive. If you want the current site, go to www.p2pu.org!

Reading Code

My recent threads

Recently updated threads

Reading Code: Your first Mission: PHP Frameworks Wordpress and Drupal

Go back to: General discussion

Week one is focused on the PHP language. As mentioned in the intro email we'll have two frameworks announced each week, and you can pick one or both, but this will give us more flexibility to your interests and the size of the class.

We will start with Wordpress and Drupal as our PHP-based open web frameworks. Below are a few starting points to give you inspiration, and links to etherpads for our collective documentation efforts. Of course, if there is a particular aspect of a framework that you have a burning desire to learn about, by all means go and explore it. These are suggestions, not constraints. We might get through one area, we might get excited and dive deeper into special areas, or we might plow through more than I have listed here. Whatever inspires your will be a positive addition to the group's understanding. 

For both frameworks, the first thing to do is go and checkout your own copy of the source code. 

Most libraries and frameworks have many common architectural features such as systems for url handling, user-defined views, data models, user profile systems, etc. It would be neat to be able to compare across different systems and languages at the end of the course. Keep that in mind! 

Wordpress
Get the source here
Some places to start:

  • Wordpress has a theming system that uses certain template files to display different page and content types. You can see this in action when you install a new theme, and edit its various files in the wordpress admin area. Make sure you're comfortable with the different template files and what they serve, and then find the code that actually does the word of routing the right content to the right templates. How does it work?  
  • Wordpress has a concept it calls the "main loop", which is basically the parent logical loop of the wordpress system as a whole. It's reasonably well documented conceptually, but find where the code lives, and get a sense of its lifecycle. What does it control, what big pieces does it pass off work to, and how does it divide up this work? What objects and classes does it make use of?
  • Wordpress is also well known for it's plugin architecture. There's interfaces that wordpress implements that lets developers write new functionality. But how does it really work under the hood? What classes and models are used? 

Dig it on the readingcode-wordpress etherpad!

Drupal

Get the source here

Some places to start:

  • Find and trace through the user profile system. How is it integrated into the rest of the system, what data models and capabilities does it make use of, and where is it made extensible?
  • How does the url handling work? That is, when a url is passed to drupal, how does it know where to serve it from? How and where are the urls constructed?
  • Drupal, like wordpress and so many other frameworks, is popular partially because of its extensibility. Go find where the interfaces for the module system are defined, and wrap your head around how they work. 

Yes, you can dig it on the readingcode-drupal etherpad!

Tools:
For many of our frameworks, grep and other bash command line tools will be your friend. Use the man pages, google them, and treat this like a good excuse to play with those tools as well. Firebug and Chrome developer tools might also be useful. And if you have any additional ones, let us know. 

Don't be afraid to make change to your copy of the code, comment inline or even print some of the source files out, as discussed in this shedding bikes post shared by Manuel.   

Discussion: 
1. feel free to hang out with others in our irc channel (you can connect from any IRC client besides the web on #p2pu-webcraft/reading-code)
2. if you come across useful debugging or code reading tools, please post them in reply to this forum
3. and of course, post questions, ideas, interesting parts of the code, and other thoughts to this forum as well. 

Your mission, open web ninjas! 
Over the next 4 days, our mission is to document our findings, questions and opinions on the wordpress etherpad and drupal etherpads (respectively) as our understanding of the architecture, coding style and tradeoffs of the 

framework increase. Don't forget to explore and have fun :) 

Go forth and conquer! Don't forget-- we meet sunday at 3pm EST in IRC (sorry, I have not calculated everyone's offset). We'll use our documentation as a launch point for the discussion.

Jessy 

ps if you need or want to start additional etherpads, you can do this by visiting http://pad.p2pu.org

 

Abhaya Agarwal's picture
Abhaya Agarwal
Thu, 2010-09-16 07:26

One thing about Drupal - it does not maintain backward compatibility and there are usually major changes in core and APIs.

Given that D6 is nearing end of its life cycle and D7 is already in alpha - it should be launched in next few months - should be instead read through D7? That will be more up to date and may also produce something valuable for the project itself. Just a thought.

1 person liked this
Abhaya Agarwal's picture
Abhaya Agarwal
Thu, 2010-09-16 07:26

One thing about Drupal - it does not maintain backward compatibility and there are usually major changes in core and APIs.

Given that D6 is nearing end of its life cycle and D7 is already in alpha - it should be launched in next few months - should be instead read through D7? That will be more up to date and may also produce something valuable for the project itself. Just a thought.

1 person liked this
Jessy Cowan-Sharp's picture
Jessy Cowan-Sharp
Thu, 2010-09-16 15:08

i think that would be fine. seems more motivating to read current stuff. what do other people think? i'd say if you are happy either way, go for 7, and if you want to read 6, then do that but perhaps make a separate section for that on the etherpad.

also, if you know v6 and are reading v7, make note of the changes between versions.

hemanth hm's picture
hemanth hm
Fri, 2010-09-17 15:05

I'm unable to connect to the etherpad links, anyways i have downloaded the drupal source and tracing the code, it very intricate, i have used drupal for more than 3 years now, had not went to the depths of what is mentioned here.

I need some suggestions here, assume i open a file user-profile.tpl.php that in turn will have
* @see user-profile-category.tpl.php
* @see user-profile-item.tpl.php
* @see template_preprocess_user_profile()

Now if one opens user-profile-category.tpl.php, he find @see's in that file also and these becomes a large chain of files.

The question is,if we assume all the @see files as the child nodes of the tree with root as the main file from which we start reading, what kind of traversal is better?

Jessy Cowan-Sharp's picture
Jessy Cowan-Sharp
Fri, 2010-09-17 15:22

cool, as we were just discussing on IRC (repeating here so others are aware) the etherpad server is very unreliable, so i'll try to keep it running, but if it proves too unavailable we can move our docs elsewhere.

as for the best way to traverse the code, one way might be to choose a specific function and trace that all the way down (so depth-first). another way would be to think about keyword or terms of interest and grep through all the files first, to select which ones to read.

personally, i would follow each of the above references a few more steps down to get a sense of the scope, a high level overview of the relevant files and how the functionality is broken down. i would also be particularly interested in user-profile-item because it looks the most specific, but that could easily be wrong ;)

Jessy Cowan-Sharp's picture
Jessy Cowan-Sharp
Fri, 2010-09-17 17:23

!NOTE! we've moved to another etherpad server due to how unstable our own is.

the docs can now be found at:

http://ietherpad.com/reading-code-drupal, and
http://ietherpad.com/reading-code-wordpress

jessy

hemanth hm's picture
hemanth hm
Sat, 2010-09-18 05:48

@Jessy Thank for suggestion on depth first read and grep based read (: