This week I’ve decided to use Smarty for a personal project. I’ve previously been leery of using a template engine with PHP because PHP is a template engine. You can embed code in what are otherwise HTML documents.
But this week I’ve come around to the Smarty way of thinking for several reasons.
- It has excellent documentation. Every function is documented (as far as I can tell) and there are sections on relevant advanced topics. As regular readers will know, I have been critical of projects lacking documentation;
- It’s compiled to PHP anyway so apart from an initial “compile”, there is performance cost for using it.
- It simplifies a lot of common task like odd-even table row styling, rendering combo boxes with a particular item selected, etc;
- There are extensive variable modifiers;
- There is very little magic going on. By “magic” I basically mean auto-loading and other things that introduce code you don’t necessarily expect. Smarty is very straightforward and is obviously designed for high-performance use, which I really appreciate;
- Smarty is extensible with it’s plugin architecture and input and output filters.
Ok, so decision made: use Smarty. Now what?
Where are the Tools?
I still haven’t found a PHP IDE that I’m comfortable with. In part, this is probably due to using Intellij IDEA, which as far as I’m concerned is by far the best Java IDE out there. So much so that many Visual Studio users consider Resharper a “must have” extension for .Net development. Resharper and Intellij are both by Jetbrains. Resharper adds a lot of the refactoring tools that Intellij has to Visual Studio.
So what am I looking for?
- Syntax highlighting;
- Code completion;
- Being able to navigate to and from templates, plugins, etc; and
- Some form of validation (eg plugin file naming).
This isn’t an exhaustive review of these tools, merely an overview based on a fairly narrow set of requirements.
I have never quite grokked the Eclipse way of thinking. The whole perspectives thing where your whole IDE changes when you are, say, debugging never sat right with me. To each their own I guess. You also have the well-known malaise known as Eclipse plugin hell.
Still, I’ve tried it a couple of times and it’s OK but it doesn’t understand Smarty templates. There is a project to add Smarty support to Eclipse but it seems to be abandoned or dead and doesn’t seem to work with Eclipse 3.5.
For PHP I’ve used Netbeans far more than Eclipse. I can’t give you a concrete reason for this other than to say that I just found it less bloated and more straightforward. But unfortunately there is no Smarty support and it appears there are no plans to add it.
I only tried the free version (Komodo IDE is commercial) but it has no Smarty support. I’ve read some people rave about this tool. Personally I found it uninspiring.
There are lot of things I like about PhpEd but it is commercial. It has one glaring problem though: You can’t change the font size menus and other UI components. You can change the editing pane but the rest is derived from the OS DPI settings. Apparently this is because of the framework PhpEd is written in from what I could gather from the forums. Still, that’s a problem. There’s a huge difference between a 24” 1920x1200 display and a 15” laptop display that’s also 1920x1200. Changing the DPI setting in the OS is fraught with problems so changing it is not always a viable option.
That being said, I am generally most impressed with this IDE out of all the others. The price (US$210) is that high but it can be a lot for a personal project considering how much you can get for free elsewhere.
One thing I don’t like is that you have to buy a Windows or a Linux version. Why? Compare this to Intellij. You simply buy a license and you can use it on Windows, Mac or Linux. Why should it matter if I want to change my OS? It’s also a greatly different version (3.3.3 on Linux, 5.8 on Windows). Is there a difference? Is Linux lagging behind?
PhpEd does understand Smarty templates though so it has to get a big plus for that.
I’ve been testing Code Lobster for a few days. It’s an interesting product. What I like about it:
- It’s lightweight at under 10 megs in size;
- The UI is modern-looking and snappy;
- It has support for Smarty, Joomla, Wordpress, CodeIgniter, Drupal and jQuery;
- It is quite cheap and you only pay for those plugins you use, basically.
That being said, I did come up with a few things that need some more work.
- No “live” search. I’ve been spoilt by Intellij on this one. This is where the cursor moves as you type so you can stop typing as soon as you get to where you want. I consider this a “must have” feature of any editor. The venerable search box needs to be retired;
- The search/replace functionality was a bit awkward in how it searches multiple files. It doesn’t list all the matches that you can just click on. Searching a subfolder is awkward;
- Making changes to the filesystem externally requires a manual ‘Reload Project’. Something like Netbeans or Intellij will just find changed files quickly;
- There doesn’t seem to be a way of moving files around within the IDE;
- Some of the auto-formatting takes a bit of getting used to. For example, you type an opening brace and it advances automatically to the next line and indents. That’s not bad. You just need to get used to it.
I can’t say this is an exhaustive list and I’m not saying it’s a bad product. Overall I like it. It’s just a bit rough around the edges.
In the last month, Jetbrains has announced the development of Web IDE in standard and PHP editions. You can download an Early Access Preview release and try it out. To me this is the Great White Hope of the PHP IDE market because I have such enormous respect for Intellij’s code editor, which to me is the most important part of any IDE.
I’ve had a brief look at the PHP support and it still seems like there is a long way to go but I’ll certainly keep an eye on it. Based on Jetbrain’s track record, I have a lot of hope for this one but as Eclipse has shown, making a good Java IDE is different to making a good PHP IDE and as soon as you try to do everything you end up being good at nothing. I usually describe this condition as “doing everything badly”.
Also, it seems Jetbrains will be rolling this functionality into the fully-featured Intellij IDEA 9 (Maia) release so if you happen to get that version anyway (which I will) you’ll get it for “free”.
The good thing about Intellij is that it’s equally usable on Mac, Linux and Windows and you can use your license for any of those. It’s out of the box functionality comes with Subversion integration and pretty much everything you need out of the box. For me, this sure beats the plugin hell of Eclipse like figuring out which Subversion plugin to use (Subclipse or Subversive).
It’s the Little Things
There are plenty of people who happily develop using a text editor such as Textmate, Notepad++, Vim or Emacs. You can but there’s nothing like an IDE that supports left-clicking on a class to open the other class. Or an IDE that understands what framework you use (eg understanding Spring is particularly useful for a Java IDE).
One of the things that really impresses me about Intellij is the little ways the editing makes your life easier. This can be as simple as you type “mysql_query(“ and it inserts a closing parenthesis for you. Lots of programs do that but in Intellij if you then type a closing parenthesis, it moves you cursor after the automatic one. No spurious parenthesis is added and I don’t have to navigate over the automatic one with cursor keys or mouse. This speeds up how fast you can type and helps not break your flow.
That may seem like a small thing but there are literally hundreds of things like that in Intellij to the point that I now look for them in anything else I use, for better or for worse.
I guess the downside of using a dynamic language like PHP is that it’s harder to do anything like validation and navigation.
For my money, at this point in time, I would have to say that PhpEd is the best of the bunch if Smarty is important to you but keep an eye on Web IDE/Intellij IDEA when the next version is released by the end of the year (Q4 2009).