Add hook and extension variables features
See original GitHub issueI’d wanted to see any of these new possibilities in Wurst. I believe they’re very helpful in some rare occasions to keep code clean and well-organized, at least for me.
For extension variables I mean something like UnitWrapper ... int UnitWrapper.killCount ... u.killCount += 1
as an example. I think that their initialization can be hooked to construct and onDestroy (like hook UnitWrapper.construct /n/t killCount = 0
for my example). And I mean they’re restricted to class types only.
Probably they could be allowed only with special flags like hookable
and extensible
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14
Top Results From Across the Web
Add hook and extension variables features · Discussion #1020 ...
I think that their initialization can be hooked to construct and onDestroy (like hook UnitWrapper.construct /n/t killCount = 0 for my example). And...
Read more >4 Modifying Workflows Using Custom Hooks
ZDT Patching provides extension points and predefined environment variables for multitenant and non-multitenant rollouts. The ZDT custom hooks feature ...
Read more >Extension:Variables - MediaWiki
The Variables extension allows you to define a variable on a page, use it later in that same page or included templates, change...
Read more >The WordPress Hooks Bootcamp: How to Use Actions, Filters ...
Learn WordPress Hooks in depth. Master Actions, Filters, and Custom Hooks by creating your own extensible plugin. Level up your WordPress ...
Read more >Building Your Own Hooks - React
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. Building your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t like the concept of hooks. It is like the COMEFROM statement and makes it very hard to read and debug source code.
If you want to call some functions every time a certain class is constructed or destroyed, you can use
callFunctionsWithAnnotation
. PutcallFunctionsWithAnnotation("@unitwrapperConstructorHook")
into the constructor ofUnitWrapper
and then all functions annotated with@unitwrapperConstructorHook
will be called. You can also use the classical observer pattern, but of course that requires some overhead.For all the effort that went into a design to move things in wurst away from the global scope, you want a feature that essentially works in the global scope. And what you want to accomplish can be solved with one mass replace. When you see a function SetUnitMoveSpeed, you need to know what it does. It is a native, so you should be familiar with it. If it is hooked to do some random thing somewhere else, then you no longer know what it does, and nobody reading your code should be expected to randomly know it is hooked to something else somewhere else.
Even partial classes suffer from this problem to a degree, which is why they are to be applied only in specific circumstances - when you know where all the parts are, and they mostly affect the class’ scope, not the global scope, aside from when you actually use the extension methods, of course.