Antipodean

Month

December 2011

Dec 26, 20111 note
Daring Fireball: Merry → daringfireball.net

timriley:

A poignant Christmas thought from Gruber. 

:’-)

Dec 26, 20113 notes
What's new in PHP 5.4

PHP 5.4 is getting pretty close to final release and there are quite a number of great new features to look forward to.

Let’s take a quick look..

Short array syntax
$items = ['a', 'b', 'c'];

This single improvement is the biggest deal for me. I’m so sick of typing array(..) all the freaking time. :-S

This alone is enough reason to upgrade. It’s something you take for granted in other languages like Python and Ruby. There’s no going back once you’ve tried it.

Better closure support

PHP 5.4 has improved closure support with better handling of $this within a closure.

As an aside—if you’re unfamiliar with the concept of closures, the idea is that closures are functions that are also objects. Confused? Great! Let’s carry on…

class Adder
{
  public $amount = 5;

  public function add($arr) {
    return array_map(function($n) {
      // Can access $this inside closure!
      return $n + $this->amount;
    }, $arr);
  }
}

$h = new Adder();
$h->add([2,6,8]); // => [7, 11, 13]

Also good to know—you can manually rebind a closure object’s $this value using Closure::bindTo(..).

If you want to see a a more advanced (crazy but cool) example of how far you can push closures to the limits in PHP, take a look at my PHP Object Orientation hack (updated for PHP 5.4) based on my original hack.

Traits

Traits are a brand new feature in PHP 5.4 and the basic idea to help with code re-use. They’re similar to what other languages would call a Mixin.

You can think of them as “Interfaces with implementation”. But I like to think of it as an assisted copy-and-paste.

It’s useful for when you want to add some behaviour to a class without having to use inheritance. If you think in OO terms—inheritance is usually thought of as a “is-a” relationship—traits are more of a “can-do” relationship.

Here’s a demo of using traits to implement the Observer design pattern:

// Observable is something that can be watched
trait Observable {
  private $__observers = array();
  public function addObserver($observer) {
    $this->__observers []= $observer;
  }

  public function notify() {
    foreach ($this->__observers as $o) {
      $o->onEvent($this);
    }
  }
}

// Observer can watch other things
trait Observer {
  abstract public function onEvent($subject);

  public function observe($observable) {
    $observable->addObserver($this);
  }
}

class Dog {
  use Observer, Observable; // Dogs can watch or be watched
  public $name;

  public function __construct($name) {
    $this->name = $name;
  }

  public function bark() {
    $this->notify();
  }

  public function onEvent($subject) {
    echo "$this->name watched $subject->name bark!\n";
  }
}

$bob = new Dog('Bob');
$doug = new Dog('Doug');

$doug->observe($bob); // Doug is now watching Bob
$bob->bark(); // Displays: "Doug watched Bob bark!"

As you can hopefully see, this is a very useful and powerful tool.

You can add some pretty sophisticated behaviour to an existing class without having to change its implementation much at all.

It’s also great from a DRY point of view, you can avoid repeating code by factoring common functionality into a trait.

For more on the finer points of traits, check out the RFC.

Closing thoughts

There’s some great improvements and a number of useful new features. It’s great to see the PHP language get some much needed polish.

Now it’s your turn to go and try this stuff out! Get the source on GitHub and compile it yourself or try out some experimental Ubuntu packages.

Dec 22, 201188 notes
#php #5.4 #programming #development
Cats cats cats! → imgur.com

Possibly the best thing ever.

Dec 22, 20114 notes
#lol #cats
Dec 21, 20113 notes
Stress

I’m not typically the stressful type, I usually pride myself on being eternally optimistic and upbeat—but I’m definitely feeling a bit low at the moment. :-(

Maybe it’s the sleep deprivation from my AI and ML classes or maybe it’s the pressure I’m under at work.

Whatever it is—this song is exactly what I needed right now:

Dec 20, 20113 notes
#:-(
Dec 20, 20112 notes
What's really behind Twitter's staff exodus → money.cnn.com

Whoa.. there’s 800 people working at Twitter?

Dec 20, 20113 notes
The rise and rise of JavaScript → dannorth.net
Dec 19, 20116 notes
Devastating Explosions, at the Touch of a Button → devastatingexplosions.com

I won’t lie.. this is awfully good fun.

Dec 19, 20113 notes
“☑ Kim Jong Il ☑ Khaddafi ☑ Osama Bin Laden ☑ Saddam Hussein ☐ Internet Explorer” —@workforfood
Dec 18, 20116 notes
Dec 17, 20111,132 notes
“In fact, talking to a lot of founders you’ll find out they feel like they simply can’t get any work done during the day. The constant barrage of interruptions, important stuff ™ to tend to and emails to answer simply don’t allow it. So they get most of their “work work” done during the night when everyone else is sleeping.” —Why programmers work at night
Dec 16, 20112 notes
Play
Dec 11, 20112 notes
Dec 8, 20116 notes
The Unintended Effects of Driverless Cars → plus.google.com
Dec 7, 20113 notes
“[Programming] language choice is not as important as all the other choices: if you have the right overall architecture, the right team of programmers, the right development process that allows for rapid development with continuous improvement, then many languages will work for you; if you don’t have those things you’re in trouble regardless of your language choice.” —Quotes: Peter Norvig on programming languages
Dec 7, 20112 notes
Dec 7, 20113 notes
Dec 6, 20113 notes
Don't Be A Free User → blog.pinboard.in

“If every additional user is putting money in the developers’ pockets, then you’re less likely to see the site disappear overnight. If every new user is costing the developers money, and the site is really taking off, then get ready to read about those synergies.”

More on Hacker News.

Dec 6, 20113 notes
Next page →
2012 2013
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
2011 2012 2013
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
2010 2011 2012
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
2009 2010 2011
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
2008 2009 2010
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
2007 2008 2009
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
2007 2008
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December