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 error handling from LBYL to EAFP #240

Closed
ljvmiranda921 opened this issue Sep 9, 2018 · 1 comment
Closed

Refactor error handling from LBYL to EAFP #240

ljvmiranda921 opened this issue Sep 9, 2018 · 1 comment
Assignees
Labels
refactor Better code quality, idiomatic Python v.1.1.0 In pipeline for next version

Comments

@ljvmiranda921
Copy link
Owner

Right now, most of our optimizers use the assertions() method to catch invalid inputs. This method is implemented in a Look Before You Leap (LBYL) fashion. However, idiomatic Python is often written in an Easy to Ask Forgiveness than Permission (EAFP) design, so it's better to catch errors using that.

This also removes the need to be very strict with the types passed in bounds or velocity_clamp. We usually require a tuple of lists, but in reality, an iterable should suffice, please check those conditions when dealing with this issue.

My idea is to delegate error handling in the backend, rather than having an assertions() method for each optimizer. Perhaps, it might even be better to have an assertionsmodule and do all checks there. Hopefully, this would make our implementation much cleaner.

@ljvmiranda921 ljvmiranda921 added v.1.1.0 In pipeline for next version refactor Better code quality, idiomatic Python labels Sep 9, 2018
@ljvmiranda921 ljvmiranda921 added this to the Refactor Sprint 2018 milestone Sep 9, 2018
@ljvmiranda921 ljvmiranda921 self-assigned this Sep 9, 2018
This was referenced Sep 10, 2018
@whzup
Copy link
Collaborator

whzup commented Sep 14, 2018

The Searches also use this type of asserting. Maybe you want to refactor them as well.

ljvmiranda921 added a commit that referenced this issue Oct 1, 2018
This commit adds test abstractions to PySwarms
Resolves #240, #241

Signed-off-by: Lester James V. Miranda <[email protected]>
ljvmiranda921 added a commit that referenced this issue Oct 1, 2018
This commit adds test abstractions to PySwarms
Resolves #240, #241

Signed-off-by: Lester James V. Miranda <[email protected]>
ljvmiranda921 added a commit that referenced this issue Oct 1, 2018
This commit adds test abstractions to PySwarms
Resolves #240, #241

Signed-off-by: Lester James V. Miranda <[email protected]>
ljvmiranda921 added a commit that referenced this issue Jan 29, 2019
This commit adds test abstractions to PySwarms
Resolves #240, #241

Signed-off-by: Lester James V. Miranda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Better code quality, idiomatic Python v.1.1.0 In pipeline for next version
Projects
None yet
Development

No branches or pull requests

2 participants