Might not be totally true but here’s my hypothesis: “Lazy programmers tend to code in a more modular way and do more automation.”
I do like SQL. But don’t like to write it. So, i decided to write a class for adding/deleting/updating from database.
$sets['fname'] = 'John';
$sets['sname'] = 'Smith';
$where['sex'] = 'm';
$where['country'] = 'USA';
$db->update('users',$sets,$where);
equivalent to
UPDATE users SET fname = 'John',sname = 'Smith' WHERE sex = 'm' AND country = 'USA';
Another example of automation is when i want a clean setup of a website i’m working on. I just go on phpMyAdmin. I drop the database. The next time the engine of the website is triggered, it checks if database exists, creates it if not, runs an install script which will recreate the tables.
$db_selected = mysql_select_db($dbsettings['dbname'],$con);
if (!$db_selected) {
___mysql_query("CREATE DATABASE {$dbsettings['dbname']}",$con);
___$db_selected = mysql_select_db($dbsettings['dbname'],$con);
___// If an installer exists, we try to run it.
___if(file_exists(ROOTDIR.'inc/install.php')){
______header('Location: '.ROOTURL.'inc/install.php');
___}
}
This laziness pushed me to write a templating system in PHP for my university Web assignment so as my HTML and PHP codings are separate.
$recipes = $Recipes->get_multiple("ORDER BY timeposted DESC");
$recipelist = "";
foreach($recipes as $recipe)
_eval("\$recipelist .= \"". $templates->simple_get("gallery_recipe") ."\";");
eval("\$contents = \"".$templates->get_page("gallery_page")."\";");
eval("\$headerincludes = \"".$headerincludes."\";");
$templates->output_page($contents);
If i would been a “hard working” guy. I wouldn’t have bothered to do these extra simple things. I would have enough energy to write 100 update queries manually. Have long html codes inside PHP loops and so on..
What do you think?