Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [constants]

The tag has no usage guidance.

2
votes
5answers
257 views

I feel like these constants should be in a different class?

I have a static class called RenderingUtilities that houses several useful methods and constants. Some of these constants are related to the Earth as an object such as the Earth's radius. I believe ...
3
votes
1answer
93 views

Should I replace a constant with static methods, if that constant usually 'cooperate' with a specific operator?

For example, to convert between g and kg, I have a constant 1000: public static final float G_TO_KG=1000; . . . this.result = someResult*1000; I found G_TO_KG always bind to operator '*'. So my ...
2
votes
3answers
158 views

When defining constants, which is more important? Easier to find? Or narrower scope?

For example, consider I have constants VOL_MIN and VOL_MAX, which is used inside 1 function only: public void setVolume(int val){ final int VOL_MIN = 1; final int VOL_MAX = 10; val=Math....
0
votes
1answer
98 views

Should I make constant for values of three choices (trivalent/ternary)?

For two choices there is boolean. In my case, I have positive, negative, and neutral which are three choices and cannot be represented by boolean. I've see there's method Math.signum(x) in Java which ...
0
votes
1answer
251 views

Is it a good practice to store constants in configuration files [duplicate]

In my project I have some constants where I reference almost everywhere: public sealed class Constants{ public static readonly int MAX_QUAL { get; } = 1080; public static readonly bool CC { ...
3
votes
1answer
113 views

Should I avoid creating a variable with shorter name for a constant?

suppose I have code like this someFunction:function(userId){ var url=SomeClass.SomeNetworkConnector.SOME_URL; if(url !== undefined && userId !== undefined){ this.openURL(url+"?userid="...
28
votes
7answers
8k views

May a value of a constant be changed over time?

During development phase, there are certain variables which need to be the fixed in the same run, but may need be modified over time. For example a boolean to signal debug mode, so we do things in the ...
3
votes
1answer
219 views

Should I rename variables that are already constants in my own library?

I'm writing a high level wrapper around the Python socket.socket object. Specifically, I want to do this for IPv4 TCP sockets (though it would be useful to be able to expand the library later with ...
6
votes
1answer
6k views

Is it bad practice to define constants using class static methods?

Instead of using #define or const, I usually define constants using class static methods as follows: //AppConstants.h #include <string> class AppConstants{ public: static int getMax(); ...
4
votes
4answers
386 views

Should I use one class for one constant?

Originally, in most languages, I would like to put constants into a class like that: public class AppConstants{ public static final double HEIGHT_MAX=20.0; public static final int COUNT_MAX=...