3 ms·
I wonder - why isn't this talked about more? We have had tens of thousands of software companies, each with probably a dozen people focused on hyperoptimizing e
by jackphilson 2y ago
I wonder - why isn't this talked about more? We have had tens of thousands of software companies, each with probably a dozen people focused on hyperoptimizing everything. Why hasn't this point been talked about more on the internet to the point where it's obvious today? And it's not specifically about this, it's more in general. Do people just learn this on their own, and not say anything? Or is the discussion related to this topic buried in some old forum somewhere?
- throwaway984393 2y ago[dead]
- mrkeen 2y agoIt's talked about, just in the opposite direction. I've left hardcoded strings (think Kafka event type names) in my source for this very reason, but after a round of code review they get squirreled away as constants in separate files because string repetition is bad or something.
- jimmaswell 2y agoWithout constants, it's too easy to let a typo sneak in or have inconvenience later replacing one "event" but not replacing an unrelated "event". I'll only do it if the string is used two times at most, but usually I'll make a constant the first time and it doesn't feel like any loss.
- mrkeen 2y agoYes, this is exactly what I was fighting against. If I have three classes that interact with "MyTable", then I can grep for places that interact with "MyTable" and I get back three classes. After refactoring, the class which now knows about "MyTable" is Constants.java, which has no business knowing about "MyTable". Grepping it now turns up a false-positive and finds 0 of the actual usage sites (3 false-negatives).
- GeneralMayhem 2y agoSure, but now you have the string constant as a symbol, which you can either grep for (in which case you're delayed by one search, not the end of the world if you were going to unwind callstacks anyway) or, if you have an LSP, you can jump directly from it to users...
- NotMichaelBay 2y agoIt's not exactly a false positive. It's just a level of indirection, 1 more search by the constant name to find usages. What you sacrifice there you gain by having the compiler help find typos and the IDE help with autocompletion.
- philipwhiuk 2y ago`Constants.java` is a massive code-smell (which I have in many projects, but it's still a smell). The file name is awful. At worst it should be 'DbConstants' but probably they should be defined elsewhere.