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

align utility function prefixes #132

Closed
cjyetman opened this issue Sep 18, 2024 · 6 comments · Fixed by #230, #232 or #233
Closed

align utility function prefixes #132

cjyetman opened this issue Sep 18, 2024 · 6 comments · Fixed by #230, #232 or #233
Assignees
Labels
upkeep maintenance, infrastructure, and similar

Comments

@cjyetman
Copy link
Member

cjyetman commented Sep 18, 2024

We have a variety of validate_*(), abort_*(), and stop_if_not_*() functions here (I take significant responsibility for that, though the misalignment was mostly created when importing the functions from pacta.multi.loanbook.analysis and pacta.multi.loanbook.plot).

Additionally, through my experience building pacta.data.validation, I came to the conclusion of using assert_*() and is_*() as prefixes for such functions, for the purpose of keeping the prefixes reasonably short while also clearly identifying which functions throw an error versus those that return TRUE or FALSE.

@jacobvjk @jdhoffa I'd like to decide which style we prefer here and implement that universally in this package.

@jdhoffa
Copy link
Member

jdhoffa commented Sep 18, 2024

I don't have strong views on this, but since we are getting pretty semantic here, here's a few thoughts:

  • I like is_*, it's clear that the result of that will be TRUE or FALSE
  • I like stop_if_not_*, it's clear that if NOT, the result of that will stop the execution of the function
  • abort_*, basically the same as stop_*, just pick one I guess. stop is probably slightly more idiomatic
  • assert_*, is a bit ambiguous. It's not immediately obvious to me what happens if the assertion is not met. I could imagine either a stop or a FALSE might be reasonable outcomes.
  • validate_* seems totally ambiguous to me

@cjyetman
Copy link
Member Author

cjyetman commented Sep 18, 2024

assert is commonly used in other languages like Python for this behavior (if TRUE do nothing, otherwise error), and e.g. is used in {checkmate} (just FYI that's where that comes from)

I think the logic is that is_*() evokes a question with an answer, TRUE or FALSE, whereas assert_*() evokes an action, error if not or continue without error.

@jdhoffa
Copy link
Member

jdhoffa commented Sep 18, 2024

@cjyetman totally understood! It's used a lot in Rust too with the same functionality.

I was just putting on my incredibly nit-picky hat, and commenting on the fact that based exclusively on the name it's not immediately/ totally unambiguous, but of course with additional context/ experience it is more clear 😊

but anyway, I leave it to you and @jacobvjk to decide, I'm more than happy with any of the approaches

@cjyetman
Copy link
Member Author

cjyetman commented Nov 7, 2024

@jdhoffa @jacobvjk I believe this is still relevant, but it would be a nice-to-have to ease development and understanding of the code, not a critical task.

@jdhoffa
Copy link
Member

jdhoffa commented Nov 7, 2024

Seems related to #54

@cjyetman
Copy link
Member Author

cjyetman commented Nov 7, 2024

yes, conceptually related, but targeted at different sets of thing that could be aligned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment