Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1014671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:17:05+00:00 2026-05-16T10:17:05+00:00

When people talk about the use of magic numbers in computer programming, what do

  • 0

When people talk about the use of “magic numbers” in computer programming, what do they mean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:17:06+00:00Added an answer on May 16, 2026 at 10:17 am

    Magic numbers are any number in your code that isn’t immediately obvious to someone with very little knowledge.

    For example, the following piece of code:

    sz = sz + 729;
    

    has a magic number in it and would be far better written as:

    sz = sz + CAPACITY_INCREMENT;
    

    Some extreme views state that you should never have any numbers in your code except -1, 0 and 1 but I prefer a somewhat less dogmatic view since I would instantly recognise 24, 1440, 86400, 3.1415, 2.71828 and 1.414 – it all depends on your knowledge.

    However, even though I know there are 1440 minutes in a day, I would probably still use a MINS_PER_DAY identifier since it makes searching for them that much easier. Whose to say that the capacity increment mentioned above wouldn’t also be 1440 and you end up changing the wrong value? This is especially true for the low numbers: the chance of dual use of 37197 is relatively low, the chance of using 5 for multiple things is pretty high.

    Use of an identifier means that you wouldn’t have to go through all your 700 source files and change 729 to 730 when the capacity increment changed. You could just change the one line:

    #define CAPACITY_INCREMENT 729
    

    to:

    #define CAPACITY_INCREMENT 730
    

    and recompile the lot.


    Contrast this with magic constants which are the result of naive people thinking that just because they remove the actual numbers from their code, they can change:

    x = x + 4;
    

    to:

    #define FOUR 4
    x = x + FOUR;
    

    That adds absolutely zero extra information to your code and is a total waste of time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Most people talk about progressive enhancement right now as serving browsers with javascript (enhanced
So I've heard people talk about things that hate to resize, and that radio
People always talk about how objects created without the new keyword are destroyed when
I often here people talk about Big O which measures algorithms against each other
I read all over the place people talk about compressing objects on a bit
I've heard a lot of people talk about how some new version of a
is f# records is the same as .net struct? I saw people talk about
a lot of the people who talk about Record an Audio from Web Page
I have been through various papers/articles/blogs and what not about Monads. People talk about
In other MVP-related questions on SO, people talk about the Presenter keeping the state

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.