a general notice...

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Ree wrote:I'm wondering what's the point of having $ before variable names? What were they thinking??? :roll:
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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post 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:

Code: Select all

$array = array();
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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

jayshields wrote:What about a backtick?
Used.
jayshields wrote:¦
Used.
jayshields wrote:¬
extended character, silly.
jayshields wrote:~
Used.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What's wrong with the current suggested syntax of constants that are ALLCAPS?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
Post Reply