On 29 June 2024 08:06:57 BST, Mike Schinkel <m...@newclarity.net> wrote:
>The takeaways that I think would be useful are PHP modules are:
>
>1. Imports
>2. Import aliases
>3. Module-level consts
>4. Module-level init() functions
>5. Module-level vars with initialization
>6. Module-level functions
>7. One directory == one module
>8. No hierarchy for modules
>9. Single word module names in lowercase.
>10. Module sytax being <module><operator><symbol>, e.g. mymodule->MySymbol
This all sounds like an interesting set of ideas for building a new language.
Most of it sounds completely impractical to apply in retrospect to an existing
one with millions of users - apart from the bits we actually already have, like
points 3 and 6.
Rather than looking at languages which have done things completely differently,
I think it would be more useful to look for inspiration for ones which are
*similar* to PHP's approach, but have extra features.
For instance, .net has both "assemblies" (multiple files compiled as one
redistributable unit) and namespaces (which are hierarchical, like PHP's).
"Package private" modifiers work at the assembly level, not the namespace one.
.Net assemblies don't have to be limited to one namespace root, but in practice
generally are. For PHP, I think there would be some benefits to making that a
fixed rule, with some tricks to "re-open" a namespace, or explicitly add
"friends" to it.
I don't know much about modern Java, but it too has hierarchical namespaces, so
there might be good and bad experiences we can learn from there, as well. And
I'm sure there are others that are much less alien than JS or Go.
Rowan Tommins
[IMSoP]