-
-
Notifications
You must be signed in to change notification settings - Fork 21
Implement analyzer
for cars-assemble
concept exercise
#277
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: main
Are you sure you want to change the base?
Conversation
+cc the @exercism/java maintainers |
output.addComment(new ReuseCode(WORKING_ITEMS_PER_MINUTE_METHOD, PRODUCTION_RATE_PER_HOUR_METHOD)); | ||
} | ||
|
||
if(useMagicNumber(n)){ |
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.
This method seems to check if the number 221
appears anywhere, but the comment in the design.md seems to suggest that it should check if the number appears more than once in the code:
If the solution is repeatedly hard-coding the value 221, inform the student that they could store this value in a field to make the code easier to maintain.
An alternate solution may to set it to a final variable (within a method), especially if it isn't used anywhere else. If the value appears only once, I think that could be fine.
BlockStmt stmt = n.getBody().get(); | ||
List<Statement> IfStmts = stmt.getStatements().stream().filter(Statement::isIfStmt).toList(); | ||
for(Statement s : IfStmts){ | ||
return ((IfStmt) s).hasElseBlock(); |
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.
Something here seems strange here. You get a list of IfStmts
, start iterating, but return true
/ false
depending on whether the first if
statement in the list is has an else block? What about the other if
statements?
Even if you really did mean to check just the first if
statement, I think the not-using-helper-method
test would fail if productionRatePerHour
used multiple returns like this community solution:
public class CarsAssemble {
public double productionRatePerHour(double speed) {
double baseProductionRate = 221;
if (speed >= 1 && speed <= 4) {
return speed * baseProductionRate;
} else if (speed >= 5 && speed <= 8) {
return speed * baseProductionRate * 0.9;
} else if (speed == 9) {
return speed * baseProductionRate * 0.8;
}
return speed * baseProductionRate * 0.77;
}
public int workingItemsPerMinute(int speed) {
return (int) productionRatePerHour(speed)/60;
}
}
public void visit(MethodDeclaration n, OutputCollector output) { | ||
|
||
if(n.getNameAsString().equals(PRODUCTION_RATE_PER_HOUR_METHOD) && !hasHelperMethod(n)){ | ||
output.addComment(new MethodTooLong(PRODUCTION_RATE_PER_HOUR_METHOD)); |
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.
I'm concerned that reusing the MethodTooLong
could be confusing for the students. There's nothing in the comment that hints students should move the if
statement. I think its really hard for the students to tell that they should move it a helper method because it only tells them to make the method smaller, but we actually them to specifically move the if
statement into a separate method. The actionable level may be too high for this comment too.
Closes #103
In the design.md of the exercise there is such rule:
informative
: If the solution hasif/else-if
statements in theproductionRatePerHour
method, inform the student that creating a helper method to calculate the succes rate might make their code easier to understand.However, I reused an existing comment: method_too_long, which I think it fits with the request. The only difference is that such comment is of type
ACTIONABLE
, meanwhile in thedesign.md
file it is requested to beINFORMATIVE
.ToDo: