PHP in Action Rotating Header Image

Posts under ‘Application design’

Refactoring is design

Refactoring is by definition a design actitivity, since the definition of refactoring is “improving the design of existing code”. But is this generally and fully recognized? After attending my friendly local agile conference (Smidig2008—sorry, it’s in Norwegian), I’m getting more of a feel for how different people think about it. And I’m wondering whether the [...]

Type hints are more useful for scalars than objects

Max Horvath has implemented a library for type hinting scalars. That interests me, since I find that type hinting for objects has limited usefulness. I tried using type hints extensively from an early beta version of PHP 5. I mostly gave up on them for three reasons: They make refactoring harder since you get lots [...]

Testing a Zend Framework action controller with View Helpers

I came across a Zend Framework (ZF) example I wanted to refactor. You really have to have unit test coverage to refactor effectively, and since there were no tests, I started trying to find out how to test it. There didn’t seem to be a wealth of information available on the web, so I’ve tried [...]

Flash messages

Redirects are useful in web programming, especially when implementing the Post-Redrect-Get pattern. But there is a problem with redirects: there is no simple way to send a message to the user across the redirect. When processing a GET request, you can display whatever messages you want. The most simplistic way is to echo them directly; [...]

The psychology of test-driven development

Silvan Mühlemann has written an excellent piece titled Unit testing makes coding more fun. I keep saying that sort of thing, too. I also say it raises your IQ. But when I attended a presentation by Uncle Bob (Robert C. Martin) last summer, I was mildly shocked to see that he described TDD as tedious [...]

I want enums in PHP

I want Enums in PHP I’m currently working about equally in PHP and Java. I can’t say I’ve fallen in love with Java. But Java does have a feature or two that would be useful in PHP. One of them is the Enum (enumeration, that is), which is traditional in some languages and DBMSes (including [...]

Immediacy and frameworks

As if to remind us that not everyone in Ruby hates PHP and vice versa, Rails creator David Heinemeier Hansson commends the immediacy of PHP. I'm vaguely wondering if he's also understood the potential of the smooth, agile ride from the immediate to the complex. Probably not. To quote myself from the Sitepoint PHP Application [...]

Fake it and raise your IQ

Implementing a new piece of software is working with a black box that doesn't even exist yet. You know something about what's supposed to come out of the black box, but typically not much. So

Secure Request object

I'm reading Chris Shiflett's Essential PHP Security. He suggests making sure all input is filtered by putting it in an array called $clean after it's filtered. This is a way to make sure you don't forget to filter any input, so that only filtered data enters the bowels of the application. I like the idea, [...]

Feature-revealing code

Making names “intention-revealing” is a well-known principle in object-oriented programming and design. You want the names of methods to communicate their purpose rather than their technical implementation. A related question is: how much should the code reveal about what's going on at a lower level? An illustrative example is the PEAR package HTML_Quickform, which handles [...]