Re: Flexible function naming

From: Date: Mon, 16 Dec 2013 05:47:21 +0000
Subject: Re: Flexible function naming
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-70648@lists.php.net to get a copy of this message
Michael Wallner wrote:
On Dec 14, 2013 7:45 AM, "Robert Cerny" wrote: [...]
When a PHP code base is growing over time it looks more and more
'diverse', because of inconsistent function and method naming in core PHP and third party libraries. This cannot be changed by any guidelines. The author of a function has the freedom to assign any name. The user of a function needs some flexibility in referring to a function. It should be possible to use 'array_key_exists', 'arrayKeyExists' or 'arraykeyExists'. Because of the performance impact and possible resolution conflicts this language feature needs to be disabled by default. Oh, I think this is not the best example, but in 5.6 you can achieve that with the new 'use function' feature. That is not what i mean. My proposal reaches much further. In the meantime, i realized how to do it with minimal performance impact. Upon parsing, PHP would need to add synonyms for function and method names to the namespace depending on the configured referral styles. By 'namespace' i do not mean a declared PHP namespace in the formal sense. By default no referral styles are configured. Users can choose between 'camel case' and 'underscore'. In this case there would be no need to normalize function names when looking up a symbol. It would be built-in glasses feature, for those who know the emacs mode.
This is not difficult to implement. It is only necessary to normalize function names: remove all but leading underscores and lower case the result. The likelihood of conflict is very small. This small change would allow coding teams to create a consistent code base based on 'their' guidelines. Motto: "Have it your way!". No. What is wrong with having a consistent code base all the way, also covering legacy code? I consider this a pretty neat language feature.
Robert

« previous php.internals (#70648) next »