PHP Annoys Me, Sorta

I’ve been learning (re)-learning PHP the last few weeks for fun and there’s a lot to the language and community that I’m loving. The PEAR libraries are by and large fantastic – there are hundreds of them, even on the most esoteric subjects (Image/Barcode?). However, there’s a ton about the language itself that is driving me bonkers. I’ll give a few examples. Now, before I get totally flamed, I know this is probably 80% me not knowing enough about the various language features to get around these issues, so bear that in mind.

Example 1 – Compound Statements are for the Weak

I have a class, that returns an associative array. I want to be able to access it like this:

$oldest_value =  $viz->find_oldest_newest()["oldest"];

This makes sense. $viz is an an instance of a class, find_oldest_newest is a function that returns an array, and [“oldest”] is the accessor in to that array.

Nope, sorry says PHP: Parse error: syntax error, unexpected ‘[‘. However, this works:

$tmp = $viz->find_oldest_newest();
$oldest_value = $tmp["oldest"];

Example 2 – DateTime is Crazy

Where do I begin. First of all, pretty much the entire C library exists with date(), time(), strtotime(), etc. That’s great, that’s good. They all work on standard Unix timestamps. It starts to get crazy when you throw in the DateTime. For a guy like me, you’re used to objects to deal with this kind of stuff (e.g. timezone offsetting), so I gravitated towards using the DateTime object.

First of all, the DateTime constructor doesn’t take a Unix timestamp directly as a value. You can blame ducktyping here, but this is what you have to do to get a DateTime from a Unix timestamp:

date_create("@" . $rawdate)

Second, the DateTime object has no default toString! I can’t explain how frustrating it is to always have to date_format something when I should have just been able to echo it directly. It leads me to a mess like this:

public static function format_date($rawdate, $format)
{
if(gettype($rawdate) == "integer")
return date_format(date_create("@" . $rawdate), $format);
elseif(gettype($rawdate) == "string")
return date_format(date_create("@" . strtotime($rawdate)), $format);
elseif(gettype($rawdate) == "object")
return date_format($rawdate, $format);
}

Example 3 – Types? What Types?

Go ahead, tell me what the difference should between gettype() and get_class(). Thought about it? Nothing was your answer? Exactly. Not in PHP. gettype() only works on primitives. For objects, it returns “object”. And get_class, it doesn’t really work on primitives. Now, I get it that PHP was originally not an object oriented language. But when in PHP4? PHP5? they started baking OO notions in the language, why not make it complete and make the primitive data types objects.

Example 4 – I, for one, accept our new String overlord

If you look at a couple of the examples above, half the default library functions return a string data type as their result (e.g. gettype()). When did strongly typing go out of fashion? I get ducktyping, it’s all good. I used to write a lot of VB (VARIANT, anyone?), but that isn’t an excuse to throw strongly typed constants out the windows.

What’s wrong with a static class like TypeCollection::String, TypeCollection::Integer, etc, etc. Maybe it’s there and I haven’t found it. Also riddled throughout the PHP libraries is the concept of an array as a data type. If you look at some of the date and time functions, they’ll unpack a timestamp in to an associative array whose keys are “minute” and “second”.

Okay, I’m done venting. PHP is acutally pretty cool. Like I said the PEAR libraries (Image/Graph, while still under development, is amazing) are phenomenal, and the availability of community resources is a big win for me. I just wish that some things of the language didn’t seem to, well, kludgey.

649 Words

Goodbye Microsoft, a Look Back, and Hello Adobe

Last Friday was my last day at Microsoft. It’s taken me a while to write this post, because I’m not really sure what to say, or what I can say to really sum up what were five amazing years with the company. I started working for Microsoft as a Student Consultant at UCSD in 2001, interned the summer of 2002 (in devdiv, the team that makes Visual Studio and .NET) and again in the summer of 2003 (in Hotmail), and the joined full time in 2003. In so many ways, the path my life has taken has been intertwined and driven in no small manner by Microsoft. I have so many good friends, good stories, and great experiences there, that it was sad to say good bye.

I remember the late nights trying to ship various versions of MSN Hotmail, fire drills dealing with live site issues. I particularly remember one were we upgraded a large number of our servers to new version of our codebase and the huge number of hours we spent debugging and testing and fighting to make things work. We ended up having a few guys from Redmond term serv to our data center, hooking up kernel debuggers and finding issues they’d never anticipated in Windows or IIS. It’s amazingly cool being part of an organization where using our own products internally make them better for our customers. It was great to be a part of the team that shipped Windows Live Hotmail (or “mail Beta” as it was called for a while), all on top of a new .NET based architecture with AJAX-y goodness. That was back in 2005, while people may not think of Microsoft as a forward thinking organization we were building the kinds of web apps people didn’t end up seeing en mass until later in 2006.

Then it was off to Shanghai for a while. What a time that was. There was so much we all learned there about building organizations, about what it means to have great people and to have a great team. I was there for nearly a year and a half, and I learned a lot more about “organizational” skills that I’d anywhere before. And I learned some Chinese! Living overseas was an experience I think everybody should have. It helps you learn so much more about who you are, and about the world we live in. We started this cool Calendar while we were there, and a year later, in November 2007 we shipped a public beta. It was a blast to see something start in Shanghai, then be part of the team in California to go live with it.

I’m waxing sentimental here, but it’s been such a fun ride, full of super smart people who love software and know what they’re doing impacts millions of people every day. I’m proud to be a part of all the teams that I’ve been in, and I know they’ll continue doing great things in the future

What’s next for me? I’ve taken a job at Adobe, in their mobile group in San Francisco. I’m really excited about what’s coming up in the mobile space and there were some really cool opportunities in Adobe to do cool things in the market. Looking around at the market, the mobile space to me feels like the Internet did in, say, 1997. Slowly opening up, with greater bandwidth to end users allowing a great wave of development and content to become a driving factor for consumers. Adobe’s in a great place in the market, already with their software (Flash Lite, etc) installed on 450m devices world wide. They’re making some moves that I found compelling and that I wanted to be a part of. This next year is going to be a crazy ride of learning a whole new segment of the tech industry and I’m looking forward to it.

Between jobs, I’ve taken two weeks off between Microsoft and Adobe. I’m halfway done with my vacation already! I’ve been spending a lot of time in coffee shops, reading, brushing up on coding (finally finding some time to work on a pet project), and cleaning up the apartment. It’s amazing how much better it looks when my frames and art are hung on the moulding and not leaning against the floor.

712 Words

San Francisco Barackified

I voted at a community center two blocks from my apartment. While walking to the polling place, I saw on nearly every door for two blocks placards that said “Vote Today” stuck to door handles. On each one there was a sticker that said for that house what the nearest polling location was. As I was driving through 16th and Mission on all four corners of the intersection. People were honking at them as they drove through the intersection (myself included) and they cheered wildly each time.

I’m totally impressed by the organization of Obama’s street teams and supporters. There at signs on the streets, posters in windows, people on the street, phone calls being made all from Obama’s camp. But what of Hillary? Nowhere to be found, at least in this city. Perhaps that’s not too surprising knowing San Francisco, but in SF, it’s Obamamania.

Now, to glue myself to the television for the next 8 hours.

157 Words

What America Earns

Forbes has a piece on the 25 worst paying jobs in America. I pulled out any occupation that had over 500,000 people employed in it.

  • Food prep (kitchen) with cooking: 2.4 million employed, earning $15.9k
  • Fast food cooks: 600k employed, earning $15.9k
  • Dishwashers: 502k employed, earning $16.1k
  • Counter attendants working at cafeteria, food concession and coffee shop: 524k employed, earning $16.9k
  • Waiters/waitresses: 2.3 million employed, earning $17.1k
  • Cashiers: 3.4 million employed, earning $17.9k
  • Personal and home care aides: 578k employed, earning$18.1k
  • Food prep (without cooking): 871k employed, earning $18.4k
  • Maids and housekeeping cleaners: 900k employed, earning$18.7k
  • Child care workers: 572k employed, earning $18.8k

That’s stunning. Back of the envelope math basically says 12.7 million Americans (people you see and interact with every day) are earning roughly $18,000 a year. That’s roughly 5% of people living on $1,500 a month. The total count didn’t include the other 15 professions that had less than half a million people employed.

After digesting that, look at the article, as it describes the top 25 earning professions and you’ll see how drastic the wealth divide in our country really is.

168 Words