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

  • Home
  • SEARCH
  • 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 3400490
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:53:57+00:00 2026-05-18T04:53:57+00:00

I have a piece of code that parses some obscure text file. This text

  • 0

I have a piece of code that parses some obscure text file.
This text file can contain various keywords. At some point, there is some lengthy part that reads like this:

void loadKeywords() {
    tmpString = getValueForKeyword("width");
    if (tmpString != NULL) {
        /* do something for several lines */
    }

    tmpString = getValueForKeyword("height");
    if (tmpString != NULL) {
        /* do something for several lines */
    }

    /* and so on a few dozen times */
}

These strings "height" and "width" are only ever used in this very piece of code. Still, I am wondering if it would be better to use defined string constants like

#define KEYWORD_WIDTH ("width")

instead of those literals in the code above.

What would you do?

  • 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-18T04:53:58+00:00Added an answer on May 18, 2026 at 4:53 am

    Start without extracting constants. Then later on, your editor can probably do this for you if you need it for some reason later on.

    Though if you think it will improve the readability for your code, then you can use constants. Do this if you can add more semantic meaning by doing so:

    BROWSER_WIDTH = "width"
    CONNECTION_POOL_MAX_SIZE = "max_size"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone show me a piece of java code that parses this date: 2009-08-05
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have this piece of code that works fine in subsonic 2.2, I migrated
I have a piece of code that look similar to this: <xsl:choose> <xsl:when test=some_test>
If have a piece of code that gets some data from a sql database
I have this piece of code that is giving me trouble. I know all
I have a piece of code that the ARC converter turned into this... //
I have this piece of code that is supposed to insert data in a
I have a piece of code working in knockout.js like this: <div> ... some
I have a piece of code that load a very big image in memory.

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.