yakshaveinc / tasks

distributed roadmap
The Unlicense
1 stars 0 forks source link

PEP for Lightweight Extension Points #43

Open techtonik opened 5 years ago

techtonik commented 5 years ago

Instrumentation - is augmenting an existing program to diagnose, debug, or extend its abilities at run-time.

Extension Point is place in code that runs all handlers assigned to it. If nothing is assigned, EP doesn't run:

def something():
     ext Log("something is run")
     return "nothing"

If there is no handler, the "ext" operation will not call anything. It will be NOP saving precious cycles. That's the main rationale to implement this PEP instead of standard logging calls etc.

https://trac.edgewall.org/wiki/TracDev/ComponentArchitecture

Alternative is to only define called function as EP:

ext log(msg):
    pass

def something():
     log("something is run")
     return "nothing"

If nothing is assigned to ext log, there is no call.

def mylog(msg):
    echo(msg)

regext(mylog, log)

extreg registers function mylog to extenstion point log, checking params. Also record who and from where called it. extlist lists all functions registered and the order they will be called. Lists also places who called it. extdir lists all extension point registered.