Making the $ optional. Lol?

I ran into a weird Reddit topic today, by the controversial user Dracony (see here for controversy), in which he argues that we should deprecate the $ sign in PHP variables.

The reason is, and I quote: "There is really no point to it, and pressing the shift+4 combination 3 times in each line of code is not making it any easier on the fingers."

Uhm.

Well, I suppose it'd be interesting to find out how much time one spends on typing the SHIFT+4 combination, but surely it would be less than the time spent on catching up to the readability that was lost because of it. Considering constants don't have the $ prefix, and some people use lowercase names for them, making the $ symbol optional would also add a layer of confusion and potential BC breaks to older apps that upgrade to a PHP version which supports this. The same goes for functions and classes - there'd be little way to differentiate between them, and naming conflicts would increase exponentially.

The $ symbol has, since PHP's inception, meant "this is a variable" and I personally see absolutely no gain in making it optional - with modern IDEs helping out with the typing, and the ability to remap literally any key combo into anything else, such an upgrade would be cosmetic at best, and confusing and harmful at worst.

What do you think about this?

5 Likes

Great, save time on pressing shift+4, then spend that time trying to work out what the hell is going on. :joy:

4 Likes

Pretty much my thoughts, yeah :smiley:

1 Like

The “save time typing” argument could be said for descriptive naming too.

eg. why type
validiate_account($id);
when you could type
v($i);

When it comes to code efficiency if that’s a concern, sure, minify, uglify, compile, whatever.

But to sacrifice readability for the sake of saving a few keystrokes is an extremely weak argument IMHO.

3 Likes

This reminds me of the comment I made on Slant. Someone said that the con of PHP is dollar signs everywhere, but I strongly disagree. It is needed for an understanding in cases where we have name collisions.

I hit # instead about 20% of the time. I dislike it.

1 Like

10 minutes saved on typing, three weeks extra spend on debugging.

4 Likes

And then eliminate the trailing semicolons. We would have Visual Basic !!!

1 Like

Without $ in a variable name how would you know what’s a variable and what’s a constant unless you knew the code concerned inside and out

2 Likes

Yeah, no more $-signs, yeah no readability, yeah no more project sharing, yeah 1000000 differnt ways to name vars to identify them … wait, what? O.o

If it ain’t broke, don’t fix it.

In this case, you would have to declare your variables before using them. Old languages like Algol, and many “non-scripting” languages have that requirement.

It works in other languages without a problem.

I wouldn’t have an issue with PHP doing this, however it would cause some practical problems due to the way PHP works internally, in PHP variables and functions/classes exist in different effective namespaces

$foo = function() {
 echo 'a';
};


function foo() {
 echo 'b';
}
$foo();

The above code will print “a”. Remove $ and you have a problem: Variables and functions can now override each other:

foo = function() {
 echo 'a';
};


function foo() {
 echo 'b';
}
foo();

I would expect the above to print “b”. Essentially to do this you’d have to make PHP like JavaSript where functions are just objects in a variable and can be overriden at runtime. So the following statements are identical:


foo = function() {
};


function foo() {

}

I don’t have a problem with this, but it would cause all kinds of problems in existing programs. On the plus side, if all functions are effectively closures, then you do get a lot more flexibility.

1 Like

Really you can write out the $ in your own php no one is forcing you to use the $ a simple parse and batch script and you no longer need $. Your a programmer if you don’t like something change it you have the power!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.