I am 100% self-taught, and so I try to read as much as I can about best practices, conventions, etc. However I freelance, and have been in a long-term contract position for the past little while with almost no peers to review my code. So I get nervous about developing bad habits.
Looking closely at this function I wrote (meant to give me a quick look over the db make sure nothing else is signed that ought to be unsigned):
$db = Database::instance();
$tables = array();
$result = $db->query('SHOW TABLES');
foreach($result as $table)
{
$create = $db->query("SHOW CREATE TABLE `".current($table)."`");
$tables[current($create->current())] = end($create->current());
}
echo var_dump($tables);
I see a couple things - $tables
and $table
are similar things, but $tables
is not made up of every $table
, so it could be confusing.
I tend to name all query results as $result
unless there is a potential naming conflict.
Concatenating a function result within a query call seems more a quality of 'fast code' than 'good code'.
Am I being too nit-picky? Does this code look like it was written by an amateur/bad programmer?