tags:

views:

240

answers:

8

Lately I've been using # instead of // for doing single line comments inside my Code. However, I see must of the people prefer //.

Is there a particular reason for preferring them instead of #? Performance? File weight? Anything?

+4  A: 

It doesn't change a single thing, I'd say ; it's just a matter of habits :

  • // comes from C, and exists in several languages used by lots of people.
  • # comes from shell and Perl, and exists in not as many "important" languages as // -- so less people use it.

And why are those two both available in PHP ? Well, PHP has been built with people knowing both C, Shell, and Perl, and they have brought what they liked from those languages ;-)

Pascal MARTIN
+2  A: 

I think it's merely a matter of taste and preference. The # as comment marker has its roots in shell scripts while // goes back to C++ so depending on the people who read your code and their background one or the other might look unfamiliar.

Joey
+2  A: 

IDE support may be a reason. For instance, with Eclipse you can automatically comment and uncomment blocks with //, but not with # (with the PHP plugin; the Python plugin does #). Looking at it that way, it depends on the IDE you and your collaborators use.

Confusion
Block comments is /* */ not //.
lfx
@lfx: Eclipse precedes every line in the selected block with `//`
Cassy
yes,but he was talking about automatic commenting out, for that // is more suitable, with /* */ one has trouble if /* */ is in the block to be commented out
johannes
+1  A: 

For single line comments, there is no significant technical reason for prefering // over the octothorpe (that's what the Zend PHP 5 Certification Study Guide calls #) or vice versa. // seems to be more the more common choice out there in the wild.

Asaph
+2  A: 

I'd probably stick with // simply because it's the same in javascript, and when you code php, you're likely going to have some javascript in your files as well. (Most websites use js nowadays)

This way your comments look the same, regardless of the language, and it'd ease readability a small bit.

Steffen
+1  A: 

"//" seems more consistent with the "/* */" block comments to me. But apart from that, I know of no reason to prefer one over the other.

Techpriester
+2  A: 

You can use #, but // is much more common. It is also the agreed upon Code Convention in PEAR.

Gordon
+1  A: 

I would only suggest you use // or /* */. As your programs grow you may wish to use a documentator like phpdoc to automate documentation for your program and most of these documentators as well as IDE's will only accept these two.

yannis