-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add #has_any_args?
method for ASTNode
s
#16115
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
base: master
Are you sure you want to change the base?
Add #has_any_args?
method for ASTNode
s
#16115
Conversation
I like the idea of code simplification 💯 One thing that stood out for me was the negated naming scheme. I'd expect such a method to be called |
I think I chose the name because the existing uses are testing for absence. I'm wondering though about the name, because Maybe |
I also think |
A more technical term would be |
Oh, I learnt a new word! |
"Nullary" is a semantic property, but a "nullary" |
#has_no_args?
method for ASTNode
s#has_any_args?
method for ASTNode
s
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
Several
ASTNode
implementations have a concept of arguments:Call
,Def
,FunDef
,Macro
,ProcPointer
,Block
,Annotation
.Arguments are often separated into different properties, such as
args
,named_args
andblock_args
onCall
. In order to know whether the node has any args, we need to check if either of them is present. This is a common pattern throughout the compiler code base. The tricky thing is to remember for each node type, which properties need to be checked. So in some cases we're not checking for all conditions. Whether this is a relevant omission, depends on the exact circumstance.This patch introduces the
#has_any_args?
method on all node types with arguments. Even those where it's really just anargs
property (Block
andProcPointer
). This makes it very convenient to check for the absence of any arguments without having to worry about the node type's data layout and potentially forgetting something.