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

Crystal naming conventions #1

Open
notramo opened this issue May 6, 2023 · 1 comment
Open

Crystal naming conventions #1

notramo opened this issue May 6, 2023 · 1 comment

Comments

@notramo
Copy link

notramo commented May 6, 2023

In Crystal, it's a common convention that method names ending in a ? do not raise, but return nil if the task can not be completed. Other use case for ? is methods that return Bool. E.g. Hash#empty? returns a Bool, indicating whether the Hash has any members. Other use case is String#to_i32 raises if the string don't contain a valid number, but String#to_i32? returns nil if the string is not a valid number. A method with a name ending in ? can confuse programmers if it raises.
E.g. CommentPolicy#show? follows the convention as it returns Bool, and doesn't raise, but CommentPolicy#show_not_found? breaks from the convention as it raises.
Please provide an alias without ? for every method that raises (with the ? version retained for backwards compatibility).

@confact
Copy link
Owner

confact commented May 6, 2023

Thanks for the issue.

The methods are not doing their full potential and are not entirely done as they would do more "macro" and magic, at least I planned to. It works fine now, but as it is now, it is not following the convention as you say.

Feel free to do a PR to change them if you want.

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