Ben Dunlap: geekery and native plants

… “and native plants”, part 2

November 7, 2009 · Leave a Comment

The first post in this series left off with my wife and I deciding to scrap our conventional lawns and do something a bit more exciting with our yards.

It was an easy decision. Lawn care, besides being frightfully dull, was taking up most of my Saturdays, and it wasn’t turning over very attractive results. Plus, the back lawn made our feet and ankles itch.

But “no lawn” isn’t really a goal to aim at. What would replace it? Dirt? Rows and rows of vegetables? Weeds?

The first inspiration came from a somewhat-unlikely source: Sunset’s Before & After Garden Makeovers.

Most of the garden makeovers in the book are high-cost, professional jobs — the sort you hire a firm for. Somebody with a degree in architecture surveys the site and draws plans, then trucks in a ton of rock, several mature trees, and a crew of laborers, and finally hands you a bill for several thousand dollars. Voilà — you’ve done the yard.

Not really my style, but the book still has a lot of good material. The project featured on the cover, for example — one of the best-looking in the book — was done entirely by the homeowner, grubbing around in her front yard for years: a long-term labor of love.

A garden that would stop traffic

But what really caught my eye was the conversion of a coastal-California front yard, from a “Martha’s Vineyard wannabe” — lollipop trees flanking the deck, white picket fence, putting-green lawn — into a flagstone-lined xeriscape that blends right in with the golden, oak-covered hills behind it (visually, anyway).

The contrast between “before” and “after” was startling. A yawner of a yard had morphed into something I would stop my car to stare at, if I were driving by. Have a look sometime if you can. Most garden stores probably carry Before & After Garden Makeovers; this project is on pages 12 and 13.

And that’s how the first idea came — that a garden ought to be a good visual fit for its natural surroundings. This wasn’t quite “native plants only,” but it was a mental step in that direction.

And it was probably the most important mental step: It meant dropping the notion that our plot of ground was an isolated canvas, to be painted in any way we saw fit, with whatever plants happened to catch our interest. Now we had a guiding principle: Our yard should look like it belongs in southern California.

The logical next step, of course, was to aim at a yard that actually does belong in southern California, but I wasn’t quite there yet. More to come.

→ Leave a CommentCategories: native plants

Maverick PHP: Self-assignment and the post-increment operator

October 2, 2009 · Leave a Comment

That’s a mouthful of a title and it should telegraph that this post will be excruciatingly dull for anyone who isn’t interested in compiler theory, the parsing of computer languages, or the like.

Let’s get right to the code, shall we? Suppose you have these lines in PHP:

$a = 1;
$a = $a++;
echo $a."\n";

What do you suppose the output will be?

If you answered “2″, you’re probably thinking about the question correctly — but your answer is wrong.

If you answered “1″, you’re right — but unless you know the answer is 1 because you’ve actually tested it, or you’re a core PHP developer, you’ve most likely missed the subtlety of the question, as I did when I first heard it.

The question came up today on the php-general mailing list. Of course everyone, including me, lectured the OP for seven or eight replies about how PHP’s post-increment operator works, which completely missed the point.

The OP was perfectly familiar with that operator, which, in theory, affects its operand after the surrounding expression has been evaluated. So let’s look at that code again and consider what’s so odd about it:


$a = 1;
$a = $a++;

If the ++ operator works as expected, the assignment should first be evaluated. Then, $a should be incremented. But which $a gets incremented? And, come to think of it, what does “which $a” even mean? There’s only one variable named $a in the current scope.

So it would seem that, after the assignment, the one and only $a in the current scope should be incremented. Which would leave $a with a value of 2.

But if you test this out for yourself, you’ll find that $a actually ends up with a value of 1. In other words, PHP acts temporarily as if there were two variables named $a in the current scope. The one on the left side of the assignment persists; the one on the right gets incremented and then vanishes. (At least this is what happens in Ubuntu 9.04’s standard version of PHP. YMMV, but I suspect this isn’t the sort of behavior that changes very often in a language.)

Now try a similar thing in C:

int a = 1;
a = a++;
printf("%d\n", a);

Oops: The output is not 1, but 2! In other words, C does exactly what you would expect when you really think it through, while PHP does not. I found with some quick testing that Perl v5.10.0 and Groovy v1.6.3 both behave the same way PHP does.

Ultimately, does it matter? I mean, who in their right mind would write $a = $a++ anyway? It’s an interesting thought exercise for a certain kind of geek, though.

→ Leave a CommentCategories: geek pedantry · little things · php

“… and native plants”, part one

October 1, 2009 · 1 Comment

I’m committed to going native. In my yard, that is.

The bug began to bite when I noticed that the most interesting front yard within walking distance of our house didn’t have a blade of grass in it. Not sure how I feel about photographing other people’s yards for this blog, so just imagine a three-terraced Mediterranean garden, each level spilling over with rosemary, Mexican bush sage, lantana, and the like.

I had been squandering my Saturdays on lawn care. Mowing, edging, thatching, raking, sweeping, bagging. Fixing broken sprinklers. Then doing it all over again the next week. We thought about hiring a gardener just to maintain our lawns, so that I could have some time to do anything else in the yard. Maybe plant a vegetable or two, or have a look at the overgrown olive tree in the back yard.

It also happened that everyone in the family was allergic to the back lawn. Nothing like your feet and ankles itching all day after a morning stroll in the garden.

My wife’s from Kansas, which helped move this train of thought along. I suspect the typical Midwesterner is amused by the way Californians baby their lawns. You see, in Kansas, it actually rains. In the summer, even. Which keeps lawns green.

Then, in the winter, the lawns go dormant. This can be quite a shock for a native Californian like me — the first time I visited Kansas it was March, and as we drove around, all I noticed was block after block of brown front yards.

But this hands-off approach to lawn care makes sense. Why fight Nature when you could spend your time and money on something more interesting?

So it didn’t take long for us to decide that, over time, we would replace the conventional lawns we had inherited when we bought the house. Maybe even aim for something like that Mediterranean paradise down the road. But that decision was just the beginning.

→ 1 CommentCategories: native plants

Using Zend Framework as glue (without the MVC)

September 30, 2009 · Leave a Comment

In his excellent Five Things I Wish They’d Told Me talk at CodeWorks ‘09, Cal Evans encouraged us in the audience to “blog the little things”.

In that spirit, then, here’s how I used Zend Framework to pull data from Twitter in four lines of PHP.

First, the script (I’ve removed the literal tweet-id from the code):

require 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

$tw = new Zend_Service_Twitter('bdunlap');
echo $tw->status->show([tweet id])->text;

That’s it! Doesn’t do much, but then I didn’t need much done. I just wanted to see the raw text of one particular tweet (I had noticed that Twitter rendered the tweet differently, on search-result pages, from the way it was rendered on other pages).

Of course, any code with bigger ambitions would need to be a bit more robust, with error-handling, etc.

All the same, it was eye-opening to find that I could query Twitter’s API with a four-line script — two lines of which I didn’t even have to write myself — without needing to know anything about the API.

You can do this too, in a few simple steps. First, the backend prep:

  1. Download Zend Framework and unpack it in your development environment.
  2. Add ZF’s “library” directory to PHP’s include path.

Now we’re ready to start writing code. We’ll let ZF worry about which classes to load, and when:

require 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

The getInstance() method registers ZF’s autoloader with PHP’s spl_autoload. In this simple case we’ll ignore the returned instance, because we’re not interested in doing anything else with ZF’s autoloader (for example, registering our own namespaces).

Now we can instantiate any Zend Framework class and start using it, as in the script above:

$tw = new Zend_Service_Twitter([username here]);

There are about a zillion more classes available. Lots of possibility.

Thank you, Cal Evans
I would never have guessed I could do this, if not for that excellent talk, wherein Cal described ZF as a “hybrid” framework.

In other words, you can either commit to the entire framework and build an MVC app “inside” ZF — or, you can use the library classes piecemeal, to glue things together. Things like my one-off CLI script above, and Twitter’s API.

I had always just assumed, in my ignorance, that ZF was a monolith and that I had to use the whole thing to get any value from it.

So thanks, Cal. And consider me happily started on another one of your assignments: Learn a Framework.

→ Leave a CommentCategories: little things · php

Domain name, URL… same difference, right?

May 20, 2009 · Leave a Comment

Normally I don’t expect a precise use of terms in pop-tech writing.  But yesterday, WSJ.com’s senior technology editor displayed an unfortunate haziness about the meaning of  “domain name”. A sample:

Social media domain names – such as Twitter.com/yourname – are a whole different ballgame.

Wait a second. I would have called “Twitter.com/yourname” a URL, not a domain name.

Maybe that was just a typo. Let’s read on.

Many sites dole out domain names on a first-come, first-serve basis. The most democratic is LinkedIn, which hands out “vanity URLs,” such as LinkedIn.com/in/JuliaAngwin,

Uh-oh. Was that LinkedIn thingy a domain name or was it a URL? Now it’s been called both.

The ambiguity continues:

Until recently, Facebook didn’t offer domain names. … But Facebook has begun quietly doling out vanity URLs to some ‘fan pages,’

What exactly is Facebook doling out, of late? Domain names or URLs? Or both? Is there a difference?

Answer: Yes, there is a difference. And the difference matters here, because the article is about claiming one’s name on social networking sites, before an impostor or a lesser namesake does.

The natural mental association is domain squatting — where a con artist grabs microsoft.com, for example, before the software giant can. And then tries to sell the name to Redmond for megabucks.

Domain squatting was big money in the ’90s, before it became illegal (in the US, at least). But in the social networking world, name squatting is as legit as Twitter or Facebook or LinkedIn wants it to be.

The WSJ article makes this point, but doesn’t say why. And by confusing domain names and URLs, it can’t explain why.

So what is a domain name, anyway? Wikipedia is tremendously opaque:

A domain name is an identification label to define realms of administrative autonomy, authority, or control … Domain names are used in various networking contexts and application-specific…

Wow, file that one under “sentences we didn’t finish.”

I suppose we can give our senior technology editor a break, then. Looks like domain name is hard to define. Maybe I’ll take a stab at it in a later post.

→ Leave a CommentCategories: geek pedantry