-
Notifications
You must be signed in to change notification settings - Fork 611
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
Added withDeadline modifier #7299
base: main
Are you sure you want to change the base?
Conversation
This PR modifies commands. Please open a corresponding PR in Python Commands and include a link to this PR. |
Pretty sure it is |
It can't be done in C++ due to the opaqueness of the underlying command type. Specific return types would cause object slicing issues when used (that's why CommandPtr was introduced). Now onto Java: The return type opaqueness is intentional, to allow for encapsulation and any later implementation changes in a non-breaking way. There's little-to-no advantage to specifying exact command types, and it breaks on any changes. The added method itself doesn't add anything, imo. It doesn't use the fact that it's a parallel group. It's more verbose than the alternatives. |
I doubt that the implementation of Commands.parallel() will change in the future; at most, any overhauls to parallel groups will modify the existing classes and not new ones |
My personal take- I agree that there's significant value in distinguishing the deadline command from the other commands. However, I also agree that it's good library design to keep the return types of the factories as an opaque These two statements lead me to the idea: Add a @Starlight220 @Daniel1464 Thoughts? |
I think that probably would be a better implementation of my current idea.
|
/format |
Re I guess go for it? |
wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java
Outdated
Show resolved
Hide resolved
wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, for what it's worth- One of the wpilib devs will also need to review this.
wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp
Outdated
Show resolved
Hide resolved
/format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a test for this to CommandDecoratorTest
.
wpilibNewCommands/src/main/native/include/frc2/command/Command.h
Outdated
Show resolved
Hide resolved
/format |
wpilibNewCommands/src/main/native/include/frc2/command/Command.h
Outdated
Show resolved
Hide resolved
wpilibNewCommands/src/main/native/include/frc2/command/CommandPtr.h
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me too, for what it's worth.
Currently, a lot of teams use the Commands.parallel(), Commands.race() and Commands.deadline() static factory methods for parallel groups. However, Commands.deadline() doesn't communicate its purpose very well(it doesn't mention the word "parallel" at all, and it doesn't make clear what the deadline of the parallel group is). Even though the deadlineWith(soon to be called deadlineFor) modifier exists, it introduces inconsistency in syntax if a team uses the parallel() and race() factories(as it is an instance method).
Thus, a withDeadline() modifier is added to the ParallelCommandGroup class to allow for
Commands.parallel(a,b,c).withDeadline(d)
. This solves the issues of syntax inconsistency while expressing the intent better to code readers. In addition, the parallel factory methods now have a return type of their respective class, which allows for this syntax to exist.