I suppose this is another example of the “can you” vs “should you” situations. It’s similar to client security. Can you detect property changes and kick the player on the client? Yes. Should you? Probably not since it can easily be worked around. I don’t agree with doing anything clientside to stop exploits, but many people, even well known developers still have this opinion and I don’t really think that’s a bad thing, as client side security checks do offer a few benefits that server side security doesn’t do as well, especially for exploiters who don’t really know what they are doing. There are still situations where it can be useful, and people will always disagree on where the line should be drawn on what is considered to be “worth it”, but I think there’s no reason to make it impossible to do it one way as there are downsides and upsides to both.
I agree with the example you’ve provided here,
__mode definitely offers some extremely useful information over
__gc in this case, but like I had given as an example before, while you can still do anything you want with
__mode that you can do with
__gc, there are cases where using it involves creating extra nested tables, and its sometimes not intuitive to use it. I think that if properly used,
__gc is very useful even if technically there are many downsides to
__gc in most situations. It really depends on the situation, and it depends on what the developer is trying to solve in terms of garbage collection.
In fact, I don’t see why
__gc can’t be used in conjunction with
__mode to diagnose further issues. If
__gc is called, the object can be placed into a weakly keyed table to ensure that the object is really getting gced or some other issue is coming up which is preventing this.
@zeuxcg In this case, I honestly see this as a good thing anyway even though I feel like
__gc can be useful, as it means less lua threads need to be created, and less gc overhead which again, is currently one of the biggest slowdowns in my compression algorithm. If gc overhead could be for the most part mitigated, that could mean hundreds of ms of time shaved off of compressions/decompressions in my case as usually my code has thousands of objects to gc which massively cuts down performance according to what I’m seeing in the microprofiler.