GoLand 2020.3 Help

Extract constant

The Extract Constant refactoring makes your source code easier to read and maintain. It also helps you avoid using hardcoded constants without any explanations about their values or purpose.

Extract a constant

  1. In the editor, select an expression or declaration of a variable you want to replace with a constant.

  2. Press Ctrl+Alt+C to introduce a constant or select Refactor | Extract | Constant.

  3. Select an expression you want to extract as constant and press Enter. Select the number of occurrences you want to replace and a name you want to use.

Example of the extract a constant refactoring

Code snippet at GitHub

Last modified: 12 August 2020