Gần đây tôi đã bắt đầu làm việc trên một CMS nhỏ. Tôi thường phát triển các ứng dụng .NET trong C#, và tôi rất quen với việc bình luận các trường và phương thức của mình. Người bạn của tôi nói với tôi rằng việc có nhận xét trong các tập lệnh PHP là khá xấu, vì PHP là động và được phân tích cú pháp khi được yêu cầu, vì vậy việc phân tích các nhận xét sẽ mất nhiều thời gian hơn.PHP - Ghi chú quá mức?
Tuyên bố này có áp dụng cho trường hợp của tôi, nhận xét mọi phương pháp và trường không?
Ví dụ về một trong các lớp học của tôi:
<?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 . "]";
}
}
}
?>
Bạn của bạn là kẻ ngốc. –
Bỏ phiếu để đóng như blatantly tấn công vì chủ quan và tranh luận chỉ không hoàn toàn cắt nó. Ngoài ra, sự tồn tại của một ai đó là người phạm tội gây xúc phạm cho tôi. –
@NSD: Đã được xếp thứ hai. Tôi không xác nhận quá bình luận với những điều ngu ngốc khi mã nói cho chính nó, nhưng các ý kiến trong mã của bạn là tốt (tốt, thậm chí). Đừng băn khoăn về thời gian phân tích cú pháp, không chỉ với các bình luận, nhưng bất cứ điều gì nhỏ như thế. Khả năng đọc là quan trọng hơn nhiều. – mpen