RE: [PHP] Why $ on variable names?

2002-11-13 Thread David Robley
In article [EMAIL PROTECTED], 
[EMAIL PROTECTED] says...
 In an earlier message, Larry Rosenman [mailto:ler;lerctr.org] said ...
 
  How about:
 
  That's the way the language designers did it, and
  there's LOTS of PRODUCTION code out there that uses it.
 
 Because that's the way it is?  Well, that's good enough for me.  I'll
 never question anything else again  I trust you won't, either.
 
   See also the precedence of PERL.
 
 Huh?  What does the precedence of PERL mean?

If I may be permitted a moment of mindreading, I think he meant 
'precedent'. Its possible he is an American and has English as a second 
language :-)

GDR

Cheers
-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

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




Re: [PHP] Why $ on variable names?

2002-11-13 Thread Pedro Garre
*This message was transferred with a trial version of CommuniGate(tm) Pro*

Hi,

JR said:
 I guess this could be true.  But I don't understand why someone would need
 an easy way to identify variables?  Why not an easy way to identify
 function names?  Or constants?
For big projects and/or safety critical projects it is very convenient to make 
a clear differentiation betwen them.
In fact, the coding standard I use for those projects is:
v_name is a variable
vg_name is a global variable (of course the use of global variables should be 
minimized)
f_name is a function
c_name is a constant
e_name is an enumerated value
t_name is a type
... maybe more
You may think it is confusing, a waste of time, or whatever, but believe me 
you get used to it very quickly and becomes very natural.
Note that using this standard is relatively easy to write your own tools for 
code static analysys or just to performs searchs, substitutions, etc.

Rasmus said:
 It also means you can have variables that are the same name as function
 names.
In my opinion this is not an advantage at all. When I read code (clearly when 
it is not your own) I want to know if this is a function or a variable or a 
constant.
Anyway, if your are calling a function you should always use the opening and 
closing brackets.

I guess PHP is not usually used for safety critical projects, but if I have to 
develop such a project in the web I would PHP, of course, and the first thing 
I would do is to write a coding standards document with these and more 
restrictions.
When PHP is used for big projects, with several programmers involved, 
programming-in-the-large, coding standards are required.

Having said that, my PHP projects are quite big and I don't use any of those 
standards :-)
(my excuse is that it is just me programming)

Pedro.


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




Re: [PHP] Why $ on variable names?

2002-11-12 Thread Leif K-Brooks
I'm just guessing here.  For one thing, to seperate variables from 
constants.  Also, it makes it possible to use variables within quotes.

brucedickey wrote:

I've searched, but haven't found the answer -- from a language design point
of view, why are there $ on the front of PHP variable names?

Thanks,

Bruce

 


--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.




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




Re: [PHP] Why $ on variable names?

2002-11-12 Thread Chris Wesley
On Tue, 12 Nov 2002, brucedickey wrote:

 I've searched, but haven't found the answer -- from a language design point
 of view, why are there $ on the front of PHP variable names?

... so Perl converts know where there variables are ;)

~Chris


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




Re: [PHP] Why $ on variable names?

2002-11-12 Thread Jason Wong
On Wednesday 13 November 2002 02:35, Leif K-Brooks wrote:
 I'm just guessing here.  For one thing, to seperate variables from
 constants.  Also, it makes it possible to use variables within quotes.

Yup. So you can have:

  print I'm a $variable;

instead of the messy javascript way:

  alert(I'm a  . $variable);

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Aleph-null bottles of beer on the wall,
Aleph-null bottles of beer,
You take one down, and pass it around,
Aleph-null bottles of beer on the wall.
*/


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




Re: [PHP] Why $ on variable names?

2002-11-12 Thread Rasmus Lerdorf
So you can put variables inside quoted strings.
Without $ how would this work?

   price = 9.95;
   echo The price is price;

It also means you can have variables that are the same name as function
names.

-Rasmus

On Tue, 12 Nov 2002, brucedickey wrote:

 I've searched, but haven't found the answer -- from a language design point
 of view, why are there $ on the front of PHP variable names?

 Thanks,

 Bruce

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



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




RE: [PHP] Why $ on variable names?

2002-11-12 Thread brucedickey
Thanks for all the replies.

I just seemed to me that to add $ everywhere was more work (and not as
aesthetic as a plain word) than using some other syntax for print. But, in
fact, it could have been designed so you could still use

print I'm a $variable;

without the use of $ in other uses of the variable (like in assignments and
references to it), right? Rhetorical question.

(Just an initial impression of PHP)...

Bruce


-Original Message-
From: Jason Wong [mailto:php-general;gremlins.com.hk]
Sent: Tuesday, November 12, 2002 11:40 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Why $ on variable names?


On Wednesday 13 November 2002 02:35, Leif K-Brooks wrote:
 I'm just guessing here.  For one thing, to seperate variables from
 constants.  Also, it makes it possible to use variables within quotes.

Yup. So you can have:

  print I'm a $variable;

instead of the messy javascript way:

  alert(I'm a  . $variable);

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Aleph-null bottles of beer on the wall,
Aleph-null bottles of beer,
You take one down, and pass it around,
Aleph-null bottles of beer on the wall.
*/


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

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




RE: [PHP] Why $ on variable names?

2002-11-12 Thread Jonathan Rosenberg \(Tabby's Place\)
In an earlier message, Jason Wong [mailto:php-general;gremlins.com.hk] said
...

 Yup. So you can have:

   print I'm a $variable;

 instead of the messy javascript way:

   alert(I'm a  . $variable);

But the language could still support variable evaluation within strings
without requiring the '$' to always appear in front of a variable name.

So, a '$' within a string would mean treat the following identifier as a
variable to be evaluated.  I believe that this introduces no
inconsistencies  removes the ugly $s that litter PHP programs.

--
JR



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




RE: [PHP] Why $ on variable names?

2002-11-12 Thread Marco Tabini
If I can venture a comment, what you think clutters the code others
may find a quick and easy way to identify a variable in it.

Just a thought.


Marco
-- 

php|architect - The magazine for PHP Professionals
The first monthly worldwide magazine dedicated to PHP programmers

Come visit us at http://www.phparch.com!

---BeginMessage---
In an earlier message, Jason Wong [mailto:php-general;gremlins.com.hk] said
...

 Yup. So you can have:

   print I'm a $variable;

 instead of the messy javascript way:

   alert(I'm a  . $variable);

But the language could still support variable evaluation within strings
without requiring the '$' to always appear in front of a variable name.

So, a '$' within a string would mean treat the following identifier as a
variable to be evaluated.  I believe that this introduces no
inconsistencies  removes the ugly $s that litter PHP programs.

--
JR



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



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


RE: [PHP] Why $ on variable names?

2002-11-12 Thread Jonathan Rosenberg \(Tabby's Place\)
In an earlier message, Marco Tabini [mailto:marcot;inicode.com] saidf ...

 If I can venture a comment, what you think
 clutters the code others may find a quick and
 easy way to identify a variable in it.

I guess this could be true.  But I don't understand why someone would need
an easy way to identify variables?  Why not an easy way to identify
function names?  Or constants?

In any case, I don't recall anyone complaining that they had trouble
identifying variables in C, C++, Modula, Pascal, Java, etc.

 Marco

--
JR



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




RE: [PHP] Why $ on variable names?

2002-11-12 Thread Larry Rosenman
How about:

   That's the way the language designers did it, and there's LOTS of 
PRODUCTION code out
there that uses it.

   See also the precedence of PERL.

LER


--On Tuesday, November 12, 2002 16:40:46 -0500 Jonathan Rosenberg (Tabby's 
Place) [EMAIL PROTECTED] wrote:

In an earlier message, Marco Tabini [mailto:marcot;inicode.com] saidf ...


If I can venture a comment, what you think
clutters the code others may find a quick and
easy way to identify a variable in it.


I guess this could be true.  But I don't understand why someone would need
an easy way to identify variables?  Why not an easy way to identify
function names?  Or constants?

In any case, I don't recall anyone complaining that they had trouble
identifying variables in C, C++, Modula, Pascal, Java, etc.


Marco


--
JR



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





--
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 972-414-9812 E-Mail: [EMAIL PROTECTED]
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749




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




RE: [PHP] Why $ on variable names?

2002-11-12 Thread Ernest E Vogelsinger
At 22:40 12.11.2002, Jonathan Rosenberg \(Tabby's Place\) said:
[snip]
I guess this could be true.  But I don't understand why someone would need
an easy way to identify variables?  Why not an easy way to identify
function names?  Or constants?

In any case, I don't recall anyone complaining that they had trouble
identifying variables in C, C++, Modula, Pascal, Java, etc.
[snip] 

Quite right. But, having developed a couple of interpreters myself, I
assume there's some sound reason.

Think of how an interpreter works. It parses the sourcecode in realtime,
not as a compiler. People must _wait_, every time, until it is finished,
not only once like a compiler. Thus designers of interpreted languages like
something that can easily be distinguished, so you don't need to lookup a
lot of hash tables to identify a symbol, or to resolve amiguities.

That's why the '$' preceds a variable name. Simply said, when the parser
sees a '$', it knows which symbol table to look it up. If a token doesn't
have a '$', it can be found in the table of keywords of the language's
state machine.

Easy explanation, huh? Simple example: taken that a PHP application
consists of 1000 tokens, 200 of the tokens are variable names, and 800
non-variable tokens, the interpreter would either 200 times look up the
wrong symbol table (if it chooses to lookup the keywords first), or 800
times (if it looks up the entity table first).

Simply saves time...

-- 
   O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



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




RE: [PHP] Why $ on variable names?

2002-11-12 Thread brucedickey
Yeah, I wondered about that. Having heard that C was designed in part for
the parser. A parser with no lookahead (or maybe 1 char of lookahead) was
used, which is why hex numbers start with 0x instead of being suffixed
with _16, just to contrive an example.

I would be curious to hear the author say whether this played a part in his
decision.

Bruce


-Original Message-
From: Ernest E Vogelsinger [mailto:ernest;vogelsinger.at]
Sent: Tuesday, November 12, 2002 3:54 PM
To: Jonathan Rosenberg (Tabby's Place)
Cc: Marco Tabini; Jonathan Rosenberg (Tabby's Place); PHP-General
Subject: RE: [PHP] Why $ on variable names?


At 22:40 12.11.2002, Jonathan Rosenberg \(Tabby's Place\) said:
[snip]
I guess this could be true.  But I don't understand why someone would need
an easy way to identify variables?  Why not an easy way to identify
function names?  Or constants?

In any case, I don't recall anyone complaining that they had trouble
identifying variables in C, C++, Modula, Pascal, Java, etc.
[snip] 

Quite right. But, having developed a couple of interpreters myself, I
assume there's some sound reason.

Think of how an interpreter works. It parses the sourcecode in realtime,
not as a compiler. People must _wait_, every time, until it is finished,
not only once like a compiler. Thus designers of interpreted languages like
something that can easily be distinguished, so you don't need to lookup a
lot of hash tables to identify a symbol, or to resolve amiguities.

That's why the '$' preceds a variable name. Simply said, when the parser
sees a '$', it knows which symbol table to look it up. If a token doesn't
have a '$', it can be found in the table of keywords of the language's
state machine.

Easy explanation, huh? Simple example: taken that a PHP application
consists of 1000 tokens, 200 of the tokens are variable names, and 800
non-variable tokens, the interpreter would either 200 times look up the
wrong symbol table (if it chooses to lookup the keywords first), or 800
times (if it looks up the entity table first).

Simply saves time...

-- 
   O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



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

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




RE: [PHP] Why $ on variable names?

2002-11-12 Thread Jonathan Rosenberg \(Tabby's Place\)
In an earlier message, Larry Rosenman [mailto:ler;lerctr.org] said ...

 How about:

 That's the way the language designers did it, and
 there's LOTS of PRODUCTION code out there that uses it.

Because that's the way it is?  Well, that's good enough for me.  I'll
never question anything else again  I trust you won't, either.

  See also the precedence of PERL.

Huh?  What does the precedence of PERL mean?

 LER

--
JR



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




RE: [PHP] Why $ on variable names?

2002-11-12 Thread Larry Rosenman


--On Tuesday, November 12, 2002 16:53:07 -0500 Jonathan Rosenberg (Tabby's 
Place) [EMAIL PROTECTED] wrote:

In an earlier message, Larry Rosenman [mailto:ler;lerctr.org] said ...


How about:



That's the way the language designers did it, and
there's LOTS of PRODUCTION code out there that uses it.


Because that's the way it is?  Well, that's good enough for me.  I'll
never question anything else again  I trust you won't, either.

You can't change the language at this date, and still call it PHP.  There 
is a LOT
of PHP code out there.  I can question, but expecting it to change is not 
realistic.




 See also the precedence of PERL.


Huh?  What does the precedence of PERL mean?

PERL has all it's variables (scalar at any rate) prefixed with Dollar 
Signs.




LER


--
JR





--
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 972-414-9812 E-Mail: [EMAIL PROTECTED]
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749




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




RE: [PHP] Why $ on variable names?

2002-11-12 Thread Jonathan Rosenberg \(Tabby's Place\)
In an earlier message, Ernest E Vogelsinger [mailto:ernest;vogelsinger.at]
said ...

 Think of how an interpreter works. It parses the
 sourcecode in realtime, not as a compiler. People must
 _wait_, every time, until it is finished,
 not only once like a compiler. Thus designers of
 interpreted languages like something that can easily be
 distinguished, so you don't need to lookup a
 lot of hash tables to identify a symbol, or to
 resolve amiguities.

Lots of other popular interpreted languages managed to get by without the
need for something unique to identify a variable name: LISP, TCL,
JavaScript, Visual Basic.  During parsing an interpreter or compiler will
know when it might see a variable (or constant, which can be stored in the
same hash table).  Look at the syntax for any language.  There's really no
need for extraneous symbol table lookups.

 That's why the '$' preceds a variable name. Simply
 said, when the parser sees a '$', it knows which symbol
 table to look it up. If a token doesn't have a '$', it
 can be found in the table of keywords of the language's
 state machine.

But, that's not true.  If the token doesn't have a '$' it could be a
function or constant name, as well as a keyword.

 --
O Ernest E. Vogelsinger

--
JR



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