Code like a chimp
public static final String HTTP = "http";
public static final String COLON = ":";
public static final String FORWARD_SLASH = "/";
private String url;
public void setUrl(String host, String path)
{
url = HTTP + COLON + FORWARD_SLASH + FORWARD_SLASH + host + FORWARD_SLASH + path;
}
The above is based on some code I came across recently; amongst other things it protects against accidental misspelling of ":". It's a classic example of following a practice without considering the principles.
A recent study(*) compared the methods that chimpanzees used to retreive an object from a translucent box, with those employed by 3 to 4 year old children. The children were happy to exactly copy all the actions of demonstrators. The chimps only followed those actions that actually had some obvious function: one of the things set sets us apart from animals is the facility for mindless imitation.
Chimps don't do cargo cults. Despite any evolutionary advantages, I'd rather the coders that I work with didn't either.
(*) Via New Scientist.

0 Comments:
Post a Comment
<< Home