Beware of Optional Curly Braces — They Will Bite You

I was looking through some PHP code from a third-party vendor recently, and saw something that made my jaw drop. It’s pretty innocent-looking, at first. Here’s a somewhat anonymized and genericized version of the code, but the thing that bothered me is still intact. It’s not really a bug, per se; the code will function as intended. But…

$currentRow = 0;
$itemId = “”;
$index = 0;
while ($row = mysql_fetch_object($result)) {
     if ($currentRow == 10) {
          renderHeaderRow();
          $currentRow = 0;
     }
     // takes an itemId and displays relevant columns
     renderSummaryRow($row->itemId);
     $currentRow++;

     if ($index > 0)
          $itemId .= “,”; # interpolate a comma
     $itemId .= $row->itemId;
     $index++;
}

See the problem? Really, there are a few ways this can go wrong. To a quick glance, the only clue that line 14 (“interpolate a comma”) is part of a conditional is its indentation. The indentation is important to a human reader — but absolutely irrelevant to the PHP interpreter, which simply treats the next line after the conditional as the conditional’s block. Regardless of how it’s indented, and regardless of what else is around.

The way it looks to a human is not the way it looks to the machine.

What happens if someone wants to add some logging? What if they add it after the comma line?

if ($index > 0)
     $itemId .= “,”; # interpolate a comma
     writeLog(“Added a comma”);
$itemId .= $row->itemId;
$index++;

Now the log claims the code has added a comma, even when it hasn’t. But still, it could be worse! What if you decided to add your logging before the other line?

if ($index > 0)
     writeLog(“Adding a comma to itemId…”);
     $itemId .= “,”; # interpolate a comma
$itemId .= $row->itemId;
$index++;

Now it adds a comma no matter what — even the first time through the loop, when the string is empty. So instead of a string like '123,124,125', $itemId will now have a leading comma: ',123,124,125'. Since this value is getting stitched into a SQL query later on, it means your app will blow up with a SQL syntax error.

This is why Python makes whitespace significant to program flow. The way the indentation makes it look like the logical structure is, is how the structure actually is.

And this is also why Perl — of all languages, one that normally errs on the side of letting you leave out anything that can be inferred from context — Perl insists in its syntax documentation that in cases like this, “the curly brackets are required — no dangling statements allowed.” (It then says, in typically Perlish fashion: “If you want to write conditionals without curly brackets there are several other ways to do it.”)

If you’re working in one of those languages that lets you omit curly braces around a single-statement conditional — DON’T DO IT! The potential maintenance and debugging problems are not worth the fun of saving two keystrokes (or just one, if you work in an editor that auto-closes your braces for you).

A Single Context for All Social Interaction: Merely Quixotic, or Dangerously Misguided?

I recently read a blog post by Leo Widrich, the co-founder of Buffer, entitled “Why do we have so many lives?” In it, Mr. Widrich says:

We have a private life, a public life. We have a work life, a school life, a party life, a love life and I am sure you can name lots of others. I never understood why.… I always felt that it is hard enough to focus on getting one life right. Why create so many? (emphasis added)

This guy is a startup founder. I expect he may well be typical of the genus. And so, he makes a great example of why so many startups* seem to be promoting the “single identity” model. It’s nice that this guy feels he can have just one life — though even he admits it’s hard! But the rest of us don’t really want to deal with everyone on the same single channel.

Mr. Widrich claims that: “I can walk into a club and speak the same thoughts I have in my head to a girl, as I can to my family. And again I can speak with the same mindset to my co-founder, give an interview or play football.” Personally, I can’t help but wonder if that’s really working out for him. The pitch you use to woo an investor is quite seriously different from the kind you use to woo a woman. The way you talk to your girlfriend is very different from the way you talk to your mother or sister (I sincerely hope!).

In fact, I can’t help but wonder if this is a manifestation of Asperger’s Syndrome, or some other failure (or refusal) to understand social interaction. Regardless, it seems like a very clear example of a geek-specific sort of fallacy that — I’m starting to think — may underlie the various new systems that try to enforce single identities:

Figuring out the rules for social interaction is hard. One of the hardest parts is figuring out which rules apply in what contexts. Wouldn’t it be great to just have one context for everything?

No. No, it would not.

Most of us react with some consternation when our contexts collide unexpectedly — for example, meeting a co-worker (or boss!) at the supermarket (or worse, nightclub or bar!). Most of us don’t want our boss to see us drunk, or trying to pick people up. We don’t even really want to introduce our boss to our friends and have to try to integrate them into the conversation. Of course, being a startup founder, Mr. Widrich (like guys like Mark Zuckerberg and Larry Page) doesn’t have a boss, and so doesn’t have to worry about this.

The combination of “boss privilege” and “desire of poorly-socialized people to not have to deal with so many social contexts” makes a powerful one-two punch, and it may go a long way toward explaining the recent spate of apps that try to enforce single identities. In the meantime, I’m happily using Seesmic as my mobile phone’s Twitter client, because it has excellent support for multiple accounts.

* I include Google and Facebook in this category. They still think they’re startups, they still think like startups, and they still have the startup culture and mindset, even if they’ve grown into ginormous corporations. ^back

An Addendum: If you think the desire for multiple identities and contexts is just “an old people issue”, as LinkedIn CEO Reid Hoffman recently described “privacy” in Davos, then ask any teenager: Would you like to hang out with your parents, in the same way you hang out with your friends? How about your teachers?

If you have any doubt what their reaction would be, you don’t know teenagers very well.

By the way, a word to Mr. Hoffman: Apparently the new common wisdom is that LinkedIn is also “for old people”, so you might want to rethink your company’s stance on privacy. And quit pissing off your own target market.

A Failed Goal

Near the beginning of this year, I published a piece called “Ada Lovelace Day Is Not Enough“. In it, I noted that only 8.69% of my 2010 posts had been marked with the “gender” tag, and it would be nice to increase that percentage. (But it was still an improvement over 2009′s 4.76%.) I said:

So I may be improving… but I’ve still got a way to go. If you’re another man in tech reading this, I tell you what: I’ll work on improving myself, and the tech field as a whole, if you’ll do the same.

It’s now the end of 2011. Looking back over my blog activity this year, I see 24 posts, with only two tagged “gender”. That marks a slight drop to 8.33%. What happened?

I’ve had one in the works for months now. (Maybe more than one; there’s more than enough material.) I started it back in the summer, when I heard about the death threats against Naomi Dunford. In quick succession, before I could marshal my thoughts and words enough, there was the incident where the atheist/skeptic community blew up over SkepChick’s very polite advice on not acting like a scary creep (including Richard Dawkins blatantly showing his ass in a way that also showed off his monumental privilege and the ignorance it’s brought him), followed by the call for a stop to misogynist trolling and the associated #MenCallMeThings hashtag on Twitter. (Yes, it’s still going, and yes, it’s still worth reading if you want to see what women put up with online.) Read More »

Are We Always New At Everything?

The trend in Microsoft’s products for the past 15 years or more has been toward making things easy for the people who have never used the software before. Of course, as time goes on, there are fewer and fewer of those people.

The Ribbon is introduced in the Help file thus:

And if you’ve used previous versions of Word, you’ll wonder where the menus and toolbars have gone. That’s the beauty of the Ribbon. No longer do you have to wander through the maze of menus, submenus, and toolbars searching for what you want.

No, instead we now have to wander through a bewildering array of Ribbon tabs and drop-down menus. It’s as if the Office 2007 design team didn’t realize that everyone who’s been using Word for more than a year or two already knows their way around Word’s menu structure. It’s as if someone re-arranged my local neighborhood so that I “no longer have to wander through” the streets I already know. Indeed, SecretGeek finds the Ribbon so hard to find things in, he suggests that the Ribbon should include its own search feature so people can find features that are hidden among all those tabs!

It’s not just Microsoft. Check out Qwiki, “the information experience”. It is very clearly optimized to look cool in a demo. A demo, of course, is the ultimate in “aimed at new users” — it’s aimed at people who aren’t even users yet, but might become users. And user interface guru Bruce Tognazzini has been decrying the OS X Dock for years, partly on the basis that “It makes for a great demo, but not a great product.”

Interestingly, while I was prepping this post for publication, I became aware of Paul Miller’s article, “The Condescending UI”. It excoriates many of the very same problems in Apple’s and Microsoft’s recent OSes, saying that “these new tricks are horrible and offensive. They’re not only condescending and overwrought, they’re actually counter-functional.”

It’s as if usability tests and design reviews are all conducted with people who have never used the software in question before… and those who already have some domain knowledge are left out in the cold, forced to discard their knowledge every few years.

Are we really always newbies at everything? Or do developers even believe that we are? Or, heck, do marketers and product managers actually believe that we’re all still newbies? Or that there’s some vast, untapped market of prospective new users out there, just waiting for an even more dumbed-down interface before they’ll buy their first computer?

Just in case anyone out there believes any of those things, please, let me be the one to disabuse you of the notion. Anyone who doesn’t already use a computer is not ever going to. The only exception here is people under about 10 years old, and they’re not scared of unfamiliar UIs — to them, every UI is new, and they’re eager to learn new things. Stop dumbing things down, and stop sacrificing your long-time users’ skills in the name of changing things just for the hell of it.

Can You Strike it Rich in a Startup?

Startups are known for being places where people work really hard, often at unsustainable paces. “Work hard, play hard,” is the oft-invoked slogan, and there are usually foosball tables, game consoles, and other signifiers of fun lying around the office. (How often they get used is another story; the reality can easily be more like “work hard, then crash” or “work, eat, sleep”.) But there’s a logic behind it:

The idea is that you work really hard for a few years, but then there’s a big payout when your company goes public. In those few years, you can make enough money to live in comfort for quite a while. Or so the story goes. Does it actually happen that way?

Let’s try a quick experiment: Think of all the people you know, or have known, who have worked at startups. If you’re like me, working as a web developer in the Bay Area, this means “think of all your past and present co-workers”, and maybe a fair number of your friends who have worked for startups… just not the same ones as you.

Okay, total that up. Got a general ballpark number, at least? Great.

Now, how many of those people have actually gotten the kind of “big payout” that lets them live in comfort? Even for just a few years? Read More »

When Your Computer Catches Fire

Occasionally, I amuse myself by reading Not Always Right. I really shouldn’t, as it’s always bad for my opinion of humanity, but sometimes I just can’t look away. And occasionally, it clues me in to a teachable moment. Like this one, which recently appeared there:

Caller: “My computer is a fire risk.”

Me: “What makes you say that?”

Caller: “It gets hot. There are papers near it.”

Me: “If you’re worried about it, you can move the papers away.”

Caller: “I am moving the papers, but you must send someone to look at it.”

[More back-and-forth, in which caller reiterates that her computer is "a fire risk" and says the situation is urgent. A technician is dispatched, who eventually reports back:]

Technician: “You know that computer that was a fire risk?”

Me: “Yes?”

Technician: “She meant it was on fire.”

This isn’t the first time I’ve heard about such mistakes, either. Rinkworks’ “Computer Stupidities” sub-site has an entire page devoted to instances of computers smoking or catching fire (or people being worried that they might). One in particular involves a tech telling a college student over the phone, “Unplug the computer right now. Your paper is lost. Your floppy drive is lost. If you’re lucky the Mac will be OK. Unplug it now.” The student doggedly insists, “But I don’t want to lose my paper!” Then the tech hears someone in the background (presumably the student’s roommate) scream. Then the dorm fire alarm goes off.

For those who need to be told, I am willing to state, as a computer professional with 15 years of experience in hardware, software, system administration, troubleshooting, and repair:

If your computer or computing device ever emits smoke, sparks, or flame: Unplug it immediately. Do not bother with “proper shutdown procedure”; simply assume all data on it is completely hosed and start emergency fire-prevention procedures. Unplug its power. If it’s a laptop, also yank out its battery. If signs of combustion continue, use a fire extinguisher or water, as appropriate.

Unplugging it means there’s no more electrical power going to it. Many times, that’s enough to kill the combustion right there — if you were quick about it, the fire may go out on its own at this point. If it doesn’t, it is at least no longer an electrical fire. That means if you haven’t got an ABC fire extinguisher handy, you can still just throw water on the thing, without risking electrocution.

Once it’s been smoking or sparking, the device is ruined anyway. Understand that all your data is gone. (This is why it’s important to have complete, current backups.) The important thing to do is to make sure the fire doesn’t spread. Don’t panic, and don’t waste any time trying to shut down carefully or in the usual manner — that will just prolong the fire.

Remember, where computing devices are concerned, if it smokes, it is toast. Or it is fried; pick whichever image works better for you. If you let it keep running once it’s on fire, all you’re doing is putting yourself at risk. Don’t do it.

Say It Short

Remember when the movie 2010: Odyssey Two came out? There was a simple, easy way to say it: We all called it “Twenty-Ten”. And for a few decades, folks like Terence McKenna have been warning about what might happen in the year 2012, and we all thought of it as “twenty-twelve”. These things are short, quick, and easy to say.

And then we hit the Aughts, and for nine long years, we had to start all our year-names with “two thousand…”. By 2006, we were pretty well habituated to it, and I started hearing people project that format onto later years: “two thousand fifty-five” and whatnot.

But starting at the beginning of last year, none of this was necessary any more. We can drop the laborious excess of “two thousand” in favor of just “twenty”. Really, nobody will have any trouble understanding you when you say this is “twenty-eleven”.

(I know, this is not exactly a pressing issue. But it bugs me. Like many geeks, seeing excess effort expended is a pet peeve, even when I’m not the one expending it.)

While we’re at it, there are a couple of TLAs in the tech world that really can and should be said as acronyms, without having to be spelled out every time.

FAQ is “fack”. It rhymes with Iraq. If someone asks you lots of them in a rapid-fire manner, it’s a FAQ attack. If you’re into goth fashion, you may like the Dye It Black FAQ — doesn’t work so well if you spell out the last word, does it?

And why does anyone pronounce APIs as “ay pee eyes” when they could just say “appies”? Honestly, I always thought it was pronounced “appies”, until a co-worker got confused by it. I was surprised to hear that most techies actually take the excess time to spell out “ay pee eye” — nobody ever bothers to spell out “en ay ess ay” or “ay jay ay ecks”, why should the just-as-pronounceable API be any different?

Her Name is Skud

Skud has been involved in Open Source, and in activism and advocacy, for years and years. She does a little of everything, having coded, written docs, managed developers, and spoken out on important topics.

She has been, or is currently, a contributor to projects ranging from Eureka to Perl to Xen to HTML::Mason.

Way back in 2007, I saw that a company named Metaweb was looking for coders for a project called Freebase. Tim O’Reilly said the Metaweb people were “building new synapses for the global brain” and the project looked cool as hell. I looked at their hiring criteria, and was scared off by the problem that involved writing some code to populate a directed graph without allowing closed cycles to form. I wish I’d at least tried; maybe I might have gotten hired.

In which case, I could have met Skud when she started working there, later in 2007. And now maybe I’d have an “I know Skud” button. Regardless, I was totally unsurprised to learn, recently, that Skud had worked at Metaweb. She’s got the kind of talent and skill that I expect would make her a natural there. (And I confess to a certain bit of envy, that she got to work on such a cool project.)

But that’s not all. She also founded the Geek Feminism wiki and built it up into the self-sustaining thing it is now. That wiki has been an invaluable resource in various things I’ve needed to write, and the Who is harmed by a “Real Names” policy? page was a superlative argument in the NymWars discussion on Google+ — back when I was still there.

Of course, Skud herself was also a major player in NymWars. Aside from writing about her experience, and noting when Google started gagging its own employees, she also performed an informal survey of people suspended from Google+, thus providing some solid data to add to the discussion.

And now she’s moving into music, which may take her outside the Ada Lovelace Day’s “women in STEM” boundaries… but when I think of women in tech, Skud is still one of the biggest names that comes to my mind.

What Are We Giving Up With E-Text?

Engineering is about tradeoffs, and each technology has its advantages and drawbacks. Whenever we leave one technology behind and adopt a new one, we’re sacrificing something. We may be making a terrific trade, getting a hundred times as much cool stuff as give up — but we’re still giving up something, and we should be aware of what it is.

We’re currently moving away from paper printing, replacing physical books with e‑books and text readers. We need to look at what we’re giving up in the process.

Lev Grossman recently wrote an article for the New York Times‘s Sunday Book Review, “From Scroll to Screen”. In it, he points out how our current book format, the codex (multiple pages bound in a rectangular shape between two covers) took over from the scroll (a single long sheet of paper wrapped around a rod or roller). He cites easy random access as the codex’s chief benefit, and an absolutely critical one.

We usually associate digital technology with nonlinearity, the forking paths that Web surfers beat through the Internet’s underbrush as they click from link to link. But e‑books and nonlinearity don’t turn out to be very compatible. Trying to jump from place to place in a long document like a novel is painfully awkward on an e-reader, like trying to play the piano with numb fingers. You either creep through the book incrementally, page by page, or leap wildly from point to point and search term to search term. It’s no wonder that the rise of e-reading has revived two words for classical-era reading technologies: scroll and tablet. That’s the kind of reading you do in an e‑book.

Not to use too much of Grossman’s text, but another section near the end of his essay points out a critical aspect of the sacrifice we’re making as we move toward e‑books:

[I]f we stop reading on paper, we should keep in mind what we’re sacrificing: that nonlinear experience, which is unique to the codex. You don’t get it from any other medium — not movies, or TV, or music or video games. The codex won out over the scroll because it did what good technologies are supposed to do: It gave readers a power they never had before, power over the flow of their own reading experience.

Except that’s not the only sacrifice involved. That’s simply the technological, UX sacrifice — but we’re also making a societal sacrifice, and it’s one that may be even worse. We’re sacrificing a huge number of readers, many of whom become writers and boosters of text as a mode of communication.

Recently, Seanan McGuire wrote “Across the Digital Divide”, in which she talks about what it’s like to be poor, and about how the current (official, U.S. government) measures of poverty are based on what was available in 1955. Read More »

A Follow-Up on Pronounceability

Late last year, I wrote about making sure your domain name is both spellable and pronounceable. Well, I just encountered a site that technically gets it right, in that its domain name is exchangebitcoins.com. But as soon as you look at their logo, which presumably tells you what they actually want to be called?

At that point, pronounceability falls apart, because their logo bills them as ExchB. How the heck do you say that? “Ecks-ch-bee” is the best I can think of, and that doesn’t exactly roll off the tongue. (Note that I’ve studied Russian, and so I consider words like znakomstvo only moderately difficult to pronounce.)

This BetaBeat story also calls them ExchB, and says in part: “‘ExchB customers can walk up to any of over 15,000 locations nationwide and make a cash deposit at any Chase or Wells Fargo branch,’ president David Sterry wrote last week.” No kidding he wrote it; if he’d tried to say it, I’m not sure what would have happened.

If anyone can tell me how to pronounce this place’s name, I’d be quite interested. I don’t mean to slag on them too much, but I’m honestly curious how their employees refer to their company in casual conversation.