3 ms·
In that code snippet, “answer” would really be the right name for the variable (because the method is called ComputeAnswer). Redundantly restating immediately a
by jmull 5y ago
In that code snippet, “answer” would really be the right name for the variable (because the method is called ComputeAnswer). Redundantly restating immediately apparent context isn’t a good style.
- moron4hire 5y agoI cannot disagree with you any harder. Redundantly naming variables is good style, as it gives you more room to rename functions slightly, split functions, introduce new variables and inject new operations in the middle. And frequently, the function name has nothing to do with the semantics of the returned value. "result := sort(someOtherResult)" doesn't tell me anything. "sortedItems := sort(items)" tells me a lot. result1 := getUserInput() result2 := validate(result1) result3 := parse(result2) result4 := getRouting(result3) or addressInsecureStr := getUserInput() addressStr := validate(ipAddressInsecureStr) address := parse(ipAddressStr) pathAddresses := getRouting(ipAddress) I know which I would choose
- jmull 5y agoYou switched the context from a unit test to something different. Here, there I'd use something like this (changing some method names, too, since we're fixing names): userInput := getUserInput() validatedInput := validateUserInput() ipAddress := parseIpAddress(validatedInput) pathAddresses := getIpPathRouteTo(ipAddress) I'm making some assumptions about what these methods do and return. E.g., if validate/validateUserInput does something more specific than general user input validation then it should have a more specific name and the variable its result is assigned to would too.