Skip to content
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

Refactor Python loader code #94

Closed
jfblomgren opened this issue Mar 16, 2021 · 4 comments
Closed

Refactor Python loader code #94

jfblomgren opened this issue Mar 16, 2021 · 4 comments

Comments

@jfblomgren
Copy link
Contributor

I am currently reading through the code for the Python loader and have found a few recurring patterns that I believe could be improved:

  1. A lot of the error handling cleanup code is quite repetitive and the current structure is quite error-prone. This could be improved by using goto to localize the cleanup code (see this link for an example).
  2. Variables are often declared at the start of scopes (i.e. C89 style), rather than when they are actually initialized. This makes it harder to reason about their scope and could be improved by only declaring the variables when they are to be initialized, thus making their scope as tight as possible.

If you agree with these observations, I will start working on implementing them in the codebase. Please see this commit for an example of how these changes might be implemented.

@viferga
Copy link
Member

viferga commented Mar 17, 2021

Respect to the second point, I have used C89 mostly because I was wondering MetaCall may work with cases like COBOL migrations. For very old computers, maybe this standard may be needed. I don't know if this restriction does pay off. I think it is too restrictive and makes the code much more uglier. Most runtimes won't work anyway with that kind of old computers so it does not make sense to continue like that.

In the first point you are right, I have avoided gotos for no real reason, just a bad practice, and error handling is basically nonexistent.

This happens in the whole codebase. If you start refactoring the Python Loader, it can be a great advance. Later on we can start moving to the Core. Respect to the commit you listed, yes, that's the proper way of doing it, feel free to refactor.

The only thing I request to you is to validate that all tests work and pass AddressSanitizer and Valgrind to verify you do not create new memory leaks, specially in fail-path tests. We just have added new PR and Issue templates, and also you can check here how to enable Asan and Valgrind for testing: https://github.com/metacall/core/blob/develop/docs/README.md#63-debugging

@jfblomgren
Copy link
Contributor Author

Great! I'll get started on the refactor.

@jfblomgren jfblomgren mentioned this issue Mar 24, 2021
9 tasks
@viferga
Copy link
Member

viferga commented Mar 25, 2021

@Encrylize Are you going to continue with this or can I close the issue?

@jfblomgren
Copy link
Contributor Author

@viferga Let's just close it for now. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants