This is definitely not PHP or IT related but is worth talking about :) The com department of the UQAM (Universite du Quebec a Montreal - Canada) has done an awesome and incredibly popular lipdub video.

This LipDub has been produced during the integration week of UQAM with 172 communication students. It was made on September 10th 2009, the footage lasted approximately 2h15min.

Available on youtube / google video, it is getting more popular every hour / minutes (more than 750k views already) and it is creating kind of a buzz on the web.

They even got an interview on CNN.

Congratulation to them all. As an ex-student of UQAM, I specially enjoyed watching it.

  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Once again, Thanks Google for their tech talks.

Here is a video from Steve Souders named “Life’s Too Short - Write Fast Code”. This video talks about how to write efficient code and discuss speed optimizations techniques in Web programing.

Steve works at Google on web performance and open source initiatives. His book, High Performance Web Sites, explains his best practices for performance; it reached the top of the Amazon computer and Internet bestseller list. His follow-up book, Even Faster Web Sites, provides performance tips for today’s Web 2.0 applications. Steve is the creator of YSlow, the performance analysis extension to Firebug, with over one million downloads.

(Source : http://stevesouders.com/bio.php)

You can also find his latest book named “Even faster websites” at books.google.com.

  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Here is a very interesting video from Linus Torvalds on Git. He emphasizes on the importance and added value for companies to use decentralized source control.

You better listen to this video or you just may end up stupid and ugly :)

  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

If you ever worked in a software company, you most likely heard once someone saying “Hey, we can’t do this, because this doesn’t scale!”

I believe “Scalability” must be on the top 10 list of the “buzz words” most used in the software industry.

It is usually considerated as a killing argument in a conversation. “If something doesn’t scale, then we don’t want it.”

One of the things that fascinates me about “buzz word” is that most of the time it has so many different definitions. Everyone has a tendency to give it a personal definition. Often, people will be too shy to ask for a clear definition. Therefore, it makes it even harder to be able to really understand what underlies behind it. So, What does Scalability mean ?

In telecommunications and software engineering, scalability is a desirable property of a system, a network, or a process, which indicates its ability to either handle growing amounts of work in a graceful manner or to be readily enlarged. (Source: Wikipedia)

In my humble opinion, there are a few important keywords (in bold) in this definition that should be kept in mind when thinking about scalability.

I recently watched that video (I love google tech talks) from Cuong Do Cuong given during a quite old conference in Seattle (in 2007). Cuong is an engineering manager at Google (YouTube).  “He was part of the engineering team that scaled the YouTube software and hardware infrastructure from its infancy to its current scale. Prior to YouTube/Google, he held various software development and management positions at PayPal and Inktomi.”

Cuong shares with us some his experiences, the different issues related to scalability he and the team faced. I hope you will enjoy it as much as I did.

  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Recently, I have been working on building a new search engine.  After performing some searches on Google, I ended up watching a tech talk from Marissa Mayer. Marissa is vice President  (Search Products & User Experience) at Google. Just to give you a background here is a short summary of her bio, she has an impressive experience (found on the google site) :

Marissa leads the company’s product management efforts on search products – web search, images, news, books, products, maps, Google Earth, the Google Toolbar, Google Desktop, Google Health, Google Labs, and more. She joined Google in 1999 as Google’s first female engineer and led the user interface and web server teams at that time. Her efforts have included designing and developing Google’s search interface, internationalizing the site to more than 100 languages, defining Google News, Gmail, and Orkut, and launching more than 100 features and products on Google.com


I saw her presentation named “Scaling Google for Every User” (June 2007) at the Seattle Conference on Scalability. I really liked the part where she talks about how much features should be presented to end users, how to present them and how basically simplcitiy beats complexity. She kinda destroys the myth that “having more features is always better”.


  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

PHP Code Comparator is a command line script allowing to compare different versions of a library, framework or package. It will detect code changes in terms of class existence or method definitions.

If you ever wanted to have a way to quickly identify what classes have been altered or methods have been changed between two different versions of the same package, PHP Code Comparator will help you achieve that.

Instead of using a diff tool, you can simply use this tool. It will basically parse a folder recursively, detect any defined classes and extract the various methods and parameters. This will then be performed on the second version of your library. Finally, a summary will be displayed showing the differences that have been detected.

This tool will detect if a class has been removed, if new classes have been added, if methods have been removed or added and also if the signature of a method has changed.

Where can I download it ?

You can browse the code and download it from github.com.

http://github.com/alfallouji/PHP-Code-Compare/

You can also directly get the source code from the git repository.

git clone git://github.com/alfallouji/PHP-Code-Compare.git

You will find more information on the official page : PHP Code Comparator

  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

The Ultimate Coder Battle

In: PHP

25 May 2009

I recently heard about a funny contest handled by Microsft. The concept is really fun, and so is their web site (Check the video!).

Here is a short description of the contest.

Microsoft presents the Ultimate Battle: It’s a knock-down, drag-em-out battle between professional and student developers! And it’s your big chance to show the world your awe-inspiring PHP application – on the Windows-based platform! We’ll select one student and one professional coder for the Ultimate Throwdown – a final bout at the “Make Web, Not War” Conference! The winner can take home up to $10,000 in total prize money!Challenge a friend, invite a colleague, ask anyone – get the whole gang in on the Ultimate Throwdown Action.

 Last day to enter the contest is June 3rd. So hurry !

http://www.phponwindows.ca/ftw/

  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

WolframAlpha is a computational knowledge engine created by Stephen Wolfram

It basically generates output by doing computations from its own internal knowledge base (composed of many trillions of elements), instead of searching the web and returning links. 

I spent some time testing it and I gotta say it is awesome. So, no it isn’t gonna replace Google, it is for a different usage.

It is very usefull when you want to find answers to a particular question, for instance, if you look for earthquake in indonesia, you will get this as a result.

Wolfram Alpha

 

I really like the way the information is reported / outputed to the end user. If you try with “barcelona montreal”, it will even display the result in a table and compare the results.

Wolfram Alpha

 

 

I took some time to read a little bio about Stephen Wolfram and well, it is pretty impressive. Here is a short summary of what we can read about him on Wikipedia.

Who is Stephen Wolfram ?

Stephen Wolfram (born  in 1959) is a British physicist, mathematician,author and businessman, known for his work in theoretical particle physics, cosmology, cellular automata, complexity theory, and computer algebra.

Wolfram is considered as a child prodigy, he published an article on particle physics at age 16 and entered Oxford University at age 17. He received his Ph.D. in particle physics from the California Institute of Technology at age 20. He developed the famous software Mathematica.

(Source : Wikipedia) 

Have fun and try that very nice tool, this is defintely going in my bookmarks folder: WolframAlpha.com

  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Some people just like to write as few line of codes as possible. Well, PHP can be tricky sometimes.. For instance, be carefull when declaring a variable and passing it as a parameter to a function or to a method at the same time. If that parameter is supposed to be passed by reference, you may end up with some unexpected behaviors !

Look at the following code, What do you think will be outputted ?

function changeStr(&$str)
{
    $str = 'foo_' . $str;
    return $str;
}

$res = changeStr($str = 'bar');

var_dump($str);
var_dump($res);

Here is the result.

string 'bar' (length=3)
string 'foo_bar' (length=7)


Surprise ! $str didn’t get passed as a reference.

So basically, $str hasn’t been affected by the changeStr() function. Let’s try with an array now..

function changeArr(&$arr)
{
    $arr['id'] = 10;
    return $arr;
}

$res = changeArr($arr = array());

var_dump($arr['id']);
var_dump($res['id']);

The result is…

null
int 10

Well, same behavior as earlier. $arr wasn’t altered by the changeArr() function !

What about objects, does it do the same thing ?

function changeObj(&$obj)
{
    $obj->id = 10;
    return $obj;
}

$res = changeObj($obj = new StdClass());

var_dump($obj->id);
var_dump($res->id);

Here is the result.

int 10
int 10

So, it doesn’t work for a string or an array, but it work with objects !

Well, I highly suggest any developer not to declare a variable and pass it to a method or a function at the same time. Just write the additional line of code, it is gonna reduce the risk of error and actually might make your core more readable !

  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

I have decided to write a serie of posts around the Singleton design pattern. This first one will discuss the uniqueness aspect of a Singleton.

What is a Singleton again ?

In software engineering, the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. (Wikipedia)

Here is a typical implementation of a Singleton class in PHP. You will see this kind of code in many different existing frameworks.

/**
 * A typical implementation of a Singleton
 */
class aSingleton
{
    private static $_instance = null;

    public $foo = null;

    private function __construct()
    {
    }

    public static function getInstance()
    {
        if(null === self::$_instance)
        {
            self::$_instance = new aSingleton();
        }

        return self::$_instance;
    }
}

So, is there anything wrong with that code ?

One of the things that I really dislike about this implementation (there are actually many others things I dislike about Singleton, but I will discuss them in others posts), is the fact you cannot (actually this isnt necessarily true as we will see later) have two different instances of a Singleton. I dont understand why a class should enforce a such rule / constraint. Why would someone want to have a such constraint ? What good would it make ?

Some may argue that sometimes in an application, you want to keep using the same instance of an object. Usually, they will say that objects like a logger,  a configuration or a database handler are good candidates for a such use. Well, that’s fine with me, but why do I have to use a Singleton for that ? Is this really the best solution to do that ?

Let’s use a parrallel. Imagine, we need to always use the same hammer to do a job for some good reason.  So, we decide you are going to enforce that requirement, by destroying all the others existing hammers and any shop / factory selling or producing hammers. That way, when we use a hammer, we are sure it is the same one (it is the only hammer that exist in the whole universe and it is impossible that for any other hammer to get built).

Doesn’t that sound crazy and  extreme ? I mean, why wouldn’t we just mark that hammer (write a name on it or something) and just store it in a specific place, so we know where to get it and we can ensure that we are using the same hammer. Also, if one day we do need to have another hammer, well we would be able to…

There is also a problem with most existing implementations of a Singleton.  The design pattern is supposed to enforce the number of different instance of a particular class, right ? Well, there are ways to bypass that and end up with different instances of a Singleton.

In PHP, we could use the clone construct.

$a = aSingleton::getInstance();
$a->foo = 10;

$b = clone $a;
$b->foo = 20;

echo $a->foo . PHP_EOL; // Display 10
echo $b->foo . PHP_EOL; // Display 20.
                        // Damn this isnt anymore my Singleton!

To prevent that, we would need to implement the __clone() method (define it as final and throw some kind of exception whenever called). This would  solve the issue with the clone construct.

Well, that still won’t completely prevent someone from being able to have two different instances of our Singleton. Someone could still use the serialization. Look at this code.

$a = aSingleton::getInstance();
$a->foo = 10;

$str = serialize($a);
$b = unserialize($str);
$b->foo = 20;

echo $a->foo . PHP_EOL; // Display 10
echo $b->foo . PHP_EOL; // Display 20.
                        // Damn this isnt anymore my Singleton!

Again, to prevent that, we could implement the __wakeup() method (also declare it as final and throw some kind of exception).

So, we just added a new constraint on the class : We cannot unserialize it anymore via the unserialize function. If we cannot unserialize, then we made serialization pretty much useless…

That’s the end of this first post on Singleton. I am hoping that after reading this, you already feel (if you are a Singleton adept) that there might be something wrong or bad using this design pattern.

My next post will discuss other aspects that I really dislike about Singleton, such as how to unit test Singleton, why Singleton is a global state and why global states are bad, etc.

  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Who am I?

My name is Bashar Al-Fallouji and this is my Blog. I currently work at Nstein as a Senior Solution Architect & Business Analyst. Nstein Technologies develops and markets multilingual solutions that power digital publishing for the most prestigious newspapers, magazines, and content-driven organizations.

I am particularly interested in Web applications, Open Source Development, Software Engineering, Information Architecture, Unit Testing, XP/Agile development, etc.

On this blog, you will find mostly technical articles and thoughts around PHP, OOP, OOD, Unit Testing, etc. I am also sharing a few open source tools and scripts.

  • Apprendre a utiliser Git | Anis Berejeb: [...] chez github. essayons de « checkouter»  un projet. Je choisis le projet [...]
  • Sheila: BAF rocks! [...]
  • anis berejeb: I think that there is no ambiguity because what is passed in the : $res = changeObj($obj = new StdC [...]
  • Pascal G.: In C#, as soon as you define a parameter as an output parameter, the compiler will force you to pass [...]
  • Bashar: Indeed, since PHP5, objects are always passed by reference. Pascal, isn't the behavior you are [...]