PHP IDE
by the heapster on Jan.22, 2010, under Uncategorized
A short while ago, I was looking at getting at spending some more time doing PHP development. For the last view years, all my PHP work has been done in vim, which is generally pretty decent. For doing significant work, though, I prefer a more capable IDE.
In the past, I’d used Zend Studio (version 5.x). It was a slow, and a little buggy, but it wasn’t terrible. I’ve also tried Eclipse PDT, the PHP IDE Eclipse subproject. This was all a few years ago, though, so I figured that I’d get a lay of the land, circa 2010.
Zend Studio has changed… it’s based off of Eclipse PDT, which Zend apparently sponsors now, and has some juicy bits that aren’t present in the open source project… profiling, code coverage, etc. You can see a comparison chart here. For a developer that does lots of PHP work, I could see the extra features being worth the $400 price tag. I seriously considered getting a license, since I’d get a discount from having previously purchased older versions. While doing research though, I made a startling discovery regarding licensing. From the Zend Studio FAQ page:
Zend Studio licenses are valid for a single user on a single machine. This means that if you have 2 developers using Zend Studio on the same machine, even if it may be at different times, you legally need two licenses of Zend Studio. If you have one developer and that developer needs to use Zend Studio on two different machines, you also need two licenses of Zend Studio.
Having to buy a license for each machine that I want to use it on is a huge turnoff. Here at home, I have a Windows 7 laptop, Windows 7 desktop and an iMac. Ideally, as long as I’m the only user, I could install a program for my own personal use on all these machines. Better still, I’d really like to be able to install a copy on my machine at work as well, again for my own use. I could live without being able to do that, but not being able to install on all my home machines is pretty much a deal breaker, and it’s a shame, because I find the additional features over Eclipse PDT compelling enough to be willing to lay down the cash for a license.
Continuing my search, I found a decent (though slightly dated) article on Smashing Magazine. The article identifies the main features that they considered important, and then built a comparison chart between a handful of different products. Zend Studio 6 was on the list, along with Eclipse PDT (versions 1 & 2), NetBeans, Aptana, Codelobster and Nusphere. Of these, NetBeans and Aptana PHP were surprising because they offer a lot of features for the low, low price of free.
I’m trying NetBeans out now. The NetBeans guys made a weird versioning change, so rather than the NetBeans 7 that appears in the comparison chart, it ended up being called 6.7, and the current version is 6.8. It’s a relatively small download, starts and runs fast, and it works like a champ. It’s a bit weird that an IDE that I thought more for Java development has such strong support for PHP, but it has all the most important features for me in a PHP IDE… code completion, syntax highlighting, phpDoc recognition (including @property, for identifying properties set through the __get and __set magic methods). Zend Studio may have more features but NetBeans fits the bill for now.
Property Syntax
by the heapster on Jan.02, 2010, under Uncategorized
This is a kind of Seinfeld post in that it really has no point. I was going through some PHP code recently (a symfony tutorial) and found myself vexed by the way that properties in the example (and I assume in symfony overall) are implemented as function calls. For example, given an object, $o, with a property named foo, its accessor is a method named getFoo ($o->getFoo()) and it’s mutator is a method named setFoo ($o->setFoo($value)). It’s silly, but my preference is for properties to be syntactically distinct from methods – $o->getFoo() becomes $o->foo, and $o->setFoo($value) becomes $o->foo = $value.
In PHP, the origins of the setFoo/getFoo methods is probably rooted in older versions of the language where classes had no control over member access. Members were identified with the var keyword and were all effectively public. A useful workaround to separate public and private members was to implement getters and setters for those members that were public, and everything else was private. This was a decent solution, though property access was on the honor system: a user of the class could still reach in and directly modify a member value regardless of its intended visibility or whether it had accessor methods defined.
When PHP 5 came along, it introduced public, private and protected visibility specifiers so that classes could finally enforce encapsulation. In addition, the __get and __set magic methods were introduced. When a user of a class attempts to access a member that either doesn’t exist or isn’t visible in the current context, access is routed to these methods (if they’ve been defined). This has the benefit of allowing the class author to perform additional processing when a value is set – setting a dirty flag, validatng the new value, etc. – while still allowing the user of the class to use property syntax. The one downside that I can see here is that __get and __set must incur a slight performance penalty because it’s a last resort for locating the property value (the engine must have to check to see whether the property exists, then check to see whether it’s visible, and failing those checks, needs to check to see whether the appropriate magic method is available and then make the call), and then the methods themselves have to do processing to resolve the property name (passed as the first argument to both methods). I can’t see this being too significant, though, so it doesn’t bother me to use it.
I explain my preference for property syntax with the following points:
- separate syntax for property access vs. method calls carries the subtle implication that you are working with data rather than triggering an action (1)
- the origins of the set/get methods for property access feels obsolete
- $o->foo feels more elegant than $o->getFoo()
- property syntax lets you do $somevar = $o->foo = 100, a seldom-used C-ism (2)
1) Though it’s not guaranteed. I’ve seen classes where property access triggers an action (setting the connected property to true makes the connection, rather than call a connect() method. That feels more than dirty to me… almost evil.)
2) You can get the same result if your setFoo method returns the new value of the property.
Interestingly, while this is probably my general preference, I’m not married to it. For example, Objective-C only recently added dot notation for properties in version 2.0 of the language, and though it’s syntactically more in line with my preference for PHP, I prefer the old method.
Prior to version 2.0, property access was very similar to what we see with PHP… property setters and getters are implemented through class methods. Given an object, someObject, with a property named age, you access the property by sending the age message to the object: [someObject age]. To set the property, you send the setAge message: [someObject setAge: 25]. When Apple released version 2, they added support for familiar dot syntax: [someObject age] becomes someObject.age, and [someObject setAge: 25] becomes someObject.age = 25.
You’d have thought that I’d be all over the dot syntax, but I’m not. I couldn’t say for sure, but I think that it’s because the Objective-C convention for working with objects is to pass messages, and that the dot notation feels out of place.
Dead Trees
by the heapster on Dec.21, 2009, under Uncategorized
I’ve got a thing for books. Computer books in particular are my interest. For the past few years, I’ve been a bit removed from convenient access to a book store with a decent stock of good computer books, but with the recent move I suddenly find myself within arm’s reach of a good supply. The funny thing is that about the same time that I got a store that I can go visit, I discovered alternatives that are about as convenient.
The first alternative was The Pragmatic Bookshelf. Discovered while Googling for an Objective-C reference, The Pragmatic Bookshelf is a book store for programmers. They offer an interesting collection of titles, without a strong focus on Microsoft topics, which is kind of a nice change. The coolest thing is that all their titles are available as e-books, and when buying the hard-copy along with the e-book you get a big discount and instant gratification. You can download beta versions of upcoming books, which is pretty cool.
The second site that has caught my interest is apress.com. I’d actually purchased from them in the past (Rocky Lhotka’s CSLA.Net books), but never really returned. Reminded that they were still there by a message in my inbox the other day, I went back and gave them a second look. They have a bigger collection of books, but I want to say that The Pragmatic Bookshelf has better prices. They also have an alpha program where chapters of some of their books are available prior to the book’s release date.
I’m actually kind of on a big kick with this stuff now, so I’ll post more information if I turn up anything else that’s relevant.
Apple TV: Living Room of the Future
by the heapster on Dec.03, 2009, under Technology
The Apple TV is super cool. We bought one a year or so ago and after finally unpacking it and setting it up after the move, we’ve been using it more than ever before. The technology is compelling — buying movies or TV episodes off the iTunes Music Store is painless — but my favorite feature by far is the remote.
The Apple TV ships with a stock white remote. I understand that it’s the same device that Apple packs with their laptops. It’s nothing special, but it does the job. If you have an iPhone, though, there’s a much better alternative: a free download from the App Store, called (appropriately) Remote.
The user interface is similar to the iPhone’s iPod interface that you use to play media on the phone. After pairing with the Apple TV, Remote talks to it over the wireless LAN to let you browse content and otherwise control the machine. Tap the movies button to get a list of the installed movies, tap the TV button to see a list of your available TV series… from there you can drill down into an episode list. Once playing, you can control playback using gestures or buttons in the interface. You can search your library, the iTunes Music Store or YouTube, and when you bring up the search interface, the iPhone displays a keyboard for data entry — a massive improvement over the regular remote (where you’re presented with an on-screen keyboard and navigate up, down, right and left with the remote to position the cursor over a letter and then hit a button to select it).
I’m convinced that this sort of interface is the future of device control in home entertainment. Universal remotes are convenient and reduce clutter, but they’re ultimately dumb devices. A friend and I were talking over the weekend and he was saying that he’s got a remote programmed with a macro that can turn on the television, receiver, and cable box with the push of a button. But since it’s still just blindly firing out IR signals he finds that his wife sometimes has trouble getting the aim right — sometimes she finds that she turns the remote away or puts it down too soon (after seeing the TV come on) leaving one or more of the other devices off. It becomes a nuisance to try and get everything up and running correctly. Hopefully, some day, device manufacturers will come together and agree on a common interface, and all the components in your home theater will be as easy to control as the Apple TV is today.
Introducing “The Heap”
by the heapster on Dec.01, 2009, under Uncategorized
base2.org came up in a discussion today with a colleague, and he asked what I was doing with the domain. I’ve had it for something near 15 years now and for the most part it’s been dormant. The thought crossed my mind that maybe I should put it to use, so I’ve installed WordPress and we’ll see what happens next!