Using Test Driven Development

Although I like the concept of Test Driven Development (TDD), I have yet to apply it in a corporate context as it might be excessively off the beaten path for management to accept comfortably.

As it will be difficult to explain TDD within 3 paragraphs, I have left it to Wikipedia to do the honours. Basically what it entails is to write the test case first before writing the code that is expected to pass the test case.

Designing Experiments

In the course of improving a process or product, you may need to utilise experiments to isolate which are the factors that are most important (remember the 80/20 rule?).

While the design of experiments is usually touched on in University, the concepts may all be forgotten by the time the student is ready to apply them in the commercial world. For a quick refresher, Wikipedia has a succinct article: http://en.wikipedia.org/wiki/Design_of_experiments

The skill of estimating activity durations

Unfortunately, this is one skill that probably can only be developed through repeated mistakes because it is not likely that a freshly minted graduate will be able to give an accurate estimate of the duration that an activity will require.

If anything, it is common for people to overestimate their abilities and underestimate the amount of time required to complete an activity. As a rule of thumb, you will probably need to add a buffer to your estimates but not to the extent that you end up “padding” your duration estimates (which is not considered professional behaviour).

Quick security improvements for your PHP code

When accepting input from users in your web application, there is always the chance that the user will key in some code that causes errors ranging from the cosmetic to the malicious.

One of the most common cosmetic errors is when the user formats everything nicely in a <textarea> but all the formatting is lost when it is redisplayed. This can usually be easily solved by using the nl2br() function where all the new lines in the user’s input is converted to HTML-friendly <br /> tags.

To guard against malicious code such as when users try a cross-site scripting attack or inject some HTML that can seriously screw up your web page, you should clean up the input by using the htmlspecialchars(), htmlentities() or strip_tags() (arranged in ascending order of “paranoidness”) functions depending on your requirements.

The Perilous Scope Creep

Much too often, projects fall victim to the “scope creep” syndrome where the project scope expands with disregard to the scope that was originally agreed when it was first chartered.

This often causes many problems inside and out of the organisation. For the organic project team working within the organisation, they will find that tasks are constantly being added to their plate in a never-ending stream and the project sponsor/s will constantly be hounding them on why deadlines are not met — even when the original deadlines were established without the new additions to the scope!

Exernal to the organisation, the vendors will also face problems as they will be caught between the wall and a very hard place: risk annoying the customers by refusing to add to the original project scope or take on the additional scope and overallocate resources beyond the original budget?

Understanding Project Scope – Work Breakdown Structure

Although the WBS is an important document to ensure that all team members have a good understanding of the project scope as it breaks the entire project down into bite-sized work packages, it does not seem to be granted a high level of importance in Singapore.

The people whom I have spoken to have seldom/never come across a WBS in the course of managing their projects. Considering the high delay rate of projects in Singapore (which I read about some time back, can’t remember from where though), perhaps we should pay more attention to documents and processes that can help us manage our projects better.

Why.use.periods?

When I have to put PHP aside for a while and do something else in Java or ASP, sometimes I will forget how to do certain things or which operators are used.

I have a particular beef with the “.” (period) being used as a concatenation operator because it is not as instinctive as the “+” or the “&” used in other languages. “+” makes sense because it implies addition, “&” also makes sense because the effect of the ampersand is similar to “and”. However, can someone tell me the reasoning behind “.”?

Why you might not want to use PHP’s rand() function anymore

If you have been using the rand() function in PHP to generate random numbers for use in your scripts, you might want to consider otherwise. Maybe C programmers might also want a rethink since the PHP rand() function is derived from libc…

Anyway, help is at hand with the mt_rand() function which is syntactically similar but it behaves better. The numbers generated will be more, erm, random. You will also be able to improve random number generation performance by 4 times! Incidentally, the “mt” in “mt_rand()” stands for Mersenne-Twister.

If you are interested in the mathematics behind this, go to this site.

Error Reporting Level for PHP Development

While there are a total of 11 error reporting levels for PHP, the combination I generally use the most often would be

error_reporting (E_ALL | E_STRICT);

The E_ALL argument is somewhat of a misnomer since it does not really include all error types. E_ALL does not include the E_STRICT error type which indicates whether your existing code (which runs perfectly now) may have a problem in future versions of PHP. Although its a never-ending race, developers should still try to future-proof their code as much as possible.

Turning off display of error messages in PHP

As an add-on to my previous post, here is one way where you can turn off the display of PHP error messages for individual scripts:

ini_set (‘display_errors’, 1);

Of course, you might prefer to just adjust the server settings, but this single line will definitely work for all cases in the event you do not have admin access to the server. You can also choose to make things easier by including all common settings in an include() file