greg's blog

Professional Software Developer Manifesto

Poor software development standards are fatal for businesses and for the morale of those who have to support bad development.

Every software developer should sign up to minimum standards:

1 Readable Code

Software development is primarily about communicating with other programmers.

2 No hidden knowledge

Other programmers must be able to take over your work without having any missing knowledge. If there is anything any other programmer should know then it must be documented.

One important related area which must be avoided is magic numbers in code. These should never be used and should always have a descriptive textual equivalent (for example an enum or a const) instead.

It is completely unacceptable for a developer to try to make themselves indispensable by any means, such as obfuscating code, using poor names for variables and methods, poor commenting and documentation.

3 Quality Documentation

Risk Management in Software Talent Investment

Quote from Forbes.com "Risk Management in Software Talent Investment" http://www.forbes.com/sites/venkateshrao/2011/12/05/the-rise-of-develope...

"On the flip side — and this doesn’t have a name, perhaps it should be called the “-10x effect” — bad software developers aren’t just a minor drag or inefficiency. For a variety of subtle reasons, they can be catastrophically toxic in a complex software system. A bad engineer writing dangerously buggy or ill-conceived software can create a ticking time-bomb that will cost thousands of times the original investment to clean up after, once it explodes (there’s a phrase for it, “technical debt”). What’s more, the clean-up effort will absorb the efforts of many more good developers."

Unit testing in Zend Framework 2

Unit testing fails in ZF2 Beta 1 if you download the tarball. Use the git repository, this contains the Bootstrap.php and phpunit.xml which are missing from the tarball.

It would be very useful to have symbollic links from the source directories to the test directories so you can quickly update tests and see the interfaces in action.

Lack of proper class method overloading is holding PHP back

The lack of proper class method overloading as found in other languages like Java and C# is holding back PHP's development as a first class language and leading to very clunky code. Here is an example based on Zend Framework 2's Zend\Tag\Item class:
   public function __construct($options)
    {
        if ($options instanceof \Zend\Config\Config) {
            $options = $options->toArray();
        }

        if (!is_array($options)) {
            throw new Exception\InvalidArgumentException('Invalid options provided to constructor');
        }
       $this->setOptions($options);
    }
And here is how it should look:

   public function __construct(\Zend\Config\Config $options)
   {
      $this->__construct($options->toArray());
   }

   public function __construct(array $options)
   {
      $this->setOptions($options);
   }
The latter is so much more elegant but sadly it is not going to work in PHP any time soon.

Setting the title in gnome-terminal

Put this in your .bashrc(s):

export PS1='\[\e]0;`hostname`\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

Now whenever you log into a remote machine the title in the gnome-terminal will change to the name of the host. When you log out it changed back.

Very neat!

7 Indicators of good software project management

Here's a very brief summary of what works for me. Take it or leave it:

1. Have a methodology

No methodology implies no path to success. Methodologies are processes and processes are useful in social activities because problems become the fault of the process, and not of the people. It takes discipline and practice to keep to the process.


2. (Almost) The last thing you do is program

This is the failing of most projects. Unless your methodology is to develop software early hold your nerve and don't develop too soon.


3. Think it through first

Think the project through clearly. Many of the pitfalls you would otherwise fall into can be worked out in your head. Design now or face expensive disaster later.


4. Estimate

I Want a goto and I Want it NOW!

This evening I was working on testing some code that is called by AJAX. It returns a string which is either "OK", if everything is fine or something else, if it isn't. If something else is returned the user is alerted.

So to test this I pull it into my test framework - except that the calls to "exit" mess everything up and make the test framework exit too. wget and curl are too clunky so, proceeding with the elegant solution I need to change the code so that instead of exiting it jumps to the end of the script, that way it will return to the test suite even if there is a problem. I'm sure PHP has a GOTO so go look in the documentation - its 5.30 - nightmare!

So instead move the AJAX code into a function and change the exit calls to be returns. Ta-da unit testable AJAX.

Still this is a milestone. The first time in my life I ever wanted a goto.

Some classic code from Squirrelmail

    if (file_exists($data_dir . '/dnscache')) {
        $fp = fopen($data_dir . '/dnscache', 'r');
    } else {
        $fp = false;
    }
    if ($fp) {
        flock($fp,LOCK_EX);
    } else {
       $fp = fopen($data_dir . '/dnscache', 'w+');
       fclose($fp);
       $fp = fopen($data_dir . '/dnscache', 'r');
       flock($fp,LOCK_EX);
    }
    $fp1=fopen($data_dir . '/dnscache', 'w+');

How the flags work

The flags above each entry in this site cause the text below the flags to be translated by Google Translate, which has a fairly good go at translating the content.

The worst of the worst

When it comes to truly abysmal software you need look no further than Windows XP's Add or Remove Software functionality.

Google can find any file anywhere on the internet in 0.05s but it still takes XP 10 minutes to figure out what software it has installed. Its not as if the answer has changed much since the last time it ran.

cgiwrap

cgiwrap, the code that much of the internet relies on for security is a total mess, and a strong indicator that unqualified programmers should not be allowed near production code.

Here are just a few of many problems:

* The total number of unit tests included in cgiwrap is ... zero (how confident does that make you feel?). This has the depressing side-effect of making it extremely difficult to see the exact purpose of cgiwrap's functions, since unit tests make excellent use cases.

IT - Master or Slave

Why have IT? In any organisation IT must exist to serve the organization, however all too often this is forgotten. When this happens business practices become defined by IT and not by the needs of the business. In some organisations updates to the IT systems may become impractical or impossible, and business rules become defined by IT rather than the organisarion's IT modelling and changing with business rules. At this stage it becomes extremely difficult for the organisation to serve its customers. "Computer says No!".

Tilde on the Italian keyboard

I've been having an interesting time this week battling the italian keyboard. At long last I've found the answer to the trickiest problem so far: Where is the tilde key? The answer is F12 on my laptop, and it only works in putty windows which is all I really need. It rings the bell but that's a small price to pay.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PS curly braces, { and } are Shift-AltGr-è and Shift-AltGr-+ respectively.

What a difference a space makes


mysql> select count(*) fromtransactionHeaders;
+------------------------+
| fromtransactionHeaders |
+------------------------+
| 1 |
+------------------------+
1 row in set (0.00 sec)

mysql> select count(*) from transactionHeaders;
+----------+
| count(*) |
+----------+
| 3035 |
+----------+
1 row in set (0.00 sec)

PHP exec unlike other execs

In PHP the exec call is part of a family of calls that can run commands on the server. These include system, passthru and shell_exec. They all offer slightly different functionality and all require careful security audit to ensure that you do not allow unscrupulous users of your site access to the operating system.

Syndicate content