allwpilib icon indicating copy to clipboard operation
allwpilib copied to clipboard

[commands] Update requirements consistently

Open spacey-sooty opened this issue 1 year ago • 12 comments

Resolves #6291

spacey-sooty avatar Jan 24 '24 05:01 spacey-sooty

This doesn't update everywhere because in many places for example ParralelRaceGroup the class uses getRequirements() which returns a Set<Subsystem> which cannot be passed into addRequirements directly. We could loop over them but I'm not sure if that's something we want to do

spacey-sooty avatar Jan 24 '24 05:01 spacey-sooty

Is it feasible to add an addRequirements(Collection) (or maybe take a Set) overload for those cases?

Starlight220 avatar Jan 24 '24 10:01 Starlight220

Is it feasible to add an addRequirements(Collection) (or maybe take a Set) overload for those cases?

I would say probably as it's already a for loop iterating through items so it'd just be the same pretty much

spacey-sooty avatar Jan 24 '24 14:01 spacey-sooty

Would it be reasonable to change Command.m_requirements to private instead of protected after this? (Potentially in a separate PR)

KangarooKoala avatar Jan 24 '24 17:01 KangarooKoala

If we add an overload this seems like a reasonable change. It'd be a long term fix for the inconsistency as well so might still be fine in this pr?

spacey-sooty avatar Jan 25 '24 00:01 spacey-sooty

/format

spacey-sooty avatar May 19 '24 15:05 spacey-sooty

PMD in the Java format CI is actually complaining that m_requirements could be made final. Was there a particular reason to make it non-final?

KangarooKoala avatar May 19 '24 15:05 KangarooKoala

PMD in the Java format CI is actually complaining that m_requirements could be made final. Was there a particular reason to make it non-final?

There is no guarantee if addRequirements being called in the constructor only. Making it final would make that guarantee which seems like a reasonable change to me, but technically a breaking change.

spacey-sooty avatar May 20 '24 01:05 spacey-sooty

PMD in the Java format CI is actually complaining that m_requirements could be made final. Was there a particular reason to make it non-final?

There is no guarantee if addRequirements being called in the constructor only. Making it final would make that guarantee which seems like a reasonable change to me, but technically a breaking change.

final just indicates that the variable can't be changed to refer to a different object, the object can still be mutated (such as adding new members).

final Set<Integer> x = new HashSet<>();
x.add(0); // This is fine
x = Set.of(1); // This is illegal

KangarooKoala avatar May 20 '24 01:05 KangarooKoala

PMD in the Java format CI is actually complaining that m_requirements could be made final. Was there a particular reason to make it non-final?

There is no guarantee if addRequirements being called in the constructor only. Making it final would make that guarantee which seems like a reasonable change to me, but technically a breaking change.

final just indicates that the variable can't be changed to refer to a different object, the object can still be mutated (such as adding new members).

final Set<Integer> x = new HashSet<>();
x.add(0); // This is fine
x = Set.of(1); // This is illegal

Ahhhh my misunderstanding its the equivalent of the const keyword in C++ that makes sense

spacey-sooty avatar May 20 '24 01:05 spacey-sooty

Flaky test :cry:

spacey-sooty avatar May 20 '24 01:05 spacey-sooty

Not required for python as it never had this problem

spacey-sooty avatar Jun 23 '24 12:06 spacey-sooty