> From: "Jani Taskinen" <[EMAIL PROTECTED]>
>
> C++ is not PHP and the sooner you realize this the better it will be.

I do realise it. However, I don't accept that as an argument against things
like operator overloading, which is found in scripting languages comparable
to PHP.

> Adding operator overloading will add yet another layer of "magic" that
> will confuse users, who for the most part have demonstrated that they
> are not ready for such features.

Judging from much of the PHP code I've seen, I'm sorry to say that you may
be right... However, that doesn't mean _no_ users are ready for it.

> If anything it'll only over complicate
> applications making them neigh impossible to debug and require all sorts
> of hackery inside the language itself to support this functionality.

My experience isn't that misuse of language features is the biggest cause of
messy code, as inexperienced developers typically aren't aware of more
"advanced" features, and therefore don't use them. Rather, my experience is
that the biggest cause of messy code is simply lack of competence, beyond
knowing the language itself. Learning to be a good programmer takes many
years, regardless of language.

Those who are experienced enough to "shoot themselves in the foot", but not
experienced enough to aim properly, :) might, however, obfuscate code with
"misuse" of more "advanced" language constructs (variable variables and
variable functions comes to mind), but that doesn't mean we should forbid
these features in the language!

Used properly, if anything, the features proposed in my postings (like
overloading, and optional type checking) would allow people to _simplify_
their code. C++ code is typically simpler than Java code, for this reason.
Take this example (incrementing an element in a map):

C++:

++my_map[key];

Java:

if ( !my_map.containsKey( key ) )
    my_map.put( key, new Integer( 1 ) );
else
{
    Integer count = ( Integer )my_map.get( key ) );
    int icount = count.IntValue();
    my_map.put( key, new Integer( ++icount ) );
}

Operator overloading isn't the only thing playing a part, here (the ability
to treat built-in and user-defined types the same way is another major
factor), but it's a major factor.

Now, for this particular example, PHP actually has a similarly succinct
form, but that's only because the PHP array _is_ a map, so you have a
built-in type with operators:

++$my_map[$key];

The advantage of operator overloading is similar to the advantage of
symbolic notation in mathematics: It allows you to succinctly express your
intent, and it's also international.

Regards,

Terje

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to