Magic numbers are unexplained values that often should be replaced with a named constant.
Questions tagged [magic-numbers]
193 questions
1
vote
3 answers
SQL Server : get max/min possible date without magic numbers
I know that the SQL Server date datatype is defined to have a range of 0001-01-01 to 9999-12-31. Is there any way to obtain those values using T-SQL without the use of magic numbers (e.g. without something like declare @MaxDate date = '12/31/9999')?

Conduit
- 2,675
- 1
- 26
- 39
1
vote
0 answers
Avoiding Magic strings Reflection vs Constant
What would be a better approach to avoid the magic, based on the following 2 examples?
Known relationship
we know the Class which is meant
public string Notes
{
get { return notes; }
set { SetPropertyValue("Notes", ref…

WiiMaxx
- 5,322
- 8
- 51
- 89
1
vote
1 answer
How do I store lookup tables in magic numbers?
I have seen something interesting here, saying you can store lookup tables at magic numbers.
I have tried using brute-force to find the magic number, but all the results are incorrect.
How do I find the correct magic number for a certain lookup…
user4447514
1
vote
2 answers
Read Magic Number from .au File
I wrote a small program to get the magic number from an .au file and print it to console, but every time I try, instead of getting the intended .snd, I get .snd$ instead.
I'm not sure why this is happening, considering that I'm only reading in 4…

Delfino
- 967
- 4
- 21
- 46
1
vote
1 answer
Avoiding magic-number boosts in ElasticSearch queries?
I'd like documents resulting from an ElasticSearch query that have a field (call it 'fubar') set to certain values that are determined at query-time to always come before documents that don't have fubar set to one of those values.
As an example, at…

Dan Sandberg
- 549
- 1
- 4
- 15
1
vote
3 answers
What is the purpose of this magic number?
The following snippet of code is taken from a Pseudo-random number generator (written in ActionScript 3):
public function random():Number {
_currentSeed = (_currentSeed * 16807) % 2147483647);
return (_currentSeed/0x7FFFFFFF) +…

IQAndreas
- 8,060
- 8
- 39
- 74
1
vote
5 answers
Are Constants Really Appropriate Here, Or Is There Another Approach? - C++
I'm a programming student in my 2nd OOP course, which is taught in C++. I know that it is generally bad practice to use magic numbers in code, so here's my question:
In the next program I have to write for this class, there is over 120 numbers given…

Alex
- 64,178
- 48
- 151
- 180
1
vote
1 answer
Remove magic numbers from size
Im working on a GUI. I am getting magic numbers for setSize values. since magic numbers are bad practice, How can i get rid of the magic numbers in size? should i assign a variable to each of them?
setSize(250x400)
so that it will be like…
user2967582
1
vote
4 answers
Are 0.0 and 1.0 considered magic numbers?
I know that -1, 0, 1, and 2 are exceptions to the magic number rule. However I was wondering if the same is true for when they are floats. Do I have to initialize a final variable for them or can I just use them directly in my program.
I am using…

user2426500
- 29
- 2
- 6
1
vote
2 answers
Embedding an applet doesn't work on my website
I'm trying to code an applet and put it in my website. I remember doing this a long time ago using Borland back when 1.4 was the latest version. It of course used the applet tag (which I'm using currently) and it had no issues. But anyways, I put…

Ben
- 11
- 3
1
vote
4 answers
Looking for determine file type from the magic number
It is possible to determine the file type from the magic number of file?
If I've understood, the magic number can have different size, maybe a reference dictionary or something like a library could help me?

CheapD AKA Ju
- 713
- 2
- 7
- 21
1
vote
2 answers
Using magic strings or constants in processing punctuation?
We do a lot of lexical processing with arbitrary strings which include arbitrary punctuation. I am divided as to whether to use magic characters/strings or symbolic constants.
The examples should be read as language-independent although most are…

peter.murray.rust
- 37,407
- 44
- 153
- 217
1
vote
1 answer
Eliminate magic number in Redis
I'm creating an index with Redis using a sorted set. I want the following order for the matching results (smaller string first):
a
ar
art
artu
artur
arturo
From the Redis documentation I using a score to store the data:
The elements are considered…

Arturo Herrero
- 12,772
- 11
- 42
- 73
1
vote
3 answers
Java Main Method Magic Numbers
So im trying to get rid of two magic numbers that i have in my main method. I tried making them static fields but i just get a different checkstyle error. I'm looking for a way to make my main method check out completely with checkstyle.
These are…

user2184587
- 11
- 3
1
vote
6 answers
Can you have magic numbers in Access 2007?
How do I store numbers in an Access column and then associate some meaningful string to each value?
Because I don't want to be seeing raw numbers when I can define the meaning of each value once at for all, and have those meanings displayed in the…

Robin Rodricks
- 110,798
- 141
- 398
- 607