Dynamic / Static Typing vs. Strong / Weak Typing

Here is a great article about Static vs. Dynamic typing and Strong vs. Weak typing.

But as to summarize it ; Dynamic typing languages are which variables’ type declarations are not mandatory and they will be generated on the fly, by their first use [PHP, Python]. While Static typing languages are the ones which variable declarations are mandatory before usage [Java, C].

/* C code */
static int num, sum;
num = 5;
sum = 10;
sum = sum + num;
/* PHP Code */
$sum = 10;
echo $sum;

On the other hand the difference between Strong and Weak typing is different; Strong typing is when a variable is declared as a specific type (no matter by Dynamic or Static typing) it is necessarily bound to that particular data type [Python, Java]. While in Weak typing variables are not of a specific data type ;  it does mean that variables are not “bound” to a specific data type [C,PHP] [1].

# Python code
>>> foo = "x"
>>> foo = foo + 2
Traceback (most recent call last):
File "", line 1, in ?
foo = foo + 2
TypeError: cannot concatenate 'str' and 'int' objects
/* PHP code */
$foo = "x";
$foo = $foo + 2; // not an error
echo $foo;

[1] Introduction to Static and Dynamic Typing

Lazy PHP

I would say I love this site. It’s a very simple to use and handy but on the other hand, knowledgeable and informative website containing tons of interesting articles, tutorials and forum discussions.

When I was about to start learning PHP and MySQL I was introduced to an article by the name of “Build you own Database Driven Website Using PHP and MySQL”. Now this is the closes thing I can find to that article, which is sample PDF of a book. I believe even this sample is enough to get you started.

All I wanted to say is this site has it all, various resources for all levels.

Today I came across another interesting article about PHP, how it works and how to make its performance better. The article is quite old but still applicable and useful.

It is very useful to know behind the scenes of the technology you’re using. The low-level knowledge of “How things work” will give you better understanding of how to improve you application and how to increase the performance. And the more you know the tools provided, the better and faster you can develop.

The way PHP scripts are being executed and interpreted, gives you an idea of how you can improve the performance. In this article it speaks about the 4 stage execution of each request by WebServer/PHP :

  1. Incoming Request : When WebServer receives the Request for the script
  2. Prepare OPCODEs : When the PHP script is being parsed and OPCODES are being generated.
  3. Execution of script and responding back to user
  4. Trash the lot including all the OPCODEs, variables and etc

We all know that now a days there are several different tools to improve the stages 2 and 4 which are the most resource consuming and duplicated tasks of the PHP Interpreter. PHP Accelerators Like APC , eAccelerator,XCache and so on help a lot to eliminate the phases #2 and #4.

Most PHP accelerators work by caching the compiled bytecode of PHP scripts to avoid the overhead of parsing and compiling source code on each request[1].

Also in this great series of articles “Anonymous functions” known as “Closures” and “Variable Functions” are being discussed and there are some simple but very helpful samples of how they work and how they can help.

Also techniques like ‘Lazy includes’ which seems to be pretty obvious but many of us forget it, have been discussed.

I will let you read the articles by yourself ; Part-1 , Part-2, Part-3 and enjoy it 🙂

[1] : http://en.wikipedia.org/wiki/PHP_accelerator

1. Incoming Request:Incoming Request