• Kevin in Technologyland

    by  • January 29, 2013 • Coding, Events, News • 0 Comments

    corei5In preparation for moving gracefully into a future with more and different types of code in it, I finally upgraded my tired old computer with a decent ASUS mobo, a core i5 3570k, 16GB of RAM, and a modestly sized but speedy Crucial SSD.  Size, it turns out, does actually matter.  Nevertheless my new system runs cool and sleek and can be stress-testing apache2 in a VMWare Player instance without my even noticing it while I play Minecraft.

    (Just kidding about Minecraft! I’ve logged 25 minutes in the last 8 months. Once I’ve uninstalled Minecraft again and get Visual Studio and Eclipse installed, I will feel ready for anything.)

    I also started shifting my web host from HostMonster to an entry-level ServerGrove VPS offering because, let’s be fair, 5 second load times for a small wordpress site are bad PR. My hair does enough bad PR for me already — I really don’t need any more.

    While I was poking around on my VPS, I found that I had PHP 5.4 installed. I finally got around to checking out the new features for 5.4 and was delighted at the prospect of exploring them!  Here’s a sampler of what’s on tap:

    • Anonymous functions and closures. I’m chagrined to admit that both of these mechanisms struck me, at first glance six years ago, as messy techniques that would promote confusion and unnecessary complexity — not unlike C/C++ macros taken to their (il)logical extreme. Working with animations in javascript, where graceful leveraging of closures is essential to building anything more than rudimentary widgetry, I finally saw the light. Now I can imagine all sorts of uses for them in PHP.
    • Short array syntax. PHP’s hashed arrays, a built-in type that radically predates their standard object implementation, are enormously useful but have, until now, been burdened by an inexplicably verbose and obscure notation.
          $data = array
              'key1' => 'This is a text string',
              'key2' => 6,
              'key3' => new ThingyMcThing(),  // delicious trailing comma to ease future additions to the array

      And that’s fine — it’s functional — but it’s awkward to type (left pinky used four times for the as and the parentheses) and looks less like a data declaration than a function call. But now, we can declare arrays just like in javascript:

          $data = 
              'key1' => 'This is a text string again', 
              'key2' => 7,
              'key3' => mcThing.factory.getMcNugget(),  // nom

      And it feels better — it feels right.

    • phphammerAnd here’s the best saved for last: effective in this version of php, <?= will (wait for it) always work regardless of whether short_open_tags is enabled or not. Short open tags have never provoked the same sort of heated dialogue as code indenting idioms or editor choice, but they have been debated deeply and at length. And while the arguments against short open tags are compelling, the utility value of inline substitution (specifically, the <?=$variable;?> form) is simply enormous. Given the amazing quantity of open source libraries, frameworks, and templating engines, it’s easy to forget that PHP is *itself* a templating engine. Indeed, disabling short_open_tag functionality makes using raw PHP template expressions cumbersome to produce and grueling to decipher (particularly with !@#$ing alternative control syntax).  This particular choice in 5.4 is ingenious. XML can keep its <?, but <?= belongs to PHP. It’s the perfect middle ground.Glyph by glyph, I’ve always thought of the abbreviated open tag assignment like this:

      < // open a channel
      ? – pass through the barrier from HTML space into PHP space
      = – assign. Helpful that the equals sign, when compressed between ? and $, looks like a pipe or a connector.
      $variable – push the content of $variable outside of PHP space, through the assignment pipe, into HTML space.
      ; – end of PHP expression
      ? – pass through the barrier from PHP space to HTML space
      > – close channel

      Of course, the symbols are entirely arbitrary and have no such intrinsic meaning — I don’t mean to say that they do. But we humans naturally excel at populating the unspecified with our own imaginations, and furnishing arbitrary symbols with meaning. We do it so well that we spend most of our lives suspended in a web of meanings that we have created ourselves and transmitted culturally. It’s great!

    I am looking forward to a new mode of existence in the not too distant future. As a result, I’m excited about new things! PHP is a messy, pragmatic language, but I’ve always found it to have a sort of neanderthal vitality to it. It’s a good place to start =)

    Addendum & Important Caveat

    “Technologyland” should not be confused with “Tomorrowland.”  Technologyland is cool, it really is.  But it isn’t particularly colorful, has very few mushrooms in it, and generally does not smell of body odor.


    Tomorrowland: colorful as hell, but bring your own sunglasses and computing devices



    Leave a Reply

    Your email address will not be published. Required fields are marked *