• Dec 05 Just released extension of popular argument validator aproba for key-value objects Follow the link
  • Nov 30 micro-requirejs - super simple resource (JavaScript/CSS) loader 2.0.0 released Follow the link
  • Nov 23 Puppetry v.1 released - end-to-end test automation tool for not just developers, but for everybody - QA-engineers, testers, people from management and so on. Follow the link
Design Patterns by PHP and JavaScript examples

After having your project fully tested, deployed and running, it seems the application architecture is pretty good enough. All the requirements met and everybody is happy. But then as it happens, the requirements change and you, all of sudden, find yourself in the time of troubles. It comes out that some modules easier to hack than to modify. Change of other ones brings endless changes in a cascade of dependent modules. Or you change one module and whole the application starts to collapse like a house of cards. And, of course, you find out that you can’t reuse already written modules for the new tasks, because the encapsulation of the desired parts would take too much risk and work. Robert C. Martin was very accurate naming those symptoms of rotting design as Viscosity, Rigidity, Fragility and Immobility

Bringing realtime to your web applications

Few years ago only lazy didn’t say about bringing desktop application experience to the web ones. However in reality, it just meant that user actions didn’t always required page reload, but could change page UI dynamically. As for other application events, as a rule they were not handled dynamically.

Well, now you can find more and more web applications acting really like desktop ones. For example, Facebook and G+ have widgets which update automatically. You can keep the page untouched, but you will see anyway new status updates appear as your friends submitting. The same for notifications. Whenever a new one arrives, the counter changes and the notification list extends.

That seems to me as a trend worth to follow. I’ve been thinking of a solution to vivify widgets on my sites. Now I’m coming up with the following pattern.

Form auto-completion tool on your own

When testing a web-site, nevermind who you are developer or QA-engineer, it happens to you pretty often to fill-in form fields again and again. Boring, stupid work, but how to make sure the form does still work as intended? Some fields added, CAPTCHA was attached, whatever else done –you have to run the test again. Besides, it will be repeated on different browsers. Browser form auto-completion feature helps a bit, but that is not the same as when you have various sets of test-data always ready to apply on a form, isn’t it?

Support Request Tool like Google Feedback

Have you ever noticed Google+ has an amazing feature called Google Feedback. You click on feedback highlight an area of the site page and getting screenshot with your marking on it sent to the Google support team. If you wonder of having this tool on your own, just take my code and adapt for your requirements.

WebSockets vs Server-Sent Events vs Long-polling

Apparently social networking is the banner of the nowadays web. Everybody intends bringing some features into his projects. Some of them require immediate notification. That is getting common, if you open a page with upcoming messages (status feed, notification subsystem, friends-list), you expected them being updated as soon as a new message (status, notification, friend-making action) arrives. As you well know, original web design allowed only one-way client-server communication (one requests, another one responds), though now HTML5 working group doing their best to fix it or rather to patch it. However, the web-projects are still using long-polling trick to emulate server-client communication.

Well, now new web browser versions appear every few months. Besides they update automatically. Thus a huge number of users have the latest browser versions, which support HTML 5 communication APIs. Is that the time to put long-polling away? Let’s find out.

Review services getting consolidated

I anticipate Google to swallow Review Services market using G+. I hate the idea of somebody having total control on everything, but when I buy a product (any product), I see number of variations from different producers. I want to read some reviews, to see some ratings on products and their producers before picking one. That’s natural. Where to get those? On the site of producer/seller? Oh, please! I would rather not trust them entirely. Well, I could try to search on or try, though I would hardly find many of the products sold in Germany and the reviews by the locals. I’ll tell you what, I’m going to end up extracting reviews on public forums and likely giving up after hours spent in vain. However, I can use Google Products ( and find everything in the place. I may even make a photo of the product right on the shelf of the store and try googling by the picture.

But in real life it’s not all so nice.

HTML5 Video on iPhone

Enabling your videos for iPhone Safari doesn’t seem as a big deal. You know it supports HTML5 . Besides, you don’t even need to write event handlers and produce a skin by yourself, but only take a ready JS component. Apparently is getting close to be the most popular one. Though, I personally like It is very simple to use any of them. The only difficulty is to get your videos converted to h.264, Theora Ogg and WebM. When two last ones are meant for desktop browsers Chrome/Opera/Firefox/EI9, the first is for mobile devices. And here we go, using a converter (e.g. E.M. Video Converter) we are getting .mp4 which looks pretty ok on iPad, but iPhone refuses even to try playing.

Drupal – nice ideas and bad coding

Working with Drupal for half of year and constantly tuning it for better maintainability, code consistency I came to the idea – Drupal is going to be a toy, a pretty popular but only toy, unless they decide to rewrite everything from the scratch. Studying Drupal 7 I find the CMS wasn’t really refactored. They dramatically improved administrator panel, included CCK/ImageCache into the core, added file handlers and Unit-test framework. However it’s still a mess of coding styles and approaches. You can enter any module folder and you’ll find bunch files with no concern separation. View components, business logic, helpers, domain entities – all can be met in the same file. I understand that laying strict requirements on modules would affect the army of contributors. But anyway with Drupal 7 all the modules must be rewritten. Maybe the committee just can’t agree on a structuring strategy. As for me, it must be like that.

ECMAScript 5 and JS frameworks

Standards are being always approved with a slow pace. Though, the features declared in drafts usually find their implementation long before the standard release. Let’s take for an instance Websockets, which were already implemented in Chrome/Safari and Firefox 4b when standard unexpectedly changed. Apparently YUI3 and jQuery have implemented for long time the features, which are only coming up with ECMAScript 5 (the implementations is called JavaScript 1.8.5) spread.

Extending MVC on Drupal

I’ve already described an approach of using MVC in Drupal . It wasn’t bad for the beginning I hope. Though in real life you face requirements which hardly can be fulfilled with such a simplicity. In, more or less, complex application you ain’t going to be satisfied by the only controller (page controller) to serve the whole bunch of components presented on the page. So, let’s assume we have a page full of components and each of them can behave differently. It means we need controllers and views for them. Reminds of Java portlets, doesn’t it? Such components are often referred as modules in IA, but I don’t dare to call them so in this context to avoid any confusion because of Drupal modules. So, let’s go with widgets.