Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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?

like image 202
Ignas R Avatar asked Nov 12 '09 19:11

Ignas R


People also ask

What is the usage of of?

Of is a preposition that indicates relationships between other words, such as belonging, things made of other things, things that contain other things, or a point of reckoning.

What is the use of of in a sentence?

Of is a preposition. Of commonly introduces prepositional phrases which are complements of nouns, creating the pattern: noun + of + noun. This pattern is very common, especially to indicate different parts, pieces, amounts and groups: Lima is the capital of Peru.

What is the use of preposition of?

The preposition “of” can be used in many different contexts. It can be used to help quantify a time or measurement (e.g., “the fifth of September” or “three pounds of potatoes”) and even identify a location (e.g., “south of California”), but it can also create more general relationships between objects and their nouns.

What kind of preposition is of?

This preposition shows that something or someone belongs to something or someone. Such as of, with and to.


2 Answers

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.

like image 161
David Pfeffer Avatar answered Oct 11 '22 14:10

David Pfeffer


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.

like image 40
Ben S Avatar answered Oct 11 '22 14:10

Ben S