NavigationUser login |
greg's blog7 Indicators of good software project managementHere'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 workThe 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 worstWhen 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. cgiwrapcgiwrap, 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 SlaveWhy 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 keyboardI'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(*) from transactionHeaders;
PHP exec unlike other execsIn 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.
Intranet use for process improvementWhen I was a Siemens some years ago, I wrote a simple intranet site which had several important functions:
The later part was linked to an SMS alert system and an on-call database, so serious errors caused SMS Text messages to be sent to the primary on-call staff. If the staff did not acknowledge the error in a few minutes the message was forwarded to secondary on-call staff.
An empty abstract class can be usefulI've been working on a system that takes different types of things in an order. The order system is split up by the type of the thing beng ordered, which isn't very clever but historically that's the way someone wrote it so we just have to live with it, refactoring the code and data is not an option. In modelling the data for the differnet types of thing being ordered it turns out to be useful to have an empty abstract class:
abstract class AbstractOrderItem implements Model {
// Add a constructor to initialise the model
}
Now order items extend AbstractOrderItem: class CarOrderItem extends AbstractOrderItem ... class PlaneOrderItem extends AbstractOrderItem ... class TrainOrderItem extends AbstractOrderItem ... Now it you want to handle a list of OrderItems that's fine:
function paintBlue(AbstractOrderItem $item) {
$item->color='blue';
$item->save();
}
Simple PHP Copy vs Clone ExampleAssigning object instances results in assigning references:
<?php
class s {
public $state = 1;
}
$s = new s();
$t=$s;
$s->state=4;
echo "s state ".$s->state."\n";
echo "t state ".$t->state."\n";
s state 4 Using clone creates a shallow copy of the object. (Add a __clone() method to define your own deep copy. See http://php.net/manual/en/language.oop5.cloning.php)
<?php
class s {
public $state = 1;
}
$s = new s();
$t=clone $s;
$s->state=4;
echo "s state ".$s->state."\n";
echo "t state ".$t->state."\n";
s state 4 Note: Use debug_zval_dump() to see the reference count for a variable.
When to RefactorToday I found a class file that had been created with 1161 lines in it. Files this big should immediately ring alarm bells because the class they contain is almost certainly doing too many things. Class files this big are inevitably difficult to test and sure enough the test file was about 1700 lines. Some guidelines on when to refactor:
Brilliant Unit Testing Evangelism
|
Recent blog posts |