Can complexity emerge from lower levels of simplicity?

‘Is there really a Universe that is not designed from the top downwards but from the bottom upwards? Can complexity emerge from lower levels of simplicity?’ It has always struck me as being bizarre that the idea of God as a creator was considered sufficient explanation for the complexity we see around us, because it simply doesn’t explain where he came from. If we imagine a designer, that implies a design and that therefore each thing he designs or causes to be designed is a level simpler than him or her, then you have to ask ‘What is the level above the designer?’ There is one peculiar model of the Universe that has turtles all the way down, but here we have gods all the way up. It really isn’t a very good answer, but a bottom-up solution, on the other hand, which rests on the incredibly powerful tautology of anything that happens, happens, clearly gives you a very simple and powerful answer that needs no other explanation whatsoever.

Douglas AdamsSpeech at Digital Biota 2

What is code? It’s not magic, just work

It’s very likely that you already know about or even read the latest issue of Bloomberg, entirely dedicated to answer What is Code? — if you haven’t, you definitely should go read it.

The entire piece is informative and fun to read, and there’s probably something new for everyone reading it. My favourite highlight is:

Computing treats human language as an arbitrary set of symbols in sequences. It treats music, imagery and film that way, too.

It’s a good and healthy exercise to ponder what your computer is doing right now […]

Thinking this way will teach you two think about computers: one, there’s no magic no matter how much it looks like there is. There’s just work to make things look like magic. And two, its crazy in there.

Which reminded me something I said to a fresh group of designers on a HTML+CSS+Javascript crash course.

Horizontally scaling PHP applications

One of the most common worries of the enterprise IT world about WordPress and other Open Source apps it’s how you can scale it — which it’s kind of ironic when their enterprise-y web services response times are usually measured in the scale of tens of seconds…

DigitalOcean has published a high-level practical-overview on horizontally scaling PHP apps that’s a good starting point and I guess it could also apply to other kinds of apps as well.

Debugging memory usage in PHP apps

As your app gets increasingly more complex, you might run into Memory exhausted errors, and even though you can always increase the allowed memory usage — either by tweaking php.ini or locally with ini_set() — it should be a better option to find out what’s using so much memory in the first place.

Continue reading “Debugging memory usage in PHP apps”

Using anonymous functions and closures for user-defined array sorting

Anonymous functions and closures are relatively new in PHP, but they’re extremely welcome.

Whenever you need to sort an array with a custom order (that is, with a user-defined comparison function such as usort, uasort or uksort) you can use anonymous functions and closures in an easy and very straight-forward way.

For instance:

// assuming you have your un-sorted elements on $elements
// and the customized order on $order

usort( $elements, function($a, $b) use ($order){
    $a_index = array_search($a->ID, $order);
    $b_index = array_search($b->ID, $order);
    if ( $a_index > $b_index ) return 1;
    if ( $a_index > $b_index ) return -1;
    return 0;
});