Page 1 of 4
PHP suggestion/rant
Posted: Sun Jan 23, 2011 4:40 pm
by Peec
What do you think?
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Get rid of the $ operator, it's there for nothing. Just indication of a variable, i think the human beings are smart enough to know that it's a variable and not a string.
Type definition
Code: Select all
class Foo{
public String barFoo(String test, Array test, Int number){
String var = 'Test';
return var;
}
}
I would LOVE to see type definition of variables in PHP 6/7!
Re: PHP suggestion/rant
Posted: Sun Jan 23, 2011 4:50 pm
by Jonah Bron
And while we're at it, we can just turn the whole thing into Java!
But seriously, why? By the way, there are reasons for the $, one of which is
here.
There's no type declaration because PHP is a
dynamically typed language. There's no need. You can do
type-hinting for method arguments though.
Both of those changes would also completely break older code.
Re: PHP suggestion/rant
Posted: Sun Jan 23, 2011 5:23 pm
by Benjamin
Uhh yeah no thanks.
Re: PHP suggestion/rant
Posted: Sun Jan 23, 2011 8:31 pm
by josh
return return;
enough said. Also then you'd have collisions between constants & variables. FOO does not necessarily equal $FOO
Re: PHP suggestion/rant
Posted: Mon Jan 24, 2011 2:20 pm
by John Cartwright
$ is not an operator
//What everyone else said
Re: PHP suggestion/rant
Posted: Mon Jan 24, 2011 2:41 pm
by josh
Another thing is code completion, it makes it easier to write IDEs presumably, or to parse PHP code. I can type $ and get a popup hint, without necessarily knowing the first letter of the variable. I can use find & replace to replace '$foo' without replacing foo()
Re: PHP suggestion/rant
Posted: Mon Jan 24, 2011 3:41 pm
by Benjamin
Not to mention a complete rewrite of all existing PHP code, including the frameworks.
Re: PHP suggestion/rant
Posted: Mon Jan 24, 2011 4:44 pm
by John Cartwright
Screw PHP. Maybe we should just all start using Java.

Re: PHP suggestion/rant
Posted: Wed Jan 26, 2011 4:14 am
by josh
Benjamin wrote:Not to mention a complete rewrite of all existing PHP code, including the frameworks.
not necessarily. If they wanted they could make the '$' optional, and keep old code running but also support a new way of doing it. Nothing is impossible. Basically the '$' token removed, but '$' added as an allowed character in variable names. I think they should keep it though, at least for code completion. I can tell the computer that its a variable for purposes of code completion, with one key. I think that's neat. It also makes find & replace easier.
Re: PHP suggestion/rant
Posted: Thu Jan 27, 2011 2:14 pm
by Peec
I support making PeecFW more like Java, but keep the simplicity of installing it. Also make PHP go away from dynamically typed language.
It will be far better web applications around the globe, no software that has buggy features.
Re: PHP suggestion/rant
Posted: Thu Jan 27, 2011 4:11 pm
by Jonah Bron
Peec wrote:I support making PeecFW more like Java, but keep the simplicity of installing it. Also make PHP go away from dynamically typed language.
Sorry, you are bound to the parameters set by the language you use. If you want to use Java, all you've got to do is add the jar to your class path.
Peec wrote:It will be far better web applications around the globe, no software that has buggy features.
The two items you mentioned will
not make people's software less buggy. All programming languages are equally easy to write buggy code in as far as I'm concerned. Humans are the weak link.
Re: PHP suggestion/rant
Posted: Thu Jan 27, 2011 8:19 pm
by josh
Peec wrote:It will be far better web applications around the globe, no software that has buggy features.
Usually my bugs are logic errors. I can't remember the last time I actually had a bug because I thought something was the wrong data type? lol.. You can pass the wrong data type in either type of language and your program can crash.
Re: PHP suggestion/rant
Posted: Fri Jan 28, 2011 6:58 pm
by Peec
josh wrote:Peec wrote:It will be far better web applications around the globe, no software that has buggy features.
Usually my bugs are logic errors. I can't remember the last time I actually had a bug because I thought something was the wrong data type? lol.. You can pass the wrong data type in either type of language and your program can crash.
That's because PHP doesn't require you to declare a variable to a datatype (only type-hinting in methods and functions).
This makes us PHP writers write
ugly code, using $var as string object. PHP is just too dynamic and messy.
When you declare the datatype you will decrease the chance of getting "logic errors" and "bugs" because you will suddenly know what a variable is, it's purpose and how the variable can be used.
Also writing IDE's for PHP will be even better, and errors will be discovered earlier.
Oh another thing:
get rid off all _ in functions and put it all in objects and classes.
VS
Code: Select all
String str = new \php\File('file.txt')->getContent();
Re: PHP suggestion/rant
Posted: Sun Jan 30, 2011 4:57 am
by Jenk
So remind us, why is it you are using PHP?
As for writing meaningless variables, that happens in every language and type-stricting does nothing to help this, in fact makes it worse because people like yourself falsesly believe it helps and get lazy when naming variables and parameters.
Re: PHP suggestion/rant
Posted: Sun Jan 30, 2011 9:11 am
by josh
Peec wrote:When you declare the datatype you will decrease the chance of getting "logic errors" and "bugs" because you will suddenly know what a variable is, it's purpose and how the variable can be used.
You'll know it's type (string vs integer, vs float). In fact it causes more opportunity for bugs (oops thought it was signed, but took the unsigned value, program crashed - this can't happen in PHP). Either way a logic error is something like sending the wrong value (yet correct type), so how exactly does strict typing help prevent logic errors?? By logic error I mean the programmer made a mistake, such as reversing a conditional accidentally during an attempted refactoring. The only thing I know of that helps reduce those kinds of errors are unit tests, which coincidentally are easier & faster to write in a dynamically typed language (no need to add new signatures).
And as for "its ugly" that doesn't even make sense, having less actual code on the screen is "ugly"? You think the more verbose way of writing the same thing is "prettier"?
Your second suggestion of wrapping primitives in objects contradicts your first suggestion of having strict type checking. If I just want an array of strings why should I have the overhead of having the objects? PHP allows you to create your own wrapper object, and just provides the primitive. Its a language, not a framework... Languages that use objects instead of primitives are at a disadvantage (presumably) as far as system resources go. Also if a language enforced usage of some particular class for all primitives, you'd have problem extending it since most languages are single inheritance. This can be seen in Java for example, where stubbing out these classes for unit testing is impossible, and it creates extra boiler plate "factory" code if you intend to extend the built in class later on down the road. (this is true of any class provided as part of the language)
For example consider something like 5.add(10) == 15, no "new" operator, they're not objects, just primitives with an object oriented like operator. Being able to mixin methods from the global namespace or something. What happens then when two libraries need to define a method called .foo() ? Does the latter defined method replace the one that was defined first? It's much easier for the two libraries to use their own class so there is no collision. This way if you want an object oriented interface, you can have one and there is no base class forced on you, and if you don't want object oriented interfaces on your primitives, you don't need one.
And in your post you say "string object", this confuses me