-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Directory and Error extension methods #1
base: master
Are you sure you want to change the base?
Conversation
After a bit of digging around, I have found a few issues with the
Taking into account the discussion on Discord and the potential use cases of these methods, my opinion is that the best solution would be to have these return a Such an implementation would take care of the issues arising from the laziness, while also giving users the choice to use either a blocking method or an asynchronous method. This is not without its own problems though. As mentioned in the discussion, the asynchronous method would still take a long time to finish in the case of hundreds or thousands of results being retrieved. However, I do not consider this to be a major problem. For one, it is unlikely that a user has thousands of files or subdirectories, and would want to query all of their paths. Even if they do, there are other ways to reduce the time taken by either method, such as by rearranging the folder structure to ensure that files or directories whose paths don't need to be retrieved at the same time are kept under different parent directories. The user could also simply go for their own implementation of such a method in cases where they would require fine-grained control over the way the query is performed. What are your thoughts @derkork? This can be discussed at length further if necessary. |
Well given the amount of "if"s surrounding this proposal I am not sure whether this can be implemented in a sufficiently generic way that is universally useful and doesn't offer ways for the developers using it to shoot themselves in the foot. Maybe this is something that depends too much on the use case and has no generic implementation. |
Yeah, this is turning out to be something for which a generic catch-all solution doesn't seem to exist. Using I'll keep thinking of alternative solutions in the meantime. |
I have added extension methods for
Directory
andError
.DirectoryExt.GetFiles()
andDirectoryExt.GetDirectories()
do what theirSystem.IO.Directory
counterparts do, and thus help make Godot's filesystem API less of a pain to work with.ErrorExt.Success()
makes it possible to check whether an error occurred or not, without having to use!=
oris not
all the time.ErrorExt.ThrowIfFailed()
makes it easy to throw an exception (and therefore terminate the application) if anError
is returned by Godot, without having to use anif
statement and compose an error message manually.