We interrupt your regularly scheduled entry to bring you some silliness.

Similar to the perl poetry of the 1990s, the past couple days many people - through twitter - have been writing short pieces of code which read as a song title or lyrics. (read about how it got started)

This is the sort of thing I enjoy. It’s creativity with definite limits. Though it gives me the feel of that Star Trek episode, Darmok, but just a little.

I could spend all day creating these, so I decided to get it all out of my system and code a complete song in PHP.

Here is The Statue Got Me High by They Might Be Giants. It does actually parse and runs without error (you need to supply a DB class, and a couple functions haven’t been implemented) but does nothing useful.

So if you haven’t had your fill of this yet, share with us your “songs in code” in the comments. It doesn’t need to be a complete song, of course. Short phrases are fun to recognize.

// Initialize environment
$statue   = new Statue();
$me       = new Person();
$you      = new Person();
$chair    = new Chair();
$truck    = new Fire_Engine();
$my_loc   = new Location();
$your_loc = new Location();
$my_loc->setContents( array( $statue, $me, $chair ) );
$your_loc->setContents( array( $statue, $you, $chair ) );
 
// BEGIN
$statue->getHigh( $me );
$statue->makeDie( $me );
$statue->callTo( $me );
 
$me->setPreference( 'company', 'monolith' );
 
$statue->getHigh( $me );
$statue->makeFry( $me );
$statue->callTo( $me );
 
$truck->setSiren( true );
$chair->remove( 'evedence' );
 
$my_loc->getContents();
$my_loc->getContents();
 
$statue->callTo( $you );
$truck->setSiren( true );
$chair->remove( 'evedence' );
 
$your_loc->getContents();
$your_loc->getContents();
 
class Statue {
 
  private $_privileges = array();
 
  public function getHigh( Person $person ) {
    if( 'high' == $person->getStatus() ) {
      $this->_sendBeam( $person->getEye() );
    } else {
      $db = new DB();
      $the_truth = $db->get( "SELECT truth
                              FROM stone
                              WHERE sculptors_chisel NOT IN ('the', 'lie')" );
    }
    $person->setStatus( 'high' );
  }
 
  public function makeDie( Person $person ) {
    $hand = $person->getHand();
    $person->dieNow();
    $this->_throw( $person, new Location( 'sky' ) );
  }
 
  public function makeFry( Person $person ) {
    $person->getCoat()->setContents( 'furnace' );
  }
 
  public function callTo( Person $person ) {
    $this->_setPrivileges( $person, 'see' );
    $this->_setPrivileges( $person, 'hear' );
    $this->_speak( 'word' );
  }
 
  private function _sendBeam( $target ) {
    $beam = new Beam();
    $beam->aim( $target );
    $beam->send();
  }
 
  private function _throw( $object, $to ) {
    $to->take( $object );
  }
 
  private function _setPrivileges( $object, $priv ) {
    $this->_privileges[ serialize( $object ) ][ $priv ] = true;
  }
 
  private function _speak( $phrase ) {
    $voice = new Voice_Box();
    $voice->speak( metaphone( $phrase ) );
  }
}
 
class Person {
 
  private $_coat;
  private $_status;
  private $_preferences;
 
  public function __construct() {
    $this->_coat = new Coat();
    $this->_coat->setContents( 'guy' );
  }
 
  public function dieNow() {
    $this->setStatus( 'dead' );
  }
 
  public function setStatus( $status ) {
    $this->_status = $status;
  }
 
  public function getStatus() {
    return $this->_status;
  }
 
  public function getCoat() {
    return $this->_coat;
  }
 
  public function getHand() {
    $hands = array( 'left', 'right' );
    return $hands[ rand( 0, 1 ) ];
  }
 
  public function getEye() {
    $hands = array( 'left', 'right' );
    return $hands[ rand( 0, 1 ) ];
  }
 
  public function setPreference( $type, $pref ) {
    $this->_preferences[ $type ] = $pref;
  }
}
 
class Location {
 
  private $_name;
  private $_contents = array( null );
 
  public function __construct( $name = '' ) {
    $this->_name = $name;
  }
 
  public function take( $contents ) {
    $contents = (array)$contents;
    $this->_contents = array_merge( $this->_contents, $contents );
  }
 
  public function setContents( array $contents = array( null ) ) {
    $this->_contents = $contents;
  }
 
  public function getContents() {
    return $this->_contents[0];
  }
}
 
class Coat {
  private $_contents;
 
  public function setContents( $contents ) {
    $this->_contents = $contents;
  }
}
 
class Chair {
 
  private $_properties = array();
 
  public function remove( $var ) {
    unset( $this->_properties[ $var ] );
  }
}
 
class Fire_Engine {
 
  private $_siren = false;
 
  public function setSiren( $on ) {
    $this->_siren = (bool)$on;
  }
}
 
class Beam {
 
  private $_target;
 
  public function aim( $target ) {
    $this->_target = $target;
  }
 
  public function send() {
    //to implement
  }
}
 
class Voice_Box {
  public function speak( $phrase ) {
    //to implement
  }
}