Skip to content

Crystal naming conventions #1

@notramo

Description

@notramo

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions