APIs - Eliminate the Ambiguity
Submitted by moxley on Thu, 2006-08-24 16:44
Programmers who design Application Programming Interfaces need to maximize the meaning that their APIs convey, while still keeping them short and simple.
In PHP, when the user uploads a file to your script, it is represented by an associative array with these five elements:
$_FILES['userfile']['name'] $_FILES['userfile']['type'] $_FILES['userfile']['size'] $_FILES['userfile']['tmp_name'] $_FILES['userfile']['error']
This is an example of an API, albeit a static, read-only one. It has names you can use to access data that you want.
Can you guess what these elements are, exactly? What is 'type'? Does that indicate whether it is a binary or ascii file? Or does it mean its either a word processor document or an image file? What is 'error'? It could be an error message, or an array of error messages, or just an error number.
I'll rename them, and then ask yourself again:
$_FILES['userfile']['clientfile'] $_FILES['userfile']['mime'] $_FILES['userfile']['size'] $_FILES['userfile']['filename'] $_FILES['userfile']['errno']
Now things are much more clear, and you don't have to go browsing the PHP manual to find out what each element means.
