question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add hook and extension variables features

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:14

github_iconTop GitHub Comments

2reactions
peqcommented, Nov 18, 2017

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. Put callFunctionsWithAnnotation("@unitwrapperConstructorHook") into the constructor of UnitWrapper 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.

1reaction
IgorSamuroviccommented, Dec 28, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found