Page 2 of 2
Posted: Fri Aug 04, 2006 2:57 pm
by alex.barylski
Ree wrote:I'm wondering what's the point of having $ before variable names? What were they thinking???

Likely to seperate the namespace of variable names and functions, etc...
Maybe to make the declaration or use explicit...?
Pascal used := for assignment whereas C style languages go with =
Whereas BASIC doesn't discriminate between Equals or Assignment...
I would also guess (based on my limited knowledge of parsing) the more explicit an syntax is, in that I mean, the less guessing a parser has to do using context, the faster it can parse and then execute a script. Which would be important for an interpreted language.
Posted: Fri Aug 04, 2006 3:28 pm
by Ollie Saunders
The more explicit an syntax is, in that I mean, the less guessing a parser has to do using context, the faster it can parse and then execute a script. Which would be important for an interpreted language.
Good point.
Posted: Fri Aug 04, 2006 3:58 pm
by jayshields
ole wrote:actually. the $ sign does have benefits..it screams at you "hey! I'm a variable!"
Yeah that is true which means you can do this:
Which is a no no in many languages.
Thing that bothers me though is, if variables have a dollar and functions have (), what do constants have? what do class names have?
You could leave class names plain but it would be nice to have a % prefix for constants.
Code: Select all
%numMonkeys = 5;
echo %numMonkeys;
%numMonkeys = 10; // E_FATAL
% is already used for the modulus operator though. What about a backtick? Or a ¦ ¬ ~. I'm guessing they aren't used...
Anyway, I like the dollar signs, as someone said before, it screams variable when you see it.
Got me thinking, do american keyboards have pound signs like english ones have dollar signs? Why don't all keyboards have the euro sign yet? What about other currencies? WHERES THE YEN SIGN?! Racists, haha.
I used a turkish keyboard when I was in Turkey last year, wooo, that's f00ked up right there, the i is replaced with a sort of | but smaller and some other funky stuff.
Posted: Fri Aug 04, 2006 4:45 pm
by feyd
jayshields wrote:What about a backtick?
Used.
jayshields wrote:¦
Used.
jayshields wrote:¬
extended character, silly.
jayshields wrote:~
Used.
Posted: Fri Aug 04, 2006 5:00 pm
by Ollie Saunders
You can have multiple uses for a symbol.
Its pretty easy to tell the difference between %monkey (constant) and 4 % 3 (expression).
In C++ you have * for pointer dereferencing, pointer instantiation and numeric multiplication.
feyd wrote:¦Used
| is used, what is ¦ used for?
Not that I'm recommending the use of ¦ for constant prefix.
Posted: Fri Aug 04, 2006 5:07 pm
by feyd
ole wrote:You can have multiple uses for a symbol.
Its pretty easy to tell the difference between %monkey (constant) and 4 % 3 (expression).
In C++ you have * for pointer dereferencing, pointer instantiation and numeric multiplication.
feyd wrote:¦Used
| is used, what is ¦ used for?
Not that I'm recommending the use of ¦ for constant prefix.
I was thinking of the old DOS font's pipe character. They character is an extended one, therefore silly.
Posted: Fri Aug 04, 2006 5:08 pm
by RobertGonzalez
What's wrong with the current suggested syntax of constants that are ALLCAPS?
Posted: Fri Aug 04, 2006 5:29 pm
by Ollie Saunders
I can think of 4 reasons:
- What if you have a class in all caps? MSQL for example
- Relying on case alone is dangerous
- %someFunnyConstant is easier to read and type than SOME_FUNNY_CONSTANT
- Why should constants shout if we had the choice for them not to?
Posted: Fri Aug 04, 2006 5:39 pm
by RobertGonzalez
ole wrote:I can think of 4 reasons:
- What if you have a class in all caps? MSQL for example
- Relying on case alone is dangerous
- %someFunnyConstant is easier to read and type than SOME_FUNNY_CONSTANT
- Why should constants shout if we had the choice for them not to?
We don't have the choice (in PHP at least). So, while all of your other arguments are very good, since we are bound by constants that cannot be denoted in some other way, it seems that ALL_CAPS_CONSTANT_NAMING works. For the most part.
Posted: Fri Aug 04, 2006 5:47 pm
by Christopher
No one has mentioned that the $ comes to PHP (and Perl) from Shell scripting. Originally there were the argv variables $0..$9 and then it was extended to named variables with SET. The main benefit of the prefix character is that you can embed the variables in double quoted strings and they will be expanded to the value. Perl followed that handy text processing style. Contrast that to C which requires a function call to concatenate strings as I recall. Languages where strings are objects usually allow the + operator.
panic! wrote:if PHP had pointers...wow that would be awesome, dunno how practical that would be on shared servers.
It has references which are essentially the same. Languages with garbage collectors can't really have pointers like languages where you manage you own memory.