2 ms·
In which ways do Traits of all things help write good, disciplined code bases? I think traits, and their Java equivalent, are OK to touch up legacy APIs (as th
by adimitrov 10y ago
In which ways do Traits of all things help write good, disciplined code bases?
I think traits, and their Java equivalent, are OK to touch up legacy APIs (as they did with the Java collections API) but I have found no good place to stick them in a new project.
Not to say PHP hasn't been introducing functionality for writing good, stable code bases (type hinting in function signatures, namespaces, better garbage collection, an actual AST — as an aside: how ON EARTH did they do without an AST pre-PHP7?) but traits don't strike me as the feature to think of when designing a new code base.
They're not extendable, they're not overridable, they're monolithic, and classes expose their implementation details to them, which makes traits super fragile.
- ryanlm 10y agoThey emitted oplines to the opcode array directly from the parse production.