Hi everyone,
Recently, a friend suggested a Game Developer's Conference presentation to me that's been really insightful for me in a lot of ways. This is
not required viewing for the course, since it's nearly an hour long, but if you have time to watch it, I highly recommend it and you can find it here:
http://www.gdcvault.com/play/1012346/Concrete-Practices-to-be-a. It's called "Concrete Practices to be a Better Leader".
He does one of my favorite lines early on. He says "intellectual comprehension does not equal mastery." This is why we spend time completing and creating PHP exercises. It's not enough to just read the PHP manual about if statements, for loops and array variables. We've got to actually practice using them.
It then occurred to me that there's one more missing component though. Practicing using the code structures is practicing the how of programming, but it's not practicing the how of application design. All of you helped me understand this during both of this week's sessions.
So, I'd like to propose a little activity. I'd like everyone to take a site that they visit regularly, or even a site that you find on Google, and try to analyze where you might find one of the structures we've covered so far (or are about to cover!) -- if/elseif/else statements, for loops, or arrays. Then go into a little bit of detail about how the data for this website might be organized. Here's my starting example:
I go to a site called "Hacker News" pretty much every day. There are some real gems in the content. The URL is
http://news.ycombinator.com/.
Looking at this site, I see a numbered list of items. But, the list is always changing. There is some kind of dynamic process at work, choosing which item to put into which numbered slot. Probably there's an array holding the item in each slot. Each item has a title, a URL and a number of points and a number of comments. I'm just talking about the main page. We can't see any of the actual comments here. Just the number of comments attached to each item. So, here's a possible application flow:
- Get a list of the top thirty hackery news items, including the title, URL, number of points and number of comments for each one.
- Store that data in an array of 30 items.
- Pretending this site is build in PHP for a moment, here's how I'd make the array
- $newsItems = array(
- 1 => array(
- 'title' => 'Some News about Hackery',
- 'url' => 'http://www.hackery.com/news/",
- 'points => 5
- 'numComments' => 12
- ),
- 2 => ...
- );
- I could then use a for statement to create the HTML ordered list for this items:
-
echo "<ul>";
- for($x=1; $x<=30; $x++) {
- echo "<li>"
- echo $newsItems[$x]['title'];
- ...
- echo "</li>";
- }
- echo "</ul>";
Try to do this activity sometime during the week, preferably after you've read up on arrays. For for loops especially, it will help to try to view the sites you frequently visit and ask yourself these questions: "What parts of this page could be generated by a software loop that does the same thing many times, except a little differently?" For if/elseif/else statements, try: "What decisions did the code have to make to bring me to this page? Are the any instances where I will get different content if I hit refresh enough times?"
- Matt