Incorrect analyzer feedback: finalSalary should not be forced to use a ternary when Math.min is clearer
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Individua la regola dell’Analyzer che emette il feedback citato sul ternario e riproducilo con l’esercizio descritto nell’issue. Determina come la regola valuta l’uso dei ternari in salaryMultiplier, bonusMultiplier e finalSalary; il lavoro è completato quando non raccomanda più un ternario meno chiaro quando il cap Math.min esistente è appropriato, con copertura di regressione per il feedback.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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:
- detect that ternaries are used elsewhere and suppress this suggestion, or
- 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.
- Lingua principale
- Java
- Stelle
- 13
- Fork
- 27
- Merge medio
- 1g 11h
- PR unite (30g)
- 9
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di exercism/java-analyzer
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
exercism/java-analyzer#271 · 5 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
exercism/java-analyzer#227 · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
exercism/java-analyzer#218 · 3 commenti ·
-
there is no need to use substring in the result method in this code, kindly reviewForse già presa @manumafe98 l’ha presa 868 giorni fa. Apertax:size/small
exercism/java-analyzer#176 · 1 commento · 1 assegnatario ·
-
gotta-snatch-em-all: implement analyzerForse di nuovo libera @manupereiraduarte l’ha presa 134 giorni fa e non c’è nessuna pull request aperta. Apertax:action/create x:knowledge/intermediate x:module/analyzer x:size/medium x:type/coding x:type/content
exercism/java-analyzer#170 · 13 commenti · 1 assegnatario ·
Tutte le issue di exercism/java-analyzer
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
NationalSecurityAgency/ghidra#9748 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
spring-mcp-tools
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
explyt/spring-plugin#591 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
jenkinsci/build-monitor-plugin#1367 ·
I maintainer di solito rispondono entro 1 giorno
-
waiting-for-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
spring-cloud/spring-cloud-openfeign#1443 ·
I maintainer di solito rispondono entro 1 giorno