You are here: Code readability vs. execution time « PHP Programming Language « IT news, forums, messages
Code readability vs. execution time

Posted by Marijn on 09/04/07 06:40

Hi there,

Again a question with no simple yes or no answer at least, opinions
will probably be scattered so no unanimous yes or no answer ;)

What would you think is the best of the following to options given
that it is more likely that the databaseConnection is set?


SomeClass {

[.............]

/**
* Sets the connection to the database in use.
*
* @return DatabaseFactory
*/
private function __getDatabaseConnection(){
if (isset($this->__databaseConnection)) {
return($this->__databaseConnection);
} else {
$this->__databaseConnection = new DatabaseFactory();
$this->__databaseConnection->create();
return($this->__databaseConnection);
};
}
}

Or

SomeClass {

[.............]


/**
* Sets the connection to the database in use.
*
* @return DatabaseFactory
*/
private function __getDatabaseConnection(){
if (!$this->__databaseConnection) {
$this->__databaseConnection = new DatabaseFactory();
};
return($this->__databaseConnection);
}
}

The second option definitely has less repetitive code but does that
really make it the better option given the fact that the
databaseConnection property is probably set?

By the way, another small convention question: Should you terminate
control structures with a semicolon?

Thanks

Marijn

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация