4 ms·
I mean, this one is solvable by not using magic constants. Pretty easy to avoid. Can also lint it.
by bpicolo 10y ago
I mean, this one is solvable by not using magic constants. Pretty easy to avoid. Can also lint it.
- look_lookatme 10y agoHow often do people write production software that doesn't have string literals?
- gakada 10y agoI don't get what you're saying. How is it possible to write code without string literals? subprocess.check_call([ "/usr/bin/env", "echo" "hello world" ])
- nitely 10y agoI think she meant to not pass the strings but assign them to constants and then pass those.
- bpicolo 10y agoYep! But, like I mentioned, linter can catch this too.
- ves 10y agohe probably meant not using string literals / ints outside of top-level declarations, so you would instead assign all these parameters to "constants" at top level and then use those constants in function calls, hence avoiding this error.
- js2 10y agoUnless I'm using a string more than once or its meaning is unclear, I always use the literal. In most cases, I find it more legible than having to go look up a constant's definition. Then yes, I rely on the linter and testing.