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

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

 



Richard Lynch wrote:
On Tue, May 9, 2006 4:48 pm, D. Dante Lorenso wrote:
If
the search for my constant follows the search I've listed above, self
would never be necessary unless you wanted to pinpoint "3" directly.
Under this same line of thinking, though, '$this->' really shouldn't
be
be necessary either unless you wanted to clarify local vs this for
same-named variables.

Languages that let you get away without specifying $this-> and self::
do exist...

But, in my experience, after a certain level of complexity is
achieved, you end up getting very confused very fast about where $foo
is coming from...

And it turns into a real nightmare when you inherit somebody else's code:

100,000 lines of code here
  echo $foo;
100,000 lines of code here

You really have no idea where $foo came from, do you? :-)

So I personally PREFER that one has to make it clear where the
variables are coming from.

Yeah, I guess I kinda agree with you about that. '$this->' and 'self ::' are nice so that a programmer 'reader' doesn't have to trace scope, but it's more work on the programmer 'writer'. In most cases, the programmer writer SHOULD go the extra step because the writer can write the code easier than the reader can read and figure out the code. So, in that regard it is nice to 'require' the notation.

I never use 'define()' in my code, however, because I think it's as dirty as 'global' and globals are bad in my world. So, as a style rule, I usually only use all uppercase variable names when defining static or constant properties of an object:

   public static $MY_STATIC = array();
   const MY_CONST = true;

and therefore, in my code, if you ever find an all uppercase variable, it's probably scoped to the class. Hence, dropping 'self ::' as a requirement when I reference class-level constants is not a scary idea for me. The other argument is that by defining the language to FORCE '$this->' and 'self ::', we do just that, we FORCE the use. Not everyone has a problem with reading code and tracing scope. Programmers should WANT to write code which is clear and easy to understand, but that style shouldn't be forced upon them, especially when the language CAN do without it.

Seems this topic could become a religious debate. But, unlike curly up 'funcname() {' or curly down 'funcname()\n{' debates, there is not choice a currently. I'm sure there are fans of it both ways, can't we offer it both ways?

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