exercism / exercism/java-analyzer
Incorrect analyzer feedback: finalSalary should not be forced to use a ternary when Math.min is clearer
- Ngôn ngữ chính
- Java
- Star
- 13
- Fork
- 27
- Merge trung bình
- 4 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 7
Mô tả
The Java analyzer is giving this automated feedback:
“As the goal of this exercise is to learn about ternary operators consider using them in finalSalary to solve this exercise.”
However, this feedback appears to be incorrect.
My implementation does use ternary operators where appropriate (e.g., in salaryMultiplier and bonusMultiplier), and the logic inside finalSalary does not naturally lend itself to a ternary expression. Instead, the method concludes by applying a salary cap using:
`return Math.min(salary, MAX_SALARY);`
This is the most idiomatic and intention-revealing way in Java to express “cap a value at a maximum.”
Forcing a ternary here would reduce clarity, for example:
`return salary > MAX_SALARY ? MAX_SALARY : salary;`
Both statements are functionally equivalent, but the Math.min version:
* more clearly communicates the intent,
* avoids nesting logic inside a ternary,
* reflects common Java practice,
* is simpler to read and maintain,
* aligns with standard clean-code guidelines.
The goal of the exercise is to learn ternary operators, not to artificially apply them in places where they decrease readability or duplicate existing standard library functionality.
Since the solution already uses ternaries appropriately and idiomatically in earlier methods, the analyzer's suggestion is misleading and encourages worse code, not better code. The feedback should either:
1. detect that ternaries are used elsewhere and suppress this suggestion, or
2. avoid prescribing the use of a ternary in situations where another construct is objectively clearer.
In short, the feedback should guide learners toward idiomatic, expressive Java—not toward unnecessary or forced use of syntax.
If needed, I can provide a minimal code example illustrating the issue.
Hướng dẫn đóng góp
Hướng nghiên cứu
Xác định rule của Analyzer phát ra feedback về ternary được trích dẫn và tái hiện nó bằng bài tập được mô tả trong issue. Xác định cách rule đánh giá việc sử dụng ternary trong salaryMultiplier, bonusMultiplier và finalSalary; hoàn thành nghĩa là rule không còn đề xuất một ternary kém rõ ràng hơn khi giới hạn Math.min hiện có là phù hợp, đồng thời có kiểm thử hồi quy cho feedback.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java
- Lĩnh vực
- tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 35/100