Re: tired of referencing static variables/constants with 'self ::'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jochem Maas wrote:
D. Dante Lorenso wrote:
$x = ($y == self :: MY_CONSTANT || $y == self :: MY_CONSTANT2);
I hate the spaces around the '::' whynot self::MY_CONSTANT?

Stupid PHP Eclipse code beautifier ;-) It's what I use to beautify and since it always does that, I've been forced to accept it as a style rule.

$x = ($y == MY_CONSTANT || $y == MY_CONSTANT2);

My philosophy is that the more code which is written, the greater the probability of bugs. Writing less code means less to read and less to read means easier to comprehend.
vs

that is such an oversimplication is almost laughable - comprenhesibility is not at all directly bound to the number of characters used to write something.
My ability to identify specific tokens is blurred by the introduction of more tokens which amount to nothing more than boiler-plate.
if you have ever read up on how reading/comprehension works
in the human brain you should know that - 'self::' is 'read' as a single 'token'
once the brain is acustomed to recognizing it.
Problem is that I should never have to SEE that token at all: 0 tokens < 1 token
From what I can tell, PHP only uses 1) LOCAL and 4) GLOBAL scope unless you specifically use $this or self, but I just don't think those should be necessary. Other than "that's just the way it is", why IS it necessary to use $this and self?
it's a consciencious design decision - and a very good one at that.
It's not good if it's redundant.  Look:

class A {
   public static $x = "dante";
   public static function y() {
   }
}

didn't I JUST say that $x and y() are static? Why do I have to say it every single time I use it:

   self :: $x;
   self :: y();

I already TOLD you it was static and heaven forbid that I change my mind later:

class A {
   public $x = "dante";
   public function y() {
   }
}

crap, now all my other code is broken and needs to be rewritten as an instance dereferencer:

   $this->x;
   $this->y();

Can't I just use $x and the code knows what I am talking about since I've already TOLD it?

'self ::' and '$this->' should only be necessary to clarify confusion, but should be FORCED when no confusion exists.
(as apposed to say not making 'self' bound at runtime from the very beginning of php5's inception [or atleast offering a sibling token to 'self' that is
bound at runtime] - but don't get me started on that!)
Oh I hear you about the need for late static binding. We can both not get started on that one ;-)

Dante

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux