bitstorm.org

weblog of a webdeveloper

  1. Report of the Dutch PHP Conference 2010

    For the third time, I visited the Dutch PHP Conference. Just as before, it was held in the RAI Convention Centre in Amsterdam. And as before, this two-day conference took place on Friday and Saturday. I always wonder why it's Friday and Saturday. Is it that if your employer or school doesn't let you go on Friday, you can at least go on Saturday? Or if your employer does let you go, you can trade in your work day, but you don't have to trade in your free Saturday? Being a free lancer, it's not really an issue for me, so I went both days.

    The conference has three tracks, so planning which presentations to see is a task on itself. There was also an unconference-track. Because during the whole conference there was always something interesting in the regular tracks and because you never know what the quality of the unconference-track will be, I didn't visit any unconference-track.

    Friday

    The conference started with a keynote from Kevlin Henney, editor of 97 Things Every Programmer Should Know. This book contains little pieces of wisdom written by different programmers. Kevlin took a couple of them and explained them. For example how to make estimates, how to have code reviews, why you shouldn't change code on the production server, why you should test, etcetera. Very informative, especially if you haven't already learned it the hard way.

    The first talk in a track was Designing for Reusability by PHP-contributor and XDebug-developer Derick Rethans. He talked about how to prevent hard dependencies, why singletons are bad for testing, the problems of ActveRecord and why traits will be a solution. Very intersting talk.

    The second talk was The Cake Is A Lie by Sebastian Bergmann. It was not a talk about how bad CakePHP is, but more a opinion about how bad generated code is. I couldn't really relate to his problems. I've worked on a large project in which the ORM-code was generated. In this project, we didn't change the generated code but instead we inherited from it and it was nice to work with. Sebastian did not present any alternatives.

    I was a bit dissapointed by The Art of Scalability, a talk from Lorenzo Alberton, and I think I was not the only one. He didn't talk about scalability from a technical point of view, but from a management point of view.

    In Under PHP's hood, Johannes Schlüter talked about the inner workings of PHP. He explained how the Zend engine and PHP Core are seperate things. He explained the difference between include and require and the -_once-variants. He also explained how references work and why you should keep having references to a minimum. He also showed how it can even hurt performance.

    Although I've never used GIT, I thought visiting Advanced Git from David Soria Parra might be interesting anyway. He adviced to make a branch for every task you do. And only rebase local branches, never pulled or pushed branches. I don't know what pulled or pushed branches are, but when I'm start using GIT, I know this tip :-) He said GIT doesn't work well on Windows because FAT doesn't support symlinks and execute-bits. Huh? Which Windows-user still uses FAT, except from portable storage? A strange assertion, I think.

    The talk Crash, Burn, Recover! from from Cal Evans showed Flex using Flash Builder. He build a recipe search app from scratch. Well, at some point it didn't work and he had to revert to a prepared app. He showed the power of Flash Builder and how you can build a program in one hour. The result can be deployed as a Flash swf-file or a AIR application. It was nice to see how Flex works.

    I didn't go to the DPC Conference Social that evening (with free beer!). Maybe next year.

    Saturday

    The second day started off with Security-Centered Design: Exploring the Impact of Human Behavior by Chris Shiflett. He showed, nicely illustrated, how humans are sensitive to certain kind of security attacks. He explained Ambient signifiers: how you can subconsciously direct your users. For example, in Tokyo they introduced different kinds of background music in the subway, depending on where you are. It turned out that as a result, many more people didn't forget to leave the train on time, resulting in a more profitable subway system (and, of course, happier customers). He showed the movie Person Swap and the Colour changing card trick, which shows how easy it is to deceive people. He also explained the Twitter Clickjacking Hack. Although it didn't really had much to do with PHP, it was a very good presentation.

    The next talk I visited was Async webservices with php and node.js by Sebastian Schürmann. He showed how asynchronous calls can improve performance and how it is done in PHP, compared to Node.js. He showed an example in PHP with Curl and an example in Node.js. The Node.js-example was much cleaner and easier. Other asynchronous API's in PHP are the Streams API and MySQLnd. He did a call to the developers of PHP to make asynchronous programming in PHP as easy as in Node.js.

    In the talk APC & Memcache the High Performance Duo, Ilia Alshanetsky explained how APC works and how you can use it as a persistent key-value store. He also compared it to Memcache and explained what the differences are. He also explained the advantages and disadvantages of igbinary: it's much faster and smaller, but not interchangeable with other languages. For me this was the most interesting and informative talk of this conference.

    After the lunch Ian Barber had a talk about local search engines: In Search Of... Integrating Site Search. He showed the pros and cons about the most popular onces: sphinx, swish-e, lucene, solr and xapian. He also showed the importance of a good stemmer.

    The last talk I visited was Plant Pyrus in your system - A guide to a plugin system by Helgi Þormar Þorbjörnsson. He explained how hard it is to develop your own plugin system which has to deal with dependencies. He worked on Pyrus, which you can integrate in your own software and should also become part of PEAR.

    The conference ended with a panel discussion about the future of PHP.

    Just like the years before, it was a very interesting conference with something for everybody. I'm quite sure I'll be there again next year.

    Comments

  2. Animate anything in jQuery

    I've been using jQuery for three years now in several projects and I love it. One of the many reasons I like jQuery is its extensibility. It's very easy to write your own plugin, your own CSS pseudo selector-like filter or your own easing function.

    What's less known is that you can also customize the animate function. Every jQuery-user knows you can animate all number-based CSS-properties. (Did you know you can also animate scrollTop and scrollLeft?) In this article I explain how to customize the animate function.

    Customizing the animation-function is not so hard and gives you a couple of features for free: think about the fx-queue, easing, callbacks and setting the duration.

    The first thing I wanted to animate was fading one color to another. It turned out John Resig himself already wrote a plugin to does just that: Color Animations.

    Unfortunately, it has a bug which makes the plugin unreliable. To initialize the animation, the plugin checks for fx.state being zero. I turned out that with consecutive calls, the animation can start without fx.state being zero and as a result, the animation not performing.

    My next quest was to rewrite the plugin to my liking. I fixed the bug. I added the missing borderColor, so to change the border color, it's not longer necessary to specify all four borders seperately. I also tried to keep the plugin very small.

    Take a look at the result: the Color animation jQuery-plugin.

    So how can you make your own custom animation? Just like the other jQuery-customizations, it's actually quite simple. Take for example the code to animate the background color:

    $.fx.step.backgroundColor = function(fx) {
    	if (!fx.init) {
    		fx.begin = parseColor($(fx.elem).css('backgroundColor'));
    		fx.end = parseColor(fx.end);
    		fx.init = true;
    	}
    	fx.elem.style.backgroundColor = calculateColor(fx.begin, fx.end, fx.pos);
    }

    Give $.fx.step a new property and assign it a function which will handle the animation. This function has one argument, say fx, which belongs to that one animation, so you can use it anyway you like. It has some properties already set. The most important are fx.elem, fx.end and fx.pos. In fx.elem you'll find the element on which the animation is applied, and in fx.end you'll find the end-value you want to animate to. fx.pos is a float, going form zero to one during the animation.

    In the example above, some initialization is done at the first call of the function in an animation. Here, the begin and end values are calculated. The rest of the functions assigns the calculated value to the CSS-property of the element. The calculation looks like this:

    begin + pos * (end - begin)

    If the animation is called with the end-value being a string, then fx.end will be that string. So when calling a.animate({color: "#ccc"}), fx.end will be "#ccc". However, if the string starts with a number then fx.end becomes that number. So when calling a.animate({myProp: "10px 20px"}), fx.end will be 10 and you'll lose the rest of the string. To get the whole string you should look at fx.options.curAnim.myProp instead of fx.end. In this last example, myProp is a self defined property.

    I thought a cool thing to animate is the new shadow CSS-property. A box shadow property consists of several parts: the color, whether it is inset, the x- and y-offset, the blur-radius and the spread-radius. All of these had to be taken into account when writing the plugin.

    The result is the Shadow animation jQuery-plugin.

    Unfortunately, this plugin does not work in Opera and Internet Explorer. Opera has a strange bug in which you can't request the current shadow-value. Internet Explorer is miles behind and doesn't support CSS-shadows. I expect the plugin will work in Internet Explorer 9.

    These two animation plugins are the first on my list of jQuery-plugins. It's my intention more will follow.

    Update: a couple of months after this article was published, jQuery 1.4.3 was released, with better support for writing custom CSS-properties and animations. Read more about this technique called jQuery.cssHooks.

    Comments

<>