Ich habe vor kurzem angefangen, an einem kleinen CMS zu arbeiten. Ich entwickle normalerweise .NET-Anwendungen in C# und bin sehr daran gewöhnt, meine Felder und Methoden zu kommentieren. Mein Freund sagte mir früher, dass Kommentare in PHP-Skripten ziemlich schlecht sind, da PHP dynamisch ist und bei Bedarf geparst wird, so dass das Parsen der Kommentare länger dauern wird.PHP - Überschreiben?
Gilt diese Aussage für meine Situation, die jede Methode und jedes Feld kommentiert?
Beispiel einer meiner Klassen:
<?php
/*
* jWeb
* Copyright (C) 2010 AJ Ravindiran
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Controls database connections.
*
* @author AJ Ravindiran
* @version 1.0.0 Jan-02-2010
*/
class database {
/**
* The database connection ip address.
* @var string
*/
private $host = "";
/**
* The database user's name.
* @var string
*/
private $username = "";
/**
* The database user's password.
* @var string
*/
private $password = "";
/**
* The database that this instance will write to, and read from.
* @var string
*/
private $database = "";
/**
* Holds the mysql connection instance.
* @var resource
*/
private $connection = null;
/**
* Whether the instance is connected to the specified database.
* @var bool
*/
private $connected = false;
/**
* Constructs a new database instance.
* @param string $host The database server host.
* @param string $port The database server port.
* @param string $username The database's username authentication.
* @param string $password The username's specified password.
*/
public function __construct($host = "localhost", $username = "root", $password = "") {
$this->host = $host;
$this->username = $username;
$this->password = $password;
}
/**
* Connects to the given database.
* @param string $database
*/
public function connect($database) {
$this->database = $database;
// TODO: handle errors.
$this->connection = @mysql_connect($this->host, $this->username, $this->password) or die();
@mysql_select_db($this->database, $this->connection) or die();
/*
* If the connection was successful, we can now
* identify that the connection is sustained.
*/
if ($this->connect != null) {
$this->connected = true;
}
}
/**
* Gets the specified connection details from this instance.
* @param boolean $show_details
* @return string The connection string.
*/
public function getConnectionString($show_details = false) {
if ($show_details) {
return "database[host=" . $this->host
. ", port=" . $this->port
. ", user=" . $this->username
. ", pass=" . $this->password
. ", database=" . $this->database . "]";
} else {
return "database[host=" . $this->host
. ", port=" . $this->port . "]";
}
}
}
?>
Ihr Freund ist ein Idiot. –
Voting zu schließen als offenkundig beleidigend, weil subjektiv und argumentativ es gerade nicht ganz schneidet. Auch die Existenz von jemandem, der so pedantisch ist, beleidigt mich. –
@NSD: 2nd. Ich befürworte nicht, dass man mit dummen Dingen übermäßig kommentiert, wenn der Code für sich selbst spricht, aber die Kommentare in Ihrem Code sind in Ordnung (gut, gerade). Ärgere dich nicht über Parse-Zeiten, nicht nur mit Kommentaren, sondern auch mit kleineren Dingen. Lesbarkeit ist viel wichtiger. – mpen