Questions tagged [constants]

Constants in programming are definitions whose value is fixed throughout a program's execution. Literals in most languages are constants, for example. In referentially transparent programming styles, all definitions are constant.

5
votes
2answers
93 views

add_const or remove_const based on another type

Here is a type trait which - I feel - could fit in std next to std::add_const and ...
1
vote
1answer
39 views

Class with predefined ellipsoids

I am creating an Ellipsoid class and I then want to instantiate a few constants (pre-defined Ellipsoids). Below is my current implementation. I am not really ...
1
vote
3answers
60 views

Finding the name of a given constant using reflection

The code below comes from the Arm_const class of my Android disassembler project: ...
5
votes
4answers
1k views

Python Constant Class, Different Enum Implementation

So I saw a need for and came up with a class implementation to group constants, which I'm calling a Constant Class. I wondered if there existed other similar implementations or if there is a flaw in ...
7
votes
2answers
780 views

Storing the API endpoints in a Pythonic way

I am currently trying to create an API-wrapper. For that, I connect to the endpoint (for example https://host.example.com/api/accounts/open) with the request module. Since there are a bunch of ...
2
votes
1answer
3k views

Static class for constants with reference to java resources

I want to store the colors I use in the colors.xml file. In addition to using them in an xml-layout, I also want to use these colors in my Java code, when drawing ...
2
votes
2answers
89 views

Elegant way to “construct” kind-of enum values in go

I'm quite new to Go and would like to improve my code. I have a representation for access levels in Go like this: ...
3
votes
1answer
75 views

Mapping Index to a String in C

Please excuse my potentially noob-ish question. I haven't touched strings in C (or C in general) in a while, and I seem to recall there being different ways you can return a C string from a function (...
-5
votes
2answers
157 views

Using templates for constant and volatile [closed]

First some motivation: I can never remember where the const or volatile specifiers goes in a declaration. For example: ...
-2
votes
1answer
98 views

Code duplication vs wordiness

In my program I read values from a configuration array. First I just used magic constants like this: ...
0
votes
1answer
2k views

Filling a matrix with values

I would like to hear your recommendations on when to use JavaScript's const over let, especially when applied to mutable objects ...
1
vote
1answer
76 views

Improving Design for structured Keys

On several occasions I had to use a fixed set of keys (constants in the sense of static final String) with some additional logic (grouping in different keySets). After some more or less lefthanded ...
-2
votes
2answers
347 views

Using C preprocessor macro instead of private static const [closed]

Recently I have been using more macros in my C++ code. I wrote a class with a private static const float because it is useful to prevent making mistakes. Then I ...
4
votes
2answers
88 views

Node.JS module to retrieve configuration from environment variables

I don't like the idea of sprinkling process.env all over the place and wanted to abstract it out a bit. I'm new to Node and know there must be a better way to do a few things. Not repeat the name 4 ...
3
votes
1answer
30 views

Translate strings from an XML attribute into corresponding constants in my module

I have a non-trivial list comprehension in Python. My goal is to take a whitespace-delimited list of strings from an XML attribute — which may not exist — and look up the corresponding constant in my ...
4
votes
2answers
17k views

Best practice for Constant Class in Java

I create a constant class by looking at some of the best practices described here in stackoverflow. Many of those have a single Constant class with variables. Some of the answers suggested creating ...
2
votes
1answer
72 views

Using a final class for string constants

I want to use something like Setting.RES_WIDTH in my code without the need for a getter function (i.e.: custom getter, enum's ...
4
votes
1answer
51 views

Initializing static, machine-specific data in C using a compile-time generated header

I'm using some rather old C code (circa 1996, written in K&R style) to do robust geometric computations, available here, for a library I'm trying to write. In order to work properly, this code has ...
8
votes
1answer
793 views

Const by default

Being a C++ developer, but also having been influenced by functional languages, I strongly believe that const should be the default for the vast majority of all ...
1
vote
0answers
70 views

Web Scraping class schedules

I just want some advice regarding code style and best practices. Also I want to know if I'm using constant declaration and closures properly. This code is used to get the data from here http://...
2
votes
1answer
83 views

Finding expiring/expired documents

This code is to find expiring/expired documents. It was included in one of the models, say Document. Is this good approach of using constant variables which holds ...
6
votes
4answers
987 views

Sonar remarks make SQL unreadable?

I ran the following code through Sonar, a static analysis tool. Original file: ...
19
votes
2answers
2k views

Enum, constants, or other to represent chess pieces

I'm learning C# and I decided to write a chess program to help me practice the concepts I'm learning in my book. I started the Board class tonight, which is going to handle 1) the board state and 2) ...
7
votes
1answer
946 views

XML tags constants vs hardcoded values

I have to create an XML body for a web service call. I want to use: ...
5
votes
1answer
99 views

My iPod is slower than my iPad

Many of the variables in my 2D mining game were declared as constants like so: DWConstants.h ...
4
votes
1answer
187 views

Model class for networking that uses notifications

I just finished a model class that represents an Instagram Networking client for my iOS app. I am specifically looking for a review of my use of static constants. These are strings that represent ...
11
votes
1answer
4k views

Storing global styles and utilizing them throughout view controllers

Assuming an app has many display styles, fonts, colors, etc., and that we never want to hardcode values, I've created an AppVariables object that houses properties ...
4
votes
4answers
19k views

Defining constants in JavaScript

I am aware JavaScript does not have the concept of constant variables, which in traditional languages, you would usually define as being static/class related since there's no point in having them ...
7
votes
2answers
901 views

Dynamically generating Strings (or other variables)

I've got a Python script which is meant to launch several other shell scripts with the appropriate setup and parameters. I construct the file paths from other variables so that it's easier to change ...
4
votes
2answers
96 views

Accessing a certain I/O controller using memory-mapped I/O [closed]

I have a program that accesses a certain I/O controller using memory-mapped I/O. I currently store the base address of this controller in a const variable. This ...
3
votes
2answers
312 views

Where should I place the constant?

The following bit of code requires a string.maketrans table that is only used inside a single function. I have written three versions of the program that place the ...
100
votes
9answers
26k views

'100' is a magic number

Magic numbers are bad... I totally agree. But there's one magic number I find hard to fix: '100' is a magic number. Consider this code: ...
9
votes
2answers
16k views

Proper use of class constants

This question specifically relates to the use of the class constants ABOVE and BELOW in the sample code below. I have a few different classes that look like this: ...
5
votes
1answer
633 views

Refactoring Java class with lots of constants

...
2
votes
4answers
323 views

Enum or Constant

I'm writing a SDK for a NFC device in .NET so I don't have to import the SDK from C++. Right now I'm working on the ISO14443-3 part which is just simple Halt, Request, and Anticollision commands. The ...
3
votes
2answers
120 views

Managing fault types

I have a FaultType enum with more than 100 members: ...
1
vote
1answer
742 views

Boolean constant for assert in if..else block

I have the following condition statement in Groovy: ...
3
votes
1answer
6k views

Class to simulate enums in PHP

I have been reading this thread on Stack Overflow about simulating enums in PHP and it seems that the most common approach is to use class constants. My problem with that is I can't use it for type ...
6
votes
1answer
251 views

Looking for a better way to define and use constants

In a custom Ant task, I have the following constants: ...