-
-
Notifications
You must be signed in to change notification settings - Fork 942
Description
After loading up my application using 9k, it prints following warning all over the place (and which breaks my application code, if I dont pass debug):
tracing (e.g. set_trace_func) will not capture all events without --debug flag
This behavior is divergent from MRI's behavior, which as I understand you try to mirror as close as possible, so I'm wondering whether this diversion is intentional or not. If it is, I'd like to appeal that it be removed.
Truthfully, the real reason I'd like for the restriction to be removed has nothing to do with above but rather, I have numerous libraries where I've been (ab?)using TracePoint (which uses set_trace_func), with regardless of whether you prefix the word or not, has been to much success.
The best use case (and an example of something that cant be done in ruby without set_trace_func), can be seen here (an abstract methods implementation). Because when the module is included I cant check which methods have been defined on the class, as module included is called before the method definitions, I can get around this by watching for the end of the class definition using trace point. I can also use a simple class instance variable setter pattern to store the method names, since all of that can happen, before calling the after_included hook allowed by tracepoint.
https://github.com/jasonayre/trax_core/blob/master/lib/trax/core/abstract_methods.rb
Because set_trace_func fires off a class end event for the current class being watched, I am able to check for the the end of the class definition, and determine whether a method was implemented, and throw an error if not.
After using TracePoint class to solve the abstract method problem, it opened my eyes to using it in several other areas, to solve various problems which are much easier to solve with deferred class evaluation (i.e. a mixin pattern which allows you to pass arguments into the module, or set them using class instance variables, which once again allows you to run the configuration behavior of the module being included lazily.)
It may strike you as janky using a library intended for debugging to do these kind of things, but I've compared for example the mixin implementations side by side, and the TracePoint version makes things much simpler, as well as opens up quite a few possibilities.
So anyways, not sure if this was even intentional since this diverges from MRI, but in the event it's not, I figured I'd plead my case for the reversion of said behavior :)