If you blindly follow IDE suggestions for variable names, the names will often repeat what is already known from the context – either from the name of the class or the name of the method in which variable is declared:
long evaluateExpression(BusinessExpression businessExpression, Map<String,Long> variables) { for (var expressionParser : listExpressionParsers()) { if (expressionParser.supports(businessExpression)) { var expressionEvaluator = businessExpressionParser.parse(businessExpression); expressionEvaluator.useVariables(variables); expressionEvaluator.useConstants(CONSTANTS); return expressionEvaluator.evaluate(); } } throw new RuntimeException("unsupported expression " + businessExpression); }
Drop all the indistinctive words that from variable names:
long evaluate(BusinessExpression expression, Map<String,Long> variables) { for (var parser : listParsers()) { if (parser.supports(expression)) { var evaluator = parser.parse(expression); evaluator.useVariables(variables) evaluator.useConstants(CONSTANTS); return evaluator.evaluate(); } } throw new RuntimeException("unsupported expression " + expression); }
In the above example, we know from the method signature, that it is about evaluation of business expression. So repeating words business
and expression
in parameter names or local variable names was redundant and only cluttered the code.
W. Gdela
Discuss Downvote Upvote Votes: 0