We've already started the pseudo-namespacing with "SSDateTime",
but now we have ugly names like "USSSDateTime" - it's just not very
readable.
I'd much prefer the "SS_" prefix.
Its actually good timing to make this change, with a major release (2.3)
being prepared. The question is, are we chasing this up time and again
and keep breaking our API bit by bit? Is there a definitive list of
reserved names for PHP 5.3 and PHP 6, and any popular extensions?
We've got heaps of common names which could collide.
Consequently we should namespace *all*core classes - but
this will mean rewriting basically every legacy application under the
sun,
plus a lot of documentation. We could mitigate this effort
with some readymade regex-rules, but its still gonna be a royal pain.
So question is, do we have a workable system with ad-hoc fixing until we
can require 5.3?
-------
Ingo Schommer | Senior Developer
SilverStripe
http://silverstripe.com
Phone: +64 4 978 7330 ext 42
Skype: chillu23
Using eval() in such a broad context seems like a pretty bad hack,
plus a performance hit (28x slower than normal code).
See http://blog.joshuaeichorn.com/archives/2005/08/01/using-eval-in-php/
>
>
> 2) It would allow easier code injection - currently, we have the
> Object::create() and related methods - but you cant overload something
> like CoreClass::function() with your own class. If this change were to
> be made, then all you would have to do is create a class called
> Controller, and it would override SS_Controller globally - and no more
> messing with Object::create() - you can just use a plain new operator.
Rails devs tend to get into trouble by this form of "monkeypatching
with mixins" -
if customization is needed that can't be solved with
DataObjectDecorator,
ss devs should rather request hooks or config-options IMHO.
Object::create() was mainly used for overloading of the Member object
a while ago, which can now be achieved by decorating.
Do you have any use cases for replacing core classes?
>
>
> 3) Its fairly easy to implement. Itll require some changes to the
> ClassInfo class, and the autoload function, but its not a majorly deep
> change. It also means that it can be implemented in stages (you dont
> have to rename every class at once!)
Thats a big benefit of course.
Hm, definetly worth a look but I'm not convinced - Sam? :)
On 25.09.2008, at 12:21, Andrew Short wrote:
>
> On Sep 23, 10:01 pm, Ingo Schommer <i...@silverstripe.com> wrote:
>>
>> Using eval() in such a broad context seems like a pretty bad hack,
>> plus a performance hit (28x slower than normal code).
>> See http://blog.joshuaeichorn.com/archives/2005/08/01/using-eval-in-php/
>
> I don't think its that bad - it took just over a second for my machine
> to create a hundred thousand objects using eval(). The speed lost can
> easily be regained by simply caching a few things in ManifestBuilder
> or some Lazy Loading etc.
I don't really see a second of processing time as "fast" ;)
>>
>> Do you have any use cases for replacing core classes?
>
> Nested URLs without hacking the core. This cant be fixed with simple
> config parameters - as theres lots of complicated static calls etc. Or
> say I wanted to completely overload the current Security
> implementation and make it call out to a remote system for all user
> information.
This example is beyond what should be customizeable by subclassing
and monkeypatching, because it affects so many areas - you'd even need
to overload CSS design and Javascript behaviour somehow.
Its core stuff that should be developed in core.
If we see a pattern where a specific featureset needs to be customized
frequently (in a non-core-fashion), we can talk about providing hooks
or easier defined class extension points. One example of this might
be replacing the rich-text-editor, something thats currently baked
into core
with TinyMCE.
I think as long as we have a striving community, a healthy release
process,
and well-documented workflow on how to get in patches,
the need for monkeypatching is greatly reduced.
Another answer here might be a switch to git version control,
which makes branching off core a lot easier.
>
> Maybe just doing an audit of classes that are very likely to conflict
> and then renaming them would be a better approach as it definitely
> adheres to the KISS approach, and has less potential for funky bugs.
Good Idea!
>
>
>> Hm, definetly worth a look but I'm not convinced - Sam? :)
>
> Good to be slightly skeptical ;)
Lets not forget that PHP doesn't really allow for "mixins" or in-
memory class replacement,
so we should evaluate really thoroughly if we need another
"language feature simulation" in SilverStripe - they tend to
make things slow and complicated...
Some opinions about core patching in rails:
http://chadfowler.com/2006/1/26/the-virtues-of-monkey-patching
http://avdi.org/devblog/2008/02/23/why-monkeypatching-is-destroying-ruby/
http://avdi.org/devblog/2008/02/25/followup-to-monkeypatching-is-destroying-ruby/
http://www.codinghorror.com/blog/archives/001151.html
http://blog.nicksieger.com/articles/2008/03/14/monkey-patching-is-part-of-the-diy-culture
http://en.wikipedia.org/wiki/Monkey_patch