Archive for the ‘Web Programming’ Category

Disabling Author Info on Drupal

Tuesday, August 25th, 2009

You know those little headers that say “Authored by at 10:00″? So far, I haven’t had a Drupal set up in which they were actually wanted. I googled it and the best suggestions I had come up with were to add display:none; to the info’s class in a custom CSS file. Not bad, but it seems a little clunky. Someone on StackOverflow almost had it right when they suggested making changes to the settings of a specific theme. Of course, not every theme (including the ones I have been using) have this option. It turns out, though, that the settings can be set globally by going to Administer -> Site Building -> Themes, then clicking the “Configure” tab. Simply uncheck whichever node types you want to disable the author information for under “Display post information on”.

Much cleaner.

An Awesome Tool

Friday, July 17th, 2009

I was having some issues with the ordinarily awesome KCacheGrind (it kept crashing, so I couldn’t do anything with it), so I decided to look for another profiling tool. I finally found and installed Webgrind (http://code.google.com/p/webgrind/) and I must say that it is excellent. It appears that, after installing, you must ensure that Xdebug spits out its profiling data with a certain naming convention, or Webgrind will fail to pick it up. This is actually kind of odd, since there is a configuration option in Webgrind which is supposed to tell it what the naming convention is going to be. I could really see Apache/MySQL/PHP/Bespin/Webgrind as being a really cool environment to set up for distributed coding. But, that is a discussion for another day.

Drupals, CMSes, and Thoughts

Wednesday, July 15th, 2009

I have been setting up a couple of Drupal sites of late. Side work. The kind of thing that doesn’t write papers or change the world, but puts a little money in my wallet. For one of these, I have been working on a fairly deep customization of one aspect of Drupal (I haven’t decided whether I will write it up or not) and, in the process, I came across this blog entry: CMS battle: Drupal vs Joomla vs Custom Programming, on a blog named Paranoid Engineering (I sympathize with the title, if nothing else). The article itself was a fairly simple comparison of Drupal and Joomla which are, almost certainly, the biggest open source content management systems.

The table of features head to head is not terribly interesting. For the most part, the two have feature parity and, where they don’t, you can extend them. The first thing I found interesting were the author’s general opinions of the two:

“After test-driving them both I’ve came to these conclusions:

    • Joomla is bloated, Drupal is minimal
    • Drupal is easy to use and intuitive, Joomla is confusing

That was more than enough for a minimalist like me.”

Oddly enough, those were my thoughts exactly when I used them. I got a chance on a contracting gig a ways back to use Joomla and I found its hierarchy of concepts to be confusing. When confronted with something confusing, there are two possibilities:

  1. It is something knew, beyond my current knowledge and learning it will be an eye-opening experience that will teach me something, even if I don’t use it or don’t like it. At least, my mind will have been stretched.
  2. It is garbage

Unfortunately, I felt that Joomla, by and large, fell under #2. I did not feel that I learned some grand cosmic ideas once I got past that initial confusion. I believed that someone had erected a large number of unhelpful, artificial barriers. Drupal (which I learned later), divides content into blocks, which you can assemble on pages. That is it, in a nutshell. There was a lot more classification in Joomla.

Moreover, I definitely fall in the minimalist camp. I would rather take something small and build it up into what I need than take something large and try to strip it down to what it should be. I used to be a Gentooer (and, if I could take a few weeks to set up my machine, I might very well be again; at this season of life I simply do not have the time), but I found the initial time compiling inconvenient. So, I tried Sabayon. Well, Sabayon had the desktop and essential apps compiled, which meant that I could at least work while upgrading everything. The problem was that Sabayon had a lot more on it than I wanted, so I tried to take the fluff off–and I broke the machine. Badly. I was running Gentoo again soon after. The moral of the story being that it is easier to add on than take away. So again, I would tend to agree with the author.

One commentator also remarked that they did not like Drupal because:

“What keeps surprising me about Drupal, is that they still stick to an outdated procedural programming style. PHP is moving more and more to OOP. Trying to force a programming style on a platform that’s moving in a completely different direction is a weird choice to make.”

Personally, I think this is a little harsh on Drupal. According to Wikipedia, the Drupal project began in 2001. Also, by Wikipedia, PHP 4 was released in May 2000. However, most servers are not running the latest release of a language (don’t shoot the messenger, it’s true) so writing in PHP 3-isms in late 2000 and early 2001 seems quite reasonable and, while PHP 4 had some OOP in it, I can tell you that it is second rate and actually pretty lousy. Frankly, if I had to write PHP 4, I wouldn’t use its OOP. I know this because I have deployed code to servers running PHP 4 and had to backport the PHP 5 style classes. PHP 4 is just not a good environment for OOP, PHP 5 is okay and we’ll see how PHP 6 does. Once your code is heavily procedural, fully OOPifying it would be a rather non trivial amount of work, if not a rewrite. And, of course, Joel on Software tells us not to rewrite.

The comments were probably more educational for me than the post. The commentators mentioned a few alternatives to the usual Joomla/Drupal dichotomy. The three I noticed there were:

  1. Typo3
  2. SilverStripe
  3. Modx

Of the three, the only one I had heard of was Typo3, SilverStripe and Modx were new ones. Typo3 aims to be, in their own words, an enterprise level content management system. Modx, on the other hand, really caught my attention. It is not so much a CMS (although it has one) as it is a framework to build CMSes. The approach is interesting because with Drupal, Joomla, or Typo3 you take the base CMS and add a lot to it. You customize it. The idea of simply expediting a custom rolled solution certainly has some appeal over stack and restacking the blocks/modules/plug-ins/add-ons (or whatever the heck else they’re called). I didn’t spend much time looking at SilverStripe, but it does appear to be a very well polished CMS.

If all this sounds like a ramble, well, it is. It is a rambling exploration of a series of things I stumbled across. If anyone has any thoughts regarding the CMSes above or one that I have omitted, I’d love to hear about it/them.

Playing Devil’s Advocate

Saturday, June 6th, 2009

In all the cool geek sites, you hear PHP put down as a matter of course. Its inferiority goes assumed by most of the audience. Every once in a while, you see someone decide to defend it, which leads to a nice old flame war, but that’s about it. The irony I find is that few of PHP’s defenders really do a good job defending the language. The extreme is this one guy, whose defense of PHP runs: “I like it. It does everything I’ve ever wanted it to do.” Not much of a defense. Leaving Turing Completeness aside, the defense says nothing. Anyone can say that about any number of languages and you could never prove them right or wrong. If PHP can do everything you ever wanted to do, then at least half a dozen other languages can (C#, Java, Perl, Python, Ruby, C++). Why PHP? What you usually find with this kind of defender is that it was a language that they picked up at some point, for some reason and they do not know enough about other programming languages or even PHP itself to be able to give an adequate reason.

The charges against PHP are that it is sloppy, inconsistent, encourages laziness (and not the Larry Wall variety), and lacks some of the cooler features of other languages. Guilty as charged. All of those things are true and have been rehashed many times. As a disclaimer, let me say that I agree with this point of view. For web programming, you are better off with Python than PHP. But, let me play devil’s advocate for a moment. If I were going to argue for the use of PHP, what would I say? Well, I would begin by pointing out that PHP is fast. Maybe not out of this world, I funrolled my own loops, and wrote my web framework in assembly fast, but it is fast. PHP is also very easy to deploy. If you set up a Python WSGI application or a Rails application on Phusion Passenger, there is a fair amount to set up in the web server and get running. Not unbearably so, but PHP wins as, in most cases, you copy over the source and you are good to go. There is a ton of library code available and many fine, large applications (obligatory Drupal and WordPress references here) written in PHP. There is an abundance of cheap hosting that has PHP set up by default (Python is starting to gain traction as GoDaddy has started offering Python over CGI in their deluxe Linux packages), which, in many cases is important. Sure, if you are personally developing a large Enterprise application, it seems reasonable to expect someone to be able to configure a server for it. On the other hand, if you are running a small business and just want a CMS to run your web site on, you do not need anything more than cheap, low-level hosting. In this case, the business is not the developer and does not hire the developer, but if you are writing the software and want this small business owner to use it, than there is a definite advantage here. WordPress would probably never have caught on if it were not written in PHP because it would be too much work for a lot of people to set up and too much work for most hosting services to support.

There are some notable, often-cited reasons to use PHP left out. For example, many have argued in PHP’s favor because there are many developers which means that it should be easier to fill any new positions in the case of departures (an obvious concern for open source and closed source teams alike). The problem with this argument is that, while it is true that there are a very high number of PHP developers, the problem here is that a very high percentage of them simply are not any good. They picked up a bit of PHP and HTML, but were too lazy to learn enough to be truly excellent developers. The end result is that this is more a problem than it is a solution, because there is a lot more chaff to sift through in the hiring process. It certainly is not obvious that you are better off this way than, say, Lisp. There are few Lisp coders on the market, but, as a rule, they are better coders. The very bottom of the barrel have not even heard of Lisp and, if you try to get them interested, you encounter the Blub phenomenon: they cannot comprehend what a more powerful language would even look like.

Playing with Prism

Monday, May 25th, 2009

This weekend, I decided to goof off with Mozilla Lab’s Prism Project. It is the Mozilla Foundation’s implementation of the Site Specific Browser (SSB) concept. I set up or downloaded applications for Napster, Pandora and Gmail. Out of the box, it has novelty value, but little of practicality uniqueness. In its current form, you fire up Prism, provide a URL, and create one or more shortcuts. when the link is clicked, it will launch in its own private browser session, without toolbars, extensions, or navigation keys by default. This is nothing that Internet Explorer hasn’t been doing for a long time and even Firefox can do most of it (with the unfortunate exception of not starting an independant browser session). You can also set a custom icon on it so that it “Feels” a little more like a desktop application. Prism’s wiki indicates that you can do more with it, like custom styling, but I haven’t seen anyone actually use these capabilities. The bundles I tried (like Gmail) simply create the shortcut and use a custom icon.

A great deal of the issue here is, no doubt, what Joel Spolsky calls the Chicken and the egg problem: to be interesting, Prism needs bundles, but no one is willing to create the bundles for Prism because Prism isn’t interesting yet. If and when it catches on, the idea has potential. Gmail, for example, can run beautifully in the browser, but have nice tie-ins on the desktop, like showing a message count when it is in the system tray, start composing an e-mail when I click an e-mail link and allow drag and drop of files (particularly for attachments).

So far, it has had one very pragmatic benefit. As many Linuxers are aware, Flash and sound are both known to be somewhat problematic. Having downgraded to Ubuntu 8.04, Flash locks up sound when run in Firefox which means that, to run a desktop sound application (like, say, Amarok) I have to kill Firefox to release the lock. This works and, with Firefox’s session management, is almost liveable, but is quite annoying. Using Prism for the Flash sites (which, for me, are few) allows me to kill the Prism “application” and release the lock, leaving my browsing and work untouched. This problem seems to have been sorted out in later versions of Ubuntu–to which I will not upgrade until suspend/resume and hibernate/resume work.However, this benefit really just makes up for two shortcomings elsewhere: the abominable state of Linux sound and the fact that Firefox does not run with separate processes for each tab (ala Chrome).

Mozilla’s is not the only project attempting to work off of the SSB concept. A quick googling turns up many options, tough most are limited to either Windows or Mac OS X. The idea itself seems to be a bridge. From where and to where, it is difficult to say. We could be bridging from desktop applications to web applications. From web applications to RIA applications on the desktop. From web back to the desktop. The motivation probably varies by implementor. For Adobe, it is most probably a bridge from web applications to RIA. Once you are started with Air, it will probably be a lot simpler to get you over to move to Flex than it would be to simply jump directly from web programming to the hybrid world of Flex. Mozilla would rather see you use Google everything than see you use Microsoft products as this keeps the browser as the focus of your world. So, they want to create a bridge that eases the desktop oriented users (which is, for the most part, medium to older users, as the younger ones are used to doing everything over the web). to the web.

So, to sum up, Prism has some potential, though right this minute it isn’t the biggest whoop in the world. However, it can still be kind of nice for odds and ends.

Old Friend…

Tuesday, May 19th, 2009

This week, I have been tasked with making some changes to code that was gnarly to write and has gone untouched in some time. I needed to backtrack and look at an older edition, so I fired up good old svn log. Snipped down, I saw these two lines:

r154 | mmcdermott | 2009-05-18 16:04:22 -0500 (Mon, 18 May 2009)

r117 | mmcdermott | 2008-05-21 15:42:22 -0500 (Wed, 21 May 2008)

These were two consecutive checkins. That’s right: this code had gone unaltered for almost exactly one year. Believe me, that is rare where I work. But what was nice about the whole thing was that I was able to look at that code and not call myself an idiot. Now that the dust had cleared, I want to rearrange a few pieces of code (and I’ll probably take this chance to do it) to reduce the number of AJAX callbacks, but the code was readable, clean, and sane.

As developers, we have all had those slap-my-forehead-what-was-I-thinking? moments when reviewing our old code. When I was in college, I spent one spring break (in addition to doing all of my semester projects), learning Scheme (this also being, I might add, my first encounter with any form of Lisp) and using it to write an application to normalize a table schema. I looked back at it later after I had learned more about Scheme and found the SRFIs and realized that I had basically reimplemented SRFI-1 and, since I was just learning the language, reimplemented it badly.

So it is really nice to look at code that was written under the gun (as we will all have to write code, at some time or another) and say that it was a legitimately good job.

All I really want in a web framework…

Saturday, May 16th, 2009

As of late, there has been a great deal of attention paid to web frameworks and these huge time savings that are supposed to be based on the framework selected. Ruby on Rails is, perhaps, the most famous and the one with the most devoted base. I played with Rails for a bit and the honest truth was that I liked the Ruby part a lot better than the Rails part. Rails tried to do a lot, to “help”–and I didn’t like it. I have written similar dislikes for CakePHP which is, by its own admission, an attempt to bring Rails to PHP. Cake is not the only attempt to give PHP users the bliss of Rails. There is also PHP on Trax and Akelos and heaven knows how many others.

It’s not just the PHP boys hopping at the Rails hype. The BBC created a Perl on Rails. Heck, on cliki I even found a project named Lisp on Lines that endeavors to provide a “Rails-like” environment in Common Lisp.

ASP.NET is a little better. It doesn’t try to help with ORM or a lot else, but I can’t help but feel that it has a tendency to be a little stiff at times. Though it is definitely one of the better frameworks out there (and, yes, it is only a framework; contrary to all-too-popular belief, you can write ASP.NET in any .NET language).

What I am saying is that I, personally, want a minimalist framework. I want to be able to assemble a toolkit based on the project at hand, not what is encouraged by the framework. I don’t want to write a plugin to be able to use a bit of JavaScript effectively. Here is what a web framework should provide:

  • Spackling over request details. I need the contents of the GET and the POST, but I sure as heck don’t want to write a GET and POST parser for every application. Preferably, this would also spackle over the exact source of the request. When writing an application, I don’t care whether the request came over CGI, FastCGI, an IIS filter, or mod_lang. I want to the variables and that’s it.
  • A templating engine. A simple, minimalist templating engine. Nothing too fancy and, if I so desire, I should be able to ignore it with impunity or even substitute another. This should be one of the most loosely coupled pieces of the framework. As time goes on, I also expect a minimum of widgets and gadgets to be provided as we get an increasingly large amount of sites and apps whose UI is AJAX/Flash/Insert-RIA-here driven. I really like Smarty for PHP work (which has a plugin API, but not controls in the ASP.NET sense). ASP.NET’s templating engine is good, but its server-side controls are biased towards a method of development that is either outdated (controls rendered and handled serverside) or opaque (how does that callback work, again?).
  • Pretty URL support. Yes, there is mod_rewrite and friends, but it makes things much cleaner to have only a couple of mod_rewrite rules and handle the rest application side.
  • Session management. HTTP is stateless, but web applications, as we all know, are not. Session management is not difficult so much as it is an annoyance to write with every app.

Data access should not, as a rule, be involved. Particularly, data access in which it is difficult to perform raw queries against the database. Generic, all encompassing data access layers are hard to use because they make a number of assumptions (in the name of simplicity) that simply do not hold true for everything. Worst of all are the schema assumptions that frameworks like Cake make.

Django is the exception to the rule, though. Their DAL is excellent. You write an object model that inherits from some base classes. This is used as a very thin layer and you can still easily (yes, easily is the key word; I know you can write raw queries in Cake and Rails, but they try to hide it as much as possible) drop down into plain old SQL. This way, the developer is not boxed in by such things as the dictionary included in the framework.

One time, I wrote an app in CakePHP and I used a term for an entity, I cannot remember what, that had a plural not recognized by Cake; now Cake requires that all tables have plural names. The plural for this word was not recognized, even though it was the correct English usage. This caused the DAL to go haywire and cost me an hour or two of debugging.

The overwhelming philosophy is to provide basic support for that which needs to be done in the act of serving up a web application and leave everything else to the user. The new wave of frameworks tries to do as much as possible for the user. In this sense, a framework is like any other tool or any other application: when you try to do the user’s work for them and are overzealous about making things “easy”, you get underfoot and make things difficult. RoR has made the “blog in 10 minutes” example almost mandatory for a new framework. Well, it’s great that you can throw together a simple blog in 10 minutes, but who wants to? Therein lies yet another rub: RoR and its kin are tuned towards mass producing almost-clones of certain types of applications. I, for one, do not like writing lots of almost-clones. I’d rather download Drupal or any one of a thousand other open source packages and configure that than write a custom almost-clone. What I want in a web framework is small. So, can I have that framework, yet?