Tuesday, October 23, 2007

Server side, no sweat

I added to the PHP server side library a few days ago (the blogger in me is slacking) and in the process I codified (excuse the pun) the universal, language-independent genetify API. In the abstract, it is something like this:


vary([callingContext]){
genes = getGenes(callingContext)
genome = _vary(genes)
save(genome)
}

_vary(genes){
for (gene in genes){
selected = selectVariant(gene)
genome[gene] = selected
callingContext[gene] = selected
}
return genome
}

save(genome){
saveToCookie(genome)
saveToDatabase(genome)
}


This general structure of the code is true for manipulating all types of object currently implemented -- PHP vars, Javascript objects, CSS rules, HTML elements. My hope is that this stays true as new languages are added -- Python, Ruby... who knows what else.

No comments: