Added support for Generic Types with my OOP library
I'm trying to make a better error detection framework for my addons so I made an OOP framework to support strong typing. This has proven to be really useful for me as it has simplified all my debugging.
It has ensured that I am not passing in nil values into functions that expect certain values and means I no longer need to add tons of if-statements to check for nils, or for certain value types. I have just added generic type classes. It's not one of the most useful features but I have used it and I think it's a cool addition to have. For example, I use it for creating lists that should only contain Frames/Buttons/instances of classes, etc... This is the syntax: Lua Code:
Basically, this creates an instance of "KeyValuePair" and specifies that the K generic type must be a string, and V must be a number. If you call the "Add" method with anything else then it will throw an error. You can also use "any" to specify any value that is not null, and "?string" to specify an optional string. What are your thoughts on this? The full project is here: http://www.wowinterface.com/download...ObjectLua.html EDIT: Also, "data" is a special table for holding private instance data. It doesn't take part in the validation and is given to the function after it has been called (you don't pass it manually during the function call). |
Unnecessary if you're not a muppet. Read this thread for points against over abstraction.
Plus, the game already has multiple OOP systems in place, why add another one? |
Quote:
Then I wanted some strongly typed parameters and return values which is the main point of the framework. It means I don't need to write so many checks for variables holding the correct values. Also, I can protect code belonging to objects from outside interference so I can eliminate debugging problems. This is the main reasoning behind "why add another one". It has definitely helped me significantly to develop code faster so it's not pointless at all. The performance so far seems very good unlike the stuff you linked in that post (not run proper tests but I get the impression that the library/framework in that post is heavy in performance/memory costs though I could be wrong...). I agree that this new feature (generic types) is a bit over the top but it's just an added extra that might rarely be used. It was more of a "this would be a cool experiment to play around with" concept, but the basic features that come with the library are far more useful. In addition to the implicit debugging support, the OOP features in this library are closer related to Java, C#, etc... than other systems I have seen which, to me at least, feels nicer to use. |
Just keep up, addons are first created to meet our own requirement, then we share if anybody need them. For me, the biggest gain from the WOW is my OOP lib which I already used for my web servers.
The code in Scorpio in not heavy, it'll bind the function directly to the system event, hook and etc. And about the __Async__, it used a heavy coroutine schedule system, but that system could keep the full fps for all addons based on the Scorpio. Like your validation system, the PLoop(the heavy part that they mentioned) also provide a full type definition and validation like: Lua Code:
The cost is tiny since I used several techniques to avoid the if-check, and the validation can be easily turn off with one setting so there is no need to change the code. There are several company started to use the PLoop on their Unity3D games, the type valiation and other features help them fixed thousands errors, like wrong type, spell error and other problems, like you said, without a fine validation system, an error can be spread to somewhere hard to trace back. The type validation may not be much powerful for addons, since they are tiny projects. But there are more features can be provided with a fine OOP system. The blz's mixin system is just a basic one. |
All times are GMT -6. The time now is 11:44 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI