开发者

Why is the usage of "#" comments frequently discouraged in PHP?

开发者 https://www.devze.com 2022-12-11 11:54 出处:网络
As far as I know, there are 3 types of comments recognized by PHP: /* A block comment */ // A single-line comment

As far as I know, there are 3 types of comments recognized by PHP:

  • /* A block comment */
  • // A single-line comment
  • # Also a single-line comment开发者_C百科

However, many coding standards, for example, those of PEAR or Kohana, discourage the last type of comments with no explanation. The question is, why is it so? Is this syntax planned for deprecation anytime soon?


C-language comment style has become an industry standard. There's nothing wrong with using # comments at all unless the particular coding standard for your project or workplace prohibits it. Standards are the key to yielding readable code.

In many cases, // and/or /* */ are considered standard comment syntax for programming languages. The only exception that commonly is encountered is VB, which uses '. In contrast, # is often considered the standard comment syntax for shell scripting.

PHP was designed to perform both tasks originally. PHP can and does function reasonably well as a shell scripting language and can be invoked from the command line. It has functions to handle reading from stdin and writing to stdout. This is probably the origin of the # syntax for comments. # is probably discouraged because PHP is thought of as a programming language nowadays, rather than a tool for shell scripting. Specifically, the style guides that the question references are for web apps, rather than some shell tool.


From the links you posted, this seems like a purely stylistic choice. PEAR and Kohana would like to have some unity when it comes to style and they have (possibly arbitrarily), chosen to prefer C-Style comments to UNIX/Perl-style ones.


maybe // and /* */ are also commenters for many other languages like c, c++, c#, javascript, css, and many more. so maybe people got used to using them. just guessing.


I would think its because a lot of other programing launages use // as a single line comment (C,C++, C#, java, ect..) and PHP gets a lot its syntax from the C like languages.

I don't belive that # will be deprecation any time soon.


The only reason I can think of is that it would hurt code readibiltiy to have two different kinds of one-line comment syntaxes floating around. // seems to be the more common way, so I'm guessing they are just trying to limit themselves to one to increase readibility


The # comment form in PHP is discouraged by PECL style guides but is still acceptable and probably won't be deprecated. similar to the reason that class names usually do not have numbers in them. it's just convention

0

精彩评论

暂无评论...
验证码 换一张
取 消