Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. Commented Sep 16, 2021 at 15:38
  • 3
    I think it’s quite clear. Google says: Do whatever you prefer. Commented Sep 18, 2021 at 16:50
  • Does anyone know the reason, why Google neither encourages nor discourages? Why not to say: "mark local variables as const whenever you can"? Commented Jan 27, 2023 at 8:47
  • There is a cost/benefit tradeoff to adding const. The cost is that it adds more characters to the code. Google essentially abstained from making a judgment on this tradeoff. Commented Jan 27, 2023 at 21:14
  • I declare and set a variable in line 100, and I want to make sure it’s the same value in line 300. So I declare it as const. A tiny bit of noise but I don’t have to check 200 lines of code that might change it. But if I only use the variable in line 101 (very next line) I add noise with very little benefit. That’s why you sometimes use “const” and sometimes you don’t. Commented Nov 10 at 19:53